Message: Fix failed messages' context menu (#3458)

This commit is contained in:
Alexander Zinchuk 2023-07-05 13:16:04 +02:00
parent 1e33c04ed4
commit 6d8f415bc1
6 changed files with 54 additions and 25 deletions

View File

@ -1319,22 +1319,34 @@ export async function forwardMessages({
await lastSendMessagePromise;
const update = await invokeRequest(new GramJs.messages.ForwardMessages({
fromPeer: buildInputPeer(fromChat.id, fromChat.accessHash),
toPeer: buildInputPeer(toChat.id, toChat.accessHash),
randomId: randomIds,
id: messageIds,
withMyScore: withMyScore || undefined,
silent: isSilent || undefined,
dropAuthor: noAuthors || undefined,
dropMediaCaptions: noCaptions || undefined,
...(toThreadId && { topMsgId: toThreadId }),
...(scheduledAt && { scheduleDate: scheduledAt }),
...(sendAs && { sendAs: buildInputPeer(sendAs.id, sendAs.accessHash) }),
}), {
shouldIgnoreUpdates: true,
});
if (update) handleMultipleLocalMessagesUpdate(localMessages, update);
try {
const update = await invokeRequest(new GramJs.messages.ForwardMessages({
fromPeer: buildInputPeer(fromChat.id, fromChat.accessHash),
toPeer: buildInputPeer(toChat.id, toChat.accessHash),
randomId: randomIds,
id: messageIds,
withMyScore: withMyScore || undefined,
silent: isSilent || undefined,
dropAuthor: noAuthors || undefined,
dropMediaCaptions: noCaptions || undefined,
...(toThreadId && { topMsgId: toThreadId }),
...(scheduledAt && { scheduleDate: scheduledAt }),
...(sendAs && { sendAs: buildInputPeer(sendAs.id, sendAs.accessHash) }),
}), {
shouldThrow: true,
shouldIgnoreUpdates: true,
});
if (update) handleMultipleLocalMessagesUpdate(localMessages, update);
} catch (error: any) {
Object.values(localMessages).forEach((localMessage) => {
onUpdate({
'@type': 'updateMessageSendFailed',
chatId: toChat.id,
localId: localMessage.id,
error: error.message,
});
});
}
}
export async function findFirstMessageIdAfterDate({

View File

@ -611,7 +611,8 @@ export default memo(withGlobal<OwnProps>(
const isChannel = chat && isChatChannel(chat);
const isLocal = isMessageLocal(message);
const isServiceNotification = isServiceNotificationMessage(message);
const canShowSeenBy = Boolean(chat
const canShowSeenBy = Boolean(!isLocal
&& chat
&& seenByMaxChatMembers
&& seenByExpiresAt
&& isChatGroup(chat)

View File

@ -96,8 +96,8 @@ import {
import { debounce, onTickEnd, rafPromise } from '../../../util/schedulers';
import {
getMessageOriginalId,
getUserFullName,
isDeletedUser,
getUserFullName, isChatChannel,
isDeletedUser, isMessageLocal,
isServiceNotificationMessage,
isUserBot,
} from '../../helpers';
@ -105,6 +105,7 @@ import { translate } from '../../../util/langProvider';
import { ensureProtocol } from '../../../util/ensureProtocol';
import { updateTabState } from '../../reducers/tabs';
import { getCurrentTabId } from '../../../util/establishMultitabRole';
import { deleteMessages } from '../apiUpdaters/messages';
const AUTOLOGIN_TOKEN_KEY = 'autologin_token';
@ -484,8 +485,18 @@ addActionHandler('deleteMessages', (global, actions, payload): ActionReturnType
}
const { chatId, threadId } = currentMessageList;
const chat = selectChat(global, chatId)!;
const messageIdsToDelete = messageIds.filter((id) => {
const message = selectChatMessage(global, chatId, id);
return message && !isMessageLocal(message);
});
void callApi('deleteMessages', { chat, messageIds, shouldDeleteForAll });
// Only local messages
if (!messageIdsToDelete.length && messageIds.length) {
deleteMessages(global, isChatChannel(chat) ? chatId : undefined, messageIds, actions);
return;
}
void callApi('deleteMessages', { chat, messageIds: messageIdsToDelete, shouldDeleteForAll });
const editingId = selectEditingId(global, chatId, threadId);
if (editingId && messageIds.includes(editingId)) {

View File

@ -894,7 +894,7 @@ function findLastMessage<T extends GlobalState>(global: T, chatId: string) {
return undefined;
}
function deleteMessages<T extends GlobalState>(
export function deleteMessages<T extends GlobalState>(
global: T, chatId: string | undefined, ids: number[], actions: RequiredGlobalActions,
) {
// Channel update

View File

@ -197,6 +197,10 @@ export function isMessageLocal(message: ApiMessage) {
return isLocalMessageId(message.id);
}
export function isMessageFailed(message: ApiMessage) {
return message.sendingState === 'messageSendingStateFailed';
}
export function isLocalMessageId(id: number) {
return !Number.isInteger(id);
}

View File

@ -50,7 +50,7 @@ import {
isUserRightBanned,
canSendReaction,
getAllowedAttachmentOptions,
isLocalMessageId,
isLocalMessageId, isMessageFailed,
} from '../helpers';
import { findLast } from '../../util/iteratees';
import { selectIsStickerFavorite } from './symbols';
@ -538,6 +538,7 @@ export function selectAllowedMessageActions<T extends GlobalState>(global: T, me
const isChannel = isChatChannel(chat);
const isBotChat = Boolean(selectBot(global, chat.id));
const isLocal = isMessageLocal(message);
const isFailed = isMessageFailed(message);
const isServiceNotification = isServiceNotificationMessage(message);
const isOwn = isOwnMessage(message);
const isAction = isActionMessage(message);
@ -582,7 +583,7 @@ export function selectAllowedMessageActions<T extends GlobalState>(global: T, me
canPin = !canUnpin;
}
const canDelete = !isLocal && !isServiceNotification && (
const canDelete = (!isLocal || isFailed) && !isServiceNotification && (
isPrivate
|| isOwn
|| isBasicGroup
@ -614,8 +615,8 @@ export function selectAllowedMessageActions<T extends GlobalState>(global: T, me
const canFaveSticker = !isAction && hasSticker && !hasFavoriteSticker;
const canUnfaveSticker = !isAction && hasFavoriteSticker;
const canCopy = !isAction;
const canCopyLink = !isAction && (isChannel || isSuperGroup);
const canSelect = !isAction;
const canCopyLink = !isLocal && !isAction && (isChannel || isSuperGroup);
const canSelect = !isLocal && !isAction;
const canDownload = Boolean(content.webPage?.document || content.webPage?.video || content.webPage?.photo
|| content.audio || content.voice || content.photo || content.video || content.document || content.sticker);