injected: Condition narrow-by-topic handler on page_params.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2020-11-30 12:55:18 -08:00
parent 047bf0ca45
commit 0632d8199f
2 changed files with 12 additions and 11 deletions

View File

@@ -48,20 +48,19 @@ interface CompatElectronBridge extends ElectronBridge {
});
}
const {page_params} = zulipWindow;
const {narrow, page_params} = zulipWindow;
if (page_params !== undefined) {
electron_bridge.send_event('zulip-loaded');
electron_bridge.send_event('zulip-loaded', {
narrow_by_topic: (id: number) => {
const narrowByTopic = narrow?.by_topic ?? narrow?.by_subject;
if (narrowByTopic !== undefined) {
narrowByTopic(id, {trigger: 'notification'});
}
}
});
}
})();
electron_bridge.on_event('narrow-by-topic', (id: number) => {
const {narrow} = zulipWindow;
const narrowByTopic = narrow?.by_topic ?? narrow?.by_subject;
if (narrowByTopic !== undefined) {
narrowByTopic(id, {trigger: 'notification'});
}
});
function attributeListener<T extends EventTarget>(type: string): PropertyDescriptor {
const symbol = Symbol('on' + type);

View File

@@ -51,7 +51,7 @@ ipcRenderer.on('show-notification-settings', () => {
}, 100);
});
electron_bridge.once('zulip-loaded', () => {
electron_bridge.once('zulip-loaded', ({narrow_by_topic}) => {
// Redirect users to network troubleshooting page
const getRestartButton = document.querySelector('.restart_get_events_button');
if (getRestartButton) {
@@ -59,6 +59,8 @@ electron_bridge.once('zulip-loaded', () => {
ipcRenderer.send('forward-message', 'reload-viewer');
});
}
electron_bridge.on('narrow-by-topic', narrow_by_topic);
});
window.addEventListener('load', (event: any): void => {