Cancel user typing on new message
This commit is contained in:
parent
babbfdb3d7
commit
6dd0153e54
@ -94,9 +94,9 @@ export function splitStringByLength(str: string, maxLength: number) {
|
||||
|
||||
//(window as any).checkRTL = checkRTL;
|
||||
|
||||
export function convertInputKeyToKey(inputKey: string) {
|
||||
export function convertInputKeyToKey<T extends string>(inputKey: string) {
|
||||
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) {
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
//import apiManager from '../mtproto/apiManager';
|
||||
import DEBUG, { MOUNT_CLASS_TO } from '../../config/debug';
|
||||
import { Update } from '../../layer';
|
||||
import { Update, Updates } from '../../layer';
|
||||
import { logger, LogTypes } from '../logger';
|
||||
import apiManager from '../mtproto/mtprotoworker';
|
||||
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<{
|
||||
override: boolean
|
||||
}> = {}) => {
|
||||
|
@ -658,25 +658,22 @@ export class AppChatsManager {
|
||||
|
||||
if(typeof(participant) !== 'number') {
|
||||
const timestamp = Date.now() / 1000 | 0;
|
||||
apiUpdatesManager.processUpdateMessage({
|
||||
_: 'updateShort',
|
||||
update: {
|
||||
_: 'updateChannelParticipant',
|
||||
channel_id: id,
|
||||
apiUpdatesManager.processLocalUpdate({
|
||||
_: 'updateChannelParticipant',
|
||||
channel_id: id,
|
||||
date: timestamp,
|
||||
actor_id: undefined,
|
||||
qts: undefined,
|
||||
user_id: peerId,
|
||||
prev_participant: participant,
|
||||
new_participant: Object.keys(banned_rights.pFlags).length ? {
|
||||
_: 'channelParticipantBanned',
|
||||
date: timestamp,
|
||||
actor_id: undefined,
|
||||
qts: undefined,
|
||||
user_id: peerId,
|
||||
prev_participant: participant,
|
||||
new_participant: Object.keys(banned_rights.pFlags).length ? {
|
||||
_: 'channelParticipantBanned',
|
||||
date: timestamp,
|
||||
banned_rights,
|
||||
kicked_by: appUsersManager.getSelf().id,
|
||||
peer: appPeersManager.getOutputPeer(peerId),
|
||||
pFlags: {}
|
||||
} : undefined
|
||||
} as Update.updateChannelParticipant
|
||||
banned_rights,
|
||||
kicked_by: appUsersManager.getSelf().id,
|
||||
peer: appPeersManager.getOutputPeer(peerId),
|
||||
pFlags: {}
|
||||
} : undefined
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -17,7 +17,7 @@ import { createPosterForVideo } from "../../helpers/files";
|
||||
import { copy, getObjectKeysAndSort } from "../../helpers/object";
|
||||
import { randomLong } from "../../helpers/random";
|
||||
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 I18n, { i18n, join, langPack, LangPackKey, _i18n } from "../langPack";
|
||||
import { logger, LogTypes } from "../logger";
|
||||
@ -1562,12 +1562,11 @@ export class AppMessagesManager {
|
||||
const {peerId, tempId, storage} = pendingData;
|
||||
const historyStorage = this.getHistoryStorage(peerId);
|
||||
|
||||
apiUpdatesManager.processUpdateMessage({
|
||||
_: 'updateShort',
|
||||
update: {
|
||||
_: 'updateDeleteMessages',
|
||||
messages: [tempId]
|
||||
}
|
||||
apiUpdatesManager.processLocalUpdate({
|
||||
_: 'updateDeleteMessages',
|
||||
messages: [tempId],
|
||||
pts: undefined,
|
||||
pts_count: undefined
|
||||
});
|
||||
|
||||
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', {
|
||||
just_clear: justClear,
|
||||
revoke: revoke,
|
||||
peer: inputPeer,
|
||||
just_clear,
|
||||
revoke,
|
||||
peer,
|
||||
max_id: 0
|
||||
}).then((affectedHistory) => {
|
||||
apiUpdatesManager.processUpdateMessage({
|
||||
@ -2003,7 +2002,7 @@ export class AppMessagesManager {
|
||||
return true;
|
||||
}
|
||||
|
||||
return this.doFlushHistory(inputPeer, justClear);
|
||||
return this.doFlushHistory(peer, just_clear);
|
||||
});
|
||||
}
|
||||
|
||||
@ -2019,13 +2018,10 @@ export class AppMessagesManager {
|
||||
channel: appChatsManager.getChannelInput(channelId),
|
||||
max_id: maxId
|
||||
}).then(() => {
|
||||
apiUpdatesManager.processUpdateMessage({
|
||||
_: 'updateShort',
|
||||
update: {
|
||||
_: 'updateChannelAvailableMessages',
|
||||
channel_id: channelId,
|
||||
available_min_id: maxId
|
||||
} as Update.updateChannelAvailableMessages
|
||||
apiUpdatesManager.processLocalUpdate({
|
||||
_: 'updateChannelAvailableMessages',
|
||||
channel_id: channelId,
|
||||
available_min_id: maxId
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
const overwriting = !!message.peerId;
|
||||
const overwriting = !!peerId;
|
||||
if(!overwriting) {
|
||||
message.date -= serverTimeManager.serverTimeOffset;
|
||||
}
|
||||
@ -2286,7 +2282,7 @@ export class AppMessagesManager {
|
||||
const myId = appUsersManager.getSelf().id;
|
||||
|
||||
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;
|
||||
} else {
|
||||
//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;
|
||||
if(action.duration === undefined) {
|
||||
type = 'started';
|
||||
if(message.peerId !== message.fromId) {
|
||||
if(peerId !== message.fromId) {
|
||||
type += '_by' + suffix;
|
||||
}
|
||||
} else {
|
||||
@ -3553,15 +3549,12 @@ export class AppMessagesManager {
|
||||
channel: appChatsManager.getChannelInput(channelId),
|
||||
id: localMessageIds
|
||||
}).then((affectedMessages) => {
|
||||
apiUpdatesManager.processUpdateMessage({
|
||||
_: 'updateShort',
|
||||
update: {
|
||||
_: 'updateDeleteChannelMessages',
|
||||
channel_id: channelId,
|
||||
messages: mids,
|
||||
pts: affectedMessages.pts,
|
||||
pts_count: affectedMessages.pts_count
|
||||
}
|
||||
apiUpdatesManager.processLocalUpdate({
|
||||
_: 'updateDeleteChannelMessages',
|
||||
channel_id: channelId,
|
||||
messages: mids,
|
||||
pts: affectedMessages.pts,
|
||||
pts_count: affectedMessages.pts_count
|
||||
});
|
||||
});
|
||||
} else {
|
||||
@ -3569,14 +3562,11 @@ export class AppMessagesManager {
|
||||
revoke,
|
||||
id: localMessageIds
|
||||
}).then((affectedMessages) => {
|
||||
apiUpdatesManager.processUpdateMessage({
|
||||
_: 'updateShort',
|
||||
update: {
|
||||
_: 'updateDeleteMessages',
|
||||
messages: mids,
|
||||
pts: affectedMessages.pts,
|
||||
pts_count: affectedMessages.pts_count
|
||||
}
|
||||
apiUpdatesManager.processLocalUpdate({
|
||||
_: 'updateDeleteMessages',
|
||||
messages: mids,
|
||||
pts: affectedMessages.pts,
|
||||
pts_count: affectedMessages.pts_count
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -3610,14 +3600,11 @@ export class AppMessagesManager {
|
||||
});
|
||||
}
|
||||
|
||||
apiUpdatesManager.processUpdateMessage({
|
||||
_: 'updateShort',
|
||||
update: {
|
||||
_: 'updateReadChannelDiscussionInbox',
|
||||
channel_id: -peerId,
|
||||
top_msg_id: threadId,
|
||||
read_max_id: maxId
|
||||
} as Update.updateReadChannelDiscussionInbox
|
||||
apiUpdatesManager.processLocalUpdate({
|
||||
_: 'updateReadChannelDiscussionInbox',
|
||||
channel_id: -peerId,
|
||||
top_msg_id: threadId,
|
||||
read_max_id: maxId
|
||||
});
|
||||
} else if(appPeersManager.isChannel(peerId)) {
|
||||
if(!historyStorage.readPromise) {
|
||||
@ -3627,13 +3614,12 @@ export class AppMessagesManager {
|
||||
});
|
||||
}
|
||||
|
||||
apiUpdatesManager.processUpdateMessage({
|
||||
_: 'updateShort',
|
||||
update: {
|
||||
_: 'updateReadChannelInbox',
|
||||
max_id: maxId,
|
||||
channel_id: -peerId
|
||||
} as Update.updateReadChannelInbox
|
||||
apiUpdatesManager.processLocalUpdate({
|
||||
_: 'updateReadChannelInbox',
|
||||
max_id: maxId,
|
||||
channel_id: -peerId,
|
||||
still_unread_count: undefined,
|
||||
pts: undefined
|
||||
});
|
||||
} else {
|
||||
if(!historyStorage.readPromise) {
|
||||
@ -3652,13 +3638,13 @@ export class AppMessagesManager {
|
||||
});
|
||||
}
|
||||
|
||||
apiUpdatesManager.processUpdateMessage({
|
||||
_: 'updateShort',
|
||||
update: {
|
||||
_: 'updateReadHistoryInbox',
|
||||
max_id: maxId,
|
||||
peer: appPeersManager.getOutputPeer(peerId)
|
||||
} as Update.updateReadHistoryInbox
|
||||
apiUpdatesManager.processLocalUpdate({
|
||||
_: 'updateReadHistoryInbox',
|
||||
max_id: maxId,
|
||||
peer: appPeersManager.getOutputPeer(peerId),
|
||||
still_unread_count: undefined,
|
||||
pts: undefined,
|
||||
pts_count: undefined
|
||||
});
|
||||
}
|
||||
|
||||
@ -3698,27 +3684,21 @@ export class AppMessagesManager {
|
||||
channel: appChatsManager.getChannelInput(channelId),
|
||||
id: msgIds
|
||||
}).then(() => {
|
||||
apiUpdatesManager.processUpdateMessage({
|
||||
_: 'updateShort',
|
||||
update: {
|
||||
_: 'updateChannelReadMessagesContents',
|
||||
channel_id: channelId,
|
||||
messages: msgIds
|
||||
} as Update.updateChannelReadMessagesContents
|
||||
apiUpdatesManager.processLocalUpdate({
|
||||
_: 'updateChannelReadMessagesContents',
|
||||
channel_id: channelId,
|
||||
messages: msgIds
|
||||
});
|
||||
});
|
||||
} else {
|
||||
apiManager.invokeApi('messages.readMessageContents', {
|
||||
id: msgIds
|
||||
}).then((affectedMessages) => {
|
||||
apiUpdatesManager.processUpdateMessage({
|
||||
_: 'updateShort',
|
||||
update: {
|
||||
_: 'updateReadMessagesContents',
|
||||
messages: msgIds,
|
||||
pts: affectedMessages.pts,
|
||||
pts_count: affectedMessages.pts_count
|
||||
} as Update.updateReadMessagesContents
|
||||
apiUpdatesManager.processLocalUpdate({
|
||||
_: 'updateReadMessagesContents',
|
||||
messages: msgIds,
|
||||
pts: affectedMessages.pts,
|
||||
pts_count: affectedMessages.pts_count
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -3887,8 +3867,39 @@ export class AppMessagesManager {
|
||||
rootScope.dispatchEvent('history_reply_markup', {peerId});
|
||||
}
|
||||
|
||||
if(message.fromId > 0 && !message.pFlags.out && message.from_id) {
|
||||
appUsersManager.forceUserOnline(message.fromId, message.date);
|
||||
const fromId = message.fromId;
|
||||
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) {
|
||||
@ -3908,7 +3919,7 @@ export class AppMessagesManager {
|
||||
}
|
||||
|
||||
if(inboxUnread/* && ($rootScope.selectedPeerID != peerID || $rootScope.idle.isIDLE) */) {
|
||||
const notifyPeer = message.peerId;
|
||||
const notifyPeer = peerId;
|
||||
let notifyPeerToHandle = this.notificationsToHandle[notifyPeer];
|
||||
if(notifyPeerToHandle === undefined) {
|
||||
notifyPeerToHandle = this.notificationsToHandle[notifyPeer] = {
|
||||
@ -3917,8 +3928,8 @@ export class AppMessagesManager {
|
||||
};
|
||||
}
|
||||
|
||||
if(notifyPeerToHandle.fromId !== message.fromId) {
|
||||
notifyPeerToHandle.fromId = message.fromId;
|
||||
if(notifyPeerToHandle.fromId !== fromId) {
|
||||
notifyPeerToHandle.fromId = fromId;
|
||||
notifyPeerToHandle.fwdCount = 0;
|
||||
}
|
||||
|
||||
|
@ -353,19 +353,16 @@ export class AppNotificationsManager {
|
||||
settings
|
||||
}).then(value => {
|
||||
if(value) {
|
||||
apiUpdatesManager.processUpdateMessage({
|
||||
_: 'updateShort',
|
||||
update: {
|
||||
_: 'updateNotifySettings',
|
||||
peer: {
|
||||
...peer,
|
||||
_: convertInputKeyToKey(peer._)
|
||||
},
|
||||
notify_settings: { // ! WOW, IT WORKS !
|
||||
...settings,
|
||||
_: 'peerNotifySettings',
|
||||
}
|
||||
} as Update.updateNotifySettings
|
||||
apiUpdatesManager.processLocalUpdate({
|
||||
_: 'updateNotifySettings',
|
||||
peer: {
|
||||
...peer as any,
|
||||
_: convertInputKeyToKey(peer._)
|
||||
},
|
||||
notify_settings: { // ! WOW, IT WORKS !
|
||||
...settings,
|
||||
_: 'peerNotifySettings',
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -44,20 +44,17 @@ export class AppPrivacyManager {
|
||||
appUsersManager.saveApiUsers(privacyRules.users);
|
||||
appChatsManager.saveApiChats(privacyRules.chats);
|
||||
|
||||
apiUpdatesManager.processUpdateMessage({
|
||||
_: 'updateShort',
|
||||
update: {
|
||||
_: 'updatePrivacy',
|
||||
key: {
|
||||
_: convertInputKeyToKey(inputKey)
|
||||
},
|
||||
rules: rules.map(inputRule => {
|
||||
const rule: PrivacyRule = {} as any;
|
||||
Object.assign(rule, inputRule);
|
||||
rule._ = convertInputKeyToKey(rule._) as any;
|
||||
return rule;
|
||||
})
|
||||
} as Update.updatePrivacy
|
||||
apiUpdatesManager.processLocalUpdate({
|
||||
_: 'updatePrivacy',
|
||||
key: {
|
||||
_: convertInputKeyToKey(inputKey)
|
||||
},
|
||||
rules: rules.map(inputRule => {
|
||||
const rule: PrivacyRule = {} as any;
|
||||
Object.assign(rule, inputRule);
|
||||
rule._ = convertInputKeyToKey(rule._) as any;
|
||||
return rule;
|
||||
})
|
||||
});
|
||||
|
||||
//console.log('privacy rules', inputKey, privacyRules, privacyRules.rules);
|
||||
|
@ -451,15 +451,12 @@ export class AppProfileManager {
|
||||
peerId: myId
|
||||
});
|
||||
|
||||
apiUpdatesManager.processUpdateMessage({
|
||||
_: 'updateShort',
|
||||
update: {
|
||||
_: 'updateUserPhoto',
|
||||
user_id: myId,
|
||||
date: tsNow(true),
|
||||
photo: appUsersManager.getUser(myId).photo,
|
||||
previous: true
|
||||
} as Update.updateUserPhoto
|
||||
apiUpdatesManager.processLocalUpdate({
|
||||
_: 'updateUserPhoto',
|
||||
user_id: myId,
|
||||
date: tsNow(true),
|
||||
photo: appUsersManager.getUser(myId).photo,
|
||||
previous: true
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -303,13 +303,10 @@ export class AppUsersManager {
|
||||
id: appPeersManager.getInputPeerById(peerId)
|
||||
}).then(value => {
|
||||
if(value) {
|
||||
apiUpdatesManager.processUpdateMessage({
|
||||
_: 'updateShort',
|
||||
update: {
|
||||
_: 'updatePeerBlocked',
|
||||
peer_id: appPeersManager.getOutputPeer(peerId),
|
||||
blocked: block
|
||||
} as Update.updatePeerBlocked
|
||||
apiUpdatesManager.processLocalUpdate({
|
||||
_: 'updatePeerBlocked',
|
||||
peer_id: appPeersManager.getOutputPeer(peerId),
|
||||
blocked: block
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user