Browse Source

Cancel user typing on new message

master
Eduard Kuzmenko 3 years ago
parent
commit
6dd0153e54
  1. 4
      src/helpers/string.ts
  2. 9
      src/lib/appManagers/apiUpdatesManager.ts
  3. 33
      src/lib/appManagers/appChatsManager.ts
  4. 173
      src/lib/appManagers/appMessagesManager.ts
  5. 23
      src/lib/appManagers/appNotificationsManager.ts
  6. 25
      src/lib/appManagers/appPrivacyManager.ts
  7. 15
      src/lib/appManagers/appProfileManager.ts
  8. 11
      src/lib/appManagers/appUsersManager.ts

4
src/helpers/string.ts

@ -94,9 +94,9 @@ export function splitStringByLength(str: string, maxLength: number) {
//(window as any).checkRTL = checkRTL; //(window as any).checkRTL = checkRTL;
export function convertInputKeyToKey(inputKey: string) { export function convertInputKeyToKey<T extends string>(inputKey: string) {
const str = inputKey.replace('input', ''); const str = inputKey.replace('input', '');
return (str[0].toLowerCase() + str.slice(1)) as string; return (str[0].toLowerCase() + str.slice(1)) as T;
} }
export function convertKeyToInputKey(key: string) { export function convertKeyToInputKey(key: string) {

9
src/lib/appManagers/apiUpdatesManager.ts

@ -11,7 +11,7 @@
//import apiManager from '../mtproto/apiManager'; //import apiManager from '../mtproto/apiManager';
import DEBUG, { MOUNT_CLASS_TO } from '../../config/debug'; import DEBUG, { MOUNT_CLASS_TO } from '../../config/debug';
import { Update } from '../../layer'; import { Update, Updates } from '../../layer';
import { logger, LogTypes } from '../logger'; import { logger, LogTypes } from '../logger';
import apiManager from '../mtproto/mtprotoworker'; import apiManager from '../mtproto/mtprotoworker';
import rootScope from '../rootScope'; import rootScope from '../rootScope';
@ -165,6 +165,13 @@ export class ApiUpdatesManager {
} }
} }
public processLocalUpdate(update: Update) {
this.processUpdateMessage({
_: 'updateShort',
update
} as Updates);
}
public processUpdateMessage = (updateMessage: any, options: Partial<{ public processUpdateMessage = (updateMessage: any, options: Partial<{
override: boolean override: boolean
}> = {}) => { }> = {}) => {

33
src/lib/appManagers/appChatsManager.ts

@ -658,25 +658,22 @@ export class AppChatsManager {
if(typeof(participant) !== 'number') { if(typeof(participant) !== 'number') {
const timestamp = Date.now() / 1000 | 0; const timestamp = Date.now() / 1000 | 0;
apiUpdatesManager.processUpdateMessage({ apiUpdatesManager.processLocalUpdate({
_: 'updateShort', _: 'updateChannelParticipant',
update: { channel_id: id,
_: 'updateChannelParticipant', date: timestamp,
channel_id: id, actor_id: undefined,
qts: undefined,
user_id: peerId,
prev_participant: participant,
new_participant: Object.keys(banned_rights.pFlags).length ? {
_: 'channelParticipantBanned',
date: timestamp, date: timestamp,
actor_id: undefined, banned_rights,
qts: undefined, kicked_by: appUsersManager.getSelf().id,
user_id: peerId, peer: appPeersManager.getOutputPeer(peerId),
prev_participant: participant, pFlags: {}
new_participant: Object.keys(banned_rights.pFlags).length ? { } : undefined
_: 'channelParticipantBanned',
date: timestamp,
banned_rights,
kicked_by: appUsersManager.getSelf().id,
peer: appPeersManager.getOutputPeer(peerId),
pFlags: {}
} : undefined
} as Update.updateChannelParticipant
}); });
} }
}); });

173
src/lib/appManagers/appMessagesManager.ts

@ -17,7 +17,7 @@ import { createPosterForVideo } from "../../helpers/files";
import { copy, getObjectKeysAndSort } from "../../helpers/object"; import { copy, getObjectKeysAndSort } from "../../helpers/object";
import { randomLong } from "../../helpers/random"; import { randomLong } from "../../helpers/random";
import { splitStringByLength, limitSymbols, escapeRegExp } from "../../helpers/string"; import { splitStringByLength, limitSymbols, escapeRegExp } from "../../helpers/string";
import { Chat, ChatFull, Dialog as MTDialog, DialogPeer, DocumentAttribute, InputMedia, InputMessage, InputPeerNotifySettings, InputSingleMedia, Message, MessageAction, MessageEntity, MessageFwdHeader, MessageMedia, MessageReplies, MessageReplyHeader, MessagesDialogs, MessagesFilter, MessagesMessages, MethodDeclMap, NotifyPeer, PeerNotifySettings, PhotoSize, SendMessageAction, Update, Photo, Updates, ReplyMarkup } from "../../layer"; import { Chat, ChatFull, Dialog as MTDialog, DialogPeer, DocumentAttribute, InputMedia, InputMessage, InputPeerNotifySettings, InputSingleMedia, Message, MessageAction, MessageEntity, MessageFwdHeader, MessageMedia, MessageReplies, MessageReplyHeader, MessagesDialogs, MessagesFilter, MessagesMessages, MethodDeclMap, NotifyPeer, PeerNotifySettings, PhotoSize, SendMessageAction, Update, Photo, Updates, ReplyMarkup, InputPeer } from "../../layer";
import { InvokeApiOptions } from "../../types"; import { InvokeApiOptions } from "../../types";
import I18n, { i18n, join, langPack, LangPackKey, _i18n } from "../langPack"; import I18n, { i18n, join, langPack, LangPackKey, _i18n } from "../langPack";
import { logger, LogTypes } from "../logger"; import { logger, LogTypes } from "../logger";
@ -1562,12 +1562,11 @@ export class AppMessagesManager {
const {peerId, tempId, storage} = pendingData; const {peerId, tempId, storage} = pendingData;
const historyStorage = this.getHistoryStorage(peerId); const historyStorage = this.getHistoryStorage(peerId);
apiUpdatesManager.processUpdateMessage({ apiUpdatesManager.processLocalUpdate({
_: 'updateShort', _: 'updateDeleteMessages',
update: { messages: [tempId],
_: 'updateDeleteMessages', pts: undefined,
messages: [tempId] pts_count: undefined
}
}); });
historyStorage.history.delete(tempId); historyStorage.history.delete(tempId);
@ -1983,11 +1982,11 @@ export class AppMessagesManager {
}); });
} }
private doFlushHistory(inputPeer: any, justClear?: boolean, revoke?: boolean): Promise<true> { private doFlushHistory(peer: InputPeer, just_clear?: boolean, revoke?: boolean): Promise<true> {
return apiManager.invokeApiSingle('messages.deleteHistory', { return apiManager.invokeApiSingle('messages.deleteHistory', {
just_clear: justClear, just_clear,
revoke: revoke, revoke,
peer: inputPeer, peer,
max_id: 0 max_id: 0
}).then((affectedHistory) => { }).then((affectedHistory) => {
apiUpdatesManager.processUpdateMessage({ apiUpdatesManager.processUpdateMessage({
@ -2003,7 +2002,7 @@ export class AppMessagesManager {
return true; return true;
} }
return this.doFlushHistory(inputPeer, justClear); return this.doFlushHistory(peer, just_clear);
}); });
} }
@ -2019,13 +2018,10 @@ export class AppMessagesManager {
channel: appChatsManager.getChannelInput(channelId), channel: appChatsManager.getChannelInput(channelId),
max_id: maxId max_id: maxId
}).then(() => { }).then(() => {
apiUpdatesManager.processUpdateMessage({ apiUpdatesManager.processLocalUpdate({
_: 'updateShort', _: 'updateChannelAvailableMessages',
update: { channel_id: channelId,
_: 'updateChannelAvailableMessages', available_min_id: maxId
channel_id: channelId,
available_min_id: maxId
} as Update.updateChannelAvailableMessages
}); });
return true; return true;
@ -2277,7 +2273,7 @@ export class AppMessagesManager {
if(message.replies.read_max_id) message.replies.read_max_id = this.generateMessageId(message.replies.read_max_id); if(message.replies.read_max_id) message.replies.read_max_id = this.generateMessageId(message.replies.read_max_id);
} }
const overwriting = !!message.peerId; const overwriting = !!peerId;
if(!overwriting) { if(!overwriting) {
message.date -= serverTimeManager.serverTimeOffset; message.date -= serverTimeManager.serverTimeOffset;
} }
@ -2286,7 +2282,7 @@ export class AppMessagesManager {
const myId = appUsersManager.getSelf().id; const myId = appUsersManager.getSelf().id;
message.peerId = peerId; message.peerId = peerId;
if(message.peerId === myId/* && !message.from_id && !message.fwd_from */) { if(peerId === myId/* && !message.from_id && !message.fwd_from */) {
message.fromId = message.fwd_from ? (message.fwd_from.from_id ? appPeersManager.getPeerId(message.fwd_from.from_id) : 0) : myId; message.fromId = message.fwd_from ? (message.fwd_from.from_id ? appPeersManager.getPeerId(message.fwd_from.from_id) : 0) : myId;
} else { } else {
//message.fromId = message.pFlags.post || (!message.pFlags.out && !message.from_id) ? peerId : appPeersManager.getPeerId(message.from_id); //message.fromId = message.pFlags.post || (!message.pFlags.out && !message.from_id) ? peerId : appPeersManager.getPeerId(message.from_id);
@ -2396,7 +2392,7 @@ export class AppMessagesManager {
let type: string; let type: string;
if(action.duration === undefined) { if(action.duration === undefined) {
type = 'started'; type = 'started';
if(message.peerId !== message.fromId) { if(peerId !== message.fromId) {
type += '_by' + suffix; type += '_by' + suffix;
} }
} else { } else {
@ -3553,15 +3549,12 @@ export class AppMessagesManager {
channel: appChatsManager.getChannelInput(channelId), channel: appChatsManager.getChannelInput(channelId),
id: localMessageIds id: localMessageIds
}).then((affectedMessages) => { }).then((affectedMessages) => {
apiUpdatesManager.processUpdateMessage({ apiUpdatesManager.processLocalUpdate({
_: 'updateShort', _: 'updateDeleteChannelMessages',
update: { channel_id: channelId,
_: 'updateDeleteChannelMessages', messages: mids,
channel_id: channelId, pts: affectedMessages.pts,
messages: mids, pts_count: affectedMessages.pts_count
pts: affectedMessages.pts,
pts_count: affectedMessages.pts_count
}
}); });
}); });
} else { } else {
@ -3569,14 +3562,11 @@ export class AppMessagesManager {
revoke, revoke,
id: localMessageIds id: localMessageIds
}).then((affectedMessages) => { }).then((affectedMessages) => {
apiUpdatesManager.processUpdateMessage({ apiUpdatesManager.processLocalUpdate({
_: 'updateShort', _: 'updateDeleteMessages',
update: { messages: mids,
_: 'updateDeleteMessages', pts: affectedMessages.pts,
messages: mids, pts_count: affectedMessages.pts_count
pts: affectedMessages.pts,
pts_count: affectedMessages.pts_count
}
}); });
}); });
} }
@ -3610,14 +3600,11 @@ export class AppMessagesManager {
}); });
} }
apiUpdatesManager.processUpdateMessage({ apiUpdatesManager.processLocalUpdate({
_: 'updateShort', _: 'updateReadChannelDiscussionInbox',
update: { channel_id: -peerId,
_: 'updateReadChannelDiscussionInbox', top_msg_id: threadId,
channel_id: -peerId, read_max_id: maxId
top_msg_id: threadId,
read_max_id: maxId
} as Update.updateReadChannelDiscussionInbox
}); });
} else if(appPeersManager.isChannel(peerId)) { } else if(appPeersManager.isChannel(peerId)) {
if(!historyStorage.readPromise) { if(!historyStorage.readPromise) {
@ -3627,13 +3614,12 @@ export class AppMessagesManager {
}); });
} }
apiUpdatesManager.processUpdateMessage({ apiUpdatesManager.processLocalUpdate({
_: 'updateShort', _: 'updateReadChannelInbox',
update: { max_id: maxId,
_: 'updateReadChannelInbox', channel_id: -peerId,
max_id: maxId, still_unread_count: undefined,
channel_id: -peerId pts: undefined
} as Update.updateReadChannelInbox
}); });
} else { } else {
if(!historyStorage.readPromise) { if(!historyStorage.readPromise) {
@ -3652,13 +3638,13 @@ export class AppMessagesManager {
}); });
} }
apiUpdatesManager.processUpdateMessage({ apiUpdatesManager.processLocalUpdate({
_: 'updateShort', _: 'updateReadHistoryInbox',
update: { max_id: maxId,
_: 'updateReadHistoryInbox', peer: appPeersManager.getOutputPeer(peerId),
max_id: maxId, still_unread_count: undefined,
peer: appPeersManager.getOutputPeer(peerId) pts: undefined,
} as Update.updateReadHistoryInbox pts_count: undefined
}); });
} }
@ -3698,27 +3684,21 @@ export class AppMessagesManager {
channel: appChatsManager.getChannelInput(channelId), channel: appChatsManager.getChannelInput(channelId),
id: msgIds id: msgIds
}).then(() => { }).then(() => {
apiUpdatesManager.processUpdateMessage({ apiUpdatesManager.processLocalUpdate({
_: 'updateShort', _: 'updateChannelReadMessagesContents',
update: { channel_id: channelId,
_: 'updateChannelReadMessagesContents', messages: msgIds
channel_id: channelId,
messages: msgIds
} as Update.updateChannelReadMessagesContents
}); });
}); });
} else { } else {
apiManager.invokeApi('messages.readMessageContents', { apiManager.invokeApi('messages.readMessageContents', {
id: msgIds id: msgIds
}).then((affectedMessages) => { }).then((affectedMessages) => {
apiUpdatesManager.processUpdateMessage({ apiUpdatesManager.processLocalUpdate({
_: 'updateShort', _: 'updateReadMessagesContents',
update: { messages: msgIds,
_: 'updateReadMessagesContents', pts: affectedMessages.pts,
messages: msgIds, pts_count: affectedMessages.pts_count
pts: affectedMessages.pts,
pts_count: affectedMessages.pts_count
} as Update.updateReadMessagesContents
}); });
}); });
} }
@ -3887,8 +3867,39 @@ export class AppMessagesManager {
rootScope.dispatchEvent('history_reply_markup', {peerId}); rootScope.dispatchEvent('history_reply_markup', {peerId});
} }
if(message.fromId > 0 && !message.pFlags.out && message.from_id) { const fromId = message.fromId;
appUsersManager.forceUserOnline(message.fromId, message.date); if(fromId > 0 && !message.pFlags.out && message.from_id) {
appUsersManager.forceUserOnline(fromId, message.date);
const action: SendMessageAction = {
_: 'sendMessageCancelAction'
};
let update: Update.updateUserTyping | Update.updateChatUserTyping | Update.updateChannelUserTyping;
if(peerId > 0) {
update = {
_: 'updateUserTyping',
action,
user_id: fromId
};
} else if(appPeersManager.isChannel(peerId)) {
update = {
_: 'updateChannelUserTyping',
action,
channel_id: -peerId,
from_id: appPeersManager.getOutputPeer(fromId),
top_msg_id: threadId ? this.getServerMessageId(threadId) : undefined
};
} else {
update = {
_: 'updateChatUserTyping',
action,
chat_id: -peerId,
from_id: appPeersManager.getOutputPeer(fromId)
};
}
apiUpdatesManager.processLocalUpdate(update);
} }
if(!pendingMessage) { if(!pendingMessage) {
@ -3908,7 +3919,7 @@ export class AppMessagesManager {
} }
if(inboxUnread/* && ($rootScope.selectedPeerID != peerID || $rootScope.idle.isIDLE) */) { if(inboxUnread/* && ($rootScope.selectedPeerID != peerID || $rootScope.idle.isIDLE) */) {
const notifyPeer = message.peerId; const notifyPeer = peerId;
let notifyPeerToHandle = this.notificationsToHandle[notifyPeer]; let notifyPeerToHandle = this.notificationsToHandle[notifyPeer];
if(notifyPeerToHandle === undefined) { if(notifyPeerToHandle === undefined) {
notifyPeerToHandle = this.notificationsToHandle[notifyPeer] = { notifyPeerToHandle = this.notificationsToHandle[notifyPeer] = {
@ -3917,8 +3928,8 @@ export class AppMessagesManager {
}; };
} }
if(notifyPeerToHandle.fromId !== message.fromId) { if(notifyPeerToHandle.fromId !== fromId) {
notifyPeerToHandle.fromId = message.fromId; notifyPeerToHandle.fromId = fromId;
notifyPeerToHandle.fwdCount = 0; notifyPeerToHandle.fwdCount = 0;
} }

23
src/lib/appManagers/appNotificationsManager.ts

@ -353,19 +353,16 @@ export class AppNotificationsManager {
settings settings
}).then(value => { }).then(value => {
if(value) { if(value) {
apiUpdatesManager.processUpdateMessage({ apiUpdatesManager.processLocalUpdate({
_: 'updateShort', _: 'updateNotifySettings',
update: { peer: {
_: 'updateNotifySettings', ...peer as any,
peer: { _: convertInputKeyToKey(peer._)
...peer, },
_: convertInputKeyToKey(peer._) notify_settings: { // ! WOW, IT WORKS !
}, ...settings,
notify_settings: { // ! WOW, IT WORKS ! _: 'peerNotifySettings',
...settings, }
_: 'peerNotifySettings',
}
} as Update.updateNotifySettings
}); });
} }
}); });

25
src/lib/appManagers/appPrivacyManager.ts

@ -44,20 +44,17 @@ export class AppPrivacyManager {
appUsersManager.saveApiUsers(privacyRules.users); appUsersManager.saveApiUsers(privacyRules.users);
appChatsManager.saveApiChats(privacyRules.chats); appChatsManager.saveApiChats(privacyRules.chats);
apiUpdatesManager.processUpdateMessage({ apiUpdatesManager.processLocalUpdate({
_: 'updateShort', _: 'updatePrivacy',
update: { key: {
_: 'updatePrivacy', _: convertInputKeyToKey(inputKey)
key: { },
_: convertInputKeyToKey(inputKey) rules: rules.map(inputRule => {
}, const rule: PrivacyRule = {} as any;
rules: rules.map(inputRule => { Object.assign(rule, inputRule);
const rule: PrivacyRule = {} as any; rule._ = convertInputKeyToKey(rule._) as any;
Object.assign(rule, inputRule); return rule;
rule._ = convertInputKeyToKey(rule._) as any; })
return rule;
})
} as Update.updatePrivacy
}); });
//console.log('privacy rules', inputKey, privacyRules, privacyRules.rules); //console.log('privacy rules', inputKey, privacyRules, privacyRules.rules);

15
src/lib/appManagers/appProfileManager.ts

@ -451,15 +451,12 @@ export class AppProfileManager {
peerId: myId peerId: myId
}); });
apiUpdatesManager.processUpdateMessage({ apiUpdatesManager.processLocalUpdate({
_: 'updateShort', _: 'updateUserPhoto',
update: { user_id: myId,
_: 'updateUserPhoto', date: tsNow(true),
user_id: myId, photo: appUsersManager.getUser(myId).photo,
date: tsNow(true), previous: true
photo: appUsersManager.getUser(myId).photo,
previous: true
} as Update.updateUserPhoto
}); });
}); });
} }

11
src/lib/appManagers/appUsersManager.ts

@ -303,13 +303,10 @@ export class AppUsersManager {
id: appPeersManager.getInputPeerById(peerId) id: appPeersManager.getInputPeerById(peerId)
}).then(value => { }).then(value => {
if(value) { if(value) {
apiUpdatesManager.processUpdateMessage({ apiUpdatesManager.processLocalUpdate({
_: 'updateShort', _: 'updatePeerBlocked',
update: { peer_id: appPeersManager.getOutputPeer(peerId),
_: 'updatePeerBlocked', blocked: block
peer_id: appPeersManager.getOutputPeer(peerId),
blocked: block
} as Update.updatePeerBlocked
}); });
} }

Loading…
Cancel
Save