Browse Source

Fix deleted status & avatar in sidebar

Fix muted icon in chat list
master
morethanwords 4 years ago
parent
commit
c69c6a841b
  1. 33
      src/lib/appManagers/appDialogsManager.ts
  2. 39
      src/lib/appManagers/appImManager.ts
  3. 181
      src/lib/appManagers/appMessagesManager.ts
  4. 17
      src/lib/appManagers/appPeersManager.ts
  5. 32
      src/lib/appManagers/appUsersManager.ts
  6. 4
      src/lib/rootScope.ts
  7. 16
      src/scss/partials/_chatlist.scss
  8. 2
      src/scss/partials/_rightSidebar.scss

33
src/lib/appManagers/appDialogsManager.ts

@ -29,7 +29,8 @@ type DialogDom = {
unreadMessagesSpan: HTMLSpanElement, unreadMessagesSpan: HTMLSpanElement,
lastMessageSpan: HTMLSpanElement, lastMessageSpan: HTMLSpanElement,
containerEl: HTMLDivElement, containerEl: HTMLDivElement,
listEl: HTMLLIElement listEl: HTMLLIElement,
muteAnimationTimeout?: number
}; };
const testScroll = false; const testScroll = false;
@ -143,16 +144,14 @@ export class AppDialogsManager {
} */ } */
$rootScope.$on('user_update', (e) => { $rootScope.$on('user_update', (e) => {
let userID = e.detail; const userID = e.detail;
const user = appUsersManager.getUser(userID);
let user = appUsersManager.getUser(userID); const dialog = appMessagesManager.getDialogByPeerID(user.id)[0];
let dialog = appMessagesManager.getDialogByPeerID(user.id)[0];
//console.log('updating user:', user, dialog); //console.log('updating user:', user, dialog);
if(dialog && !appUsersManager.isBot(dialog.peerID) && dialog.peerID != $rootScope.myID) { if(dialog && !appUsersManager.isBot(dialog.peerID) && dialog.peerID != $rootScope.myID) {
let online = user.status && user.status._ == 'userStatusOnline'; const online = user.status?._ == 'userStatusOnline';
let dom = this.getDialogDom(dialog.peerID); const dom = this.getDialogDom(dialog.peerID);
if(dom) { if(dom) {
dom.avatarEl.classList.toggle('is-online', online); dom.avatarEl.classList.toggle('is-online', online);
@ -737,8 +736,18 @@ export class AppDialogsManager {
} }
const isMuted = (dialog.notify_settings?.mute_until * 1000) > Date.now(); const isMuted = (dialog.notify_settings?.mute_until * 1000) > Date.now();
const wasMuted = dom.listEl.classList.contains('is-muted');
dom.listEl.classList.toggle('is-muted', isMuted); if(!isMuted && wasMuted) {
dom.listEl.classList.add('backwards');
if(dom.muteAnimationTimeout) clearTimeout(dom.muteAnimationTimeout);
dom.muteAnimationTimeout = window.setTimeout(() => {
delete dom.muteAnimationTimeout;
dom.listEl.classList.remove('backwards', 'is-muted');
}, 200);
} else {
dom.listEl.classList.toggle('is-muted', isMuted);
}
const lastMessage = appMessagesManager.getMessage(dialog.top_message); const lastMessage = appMessagesManager.getMessage(dialog.top_message);
if(lastMessage._ != 'messageEmpty' && !lastMessage.deleted && if(lastMessage._ != 'messageEmpty' && !lastMessage.deleted &&
@ -772,9 +781,9 @@ export class AppDialogsManager {
if(dialog.unread_count || dialog.pFlags.unread_mark) { if(dialog.unread_count || dialog.pFlags.unread_mark) {
//dom.unreadMessagesSpan.innerText = '' + (dialog.unread_count ? formatNumber(dialog.unread_count, 1) : ' '); //dom.unreadMessagesSpan.innerText = '' + (dialog.unread_count ? formatNumber(dialog.unread_count, 1) : ' ');
dom.unreadMessagesSpan.innerText = '' + (dialog.unread_count || ' '); dom.unreadMessagesSpan.innerText = '' + (dialog.unread_count || ' ');
dom.unreadMessagesSpan.classList.add(isMuted ? 'unread-muted' : 'unread'); dom.unreadMessagesSpan.classList.add('unread');
} else if(isPinned) { } else if(isPinned) {
dom.unreadMessagesSpan.classList.remove('unread', 'unread-muted'); dom.unreadMessagesSpan.classList.remove('unread');
dom.unreadMessagesSpan.classList.add('tgico-pinnedchat'); dom.unreadMessagesSpan.classList.add('tgico-pinnedchat');
} }
} }

39
src/lib/appManagers/appImManager.ts

@ -23,7 +23,7 @@ import { wrapAlbum, wrapDocument, wrapPhoto, wrapPoll, wrapReply, wrapSticker, w
import mediaSizes from '../../helpers/mediaSizes'; import mediaSizes from '../../helpers/mediaSizes';
import { isTouchSupported } from '../../helpers/touchSupport'; import { isTouchSupported } from '../../helpers/touchSupport';
import { isAndroid, isApple, isSafari } from '../../helpers/userAgent'; import { isAndroid, isApple, isSafari } from '../../helpers/userAgent';
import { InputNotifyPeer, InputPeerNotifySettings } from '../../layer'; import { InputNotifyPeer, InputPeerNotifySettings, NotifyPeer, Update } from '../../layer';
import { logger, LogLevels } from "../logger"; import { logger, LogLevels } from "../logger";
import apiManager from '../mtproto/mtprotoworker'; import apiManager from '../mtproto/mtprotoworker';
import { MOUNT_CLASS_TO } from '../mtproto/mtproto_config'; import { MOUNT_CLASS_TO } from '../mtproto/mtproto_config';
@ -910,7 +910,7 @@ export class AppImManager {
} }
public setPeerStatus(needClear = false) { public setPeerStatus(needClear = false) {
if(!this.myID) return; if(!this.myID || !this.peerID) return;
const profileElements = appSidebarRight.sharedMediaTab.profileElements; const profileElements = appSidebarRight.sharedMediaTab.profileElements;
@ -950,7 +950,7 @@ export class AppImManager {
if(this.myID == this.peerID) { if(this.myID == this.peerID) {
this.subtitleEl.innerText = profileElements.subtitle.innerText = ''; this.subtitleEl.innerText = profileElements.subtitle.innerText = '';
} else if(user && user.status) { } else if(user) {
let subtitle = appUsersManager.getUserStatusString(user.id); let subtitle = appUsersManager.getUserStatusString(user.id);
if(subtitle == 'online') { if(subtitle == 'online') {
@ -2629,7 +2629,19 @@ export class AppImManager {
peer: inputNotifyPeer, peer: inputNotifyPeer,
settings: settings settings: settings
}).then(bool => { }).then(bool => {
this.handleUpdate({_: 'updateNotifySettings', peer: inputNotifyPeer, notify_settings: settings}); if(bool) {
this.handleUpdate({
_: 'updateNotifySettings',
peer: {
_: 'notifyPeer',
peer: appPeersManager.getOutputPeer(peerID)
},
notify_settings: { // ! WOW, IT WORKS !
...settings,
_: 'peerNotifySettings',
}
});
}
}); });
/* return apiManager.invokeApi('account.getNotifySettings', { /* return apiManager.invokeApi('account.getNotifySettings', {
@ -2649,7 +2661,7 @@ export class AppImManager {
} }
public handleUpdate(update: any) { public handleUpdate(update: Update) {
switch(update._) { switch(update._) {
case 'updateUserTyping': case 'updateUserTyping':
case 'updateChatUserTyping': { case 'updateChatUserTyping': {
@ -2661,8 +2673,10 @@ export class AppImManager {
this.typingUsers[update.user_id] = peerID; this.typingUsers[update.user_id] = peerID;
if(!appUsersManager.hasUser(update.user_id)) { if(!appUsersManager.hasUser(update.user_id)) {
if(update.chat_id && appChatsManager.hasChat(update.chat_id) && !appChatsManager.isChannel(update.chat_id)) { if(update._ == 'updateChatUserTyping') {
appProfileManager.getChatFull(update.chat_id); if(update.chat_id && appChatsManager.hasChat(update.chat_id) && !appChatsManager.isChannel(update.chat_id)) {
appProfileManager.getChatFull(update.chat_id);
}
} }
//return; //return;
@ -2698,21 +2712,18 @@ export class AppImManager {
} }
case 'updateNotifySettings': { case 'updateNotifySettings': {
let {peer, notify_settings} = update; const {peer, notify_settings} = update;
// peer was NotifyPeer
peer = peer.peer;
let peerID = appPeersManager.getPeerID(peer); const peerID = appPeersManager.getPeerID((peer as NotifyPeer.notifyPeer).peer);
let dialog = appMessagesManager.getDialogByPeerID(peerID)[0]; const dialog = appMessagesManager.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', peerID);
} }
if(peerID == this.peerID) { if(peerID == this.peerID) {
let muted = notify_settings.mute_until ? new Date(notify_settings.mute_until * 1000) > new Date() : false; const muted = notify_settings.mute_until ? new Date(notify_settings.mute_until * 1000) > new Date() : false;
this.setMutedState(muted); this.setMutedState(muted);
} }

181
src/lib/appManagers/appMessagesManager.ts

@ -1,6 +1,6 @@
import ProgressivePreloader from "../../components/preloader"; import ProgressivePreloader from "../../components/preloader";
import { CancellablePromise, deferredPromise } from "../../helpers/cancellablePromise"; import { CancellablePromise, deferredPromise } from "../../helpers/cancellablePromise";
import { Dialog as MTDialog, DialogFilter, DocumentAttribute, InputMessage, Message, MessagesDialogs, MessagesFilter, MessagesMessages, MessagesPeerDialogs, MethodDeclMap, PhotoSize } from "../../layer"; import { Dialog as MTDialog, DialogFilter, DialogPeer, DocumentAttribute, InputMessage, Message, MessagesDialogs, MessagesFilter, MessagesMessages, MessagesPeerDialogs, MethodDeclMap, PhotoSize, Update } from "../../layer";
import { Modify } from "../../types"; import { Modify } from "../../types";
import { bigint, nextRandomInt } from "../bin_utils"; import { bigint, nextRandomInt } from "../bin_utils";
import { logger } from "../logger"; import { logger } from "../logger";
@ -240,12 +240,12 @@ export class FiltersStorage {
}); });
} }
public handleUpdate(update: any) { public handleUpdate(update: Update) {
switch(update._) { switch(update._) {
case 'updateDialogFilter': { case 'updateDialogFilter': {
//console.log('updateDialogFilter', update); //console.log('updateDialogFilter', update);
if(update.filter) { if(update.filter) {
this.saveDialogFilter(update.filter); this.saveDialogFilter(update.filter as any);
} else if(this.filters[update.id]) { // Папка удалена } else if(this.filters[update.id]) { // Папка удалена
//this.getDialogFilters(true); //this.getDialogFilters(true);
$rootScope.$broadcast('filter_delete', this.filters[update.id]); $rootScope.$broadcast('filter_delete', this.filters[update.id]);
@ -361,7 +361,7 @@ export class FiltersStorage {
this.handleUpdate({ this.handleUpdate({
_: 'updateDialogFilter', _: 'updateDialogFilter',
id: filter.id, id: filter.id,
filter: remove ? undefined : filter filter: remove ? undefined : filter as any
}); });
} }
@ -2521,20 +2521,18 @@ export class AppMessagesManager {
const dialog = this.getDialogByPeerID(peerID)[0]; const dialog = this.getDialogByPeerID(peerID)[0];
if(!dialog) return Promise.reject(); if(!dialog) return Promise.reject();
const peer = appPeersManager.getInputDialogPeerByID(peerID); const pinned = dialog.pFlags?.pinned ? undefined : true;
const flags = dialog.pFlags?.pinned ? 0 : 1;
return apiManager.invokeApi('messages.toggleDialogPin', { return apiManager.invokeApi('messages.toggleDialogPin', {
flags, peer: appPeersManager.getInputDialogPeerByID(peerID),
peer pinned
}).then(bool => { }).then(bool => {
if(bool) { if(bool) {
const pFlags: Update.updateDialogPinned['pFlags'] = pinned ? {pinned} : {};
this.handleUpdate({ this.handleUpdate({
_: 'updateDialogPinned', _: 'updateDialogPinned',
peer: peer, peer: appPeersManager.getDialogPeer(peerID),
pFlags: { folder_id: filterID,
pinned: flags pFlags
}
}); });
} }
}); });
@ -2544,20 +2542,17 @@ export class AppMessagesManager {
const dialog = this.getDialogByPeerID(peerID)[0]; const dialog = this.getDialogByPeerID(peerID)[0];
if(!dialog) return Promise.reject(); if(!dialog) return Promise.reject();
const peer = appPeersManager.getInputDialogPeerByID(peerID); const unread = read || dialog.pFlags?.unread_mark ? undefined : true;
const flags = read || dialog.pFlags?.unread_mark ? 0 : 1;
return apiManager.invokeApi('messages.markDialogUnread', { return apiManager.invokeApi('messages.markDialogUnread', {
flags, peer: appPeersManager.getInputDialogPeerByID(peerID),
peer unread
}).then(bool => { }).then(bool => {
if(bool) { if(bool) {
const pFlags: Update.updateDialogUnreadMark['pFlags'] = unread ? {unread} : {};
this.handleUpdate({ this.handleUpdate({
_: 'updateDialogUnreadMark', _: 'updateDialogUnreadMark',
peer: peer, peer: appPeersManager.getDialogPeer(peerID),
pFlags: { pFlags
unread: flags
}
}); });
} }
}); });
@ -3336,22 +3331,22 @@ export class AppMessagesManager {
}); });
} }
public handleUpdate(update: any) { public handleUpdate(update: Update) {
this.log.debug('AMM: handleUpdate:', update._); this.log.debug('AMM: handleUpdate:', update._);
switch(update._) { switch(update._) {
case 'updateMessageID': { case 'updateMessageID': {
var randomID = update.random_id; const randomID = update.random_id;
var pendingData = this.pendingByRandomID[randomID]; const pendingData = this.pendingByRandomID[randomID];
//this.log('AMM updateMessageID:', update, pendingData); //this.log('AMM updateMessageID:', update, pendingData);
if(pendingData) { if(pendingData) {
var peerID: number = pendingData[0]; const peerID: number = pendingData[0];
var tempID = pendingData[1]; const tempID = pendingData[1];
var channelID = appPeersManager.isChannel(peerID) ? -peerID : 0; const channelID = appPeersManager.isChannel(peerID) ? -peerID : 0;
var mid = appMessagesIDsManager.getFullMessageID(update.id, channelID); const mid = appMessagesIDsManager.getFullMessageID(update.id, channelID);
var message = this.messagesStorage[mid]; const message = this.messagesStorage[mid];
if(message) { if(message) {
var historyStorage = this.historiesStorage[peerID]; const historyStorage = this.historiesStorage[peerID];
var pos = historyStorage.pending.indexOf(tempID); const pos = historyStorage.pending.indexOf(tempID);
if(pos != -1) { if(pos != -1) {
historyStorage.pending.splice(pos, 1); historyStorage.pending.splice(pos, 1);
} }
@ -3367,10 +3362,9 @@ export class AppMessagesManager {
case 'updateNewMessage': case 'updateNewMessage':
case 'updateNewChannelMessage': { case 'updateNewChannelMessage': {
var message = update.message; const message = update.message as MyMessage;
var peerID = this.getMessagePeer(message); const peerID = this.getMessagePeer(message);
var historyStorage = this.historiesStorage[peerID]; const foundDialog = this.getDialogByPeerID(peerID);
let foundDialog = this.getDialogByPeerID(peerID);
if(!foundDialog.length) { if(!foundDialog.length) {
this.newDialogsToHandle[peerID] = {reload: true}; this.newDialogsToHandle[peerID] = {reload: true};
@ -3383,7 +3377,7 @@ export class AppMessagesManager {
} }
if(update._ == 'updateNewChannelMessage') { if(update._ == 'updateNewChannelMessage') {
var chat = appChatsManager.getChat(-peerID); const chat = appChatsManager.getChat(-peerID);
if(chat.pFlags && (chat.pFlags.left || chat.pFlags.kicked)) { if(chat.pFlags && (chat.pFlags.left || chat.pFlags.kicked)) {
break; break;
} }
@ -3392,6 +3386,7 @@ export class AppMessagesManager {
this.saveMessages([message]); this.saveMessages([message]);
// this.log.warn(dT(), 'message unread', message.mid, message.pFlags.unread) // this.log.warn(dT(), 'message unread', message.mid, message.pFlags.unread)
let historyStorage = this.historiesStorage[peerID];
if(historyStorage === undefined) { if(historyStorage === undefined) {
historyStorage = this.historiesStorage[peerID] = { historyStorage = this.historiesStorage[peerID] = {
count: null, count: null,
@ -3400,11 +3395,11 @@ export class AppMessagesManager {
}; };
} }
var history = message.mid > 0 ? historyStorage.history : historyStorage.pending; const history = message.mid > 0 ? historyStorage.history : historyStorage.pending;
if(history.indexOf(message.mid) != -1) { if(history.indexOf(message.mid) != -1) {
return false; return false;
} }
var topMsgID = history[0]; const topMsgID = history[0];
history.unshift(message.mid); history.unshift(message.mid);
if(message.mid > 0 && message.mid < topMsgID) { if(message.mid > 0 && message.mid < topMsgID) {
history.sort((a, b) => { history.sort((a, b) => {
@ -3425,8 +3420,8 @@ export class AppMessagesManager {
appUsersManager.forceUserOnline(appPeersManager.getPeerID(message.from_id)); appUsersManager.forceUserOnline(appPeersManager.getPeerID(message.from_id));
} }
var randomID = this.pendingByMessageID[message.mid], const randomID = this.pendingByMessageID[message.mid];
pendingMessage; let pendingMessage: any;
if(randomID) { if(randomID) {
if(pendingMessage = this.finalizePendingMessage(randomID, message)) { if(pendingMessage = this.finalizePendingMessage(randomID, message)) {
@ -3447,8 +3442,8 @@ export class AppMessagesManager {
} }
} }
var inboxUnread = !message.pFlags.out && message.pFlags.unread; const inboxUnread = !message.pFlags.out && message.pFlags.unread;
var dialog = foundDialog[0]; const dialog = foundDialog[0];
dialog.top_message = message.mid; dialog.top_message = message.mid;
if(inboxUnread) { if(inboxUnread) {
dialog.unread_count++; dialog.unread_count++;
@ -3465,14 +3460,14 @@ export class AppMessagesManager {
case 'updateDialogUnreadMark': { case 'updateDialogUnreadMark': {
this.log('updateDialogUnreadMark', update); this.log('updateDialogUnreadMark', update);
let peerID = appPeersManager.getPeerID(update.peer.peer); const peerID = appPeersManager.getPeerID((update.peer as DialogPeer.dialogPeer).peer);
let foundDialog = this.getDialogByPeerID(peerID); const foundDialog = this.getDialogByPeerID(peerID);
if(!foundDialog.length) { if(!foundDialog.length) {
this.newDialogsToHandle[peerID] = {reload: true}; this.newDialogsToHandle[peerID] = {reload: true};
this.scheduleHandleNewDialogs(); this.scheduleHandleNewDialogs();
} else { } else {
let dialog = foundDialog[0]; const dialog = foundDialog[0];
if(!update.pFlags.unread) { if(!update.pFlags.unread) {
delete dialog.pFlags.unread_mark; delete dialog.pFlags.unread_mark;
@ -3519,7 +3514,7 @@ export class AppMessagesManager {
case 'updateDialogPinned': { case 'updateDialogPinned': {
const folderID = update.folder_id ?? 0; const folderID = update.folder_id ?? 0;
this.log('updateDialogPinned', update); this.log('updateDialogPinned', update);
const peerID = appPeersManager.getPeerID(update.peer.peer); const peerID = appPeersManager.getPeerID((update.peer as DialogPeer.dialogPeer).peer);
const foundDialog = this.getDialogByPeerID(peerID); const foundDialog = this.getDialogByPeerID(peerID);
// этот код внизу никогда не сработает, в папках за пиннед отвечает updateDialogFilter // этот код внизу никогда не сработает, в папках за пиннед отвечает updateDialogFilter
@ -3621,10 +3616,10 @@ export class AppMessagesManager {
case 'updateEditMessage': case 'updateEditMessage':
case 'updateEditChannelMessage': { case 'updateEditChannelMessage': {
var message = update.message; const message = update.message as MyMessage;
var peerID = this.getMessagePeer(message); const peerID = this.getMessagePeer(message);
var channelID = message.peer_id._ == 'peerChannel' ? -peerID : 0; const channelID = message.peer_id._ == 'peerChannel' ? -peerID : 0;
var mid = appMessagesIDsManager.getFullMessageID(message.id, channelID); const mid = appMessagesIDsManager.getFullMessageID(message.id, channelID);
if(this.messagesStorage[mid] === undefined) { if(this.messagesStorage[mid] === undefined) {
break; break;
} }
@ -3633,8 +3628,9 @@ export class AppMessagesManager {
this.saveMessages([message], {isEdited: true}); this.saveMessages([message], {isEdited: true});
safeReplaceObject(this.messagesStorage[mid], message); safeReplaceObject(this.messagesStorage[mid], message);
var dialog = this.getDialogByPeerID(peerID)[0]; const dialog = this.getDialogByPeerID(peerID)[0];
var isTopMessage = dialog && dialog.top_message == mid; const isTopMessage = dialog && dialog.top_message == mid;
// @ts-ignore
if(message.clear_history) { // that's will never happen if(message.clear_history) { // that's will never happen
if(isTopMessage) { if(isTopMessage) {
$rootScope.$broadcast('dialog_flush', {peerID: peerID}); $rootScope.$broadcast('dialog_flush', {peerID: peerID});
@ -3648,7 +3644,7 @@ export class AppMessagesManager {
}); });
if(isTopMessage) { if(isTopMessage) {
var updatedDialogs: {[peerID: number]: Dialog} = {}; const updatedDialogs: {[peerID: number]: Dialog} = {};
updatedDialogs[peerID] = dialog; updatedDialogs[peerID] = dialog;
$rootScope.$broadcast('dialogs_multiupdate', updatedDialogs); $rootScope.$broadcast('dialogs_multiupdate', updatedDialogs);
} }
@ -3660,9 +3656,9 @@ export class AppMessagesManager {
case 'updateReadHistoryOutbox': case 'updateReadHistoryOutbox':
case 'updateReadChannelInbox': case 'updateReadChannelInbox':
case 'updateReadChannelOutbox': { case 'updateReadChannelOutbox': {
const channelID: number = update.channel_id; const channelID: number = (update as Update.updateReadChannelInbox).channel_id;
const maxID = appMessagesIDsManager.getFullMessageID(update.max_id, channelID); const maxID = appMessagesIDsManager.getFullMessageID(update.max_id, channelID);
const peerID = channelID ? -channelID : appPeersManager.getPeerID(update.peer); const peerID = channelID ? -channelID : appPeersManager.getPeerID((update as Update.updateReadHistoryInbox).peer);
const isOut = update._ == 'updateReadHistoryOutbox' || update._ == 'updateReadChannelOutbox' ? true : undefined; const isOut = update._ == 'updateReadHistoryOutbox' || update._ == 'updateReadChannelOutbox' ? true : undefined;
const foundDialog = this.getDialogByPeerID(peerID)[0]; const foundDialog = this.getDialogByPeerID(peerID)[0];
const history = getObjectKeysAndSort(this.messagesStorageByPeerID[peerID] || {}, 'desc'); const history = getObjectKeysAndSort(this.messagesStorageByPeerID[peerID] || {}, 'desc');
@ -3753,10 +3749,10 @@ export class AppMessagesManager {
} }
case 'updateChannelAvailableMessages': { case 'updateChannelAvailableMessages': {
var channelID: number = update.channel_id; const channelID: number = update.channel_id;
var messages: any[] = []; const messages: number[] = [];
var peerID: number = -channelID; const peerID: number = -channelID;
var history = (this.historiesStorage[peerID] || {}).history || []; const history = (this.historiesStorage[peerID] || {}).history || [];
if(history.length) { if(history.length) {
history.forEach((msgID: number) => { history.forEach((msgID: number) => {
if(!update.available_min_id || if(!update.available_min_id ||
@ -3765,24 +3761,26 @@ export class AppMessagesManager {
} }
}); });
} }
update.messages = messages;
(update as any as Update.updateDeleteChannelMessages).messages = messages;
} }
case 'updateDeleteMessages': case 'updateDeleteMessages':
case 'updateDeleteChannelMessages': { case 'updateDeleteChannelMessages': {
let historiesUpdated: {[peerID: number]: {count: number, unread: number, msgs: {[mid: number]: true}}} = {}; const historiesUpdated: {[peerID: number]: {count: number, unread: number, msgs: {[mid: number]: true}}} = {};
let channelID: number = update.channel_id; const channelID: number = (update as Update.updateDeleteChannelMessages).channel_id;
const messages = (update as any as Update.updateDeleteChannelMessages).messages;
for(let i = 0; i < update.messages.length; i++) { for(let i = 0; i < messages.length; i++) {
let messageID = appMessagesIDsManager.getFullMessageID(update.messages[i], channelID); const messageID = appMessagesIDsManager.getFullMessageID(messages[i], channelID);
let message: MyMessage = this.messagesStorage[messageID]; const message: MyMessage = this.messagesStorage[messageID];
if(message) { if(message) {
let peerID = this.getMessagePeer(message); const peerID = this.getMessagePeer(message);
let history = historiesUpdated[peerID] || (historiesUpdated[peerID] = {count: 0, unread: 0, msgs: {}}); const history = historiesUpdated[peerID] || (historiesUpdated[peerID] = {count: 0, unread: 0, msgs: {}});
if((message as Message.message).media) { if((message as Message.message).media) {
// @ts-ignore // @ts-ignore
let c = message.media.webpage || message.media; const c = message.media.webpage || message.media;
const smth = c.photo || c.document; const smth = c.photo || c.document;
if(smth?.file_reference) { if(smth?.file_reference) {
@ -3806,9 +3804,9 @@ export class AppMessagesManager {
date: message.date date: message.date
}; };
let peerMessagesToHandle = this.newMessagesToHandle[peerID]; const peerMessagesToHandle = this.newMessagesToHandle[peerID];
if(peerMessagesToHandle && peerMessagesToHandle.length) { if(peerMessagesToHandle && peerMessagesToHandle.length) {
let peerMessagesHandlePos = peerMessagesToHandle.indexOf(messageID); const peerMessagesHandlePos = peerMessagesToHandle.indexOf(messageID);
if(peerMessagesHandlePos != -1) { if(peerMessagesHandlePos != -1) {
peerMessagesToHandle.splice(peerMessagesHandlePos); peerMessagesToHandle.splice(peerMessagesHandlePos);
} }
@ -3818,11 +3816,11 @@ export class AppMessagesManager {
Object.keys(historiesUpdated).forEach(_peerID => { Object.keys(historiesUpdated).forEach(_peerID => {
const peerID = +_peerID; const peerID = +_peerID;
let updatedData = historiesUpdated[peerID]; const updatedData = historiesUpdated[peerID];
let historyStorage = this.historiesStorage[peerID]; const historyStorage = this.historiesStorage[peerID];
if(historyStorage !== undefined) { if(historyStorage !== undefined) {
let newHistory: number[] = []; const newHistory: number[] = [];
let newPending: number[] = []; const newPending: number[] = [];
for(let i = 0; i < historyStorage.history.length; i++) { for(let i = 0; i < historyStorage.history.length; i++) {
if(!updatedData.msgs[historyStorage.history[i]]) { if(!updatedData.msgs[historyStorage.history[i]]) {
newHistory.push(historyStorage.history[i]); newHistory.push(historyStorage.history[i]);
@ -3838,9 +3836,9 @@ export class AppMessagesManager {
} }
} }
for(let i = 0; i < historyStorage.pending.length; i++) { for(const mid of historyStorage.pending) {
if(!updatedData.msgs[historyStorage.pending[i]]) { if(!updatedData.msgs[mid]) {
newPending.push(historyStorage.pending[i]); newPending.push(mid);
} }
} }
historyStorage.pending = newPending; historyStorage.pending = newPending;
@ -3848,7 +3846,7 @@ export class AppMessagesManager {
$rootScope.$broadcast('history_delete', {peerID, msgs: updatedData.msgs}); $rootScope.$broadcast('history_delete', {peerID, msgs: updatedData.msgs});
} }
let foundDialog = this.getDialogByPeerID(peerID)[0]; const foundDialog = this.getDialogByPeerID(peerID)[0];
if(foundDialog) { if(foundDialog) {
if(updatedData.unread) { if(updatedData.unread) {
foundDialog.unread_count -= updatedData.unread; foundDialog.unread_count -= updatedData.unread;
@ -3899,7 +3897,9 @@ export class AppMessagesManager {
break; break;
} }
// @ts-ignore
case 'updateChannelReload': { case 'updateChannelReload': {
// @ts-ignore
const channelID: number = update.channel_id; const channelID: number = update.channel_id;
const peerID = -channelID; const peerID = -channelID;
@ -3914,9 +3914,9 @@ export class AppMessagesManager {
} }
case 'updateChannelMessageViews': { case 'updateChannelMessageViews': {
let views = update.views; const views = update.views;
let mid = appMessagesIDsManager.getFullMessageID(update.id, update.channel_id); const mid = appMessagesIDsManager.getFullMessageID(update.id, update.channel_id);
let message = this.getMessage(mid); const message = this.getMessage(mid);
if(message && message.views && message.views < views) { if(message && message.views && message.views < views) {
message.views = views; message.views = views;
$rootScope.$broadcast('message_views', {mid, views}); $rootScope.$broadcast('message_views', {mid, views});
@ -3926,10 +3926,10 @@ export class AppMessagesManager {
case 'updateServiceNotification': { case 'updateServiceNotification': {
this.log('updateServiceNotification', update); this.log('updateServiceNotification', update);
var fromID = 777000; const fromID = 777000;
var peerID = fromID; const peerID = fromID;
var messageID = this.tempID--; const messageID = this.tempID--;
var message: any = { const message: any = {
_: 'message', _: 'message',
id: messageID, id: messageID,
from_id: appPeersManager.getOutputPeer(fromID), from_id: appPeersManager.getOutputPeer(fromID),
@ -3957,19 +3957,18 @@ export class AppMessagesManager {
this.handleUpdate({ this.handleUpdate({
_: 'updateNewMessage', _: 'updateNewMessage',
message: message message: message
}); } as any);
} }
break; break;
} }
case 'updateChannelPinnedMessage':
case 'updateChatPinnedMessage': case 'updateChatPinnedMessage':
case 'updateUserPinnedMessage': { case 'updateUserPinnedMessage': {
let {id} = update;
// hz nado li tut appMessagesIDsManager.getFullMessageID(update.max_id, channelID); // hz nado li tut appMessagesIDsManager.getFullMessageID(update.max_id, channelID);
let peerID = update.user_id || -update.chat_id || -update.channel_id; const peerID = appPeersManager.getPeerID(update);
this.savePinnedMessage(peerID, id); this.savePinnedMessage(peerID, update.id);
break; break;
} }

17
src/lib/appManagers/appPeersManager.ts

@ -1,9 +1,9 @@
import appUsersManager from "./appUsersManager"; import { DialogPeer, InputDialogPeer, InputPeer, Peer } from "../../layer";
import appChatsManager from "./appChatsManager";
import { isObject } from "../utils";
import { RichTextProcessor } from "../richtextprocessor"; import { RichTextProcessor } from "../richtextprocessor";
import { InputPeer, InputDialogPeer, Peer } from "../../layer"; import { isObject } from "../utils";
import appChatsManager from "./appChatsManager";
import appStateManager from "./appStateManager"; import appStateManager from "./appStateManager";
import appUsersManager from "./appUsersManager";
// https://github.com/eelcohn/Telegram-API/wiki/Calculating-color-for-a-Telegram-user-on-IRC // https://github.com/eelcohn/Telegram-API/wiki/Calculating-color-for-a-Telegram-user-on-IRC
/* /*
@ -66,7 +66,7 @@ export class AppPeersManager {
if(peer.first_name) title += peer.first_name; if(peer.first_name) title += peer.first_name;
if(peer.last_name) title += ' ' + peer.last_name; if(peer.last_name) title += ' ' + peer.last_name;
if(!title) title = peer.pFlags.deleted ? 'Deleted account' : peer.username; if(!title) title = peer.pFlags.deleted ? 'Deleted Account' : peer.username;
else title = title.trim(); else title = title.trim();
} else { } else {
title = peer.title; title = peer.title;
@ -123,6 +123,13 @@ export class AppPeersManager {
return isUser ? peerParams[0] : -peerParams[0] || 0; return isUser ? peerParams[0] : -peerParams[0] || 0;
} }
public getDialogPeer(peerID: number): DialogPeer {
return {
_: 'dialogPeer',
peer: this.getOutputPeer(peerID)
};
}
public isChannel(peerID: number): boolean { public isChannel(peerID: number): boolean {
return (peerID < 0) && appChatsManager.isChannel(-peerID); return (peerID < 0) && appChatsManager.isChannel(-peerID);
} }

32
src/lib/appManagers/appUsersManager.ts

@ -1,15 +1,15 @@
import { safeReplaceObject, isObject, tsNow, getAbbreviation } from "../utils"; import { formatPhoneNumber } from "../../components/misc";
import { RichTextProcessor } from "../richtextprocessor"; import { InputUser, Update, User as MTUser } from "../../layer";
import appChatsManager from "./appChatsManager";
//import apiManager from '../mtproto/apiManager'; //import apiManager from '../mtproto/apiManager';
import apiManager from '../mtproto/mtprotoworker'; import apiManager from '../mtproto/mtprotoworker';
import serverTimeManager from "../mtproto/serverTimeManager"; import serverTimeManager from "../mtproto/serverTimeManager";
import { formatPhoneNumber } from "../../components/misc"; import { RichTextProcessor } from "../richtextprocessor";
import $rootScope from "../rootScope";
import searchIndexManager from "../searchIndexManager"; import searchIndexManager from "../searchIndexManager";
import { getAbbreviation, isObject, safeReplaceObject, tsNow } from "../utils";
import appChatsManager from "./appChatsManager";
import appPeersManager from "./appPeersManager"; import appPeersManager from "./appPeersManager";
import appStateManager from "./appStateManager"; import appStateManager from "./appStateManager";
import { InputUser, User as MTUser } from "../../layer";
import $rootScope from "../rootScope";
/* export type User = { /* export type User = {
_: 'user', _: 'user',
@ -65,12 +65,12 @@ export class AppUsersManager {
$rootScope.$on('stateSynchronized', this.updateUsersStatuses.bind(this)); $rootScope.$on('stateSynchronized', this.updateUsersStatuses.bind(this));
$rootScope.$on('apiUpdate', (e) => { $rootScope.$on('apiUpdate', (e) => {
let update = e.detail; const update = e.detail as Update;
//console.log('on apiUpdate', update); //console.log('on apiUpdate', update);
switch(update._) { switch(update._) {
case 'updateUserStatus': case 'updateUserStatus':
var userID = update.user_id; const userID = update.user_id;
var user = this.users[userID]; const user = this.users[userID];
if(user) { if(user) {
user.status = update.status; user.status = update.status;
if(user.status) { if(user.status) {
@ -88,9 +88,9 @@ export class AppUsersManager {
} //////else console.warn('No user by id:', userID); } //////else console.warn('No user by id:', userID);
break; break;
case 'updateUserPhoto': case 'updateUserPhoto': {
var userID = update.user_id; const userID = update.user_id;
var user = this.users[userID]; const user = this.users[userID];
if(user) { if(user) {
this.forceUserOnline(userID); this.forceUserOnline(userID);
if(!user.photo) { if(!user.photo) {
@ -107,7 +107,10 @@ export class AppUsersManager {
$rootScope.$broadcast('user_update', userID); $rootScope.$broadcast('user_update', userID);
$rootScope.$broadcast('avatar_update', userID); $rootScope.$broadcast('avatar_update', userID);
} else console.warn('No user by id:', userID); } else console.warn('No user by id:', userID);
break
break;
}
/* case 'updateContactLink': /* case 'updateContactLink':
this.onContactUpdated(update.user_id, update.my_link._ == 'contactLinkContact'); this.onContactUpdated(update.user_id, update.my_link._ == 'contactLinkContact');
@ -470,7 +473,8 @@ export class AppUsersManager {
user.status && user.status &&
user.status._ != 'userStatusOnline' && user.status._ != 'userStatusOnline' &&
user.status._ != 'userStatusEmpty' && user.status._ != 'userStatusEmpty' &&
!user.pFlags.support) { !user.pFlags.support &&
!user.pFlags.deleted) {
user.status = { user.status = {
_: 'userStatusOnline', _: 'userStatusOnline',

4
src/lib/rootScope.ts

@ -1,4 +1,4 @@
import type { StickerSet } from "../layer"; import type { StickerSet, Update } from "../layer";
import type { MyDocument } from "./appManagers/appDocsManager"; import type { MyDocument } from "./appManagers/appDocsManager";
import type { AppMessagesManager, Dialog, MyDialogFilter } from "./appManagers/appMessagesManager"; import type { AppMessagesManager, Dialog, MyDialogFilter } from "./appManagers/appMessagesManager";
import type { Poll, PollResults } from "./appManagers/appPollsManager"; import type { Poll, PollResults } from "./appManagers/appPollsManager";
@ -55,7 +55,7 @@ type BroadcastEvents = {
'channel_settings': {channelID: number}, 'channel_settings': {channelID: number},
'webpage_updated': {id: string, msgs: number[]}, 'webpage_updated': {id: string, msgs: number[]},
'apiUpdate': any, 'apiUpdate': Update,
'download_progress': any, 'download_progress': any,
//'draft_updated': any, //'draft_updated': any,
}; };

16
src/scss/partials/_chatlist.scss

@ -118,8 +118,13 @@
margin-left: .125rem; margin-left: .125rem;
display: inline-block; display: inline-block;
height: 29px; height: 29px;
animation: fade-in-opacity .2s ease forwards;
} }
} }
&.backwards .user-title:after {
animation: fade-in-backwards-opacity .2s ease forwards;
}
} }
} }
@ -299,7 +304,7 @@
} }
} }
.unread, .unread-muted, .tgico-pinnedchat { .unread, .tgico-pinnedchat {
height: 24px; height: 24px;
text-align: center; text-align: center;
line-height: 24px; line-height: 24px;
@ -310,10 +315,11 @@
flex: 0 0 auto; flex: 0 0 auto;
} }
.unread, .unread-muted { .unread {
min-width: 24px; min-width: 24px;
padding: 0 8px; padding: 0 8px;
font-weight: 500; font-weight: 500;
transition: .2s background-color;
} }
.tgico-pinnedchat { .tgico-pinnedchat {
@ -321,15 +327,15 @@
font-size: 1.5rem; font-size: 1.5rem;
} }
.unread:empty, .unread-muted:empty { .unread:empty {
visibility: hidden; visibility: hidden;
} }
.unread { .unread, li.is-muted.backwards .unread {
background: $color-green; background: $color-green;
} }
.unread-muted, .tgico-pinnedchat { li.is-muted .unread, .tgico-pinnedchat {
background: #c5c9cc; background: #c5c9cc;
} }

2
src/scss/partials/_rightSidebar.scss

@ -229,7 +229,7 @@
} }
&.tgico-avatar_deletedaccount { &.tgico-avatar_deletedaccount {
font-size: 6rem; font-size: 6rem !important;
} }
} }

Loading…
Cancel
Save