Notification exceptions
This commit is contained in:
parent
9fa40b50f7
commit
4c42091926
@ -460,10 +460,8 @@ export default class ChatBubbles {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.listenerSetter.add(rootScope, 'dialog_notify_settings', (e) => {
|
this.listenerSetter.add(rootScope, 'dialog_notify_settings', (dialog) => {
|
||||||
const peerId = e;
|
if(this.peerId === dialog.peerId) {
|
||||||
|
|
||||||
if(this.peerId === peerId) {
|
|
||||||
this.chat.input.setUnreadCount();
|
this.chat.input.setUnreadCount();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import type { AppNotificationsManager } from "../../lib/appManagers/appNotificationsManager";
|
||||||
import type { AppChatsManager } from "../../lib/appManagers/appChatsManager";
|
import type { AppChatsManager } from "../../lib/appManagers/appChatsManager";
|
||||||
import type { AppDocsManager } from "../../lib/appManagers/appDocsManager";
|
import type { AppDocsManager } from "../../lib/appManagers/appDocsManager";
|
||||||
import type { AppImManager } from "../../lib/appManagers/appImManager";
|
import type { AppImManager } from "../../lib/appManagers/appImManager";
|
||||||
@ -53,7 +54,7 @@ export default class Chat extends EventListenerBase<{
|
|||||||
|
|
||||||
public type: ChatType = 'chat';
|
public type: ChatType = 'chat';
|
||||||
|
|
||||||
constructor(public appImManager: AppImManager, public appChatsManager: AppChatsManager, public appDocsManager: AppDocsManager, public appInlineBotsManager: AppInlineBotsManager, public appMessagesManager: AppMessagesManager, public appPeersManager: AppPeersManager, public appPhotosManager: AppPhotosManager, public appProfileManager: AppProfileManager, public appStickersManager: AppStickersManager, public appUsersManager: AppUsersManager, public appWebPagesManager: AppWebPagesManager, public appPollsManager: AppPollsManager, public apiManager: ApiManagerProxy, public appDraftsManager: AppDraftsManager, public serverTimeManager: ServerTimeManager, public storage: typeof sessionStorage) {
|
constructor(public appImManager: AppImManager, public appChatsManager: AppChatsManager, public appDocsManager: AppDocsManager, public appInlineBotsManager: AppInlineBotsManager, public appMessagesManager: AppMessagesManager, public appPeersManager: AppPeersManager, public appPhotosManager: AppPhotosManager, public appProfileManager: AppProfileManager, public appStickersManager: AppStickersManager, public appUsersManager: AppUsersManager, public appWebPagesManager: AppWebPagesManager, public appPollsManager: AppPollsManager, public apiManager: ApiManagerProxy, public appDraftsManager: AppDraftsManager, public serverTimeManager: ServerTimeManager, public storage: typeof sessionStorage, public appNotificationsManager: AppNotificationsManager) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.container = document.createElement('div');
|
this.container = document.createElement('div');
|
||||||
@ -113,9 +114,9 @@ export default class Chat extends EventListenerBase<{
|
|||||||
public init(peerId: number) {
|
public init(peerId: number) {
|
||||||
this.initPeerId = peerId;
|
this.initPeerId = peerId;
|
||||||
|
|
||||||
this.topbar = new ChatTopbar(this, appSidebarRight, this.appMessagesManager, this.appPeersManager, this.appChatsManager);
|
this.topbar = new ChatTopbar(this, appSidebarRight, this.appMessagesManager, this.appPeersManager, this.appChatsManager, this.appNotificationsManager);
|
||||||
this.bubbles = new ChatBubbles(this, this.appMessagesManager, this.appStickersManager, this.appUsersManager, this.appInlineBotsManager, this.appPhotosManager, this.appDocsManager, this.appPeersManager, this.appChatsManager, this.storage);
|
this.bubbles = new ChatBubbles(this, this.appMessagesManager, this.appStickersManager, this.appUsersManager, this.appInlineBotsManager, this.appPhotosManager, this.appDocsManager, this.appPeersManager, this.appChatsManager, this.storage);
|
||||||
this.input = new ChatInput(this, this.appMessagesManager, this.appDocsManager, this.appChatsManager, this.appPeersManager, this.appWebPagesManager, this.appImManager, this.appDraftsManager, this.serverTimeManager);
|
this.input = new ChatInput(this, this.appMessagesManager, this.appDocsManager, this.appChatsManager, this.appPeersManager, this.appWebPagesManager, this.appImManager, this.appDraftsManager, this.serverTimeManager, this.appNotificationsManager);
|
||||||
this.selection = new ChatSelection(this, this.bubbles, this.input, this.appMessagesManager);
|
this.selection = new ChatSelection(this, this.bubbles, this.input, this.appMessagesManager);
|
||||||
this.contextMenu = new ChatContextMenu(this.bubbles.bubblesContainer, this, this.appMessagesManager, this.appChatsManager, this.appPeersManager, this.appPollsManager);
|
this.contextMenu = new ChatContextMenu(this.bubbles.bubblesContainer, this, this.appMessagesManager, this.appChatsManager, this.appPeersManager, this.appPollsManager);
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import type { AppNotificationsManager } from '../../lib/appManagers/appNotificationsManager';
|
||||||
import type { AppChatsManager } from '../../lib/appManagers/appChatsManager';
|
import type { AppChatsManager } from '../../lib/appManagers/appChatsManager';
|
||||||
import type { AppDocsManager, MyDocument } from "../../lib/appManagers/appDocsManager";
|
import type { AppDocsManager, MyDocument } from "../../lib/appManagers/appDocsManager";
|
||||||
import type { AppMessagesManager } from "../../lib/appManagers/appMessagesManager";
|
import type { AppMessagesManager } from "../../lib/appManagers/appMessagesManager";
|
||||||
@ -114,7 +115,7 @@ export default class ChatInput {
|
|||||||
|
|
||||||
public saveDraftDebounced: () => void;
|
public saveDraftDebounced: () => void;
|
||||||
|
|
||||||
constructor(private chat: Chat, private appMessagesManager: AppMessagesManager, private appDocsManager: AppDocsManager, private appChatsManager: AppChatsManager, private appPeersManager: AppPeersManager, private appWebPagesManager: AppWebPagesManager, private appImManager: AppImManager, private appDraftsManager: AppDraftsManager, private serverTimeManager: ServerTimeManager) {
|
constructor(private chat: Chat, private appMessagesManager: AppMessagesManager, private appDocsManager: AppDocsManager, private appChatsManager: AppChatsManager, private appPeersManager: AppPeersManager, private appWebPagesManager: AppWebPagesManager, private appImManager: AppImManager, private appDraftsManager: AppDraftsManager, private serverTimeManager: ServerTimeManager, private appNotificationsManager: AppNotificationsManager) {
|
||||||
this.listenerSetter = new ListenerSetter();
|
this.listenerSetter = new ListenerSetter();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -552,7 +553,7 @@ export default class ChatInput {
|
|||||||
const dialog = this.appMessagesManager.getDialogByPeerId(this.chat.peerId)[0];
|
const dialog = this.appMessagesManager.getDialogByPeerId(this.chat.peerId)[0];
|
||||||
const count = dialog?.unread_count;
|
const count = dialog?.unread_count;
|
||||||
this.goDownUnreadBadge.innerText = '' + (count || '');
|
this.goDownUnreadBadge.innerText = '' + (count || '');
|
||||||
this.goDownUnreadBadge.classList.toggle('badge-gray', this.appMessagesManager.isPeerMuted(this.chat.peerId));
|
this.goDownUnreadBadge.classList.toggle('badge-gray', this.appNotificationsManager.isPeerLocalMuted(this.chat.peerId, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public saveDraft() {
|
public saveDraft() {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import type { AppNotificationsManager } from "../../lib/appManagers/appNotificationsManager";
|
||||||
import type { AppChatsManager, Channel } from "../../lib/appManagers/appChatsManager";
|
import type { AppChatsManager, Channel } from "../../lib/appManagers/appChatsManager";
|
||||||
import type { AppMessagesManager } from "../../lib/appManagers/appMessagesManager";
|
import type { AppMessagesManager } from "../../lib/appManagers/appMessagesManager";
|
||||||
import type { AppPeersManager } from "../../lib/appManagers/appPeersManager";
|
import type { AppPeersManager } from "../../lib/appManagers/appPeersManager";
|
||||||
@ -47,7 +48,7 @@ export default class ChatTopbar {
|
|||||||
|
|
||||||
public menuButtons: (ButtonMenuItemOptions & {verify: () => boolean})[] = [];
|
public menuButtons: (ButtonMenuItemOptions & {verify: () => boolean})[] = [];
|
||||||
|
|
||||||
constructor(private chat: Chat, private appSidebarRight: AppSidebarRight, private appMessagesManager: AppMessagesManager, private appPeersManager: AppPeersManager, private appChatsManager: AppChatsManager) {
|
constructor(private chat: Chat, private appSidebarRight: AppSidebarRight, private appMessagesManager: AppMessagesManager, private appPeersManager: AppPeersManager, private appChatsManager: AppChatsManager, private appNotificationsManager: AppNotificationsManager) {
|
||||||
this.listenerSetter = new ListenerSetter();
|
this.listenerSetter = new ListenerSetter();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,14 +191,14 @@ export default class ChatTopbar {
|
|||||||
onClick: () => {
|
onClick: () => {
|
||||||
this.appMessagesManager.mutePeer(this.peerId);
|
this.appMessagesManager.mutePeer(this.peerId);
|
||||||
},
|
},
|
||||||
verify: () => this.chat.type === 'chat' && rootScope.myId !== this.peerId && !this.appMessagesManager.isPeerMuted(this.peerId)
|
verify: () => this.chat.type === 'chat' && rootScope.myId !== this.peerId && !this.appNotificationsManager.isPeerLocalMuted(this.peerId, false)
|
||||||
}, {
|
}, {
|
||||||
icon: 'unmute',
|
icon: 'unmute',
|
||||||
text: 'Unmute',
|
text: 'Unmute',
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
this.appMessagesManager.mutePeer(this.peerId);
|
this.appMessagesManager.mutePeer(this.peerId);
|
||||||
},
|
},
|
||||||
verify: () => this.chat.type === 'chat' && rootScope.myId !== this.peerId && this.appMessagesManager.isPeerMuted(this.peerId)
|
verify: () => this.chat.type === 'chat' && rootScope.myId !== this.peerId && this.appNotificationsManager.isPeerLocalMuted(this.peerId, false)
|
||||||
}, {
|
}, {
|
||||||
icon: 'select',
|
icon: 'select',
|
||||||
text: 'Select Messages',
|
text: 'Select Messages',
|
||||||
@ -280,10 +281,8 @@ export default class ChatTopbar {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.listenerSetter.add(rootScope, 'dialog_notify_settings', (e) => {
|
this.listenerSetter.add(rootScope, 'dialog_notify_settings', (dialog) => {
|
||||||
const peerId = e;
|
if(dialog.peerId === this.peerId) {
|
||||||
|
|
||||||
if(peerId === this.peerId) {
|
|
||||||
this.setMutedState();
|
this.setMutedState();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -487,7 +486,7 @@ export default class ChatTopbar {
|
|||||||
if(!this.btnMute) return;
|
if(!this.btnMute) return;
|
||||||
|
|
||||||
const peerId = this.peerId;
|
const peerId = this.peerId;
|
||||||
let muted = this.appMessagesManager.isPeerMuted(peerId);
|
let muted = this.appNotificationsManager.isPeerLocalMuted(peerId, false);
|
||||||
if(this.appPeersManager.isBroadcast(peerId)) { // not human
|
if(this.appPeersManager.isBroadcast(peerId)) { // not human
|
||||||
this.btnMute.classList.remove('tgico-mute', 'tgico-unmute');
|
this.btnMute.classList.remove('tgico-mute', 'tgico-unmute');
|
||||||
this.btnMute.classList.add(muted ? 'tgico-unmute' : 'tgico-mute');
|
this.btnMute.classList.add(muted ? 'tgico-unmute' : 'tgico-mute');
|
||||||
|
@ -39,7 +39,8 @@ export default class AppNotificationsTab extends SliderSuperTabEventable {
|
|||||||
this.scrollable.append(section.container);
|
this.scrollable.append(section.container);
|
||||||
|
|
||||||
const inputNotifyPeer = {_: options.inputKey};
|
const inputNotifyPeer = {_: options.inputKey};
|
||||||
appNotificationsManager.getNotifySettings(inputNotifyPeer).then((notifySettings) => {
|
const ret = appNotificationsManager.getNotifySettings(inputNotifyPeer);
|
||||||
|
(ret instanceof Promise ? ret : Promise.resolve(ret)).then((notifySettings) => {
|
||||||
const applySettings = () => {
|
const applySettings = () => {
|
||||||
const muted = appNotificationsManager.isMuted(notifySettings);
|
const muted = appNotificationsManager.isMuted(notifySettings);
|
||||||
enabledRow.checkboxField.value = !muted;
|
enabledRow.checkboxField.value = !muted;
|
||||||
|
@ -14,6 +14,7 @@ import CheckboxField from "../../checkboxField";
|
|||||||
import { attachClickEvent, cancelEvent } from "../../../helpers/dom";
|
import { attachClickEvent, cancelEvent } from "../../../helpers/dom";
|
||||||
import appSidebarRight from "..";
|
import appSidebarRight from "..";
|
||||||
import { TransitionSlider } from "../../transition";
|
import { TransitionSlider } from "../../transition";
|
||||||
|
import appNotificationsManager from "../../../lib/appManagers/appNotificationsManager";
|
||||||
|
|
||||||
let setText = (text: string, el: HTMLDivElement) => {
|
let setText = (text: string, el: HTMLDivElement) => {
|
||||||
window.requestAnimationFrame(() => {
|
window.requestAnimationFrame(() => {
|
||||||
@ -126,9 +127,9 @@ export default class AppSharedMediaTab implements SliderTab {
|
|||||||
appMessagesManager.mutePeer(this.peerId);
|
appMessagesManager.mutePeer(this.peerId);
|
||||||
});
|
});
|
||||||
|
|
||||||
rootScope.on('dialog_notify_settings', (e) => {
|
rootScope.on('dialog_notify_settings', (dialog) => {
|
||||||
if(this.peerId === e) {
|
if(this.peerId === dialog.peerId) {
|
||||||
const muted = appMessagesManager.isPeerMuted(this.peerId);
|
const muted = appNotificationsManager.isPeerLocalMuted(this.peerId, false);
|
||||||
this.profileElements.notificationsCheckbox.checked = !muted;
|
this.profileElements.notificationsCheckbox.checked = !muted;
|
||||||
this.profileElements.notificationsStatus.innerText = muted ? 'Disabled' : 'Enabled';
|
this.profileElements.notificationsStatus.innerText = muted ? 'Disabled' : 'Enabled';
|
||||||
}
|
}
|
||||||
@ -306,7 +307,7 @@ export default class AppSharedMediaTab implements SliderTab {
|
|||||||
setText(appPeersManager.getPeerUsername(peerId), this.profileElements.username);
|
setText(appPeersManager.getPeerUsername(peerId), this.profileElements.username);
|
||||||
}
|
}
|
||||||
|
|
||||||
const muted = appMessagesManager.isPeerMuted(peerId);
|
const muted = appNotificationsManager.isPeerLocalMuted(peerId, false);
|
||||||
this.profileElements.notificationsCheckbox.checked = !muted;
|
this.profileElements.notificationsCheckbox.checked = !muted;
|
||||||
this.profileElements.notificationsStatus.innerText = muted ? 'Disabled' : 'Enabled';
|
this.profileElements.notificationsStatus.innerText = muted ? 'Disabled' : 'Enabled';
|
||||||
} else {
|
} else {
|
||||||
|
@ -26,6 +26,8 @@ import appDraftsManager, { MyDraftMessage } from "./appDraftsManager";
|
|||||||
import ProgressivePreloader from "../../components/preloader";
|
import ProgressivePreloader from "../../components/preloader";
|
||||||
import App from "../../config/app";
|
import App from "../../config/app";
|
||||||
import DEBUG, { MOUNT_CLASS_TO } from "../../config/debug";
|
import DEBUG, { MOUNT_CLASS_TO } from "../../config/debug";
|
||||||
|
import appNotificationsManager from "./appNotificationsManager";
|
||||||
|
import { InputNotifyPeer } from "../../layer";
|
||||||
|
|
||||||
type DialogDom = {
|
type DialogDom = {
|
||||||
avatarEl: AvatarElement,
|
avatarEl: AvatarElement,
|
||||||
@ -354,11 +356,8 @@ export class AppDialogsManager {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
rootScope.on('dialog_notify_settings', e => {
|
rootScope.on('dialog_notify_settings', (dialog) => {
|
||||||
const dialog = appMessagesManager.getDialogByPeerId(e)[0];
|
this.setUnreadMessages(dialog); // возможно это не нужно, но нужно менять is-muted
|
||||||
if(dialog) {
|
|
||||||
this.setUnreadMessages(dialog); // возможно это не нужно, но нужно менять is-muted
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
rootScope.on('dialog_draft', (e) => {
|
rootScope.on('dialog_draft', (e) => {
|
||||||
@ -484,6 +483,11 @@ export class AppDialogsManager {
|
|||||||
//selectTab(0);
|
//selectTab(0);
|
||||||
(this.folders.menu.firstElementChild as HTMLElement).click();
|
(this.folders.menu.firstElementChild as HTMLElement).click();
|
||||||
appStateManager.getState().then((state) => {
|
appStateManager.getState().then((state) => {
|
||||||
|
(['inputNotifyBroadcasts', 'inputNotifyUsers', 'inputNotifyChats'] as Exclude<InputNotifyPeer['_'], 'inputNotifyPeer'>[])
|
||||||
|
.forEach((inputKey) => {
|
||||||
|
appNotificationsManager.getNotifySettings({_: inputKey});
|
||||||
|
});
|
||||||
|
|
||||||
const getFiltersPromise = appMessagesManager.filtersStorage.getDialogFilters();
|
const getFiltersPromise = appMessagesManager.filtersStorage.getDialogFilters();
|
||||||
getFiltersPromise.then((filters) => {
|
getFiltersPromise.then((filters) => {
|
||||||
for(const filter of filters) {
|
for(const filter of filters) {
|
||||||
@ -616,7 +620,7 @@ export class AppDialogsManager {
|
|||||||
let mutedCount = 0;
|
let mutedCount = 0;
|
||||||
let notMutedCount = 0;
|
let notMutedCount = 0;
|
||||||
folder.forEach(dialog => {
|
folder.forEach(dialog => {
|
||||||
const isMuted = appMessagesManager.isDialogMuted(dialog);
|
const isMuted = appNotificationsManager.isPeerLocalMuted(dialog.peerId, true);
|
||||||
|
|
||||||
if(isMuted && filterId === 0) {
|
if(isMuted && filterId === 0) {
|
||||||
return;
|
return;
|
||||||
@ -1117,7 +1121,7 @@ export class AppDialogsManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isMuted = appMessagesManager.isDialogMuted(dialog);
|
const isMuted = appNotificationsManager.isPeerLocalMuted(dialog.peerId, true);
|
||||||
const wasMuted = dom.listEl.classList.contains('is-muted');
|
const wasMuted = dom.listEl.classList.contains('is-muted');
|
||||||
if(isMuted !== wasMuted) {
|
if(isMuted !== wasMuted) {
|
||||||
SetTransition(dom.listEl, 'is-muted', isMuted, 200);
|
SetTransition(dom.listEl, 'is-muted', isMuted, 200);
|
||||||
@ -1351,7 +1355,7 @@ export class AppDialogsManager {
|
|||||||
container.append(li);
|
container.append(li);
|
||||||
} */
|
} */
|
||||||
|
|
||||||
const isMuted = appMessagesManager.isDialogMuted(dialog);
|
const isMuted = appNotificationsManager.isPeerLocalMuted(dialog.peerId, true);
|
||||||
if(isMuted) {
|
if(isMuted) {
|
||||||
li.classList.add('is-muted');
|
li.classList.add('is-muted');
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ import appDownloadManager from './appDownloadManager';
|
|||||||
import appStateManager, { AppStateManager } from './appStateManager';
|
import appStateManager, { AppStateManager } from './appStateManager';
|
||||||
import { MOUNT_CLASS_TO } from '../../config/debug';
|
import { MOUNT_CLASS_TO } from '../../config/debug';
|
||||||
import appNavigationController from '../../components/appNavigationController';
|
import appNavigationController from '../../components/appNavigationController';
|
||||||
|
import appNotificationsManager from './appNotificationsManager';
|
||||||
|
|
||||||
//console.log('appImManager included33!');
|
//console.log('appImManager included33!');
|
||||||
|
|
||||||
@ -593,7 +594,7 @@ export class AppImManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private createNewChat() {
|
private createNewChat() {
|
||||||
const chat = new Chat(this, appChatsManager, appDocsManager, appInlineBotsManager, appMessagesManager, appPeersManager, appPhotosManager, appProfileManager, appStickersManager, appUsersManager, appWebPagesManager, appPollsManager, apiManager, appDraftsManager, serverTimeManager, sessionStorage);
|
const chat = new Chat(this, appChatsManager, appDocsManager, appInlineBotsManager, appMessagesManager, appPeersManager, appPhotosManager, appProfileManager, appStickersManager, appUsersManager, appWebPagesManager, appPollsManager, apiManager, appDraftsManager, serverTimeManager, sessionStorage, appNotificationsManager);
|
||||||
|
|
||||||
if(this.chats.length) {
|
if(this.chats.length) {
|
||||||
chat.backgroundEl.append(this.chat.backgroundEl.lastElementChild.cloneNode(true));
|
chat.backgroundEl.append(this.chat.backgroundEl.lastElementChild.cloneNode(true));
|
||||||
|
@ -196,6 +196,22 @@ export class AppMessagesManager {
|
|||||||
this.handleUpdate(e);
|
this.handleUpdate(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ! Invalidate notify settings, can optimize though
|
||||||
|
rootScope.on('notify_peer_type_settings', ({key, settings}) => {
|
||||||
|
this.getConversationsAll().then(dialogs => {
|
||||||
|
let filterFunc: (dialog: Dialog) => boolean;
|
||||||
|
if(key === 'notifyUsers') filterFunc = (dialog) => dialog.peerId > 0;
|
||||||
|
else if(key === 'notifyBroadcasts') filterFunc = (dialog) => appChatsManager.isBroadcast(-dialog.peerId);
|
||||||
|
else filterFunc = (dialog) => appPeersManager.isAnyGroup(dialog.peerId);
|
||||||
|
|
||||||
|
dialogs
|
||||||
|
.filter(filterFunc)
|
||||||
|
.forEach(dialog => {
|
||||||
|
rootScope.broadcast('dialog_notify_settings', dialog);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
rootScope.on('webpage_updated', (e) => {
|
rootScope.on('webpage_updated', (e) => {
|
||||||
const eventData = e;
|
const eventData = e;
|
||||||
eventData.msgs.forEach((mid) => {
|
eventData.msgs.forEach((mid) => {
|
||||||
@ -4368,7 +4384,7 @@ export class AppMessagesManager {
|
|||||||
const dialog = this.getDialogByPeerId(peerId)[0];
|
const dialog = this.getDialogByPeerId(peerId)[0];
|
||||||
if(dialog) {
|
if(dialog) {
|
||||||
dialog.notify_settings = notify_settings;
|
dialog.notify_settings = notify_settings;
|
||||||
rootScope.broadcast('dialog_notify_settings', peerId);
|
rootScope.broadcast('dialog_notify_settings', dialog);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4464,22 +4480,6 @@ export class AppMessagesManager {
|
|||||||
return pendingMessage;
|
return pendingMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public isDialogMuted(dialog: MTDialog.dialog) {
|
|
||||||
let muted = false;
|
|
||||||
if(dialog && dialog.notify_settings && dialog.notify_settings.mute_until) {
|
|
||||||
//muted = new Date(dialog.notify_settings.mute_until * 1000) > new Date();
|
|
||||||
muted = (dialog.notify_settings.mute_until * 1000) > Date.now();
|
|
||||||
}
|
|
||||||
|
|
||||||
return muted;
|
|
||||||
}
|
|
||||||
|
|
||||||
public isPeerMuted(peerId: number) {
|
|
||||||
if(peerId === rootScope.myId) return false;
|
|
||||||
|
|
||||||
return this.isDialogMuted(this.getDialogByPeerId(peerId)[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public mutePeer(peerId: number) {
|
public mutePeer(peerId: number) {
|
||||||
const settings: InputPeerNotifySettings = {
|
const settings: InputPeerNotifySettings = {
|
||||||
_: 'inputPeerNotifySettings'
|
_: 'inputPeerNotifySettings'
|
||||||
|
@ -31,6 +31,7 @@ export type NotifyOptions = Partial<{
|
|||||||
onclick: () => void;
|
onclick: () => void;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
|
type ImSadAboutIt = Promise<PeerNotifySettings> | PeerNotifySettings;
|
||||||
export class AppNotificationsManager {
|
export class AppNotificationsManager {
|
||||||
private notificationsUiSupport: boolean;
|
private notificationsUiSupport: boolean;
|
||||||
private notificationsShown: {[key: string]: MyNotification} = {};
|
private notificationsShown: {[key: string]: MyNotification} = {};
|
||||||
@ -41,10 +42,10 @@ export class AppNotificationsManager {
|
|||||||
private nextSoundAt: number;
|
private nextSoundAt: number;
|
||||||
private prevSoundVolume: number;
|
private prevSoundVolume: number;
|
||||||
private peerSettings = {
|
private peerSettings = {
|
||||||
notifyPeer: {} as {[peerId: number]: Promise<PeerNotifySettings>},
|
notifyPeer: {} as {[peerId: number]: ImSadAboutIt},
|
||||||
notifyUsers: null as Promise<PeerNotifySettings>,
|
notifyUsers: null as ImSadAboutIt,
|
||||||
notifyChats: null as Promise<PeerNotifySettings>,
|
notifyChats: null as ImSadAboutIt,
|
||||||
notifyBroadcasts: null as Promise<PeerNotifySettings>
|
notifyBroadcasts: null as ImSadAboutIt
|
||||||
};
|
};
|
||||||
private exceptions: {[peerId: string]: PeerNotifySettings} = {};
|
private exceptions: {[peerId: string]: PeerNotifySettings} = {};
|
||||||
private notifyContactsSignUp: Promise<boolean>;
|
private notifyContactsSignUp: Promise<boolean>;
|
||||||
@ -293,7 +294,7 @@ export class AppNotificationsManager {
|
|||||||
return this.settings;
|
return this.settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getNotifySettings(peer: InputNotifyPeer): Promise<PeerNotifySettings> {
|
public getNotifySettings(peer: InputNotifyPeer): ImSadAboutIt {
|
||||||
let key: any = convertInputKeyToKey(peer._);
|
let key: any = convertInputKeyToKey(peer._);
|
||||||
let obj: any = this.peerSettings[key as NotifyPeer['_']];
|
let obj: any = this.peerSettings[key as NotifyPeer['_']];
|
||||||
|
|
||||||
@ -306,9 +307,11 @@ export class AppNotificationsManager {
|
|||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (obj || this.peerSettings)[key] = apiManager.invokeApi('account.getNotifySettings', {peer})/* .then(settings => {
|
return (obj || this.peerSettings)[key] = apiManager.invokeApi('account.getNotifySettings', {peer})
|
||||||
|
.then(settings => {
|
||||||
|
this.savePeerSettings(key, settings);
|
||||||
return settings;
|
return settings;
|
||||||
}) */;
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public updateNotifySettings(peer: InputNotifyPeer, settings: InputPeerNotifySettings) {
|
public updateNotifySettings(peer: InputNotifyPeer, settings: InputPeerNotifySettings) {
|
||||||
@ -372,14 +375,17 @@ export class AppNotificationsManager {
|
|||||||
this.prevFavicon = href;
|
this.prevFavicon = href;
|
||||||
}
|
}
|
||||||
|
|
||||||
public savePeerSettings(key: number | NotifyPeer['_'], settings: PeerNotifySettings) {
|
public savePeerSettings(key: number | Exclude<NotifyPeer['_'], 'notifyPeer'>, settings: PeerNotifySettings) {
|
||||||
const p = Promise.resolve(settings);
|
|
||||||
let obj: any;
|
let obj: any;
|
||||||
if(typeof(key) === 'number') {
|
if(typeof(key) === 'number') {
|
||||||
obj = this.peerSettings['notifyPeer'];
|
obj = this.peerSettings['notifyPeer'];
|
||||||
}
|
}
|
||||||
|
|
||||||
(obj || this.peerSettings)[key] = p;
|
(obj || this.peerSettings)[key] = settings;
|
||||||
|
|
||||||
|
if(typeof(key) !== 'number') {
|
||||||
|
rootScope.broadcast('notify_peer_type_settings', {key, settings});
|
||||||
|
}
|
||||||
|
|
||||||
//rootScope.broadcast('notify_settings', {peerId: peerId});
|
//rootScope.broadcast('notify_settings', {peerId: peerId});
|
||||||
}
|
}
|
||||||
@ -390,10 +396,47 @@ export class AppNotificationsManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getPeerMuted(peerId: number) {
|
public getPeerMuted(peerId: number) {
|
||||||
return this.getNotifySettings({_: 'inputNotifyPeer', peer: appPeersManager.getInputPeerById(peerId)})
|
const ret = this.getNotifySettings({_: 'inputNotifyPeer', peer: appPeersManager.getInputPeerById(peerId)});
|
||||||
|
return (ret instanceof Promise ? ret : Promise.resolve(ret))
|
||||||
.then((peerNotifySettings) => this.isMuted(peerNotifySettings));
|
.then((peerNotifySettings) => this.isMuted(peerNotifySettings));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getPeerLocalSettings(peerId: number, respectType = true): PeerNotifySettings {
|
||||||
|
const n: PeerNotifySettings = {
|
||||||
|
_: 'peerNotifySettings'
|
||||||
|
};
|
||||||
|
|
||||||
|
const notifySettings = this.peerSettings['notifyPeer'][peerId];
|
||||||
|
//if(!notifySettings || (notifySettings instanceof Promise)) return false;
|
||||||
|
if(notifySettings && !(notifySettings instanceof Promise)) {
|
||||||
|
Object.assign(n, notifySettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(respectType) {
|
||||||
|
const inputNotify = appPeersManager.getInputNotifyPeerById(peerId, true);
|
||||||
|
const key = convertInputKeyToKey(inputNotify._);
|
||||||
|
const typeNotifySettings = this.peerSettings[key as NotifyPeer['_']];
|
||||||
|
if(typeNotifySettings && !(typeNotifySettings instanceof Promise)) {
|
||||||
|
for(let i in typeNotifySettings) {
|
||||||
|
// @ts-ignore
|
||||||
|
if(n[i] === undefined) {
|
||||||
|
// @ts-ignore
|
||||||
|
n[i] = typeNotifySettings[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
public isPeerLocalMuted(peerId: number, respectType = true) {
|
||||||
|
if(peerId === rootScope.myId) return false;
|
||||||
|
|
||||||
|
const notifySettings = this.getPeerLocalSettings(peerId, respectType);
|
||||||
|
return this.isMuted(notifySettings);
|
||||||
|
}
|
||||||
|
|
||||||
public start() {
|
public start() {
|
||||||
this.updateLocalSettings();
|
this.updateLocalSettings();
|
||||||
//rootScope.on('settings_changed', this.updateNotifySettings);
|
//rootScope.on('settings_changed', this.updateNotifySettings);
|
||||||
|
@ -155,21 +155,14 @@ export class AppPeersManager {
|
|||||||
return (peerId < 0) && !appChatsManager.isBroadcast(-peerId);
|
return (peerId < 0) && !appChatsManager.isBroadcast(-peerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public isBroadcast(id: number): boolean {
|
public isBroadcast(peerId: number): boolean {
|
||||||
return this.isChannel(id) && !this.isMegagroup(id);
|
return this.isChannel(peerId) && !this.isMegagroup(peerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public isBot(peerId: number): boolean {
|
public isBot(peerId: number): boolean {
|
||||||
return (peerId > 0) && appUsersManager.isBot(peerId);
|
return (peerId > 0) && appUsersManager.isBot(peerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Will check notification exceptions by type too
|
|
||||||
*/
|
|
||||||
public isPeerMuted(peerId: number) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* public getInputPeer(peerString: string): InputPeer {
|
/* public getInputPeer(peerString: string): InputPeer {
|
||||||
var firstChar = peerString.charAt(0);
|
var firstChar = peerString.charAt(0);
|
||||||
var peerParams = peerString.substr(1).split('_');
|
var peerParams = peerString.substr(1).split('_');
|
||||||
@ -202,7 +195,9 @@ export class AppPeersManager {
|
|||||||
}
|
}
|
||||||
} */
|
} */
|
||||||
|
|
||||||
public getInputNotifyPeerById(peerId: number, ignorePeerId = false): InputNotifyPeer {
|
public getInputNotifyPeerById(peerId: number, ignorePeerId: true): Exclude<InputNotifyPeer, InputNotifyPeer.inputNotifyPeer>;
|
||||||
|
public getInputNotifyPeerById(peerId: number, ignorePeerId?: false): InputNotifyPeer.inputNotifyPeer;
|
||||||
|
public getInputNotifyPeerById(peerId: number, ignorePeerId?: boolean): InputNotifyPeer {
|
||||||
if(ignorePeerId) {
|
if(ignorePeerId) {
|
||||||
if(peerId > 0) {
|
if(peerId > 0) {
|
||||||
return {_: 'inputNotifyUsers'};
|
return {_: 'inputNotifyUsers'};
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import type { Message, StickerSet, Update } from "../layer";
|
import type { Message, StickerSet, Update, NotifyPeer, PeerNotifySettings } from "../layer";
|
||||||
import type { MyDocument } from "./appManagers/appDocsManager";
|
import type { MyDocument } from "./appManagers/appDocsManager";
|
||||||
import type { AppMessagesManager, Dialog, MessagesStorage } from "./appManagers/appMessagesManager";
|
import type { AppMessagesManager, Dialog, MessagesStorage } from "./appManagers/appMessagesManager";
|
||||||
import type { Poll, PollResults } from "./appManagers/appPollsManager";
|
import type { Poll, PollResults } from "./appManagers/appPollsManager";
|
||||||
@ -32,7 +32,7 @@ export type BroadcastEvents = {
|
|||||||
'dialog_drop': {peerId: number, dialog?: Dialog},
|
'dialog_drop': {peerId: number, dialog?: Dialog},
|
||||||
'dialog_migrate': {migrateFrom: number, migrateTo: number},
|
'dialog_migrate': {migrateFrom: number, migrateTo: number},
|
||||||
//'dialog_top': Dialog,
|
//'dialog_top': Dialog,
|
||||||
'dialog_notify_settings': number,
|
'dialog_notify_settings': Dialog,
|
||||||
'dialogs_multiupdate': {[peerId: string]: Dialog},
|
'dialogs_multiupdate': {[peerId: string]: Dialog},
|
||||||
'dialogs_archived_unread': {count: number},
|
'dialogs_archived_unread': {count: number},
|
||||||
|
|
||||||
@ -97,7 +97,8 @@ export type BroadcastEvents = {
|
|||||||
|
|
||||||
'privacy_update': Update.updatePrivacy,
|
'privacy_update': Update.updatePrivacy,
|
||||||
|
|
||||||
'notify_settings': Update.updateNotifySettings
|
'notify_settings': Update.updateNotifySettings,
|
||||||
|
'notify_peer_type_settings': {key: Exclude<NotifyPeer['_'], 'notifyPeer'>, settings: PeerNotifySettings},
|
||||||
};
|
};
|
||||||
|
|
||||||
class RootScope extends EventListenerBase<any> {
|
class RootScope extends EventListenerBase<any> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user