[MM-59489] Change logged in tracking code for new API, check for / when navigating tabs (#3105)

* [MM-59489] Change logged in tracking code for new API, check for `/` when navigating tabs

* Better naming
This commit is contained in:
Devin Binnie 2024-07-24 18:36:36 -04:00 committed by GitHub
parent 7af6601e23
commit a00cb4c814
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 26 additions and 3 deletions

View file

@ -98,6 +98,7 @@ export const NO_UPDATE_AVAILABLE = 'no-update-available';
export const BROWSER_HISTORY_PUSH = 'browser-history-push'; export const BROWSER_HISTORY_PUSH = 'browser-history-push';
export const APP_LOGGED_IN = 'app-logged-in'; export const APP_LOGGED_IN = 'app-logged-in';
export const APP_LOGGED_OUT = 'app-logged-out'; export const APP_LOGGED_OUT = 'app-logged-out';
export const TAB_LOGIN_CHANGED = 'tab-login-changed';
export const GET_AVAILABLE_SPELL_CHECKER_LANGUAGES = 'get-available-spell-checker-languages'; export const GET_AVAILABLE_SPELL_CHECKER_LANGUAGES = 'get-available-spell-checker-languages';

View file

@ -42,6 +42,7 @@ import {
GET_DESKTOP_SOURCES, GET_DESKTOP_SOURCES,
UNREADS_AND_MENTIONS, UNREADS_AND_MENTIONS,
LEGACY_OFF, LEGACY_OFF,
TAB_LOGIN_CHANGED,
} from 'common/communication'; } from 'common/communication';
import type {ExternalAPI} from 'types/externalAPI'; import type {ExternalAPI} from 'types/externalAPI';
@ -73,8 +74,8 @@ const desktopAPI: DesktopAPI = {
setSessionExpired: (isExpired) => ipcRenderer.send(SESSION_EXPIRED, isExpired), setSessionExpired: (isExpired) => ipcRenderer.send(SESSION_EXPIRED, isExpired),
onUserActivityUpdate: (listener) => createListener(USER_ACTIVITY_UPDATE, listener), onUserActivityUpdate: (listener) => createListener(USER_ACTIVITY_UPDATE, listener),
onLogin: () => ipcRenderer.send(APP_LOGGED_IN), onLogin: () => ipcRenderer.send(TAB_LOGIN_CHANGED, true),
onLogout: () => ipcRenderer.send(APP_LOGGED_OUT), onLogout: () => ipcRenderer.send(TAB_LOGIN_CHANGED, false),
// Unreads/mentions/notifications // Unreads/mentions/notifications
sendNotification: (title, body, channelId, teamId, url, silent, soundName) => sendNotification: (title, body, channelId, teamId, url, silent, soundName) =>

View file

@ -33,6 +33,7 @@ import {
REQUEST_BROWSER_HISTORY_STATUS, REQUEST_BROWSER_HISTORY_STATUS,
LEGACY_OFF, LEGACY_OFF,
UNREADS_AND_MENTIONS, UNREADS_AND_MENTIONS,
TAB_LOGIN_CHANGED,
} from 'common/communication'; } from 'common/communication';
import Config from 'common/config'; import Config from 'common/config';
import {Logger} from 'common/log'; import {Logger} from 'common/log';
@ -80,6 +81,7 @@ export class ViewManager {
ipcMain.on(BROWSER_HISTORY_PUSH, this.handleBrowserHistoryPush); ipcMain.on(BROWSER_HISTORY_PUSH, this.handleBrowserHistoryPush);
ipcMain.on(APP_LOGGED_IN, this.handleAppLoggedIn); ipcMain.on(APP_LOGGED_IN, this.handleAppLoggedIn);
ipcMain.on(APP_LOGGED_OUT, this.handleAppLoggedOut); ipcMain.on(APP_LOGGED_OUT, this.handleAppLoggedOut);
ipcMain.on(TAB_LOGIN_CHANGED, this.handleTabLoginChanged);
ipcMain.on(RELOAD_CURRENT_VIEW, this.handleReloadCurrentView); ipcMain.on(RELOAD_CURRENT_VIEW, this.handleReloadCurrentView);
ipcMain.on(UNREAD_RESULT, this.handleUnreadChanged); ipcMain.on(UNREAD_RESULT, this.handleUnreadChanged);
ipcMain.on(UNREADS_AND_MENTIONS, this.handleUnreadsAndMentionsChanged); ipcMain.on(UNREADS_AND_MENTIONS, this.handleUnreadsAndMentionsChanged);
@ -504,6 +506,25 @@ export class ViewManager {
flushCookiesStore(); flushCookiesStore();
}; };
private handleTabLoginChanged = (event: IpcMainEvent, loggedIn: boolean) => {
log.debug('handleTabLoggedIn', event.sender.id);
const view = this.getViewByWebContentsId(event.sender.id);
if (!view) {
return;
}
// This method is only called when the specific view is logged in
// so we need to call the `onLogin` for all of the views for the same server
[...this.views.values()].
filter((v) => v.view.server.id === view.view.server.id).
forEach((v) => v.onLogin(loggedIn));
if (!loggedIn) {
AppState.clear(view.id);
}
flushCookiesStore();
};
private handleBrowserHistoryPush = (e: IpcMainEvent, pathName: string) => { private handleBrowserHistoryPush = (e: IpcMainEvent, pathName: string) => {
log.debug('handleBrowserHistoryPush', e.sender.id, pathName); log.debug('handleBrowserHistoryPush', e.sender.id, pathName);
@ -522,7 +543,7 @@ export class ViewManager {
return; return;
} }
let redirectedView = this.getView(redirectedviewId) || currentView; let redirectedView = this.getView(redirectedviewId) || currentView;
if (redirectedView !== currentView && redirectedView?.view.server.id === ServerViewState.getCurrentServer().id && redirectedView?.isLoggedIn) { if (redirectedView !== currentView && redirectedView?.view.server.id === ServerViewState.getCurrentServer().id && (redirectedView?.isLoggedIn || cleanedPathName === '/')) {
log.info('redirecting to a new view', redirectedView?.id || currentView.id); log.info('redirecting to a new view', redirectedView?.id || currentView.id);
this.showById(redirectedView?.id || currentView.id); this.showById(redirectedView?.id || currentView.id);
} else { } else {