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) {
|
export function buildMessageDraft(draft: GramJs.TypeDraftMessage) {
|
||||||
if (draft instanceof GramJs.DraftMessageEmpty || !draft.message) {
|
if (draft instanceof GramJs.DraftMessageEmpty) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
formattedText: buildMessageTextContent(draft.message, draft.entities),
|
formattedText: draft.message ? buildMessageTextContent(draft.message, draft.entities) : undefined,
|
||||||
replyingToId: draft.replyToMsgId,
|
replyingToId: draft.replyToMsgId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import {
|
|||||||
buildPoll,
|
buildPoll,
|
||||||
buildPollResults,
|
buildPollResults,
|
||||||
buildApiMessageFromNotification,
|
buildApiMessageFromNotification,
|
||||||
|
buildMessageDraft,
|
||||||
} from './apiBuilders/messages';
|
} from './apiBuilders/messages';
|
||||||
import {
|
import {
|
||||||
getApiChatIdFromMtpPeer,
|
getApiChatIdFromMtpPeer,
|
||||||
@ -764,6 +765,14 @@ export function updater(update: Update, originRequest?: GramJs.AnyRequest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Misc
|
// 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) {
|
} else if (update instanceof GramJs.UpdateContactsReset) {
|
||||||
onUpdate({ '@type': 'updateResetContactList' });
|
onUpdate({ '@type': 'updateResetContactList' });
|
||||||
} else if (update instanceof GramJs.UpdateFavedStickers) {
|
} else if (update instanceof GramJs.UpdateFavedStickers) {
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import {
|
|||||||
ApiChatFolder,
|
ApiChatFolder,
|
||||||
} from './chats';
|
} from './chats';
|
||||||
import {
|
import {
|
||||||
ApiMessage, ApiPhoto, ApiPoll, ApiStickerSet, ApiThreadInfo,
|
ApiFormattedText, ApiMessage, ApiPhoto, ApiPoll, ApiStickerSet, ApiThreadInfo,
|
||||||
} from './messages';
|
} from './messages';
|
||||||
import { ApiUser, ApiUserFullInfo, ApiUserStatus } from './users';
|
import { ApiUser, ApiUserFullInfo, ApiUserStatus } from './users';
|
||||||
import { ApiSessionData } from './misc';
|
import { ApiSessionData } from './misc';
|
||||||
@ -259,6 +259,13 @@ export type ApiUpdateResetMessages = {
|
|||||||
id: number;
|
id: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type ApiUpdateDraftMessage = {
|
||||||
|
'@type': 'draftMessage';
|
||||||
|
chatId: number;
|
||||||
|
formattedText?: ApiFormattedText;
|
||||||
|
replyingToId?: number;
|
||||||
|
};
|
||||||
|
|
||||||
export type ApiDeleteUser = {
|
export type ApiDeleteUser = {
|
||||||
'@type': 'deleteUser';
|
'@type': 'deleteUser';
|
||||||
id: number;
|
id: number;
|
||||||
@ -376,7 +383,7 @@ export type ApiUpdate = (
|
|||||||
ApiUpdateDeleteMessages | ApiUpdateMessagePoll | ApiUpdateMessagePollVote | ApiUpdateDeleteHistory |
|
ApiUpdateDeleteMessages | ApiUpdateMessagePoll | ApiUpdateMessagePollVote | ApiUpdateDeleteHistory |
|
||||||
ApiUpdateMessageSendSucceeded | ApiUpdateMessageSendFailed |
|
ApiUpdateMessageSendSucceeded | ApiUpdateMessageSendFailed |
|
||||||
ApiDeleteUser | ApiUpdateUser | ApiUpdateUserStatus | ApiUpdateUserFullInfo | ApiUpdateDeleteProfilePhotos |
|
ApiDeleteUser | ApiUpdateUser | ApiUpdateUserStatus | ApiUpdateUserFullInfo | ApiUpdateDeleteProfilePhotos |
|
||||||
ApiUpdateAvatar | ApiUpdateMessageImage |
|
ApiUpdateAvatar | ApiUpdateMessageImage | ApiUpdateDraftMessage |
|
||||||
ApiUpdateError | ApiUpdateResetContacts |
|
ApiUpdateError | ApiUpdateResetContacts |
|
||||||
ApiUpdateFavoriteStickers | ApiUpdateStickerSet |
|
ApiUpdateFavoriteStickers | ApiUpdateStickerSet |
|
||||||
ApiUpdateNewScheduledMessage | ApiUpdateScheduledMessageSendSucceeded | ApiUpdateScheduledMessage |
|
ApiUpdateNewScheduledMessage | ApiUpdateScheduledMessageSendSucceeded | ApiUpdateScheduledMessage |
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import {
|
|||||||
replaceChatListIds,
|
replaceChatListIds,
|
||||||
updateChatListIds,
|
updateChatListIds,
|
||||||
updateChatListType,
|
updateChatListType,
|
||||||
|
replaceThreadParam,
|
||||||
} from '../../reducers';
|
} from '../../reducers';
|
||||||
import {
|
import {
|
||||||
selectChat,
|
selectChat,
|
||||||
@ -360,5 +361,17 @@ addReducer('apiUpdate', (global, actions, update: ApiUpdate) => {
|
|||||||
}
|
}
|
||||||
break;
|
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