Composer: Support updates for drafts (#1168)
This commit is contained in:
parent
6cd13db35f
commit
bf1569cfd6
@ -184,12 +184,12 @@ export function buildMessageTextContent(
|
||||
}
|
||||
|
||||
export function buildMessageDraft(draft: GramJs.TypeDraftMessage) {
|
||||
if (draft instanceof GramJs.DraftMessageEmpty || !draft.message) {
|
||||
if (draft instanceof GramJs.DraftMessageEmpty) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return {
|
||||
formattedText: buildMessageTextContent(draft.message, draft.entities),
|
||||
formattedText: draft.message ? buildMessageTextContent(draft.message, draft.entities) : undefined,
|
||||
replyingToId: draft.replyToMsgId,
|
||||
};
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ import {
|
||||
buildPoll,
|
||||
buildPollResults,
|
||||
buildApiMessageFromNotification,
|
||||
buildMessageDraft,
|
||||
} from './apiBuilders/messages';
|
||||
import {
|
||||
getApiChatIdFromMtpPeer,
|
||||
@ -764,6 +765,14 @@ export function updater(update: Update, originRequest?: GramJs.AnyRequest) {
|
||||
}
|
||||
|
||||
// Misc
|
||||
} else if (update instanceof GramJs.UpdateDraftMessage) {
|
||||
const { replyingToId, formattedText } = buildMessageDraft(update.draft) || {};
|
||||
onUpdate({
|
||||
'@type': 'draftMessage',
|
||||
chatId: getApiChatIdFromMtpPeer(update.peer),
|
||||
formattedText,
|
||||
replyingToId,
|
||||
});
|
||||
} else if (update instanceof GramJs.UpdateContactsReset) {
|
||||
onUpdate({ '@type': 'updateResetContactList' });
|
||||
} else if (update instanceof GramJs.UpdateFavedStickers) {
|
||||
|
||||
@ -6,7 +6,7 @@ import {
|
||||
ApiChatFolder,
|
||||
} from './chats';
|
||||
import {
|
||||
ApiMessage, ApiPhoto, ApiPoll, ApiStickerSet, ApiThreadInfo,
|
||||
ApiFormattedText, ApiMessage, ApiPhoto, ApiPoll, ApiStickerSet, ApiThreadInfo,
|
||||
} from './messages';
|
||||
import { ApiUser, ApiUserFullInfo, ApiUserStatus } from './users';
|
||||
import { ApiSessionData } from './misc';
|
||||
@ -259,6 +259,13 @@ export type ApiUpdateResetMessages = {
|
||||
id: number;
|
||||
};
|
||||
|
||||
export type ApiUpdateDraftMessage = {
|
||||
'@type': 'draftMessage';
|
||||
chatId: number;
|
||||
formattedText?: ApiFormattedText;
|
||||
replyingToId?: number;
|
||||
};
|
||||
|
||||
export type ApiDeleteUser = {
|
||||
'@type': 'deleteUser';
|
||||
id: number;
|
||||
@ -376,7 +383,7 @@ export type ApiUpdate = (
|
||||
ApiUpdateDeleteMessages | ApiUpdateMessagePoll | ApiUpdateMessagePollVote | ApiUpdateDeleteHistory |
|
||||
ApiUpdateMessageSendSucceeded | ApiUpdateMessageSendFailed |
|
||||
ApiDeleteUser | ApiUpdateUser | ApiUpdateUserStatus | ApiUpdateUserFullInfo | ApiUpdateDeleteProfilePhotos |
|
||||
ApiUpdateAvatar | ApiUpdateMessageImage |
|
||||
ApiUpdateAvatar | ApiUpdateMessageImage | ApiUpdateDraftMessage |
|
||||
ApiUpdateError | ApiUpdateResetContacts |
|
||||
ApiUpdateFavoriteStickers | ApiUpdateStickerSet |
|
||||
ApiUpdateNewScheduledMessage | ApiUpdateScheduledMessageSendSucceeded | ApiUpdateScheduledMessage |
|
||||
|
||||
@ -11,6 +11,7 @@ import {
|
||||
replaceChatListIds,
|
||||
updateChatListIds,
|
||||
updateChatListType,
|
||||
replaceThreadParam,
|
||||
} from '../../reducers';
|
||||
import {
|
||||
selectChat,
|
||||
@ -360,5 +361,17 @@ addReducer('apiUpdate', (global, actions, update: ApiUpdate) => {
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 'draftMessage': {
|
||||
const { chatId, formattedText, replyingToId } = update;
|
||||
const chat = global.chats.byId[chatId];
|
||||
|
||||
if (chat) {
|
||||
global = replaceThreadParam(global, chatId, MAIN_THREAD_ID, 'draft', formattedText);
|
||||
global = replaceThreadParam(global, chatId, MAIN_THREAD_ID, 'replyingToId', replyingToId);
|
||||
|
||||
setGlobal(global);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user