Skip to content

Commit

Permalink
feat: make channel reopening toggleable
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexogamer committed Aug 16, 2024
1 parent 388fe32 commit 13d802a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 26 deletions.
60 changes: 34 additions & 26 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,30 @@ import {openUrl, sleep} from '@rvmob/lib/utils';

const isFoss = getBundleId().match('foss');

async function openLastChannel() {
try {
const lastServer = await AsyncStorage.getItem('lastServer');
if (lastServer) {
app.openServer(client.servers.get(lastServer));
try {
const channelData = await AsyncStorage.getItem('serverLastChannels');
let serverLastChannels = JSON.parse(channelData || '{}') || {};
let lastChannel = serverLastChannels[lastServer];
if (lastChannel) {
let fetchedLastChannel = client.channels.get(lastChannel);
if (fetchedLastChannel) {
app.openChannel(fetchedLastChannel);
}
}
} catch (channelErr) {
console.log(`[APP] Error getting last channel: ${channelErr}`);
}
}
} catch (serverErr) {
console.log(`[APP] Error getting last server: ${serverErr}`);
}
}

class MainView extends ReactComponent {
constructor(props) {
super(props);
Expand Down Expand Up @@ -157,39 +181,23 @@ class MainView extends ReactComponent {
imports.setUpNotifeeListener(client, this.setState);
}

AsyncStorage.getItem('lastServer', async (err, lastServer) => {
if (!err) {
if (lastServer) {
app.openServer(client.servers.get(lastServer));
await AsyncStorage.getItem('serverLastChannels', (cerr, data) => {
if (!cerr) {
let serverLastChannels = JSON.parse(data || '{}') || {};
let lastChannel = serverLastChannels[lastServer];
if (lastChannel) {
let fetchedLastChannel = client.channels.get(lastChannel);
if (fetchedLastChannel) {
app.openChannel(fetchedLastChannel);
}
}
} else {
console.log(`[APP] Error getting last channel: ${err}`);
}
});
}
} else {
console.log(`[APP] Error getting last server: ${err}`);
}
});
if (app.settings.get('app.reopenLastChannel')) {
await openLastChannel();
}
});

client.on('dropped', async () => {
this.setState({network: 'dropped'});
});
client.on('message', async msg => {
console.log(`[APP] Handling message ${msg._id}`);

let channelNotif = this.state.channelNotifications ? this.state.channelNotifications[msg.channel?._id] : undefined;
let serverNotif =
this.state.serverNotifications ? this.state.serverNotifications[msg.channel?.server?._id] : undefined;
let channelNotif = this.state.channelNotifications
? this.state.channelNotifications[msg.channel?._id]
: undefined;
let serverNotif = this.state.serverNotifications
? this.state.serverNotifications[msg.channel?.server?._id]
: undefined;

const isMuted =
(channelNotif && channelNotif === 'none') ||
Expand Down
1 change: 1 addition & 0 deletions i18n/strings/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
"app": {
"language": "Select your language",
"refetchOnReconnect": "Refetch messages when reconnecting",
"reopenLastChannel": "Reopen the last channel you were in when opening the app",
"notifications": {
"enabled": "Enable push notifications",
"notifyOnSelfPing": "Receive a notification when you ping yourself"
Expand Down
6 changes: 6 additions & 0 deletions src/Generic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ export const app = {
default: true,
type: 'boolean',
},
{
key: 'app.reopenLastChannel',
category: 'functionality',
default: true,
type: 'boolean',
},
{
key: 'app.notifications.enabled',
category: 'functionality',
Expand Down

0 comments on commit 13d802a

Please sign in to comment.