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. 5
      src/lib/appManagers/appChatsManager.ts
  4. 117
      src/lib/appManagers/appMessagesManager.ts
  5. 7
      src/lib/appManagers/appNotificationsManager.ts
  6. 5
      src/lib/appManagers/appPrivacyManager.ts
  7. 5
      src/lib/appManagers/appProfileManager.ts
  8. 5
      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
}> = {}) => { }> = {}) => {

5
src/lib/appManagers/appChatsManager.ts

@ -658,9 +658,7 @@ 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',
update: {
_: 'updateChannelParticipant', _: 'updateChannelParticipant',
channel_id: id, channel_id: id,
date: timestamp, date: timestamp,
@ -676,7 +674,6 @@ export class AppChatsManager {
peer: appPeersManager.getOutputPeer(peerId), peer: appPeersManager.getOutputPeer(peerId),
pFlags: {} pFlags: {}
} : undefined } : undefined
} as Update.updateChannelParticipant
}); });
} }
}); });

117
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',
update: {
_: 'updateDeleteMessages', _: 'updateDeleteMessages',
messages: [tempId] messages: [tempId],
} pts: undefined,
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',
update: {
_: 'updateChannelAvailableMessages', _: 'updateChannelAvailableMessages',
channel_id: channelId, channel_id: channelId,
available_min_id: maxId 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',
update: {
_: 'updateDeleteChannelMessages', _: 'updateDeleteChannelMessages',
channel_id: channelId, channel_id: channelId,
messages: mids, messages: mids,
pts: affectedMessages.pts, pts: affectedMessages.pts,
pts_count: affectedMessages.pts_count 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',
update: {
_: 'updateDeleteMessages', _: 'updateDeleteMessages',
messages: mids, messages: mids,
pts: affectedMessages.pts, pts: affectedMessages.pts,
pts_count: affectedMessages.pts_count pts_count: affectedMessages.pts_count
}
}); });
}); });
} }
@ -3610,14 +3600,11 @@ export class AppMessagesManager {
}); });
} }
apiUpdatesManager.processUpdateMessage({ apiUpdatesManager.processLocalUpdate({
_: 'updateShort',
update: {
_: 'updateReadChannelDiscussionInbox', _: 'updateReadChannelDiscussionInbox',
channel_id: -peerId, channel_id: -peerId,
top_msg_id: threadId, top_msg_id: threadId,
read_max_id: maxId 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',
update: {
_: 'updateReadChannelInbox', _: 'updateReadChannelInbox',
max_id: maxId, max_id: maxId,
channel_id: -peerId channel_id: -peerId,
} as Update.updateReadChannelInbox still_unread_count: undefined,
pts: undefined
}); });
} else { } else {
if(!historyStorage.readPromise) { if(!historyStorage.readPromise) {
@ -3652,13 +3638,13 @@ export class AppMessagesManager {
}); });
} }
apiUpdatesManager.processUpdateMessage({ apiUpdatesManager.processLocalUpdate({
_: 'updateShort',
update: {
_: 'updateReadHistoryInbox', _: 'updateReadHistoryInbox',
max_id: maxId, max_id: maxId,
peer: appPeersManager.getOutputPeer(peerId) peer: appPeersManager.getOutputPeer(peerId),
} as Update.updateReadHistoryInbox still_unread_count: undefined,
pts: undefined,
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',
update: {
_: 'updateChannelReadMessagesContents', _: 'updateChannelReadMessagesContents',
channel_id: channelId, channel_id: channelId,
messages: msgIds 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',
update: {
_: 'updateReadMessagesContents', _: 'updateReadMessagesContents',
messages: msgIds, messages: msgIds,
pts: affectedMessages.pts, pts: affectedMessages.pts,
pts_count: affectedMessages.pts_count 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;
} }

7
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',
update: {
_: 'updateNotifySettings', _: 'updateNotifySettings',
peer: { peer: {
...peer, ...peer as any,
_: convertInputKeyToKey(peer._) _: convertInputKeyToKey(peer._)
}, },
notify_settings: { // ! WOW, IT WORKS ! notify_settings: { // ! WOW, IT WORKS !
...settings, ...settings,
_: 'peerNotifySettings', _: 'peerNotifySettings',
} }
} as Update.updateNotifySettings
}); });
} }
}); });

5
src/lib/appManagers/appPrivacyManager.ts

@ -44,9 +44,7 @@ export class AppPrivacyManager {
appUsersManager.saveApiUsers(privacyRules.users); appUsersManager.saveApiUsers(privacyRules.users);
appChatsManager.saveApiChats(privacyRules.chats); appChatsManager.saveApiChats(privacyRules.chats);
apiUpdatesManager.processUpdateMessage({ apiUpdatesManager.processLocalUpdate({
_: 'updateShort',
update: {
_: 'updatePrivacy', _: 'updatePrivacy',
key: { key: {
_: convertInputKeyToKey(inputKey) _: convertInputKeyToKey(inputKey)
@ -57,7 +55,6 @@ export class AppPrivacyManager {
rule._ = convertInputKeyToKey(rule._) as any; rule._ = convertInputKeyToKey(rule._) as any;
return rule; return rule;
}) })
} as Update.updatePrivacy
}); });
//console.log('privacy rules', inputKey, privacyRules, privacyRules.rules); //console.log('privacy rules', inputKey, privacyRules, privacyRules.rules);

5
src/lib/appManagers/appProfileManager.ts

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

5
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',
update: {
_: 'updatePeerBlocked', _: 'updatePeerBlocked',
peer_id: appPeersManager.getOutputPeer(peerId), peer_id: appPeersManager.getOutputPeer(peerId),
blocked: block blocked: block
} as Update.updatePeerBlocked
}); });
} }

Loading…
Cancel
Save