Browse Source

Fix showing notifications on muted types

master
morethanwords 3 years ago
parent
commit
be1cd0d3bf
  1. 4
      src/components/colorPicker.ts
  2. 8
      src/components/dialogsContextMenu.ts
  3. 2
      src/lib/appManagers/appChatsManager.ts
  4. 5
      src/lib/appManagers/appDialogsManager.ts
  5. 18
      src/lib/appManagers/appMessagesManager.ts
  6. 13
      src/lib/appManagers/appNotificationsManager.ts

4
src/components/colorPicker.ts

@ -1,4 +1,4 @@
import { ColorHsla, hexaToHsla, hslaToRgba, rgbaToHexa as rgbaToHexa, rgbaToHsla } from "../helpers/color"; import { ColorHsla, ColorRgba, hexaToHsla, hslaToRgba, rgbaToHexa as rgbaToHexa, rgbaToHsla } from "../helpers/color";
import attachGrabListeners from "../helpers/dom/attachGrabListeners"; import attachGrabListeners from "../helpers/dom/attachGrabListeners";
import { clamp } from "../helpers/number"; import { clamp } from "../helpers/number";
import InputField, { InputState } from "./inputField"; import InputField, { InputState } from "./inputField";
@ -10,7 +10,7 @@ export type ColorPickerColor = {
hsla: string; hsla: string;
rgba: string; rgba: string;
hexa: string; hexa: string;
rgbaArray: import("f:/tweb/src/helpers/color").ColorRgba; rgbaArray: ColorRgba;
}; };
export default class ColorPicker { export default class ColorPicker {

8
src/components/dialogsContextMenu.ts

@ -66,7 +66,7 @@ export default class DialogsContextMenu {
}, { }, {
icon: 'unmute', icon: 'unmute',
text: 'ChatList.Context.Unmute', text: 'ChatList.Context.Unmute',
onClick: this.onMuteClick, onClick: this.onUnmuteClick,
verify: () => { verify: () => {
return this.selectedId !== rootScope.myId && appNotificationsManager.isPeerLocalMuted(this.dialog.peerId); return this.selectedId !== rootScope.myId && appNotificationsManager.isPeerLocalMuted(this.dialog.peerId);
} }
@ -104,8 +104,12 @@ export default class DialogsContextMenu {
appMessagesManager.toggleDialogPin(this.selectedId, this.filterId); appMessagesManager.toggleDialogPin(this.selectedId, this.filterId);
}; };
private onUnmuteClick = () => {
appMessagesManager.mutePeer(this.selectedId, false);
};
private onMuteClick = () => { private onMuteClick = () => {
appMessagesManager.mutePeer(this.selectedId); appMessagesManager.mutePeer(this.selectedId, true);
}; };
private onUnreadClick = () => { private onUnreadClick = () => {

2
src/lib/appManagers/appChatsManager.ts

@ -74,7 +74,7 @@ export class AppChatsManager {
case 'updateChatUserTyping': case 'updateChatUserTyping':
case 'updateChannelUserTyping': { case 'updateChannelUserTyping': {
const fromId = (update as Update.updateUserTyping).user_id || appPeersManager.getPeerId((update as Update.updateChatUserTyping).from_id); const fromId = (update as Update.updateUserTyping).user_id || appPeersManager.getPeerId((update as Update.updateChatUserTyping).from_id);
if(rootScope.myId === fromId) { if(rootScope.myId === fromId || update.action._ === 'speakingInGroupCallAction') {
break; break;
} }

5
src/lib/appManagers/appDialogsManager.ts

@ -498,10 +498,7 @@ 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'>[]) appNotificationsManager.getNotifyPeerTypeSettings();
.forEach((inputKey) => {
appNotificationsManager.getNotifySettings({_: inputKey});
});
const getFiltersPromise = appMessagesManager.filtersStorage.getDialogFilters(); const getFiltersPromise = appMessagesManager.filtersStorage.getDialogFilters();
getFiltersPromise.then((filters) => { getFiltersPromise.then((filters) => {

18
src/lib/appManagers/appMessagesManager.ts

@ -3905,11 +3905,11 @@ export class AppMessagesManager {
const notifyPeerToHandle = this.notificationsToHandle[peerId]; const notifyPeerToHandle = this.notificationsToHandle[peerId];
Promise.all([ Promise.all([
appNotificationsManager.getPeerMuted(peerId), appNotificationsManager.getNotifyPeerTypeSettings(),
appNotificationsManager.getNotifySettings(appPeersManager.getInputNotifyPeerById(peerId, true)) appNotificationsManager.getNotifySettings(appPeersManager.getInputNotifyPeerById(peerId, true))
]).then(([muted, peerTypeNotifySettings]) => { ]).then(([_, peerTypeNotifySettings]) => {
const topMessage = notifyPeerToHandle.topMessage; const topMessage = notifyPeerToHandle.topMessage;
if(muted || !topMessage.pFlags.unread) { if(appNotificationsManager.isPeerLocalMuted(peerId, true) || !topMessage.pFlags.unread) {
return; return;
} }
@ -4787,21 +4787,21 @@ export class AppMessagesManager {
return pendingMessage; return pendingMessage;
} }
public mutePeer(peerId: number) { public mutePeer(peerId: number, mute?: boolean) {
const settings: InputPeerNotifySettings = { const settings: InputPeerNotifySettings = {
_: 'inputPeerNotifySettings' _: 'inputPeerNotifySettings'
}; };
if(mute === undefined) {
mute = false;
const dialog = appMessagesManager.getDialogByPeerId(peerId)[0]; const dialog = appMessagesManager.getDialogByPeerId(peerId)[0];
let muted = true;
if(dialog && dialog.notify_settings) { if(dialog && dialog.notify_settings) {
muted = dialog.notify_settings.mute_until > (Date.now() / 1000 | 0); mute = (dialog.notify_settings.mute_until || 0) <= (Date.now() / 1000 | 0);
} }
if(!muted) {
settings.mute_until = 2147483647;
} }
settings.mute_until = mute ? 0xFFFFFFFF : 0;
return appNotificationsManager.updateNotifySettings({ return appNotificationsManager.updateNotifySettings({
_: 'inputNotifyPeer', _: 'inputNotifyPeer',
peer: appPeersManager.getInputPeerById(peerId) peer: appPeersManager.getInputPeerById(peerId)

13
src/lib/appManagers/appNotificationsManager.ts

@ -82,6 +82,8 @@ export class AppNotificationsManager {
private notifySoundEl: HTMLElement; private notifySoundEl: HTMLElement;
private getNotifyPeerTypePromise: Promise<any>;
constructor() { constructor() {
// @ts-ignore // @ts-ignore
navigator.vibrate = navigator.vibrate || navigator.mozVibrate || navigator.webkitVibrate; navigator.vibrate = navigator.vibrate || navigator.mozVibrate || navigator.webkitVibrate;
@ -322,6 +324,17 @@ export class AppNotificationsManager {
}); });
} }
public getNotifyPeerTypeSettings() {
if(this.getNotifyPeerTypePromise) return this.getNotifyPeerTypePromise;
const promises = (['inputNotifyBroadcasts', 'inputNotifyUsers', 'inputNotifyChats'] as Exclude<InputNotifyPeer['_'], 'inputNotifyPeer'>[])
.map((inputKey) => {
return this.getNotifySettings({_: inputKey});
});
return this.getNotifyPeerTypePromise = Promise.all(promises);
}
public updateNotifySettings(peer: InputNotifyPeer, settings: InputPeerNotifySettings) { public updateNotifySettings(peer: InputNotifyPeer, settings: InputPeerNotifySettings) {
//this.savePeerSettings(peerId, settings); //this.savePeerSettings(peerId, settings);

Loading…
Cancel
Save