mirror of
https://github.com/danog/telegram-tt.git
synced 2025-01-22 05:11:55 +01:00
Support forced replies to bots (#1471)
This commit is contained in:
parent
2f608b4705
commit
2dcf951f4c
@ -171,6 +171,7 @@ export function buildApiMessageWithChatId(chatId: number, mtpMessage: UniversalM
|
||||
...(isEdited && { isEdited }),
|
||||
...(isMediaUnread && { isMediaUnread }),
|
||||
...(mtpMessage.mentioned && isMediaUnread && { hasUnreadMention: true }),
|
||||
...(mtpMessage.mentioned && { isMentioned: true }),
|
||||
...(groupedId && {
|
||||
groupedId,
|
||||
isInAlbum,
|
||||
|
@ -85,6 +85,7 @@ export function updater(update: Update, originRequest?: GramJs.AnyRequest) {
|
||||
|| update instanceof GramJs.UpdateServiceNotification
|
||||
) {
|
||||
let message: ApiMessage | undefined;
|
||||
let shouldForceReply: boolean | undefined;
|
||||
|
||||
if (update instanceof GramJs.UpdateShortChatMessage) {
|
||||
message = buildApiMessageFromShortChat(update);
|
||||
@ -113,6 +114,9 @@ export function updater(update: Update, originRequest?: GramJs.AnyRequest) {
|
||||
}
|
||||
|
||||
message = buildApiMessage(update.message)!;
|
||||
shouldForceReply = 'replyMarkup' in update.message
|
||||
&& update.message?.replyMarkup instanceof GramJs.ReplyKeyboardForceReply
|
||||
&& (!update.message.replyMarkup.selective || message.isMentioned);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-underscore-dangle
|
||||
@ -161,6 +165,7 @@ export function updater(update: Update, originRequest?: GramJs.AnyRequest) {
|
||||
id: message.id,
|
||||
chatId: message.chatId,
|
||||
message,
|
||||
shouldForceReply,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -245,6 +245,7 @@ export interface ApiMessage {
|
||||
previousLocalId?: number;
|
||||
views?: number;
|
||||
isEdited?: boolean;
|
||||
isMentioned?: boolean;
|
||||
isMediaUnread?: boolean;
|
||||
groupedId?: string;
|
||||
isInAlbum?: boolean;
|
||||
|
@ -158,6 +158,7 @@ export type ApiUpdateNewMessage = {
|
||||
chatId: number;
|
||||
id: number;
|
||||
message: Partial<ApiMessage>;
|
||||
shouldForceReply?: boolean;
|
||||
};
|
||||
|
||||
export type ApiUpdateMessage = {
|
||||
|
@ -334,15 +334,15 @@
|
||||
font-size: var(--composer-text-size, 1rem);
|
||||
top: calc((3.25rem - var(--composer-text-size, 1rem) * 1.375) / 2);
|
||||
bottom: auto;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.forced-placeholder {
|
||||
z-index: var(--z-below);
|
||||
left: 0;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
max-width: 100%;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
&[dir=rtl] .placeholder-text {
|
||||
|
@ -46,7 +46,9 @@ const ANIMATION_DELAY = 350;
|
||||
addReducer('apiUpdate', (global, actions, update: ApiUpdate) => {
|
||||
switch (update['@type']) {
|
||||
case 'newMessage': {
|
||||
const { chatId, id, message } = update;
|
||||
const {
|
||||
chatId, id, message, shouldForceReply,
|
||||
} = update;
|
||||
global = updateWithLocalMedia(global, chatId, id, message);
|
||||
global = updateListedAndViewportIds(global, actions, message as ApiMessage);
|
||||
|
||||
@ -86,7 +88,11 @@ addReducer('apiUpdate', (global, actions, update: ApiUpdate) => {
|
||||
// @perf Wait until scroll animation finishes or simply rely on delivery status update (which is itself delayed)
|
||||
if (!isMessageLocal(message as ApiMessage)) {
|
||||
setTimeout(() => {
|
||||
setGlobal(updateChatLastMessage(getGlobal(), chatId, newMessage));
|
||||
let delayedGlobal = getGlobal();
|
||||
if (shouldForceReply) {
|
||||
delayedGlobal = replaceThreadParam(delayedGlobal, chatId, MAIN_THREAD_ID, 'replyingToId', id);
|
||||
}
|
||||
setGlobal(updateChatLastMessage(delayedGlobal, chatId, newMessage));
|
||||
}, ANIMATION_DELAY);
|
||||
}
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user