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 }),
|
...(isEdited && { isEdited }),
|
||||||
...(isMediaUnread && { isMediaUnread }),
|
...(isMediaUnread && { isMediaUnread }),
|
||||||
...(mtpMessage.mentioned && isMediaUnread && { hasUnreadMention: true }),
|
...(mtpMessage.mentioned && isMediaUnread && { hasUnreadMention: true }),
|
||||||
|
...(mtpMessage.mentioned && { isMentioned: true }),
|
||||||
...(groupedId && {
|
...(groupedId && {
|
||||||
groupedId,
|
groupedId,
|
||||||
isInAlbum,
|
isInAlbum,
|
||||||
|
|||||||
@ -85,6 +85,7 @@ export function updater(update: Update, originRequest?: GramJs.AnyRequest) {
|
|||||||
|| update instanceof GramJs.UpdateServiceNotification
|
|| update instanceof GramJs.UpdateServiceNotification
|
||||||
) {
|
) {
|
||||||
let message: ApiMessage | undefined;
|
let message: ApiMessage | undefined;
|
||||||
|
let shouldForceReply: boolean | undefined;
|
||||||
|
|
||||||
if (update instanceof GramJs.UpdateShortChatMessage) {
|
if (update instanceof GramJs.UpdateShortChatMessage) {
|
||||||
message = buildApiMessageFromShortChat(update);
|
message = buildApiMessageFromShortChat(update);
|
||||||
@ -113,6 +114,9 @@ export function updater(update: Update, originRequest?: GramJs.AnyRequest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message = buildApiMessage(update.message)!;
|
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
|
// eslint-disable-next-line no-underscore-dangle
|
||||||
@ -161,6 +165,7 @@ export function updater(update: Update, originRequest?: GramJs.AnyRequest) {
|
|||||||
id: message.id,
|
id: message.id,
|
||||||
chatId: message.chatId,
|
chatId: message.chatId,
|
||||||
message,
|
message,
|
||||||
|
shouldForceReply,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -245,6 +245,7 @@ export interface ApiMessage {
|
|||||||
previousLocalId?: number;
|
previousLocalId?: number;
|
||||||
views?: number;
|
views?: number;
|
||||||
isEdited?: boolean;
|
isEdited?: boolean;
|
||||||
|
isMentioned?: boolean;
|
||||||
isMediaUnread?: boolean;
|
isMediaUnread?: boolean;
|
||||||
groupedId?: string;
|
groupedId?: string;
|
||||||
isInAlbum?: boolean;
|
isInAlbum?: boolean;
|
||||||
|
|||||||
@ -158,6 +158,7 @@ export type ApiUpdateNewMessage = {
|
|||||||
chatId: number;
|
chatId: number;
|
||||||
id: number;
|
id: number;
|
||||||
message: Partial<ApiMessage>;
|
message: Partial<ApiMessage>;
|
||||||
|
shouldForceReply?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ApiUpdateMessage = {
|
export type ApiUpdateMessage = {
|
||||||
|
|||||||
@ -334,15 +334,15 @@
|
|||||||
font-size: var(--composer-text-size, 1rem);
|
font-size: var(--composer-text-size, 1rem);
|
||||||
top: calc((3.25rem - var(--composer-text-size, 1rem) * 1.375) / 2);
|
top: calc((3.25rem - var(--composer-text-size, 1rem) * 1.375) / 2);
|
||||||
bottom: auto;
|
bottom: auto;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.forced-placeholder {
|
.forced-placeholder {
|
||||||
z-index: var(--z-below);
|
z-index: var(--z-below);
|
||||||
left: 0;
|
left: 0;
|
||||||
white-space: nowrap;
|
|
||||||
overflow: hidden;
|
|
||||||
max-width: 100%;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&[dir=rtl] .placeholder-text {
|
&[dir=rtl] .placeholder-text {
|
||||||
|
|||||||
@ -46,7 +46,9 @@ const ANIMATION_DELAY = 350;
|
|||||||
addReducer('apiUpdate', (global, actions, update: ApiUpdate) => {
|
addReducer('apiUpdate', (global, actions, update: ApiUpdate) => {
|
||||||
switch (update['@type']) {
|
switch (update['@type']) {
|
||||||
case 'newMessage': {
|
case 'newMessage': {
|
||||||
const { chatId, id, message } = update;
|
const {
|
||||||
|
chatId, id, message, shouldForceReply,
|
||||||
|
} = update;
|
||||||
global = updateWithLocalMedia(global, chatId, id, message);
|
global = updateWithLocalMedia(global, chatId, id, message);
|
||||||
global = updateListedAndViewportIds(global, actions, message as ApiMessage);
|
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)
|
// @perf Wait until scroll animation finishes or simply rely on delivery status update (which is itself delayed)
|
||||||
if (!isMessageLocal(message as ApiMessage)) {
|
if (!isMessageLocal(message as ApiMessage)) {
|
||||||
setTimeout(() => {
|
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);
|
}, ANIMATION_DELAY);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user