Message: Fix failed messages' context menu (#3458)
This commit is contained in:
parent
1e33c04ed4
commit
6d8f415bc1
@ -1319,22 +1319,34 @@ export async function forwardMessages({
|
|||||||
|
|
||||||
await lastSendMessagePromise;
|
await lastSendMessagePromise;
|
||||||
|
|
||||||
const update = await invokeRequest(new GramJs.messages.ForwardMessages({
|
try {
|
||||||
fromPeer: buildInputPeer(fromChat.id, fromChat.accessHash),
|
const update = await invokeRequest(new GramJs.messages.ForwardMessages({
|
||||||
toPeer: buildInputPeer(toChat.id, toChat.accessHash),
|
fromPeer: buildInputPeer(fromChat.id, fromChat.accessHash),
|
||||||
randomId: randomIds,
|
toPeer: buildInputPeer(toChat.id, toChat.accessHash),
|
||||||
id: messageIds,
|
randomId: randomIds,
|
||||||
withMyScore: withMyScore || undefined,
|
id: messageIds,
|
||||||
silent: isSilent || undefined,
|
withMyScore: withMyScore || undefined,
|
||||||
dropAuthor: noAuthors || undefined,
|
silent: isSilent || undefined,
|
||||||
dropMediaCaptions: noCaptions || undefined,
|
dropAuthor: noAuthors || undefined,
|
||||||
...(toThreadId && { topMsgId: toThreadId }),
|
dropMediaCaptions: noCaptions || undefined,
|
||||||
...(scheduledAt && { scheduleDate: scheduledAt }),
|
...(toThreadId && { topMsgId: toThreadId }),
|
||||||
...(sendAs && { sendAs: buildInputPeer(sendAs.id, sendAs.accessHash) }),
|
...(scheduledAt && { scheduleDate: scheduledAt }),
|
||||||
}), {
|
...(sendAs && { sendAs: buildInputPeer(sendAs.id, sendAs.accessHash) }),
|
||||||
shouldIgnoreUpdates: true,
|
}), {
|
||||||
});
|
shouldThrow: true,
|
||||||
if (update) handleMultipleLocalMessagesUpdate(localMessages, update);
|
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({
|
export async function findFirstMessageIdAfterDate({
|
||||||
|
|||||||
@ -611,7 +611,8 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
const isChannel = chat && isChatChannel(chat);
|
const isChannel = chat && isChatChannel(chat);
|
||||||
const isLocal = isMessageLocal(message);
|
const isLocal = isMessageLocal(message);
|
||||||
const isServiceNotification = isServiceNotificationMessage(message);
|
const isServiceNotification = isServiceNotificationMessage(message);
|
||||||
const canShowSeenBy = Boolean(chat
|
const canShowSeenBy = Boolean(!isLocal
|
||||||
|
&& chat
|
||||||
&& seenByMaxChatMembers
|
&& seenByMaxChatMembers
|
||||||
&& seenByExpiresAt
|
&& seenByExpiresAt
|
||||||
&& isChatGroup(chat)
|
&& isChatGroup(chat)
|
||||||
|
|||||||
@ -96,8 +96,8 @@ import {
|
|||||||
import { debounce, onTickEnd, rafPromise } from '../../../util/schedulers';
|
import { debounce, onTickEnd, rafPromise } from '../../../util/schedulers';
|
||||||
import {
|
import {
|
||||||
getMessageOriginalId,
|
getMessageOriginalId,
|
||||||
getUserFullName,
|
getUserFullName, isChatChannel,
|
||||||
isDeletedUser,
|
isDeletedUser, isMessageLocal,
|
||||||
isServiceNotificationMessage,
|
isServiceNotificationMessage,
|
||||||
isUserBot,
|
isUserBot,
|
||||||
} from '../../helpers';
|
} from '../../helpers';
|
||||||
@ -105,6 +105,7 @@ import { translate } from '../../../util/langProvider';
|
|||||||
import { ensureProtocol } from '../../../util/ensureProtocol';
|
import { ensureProtocol } from '../../../util/ensureProtocol';
|
||||||
import { updateTabState } from '../../reducers/tabs';
|
import { updateTabState } from '../../reducers/tabs';
|
||||||
import { getCurrentTabId } from '../../../util/establishMultitabRole';
|
import { getCurrentTabId } from '../../../util/establishMultitabRole';
|
||||||
|
import { deleteMessages } from '../apiUpdaters/messages';
|
||||||
|
|
||||||
const AUTOLOGIN_TOKEN_KEY = 'autologin_token';
|
const AUTOLOGIN_TOKEN_KEY = 'autologin_token';
|
||||||
|
|
||||||
@ -484,8 +485,18 @@ addActionHandler('deleteMessages', (global, actions, payload): ActionReturnType
|
|||||||
}
|
}
|
||||||
const { chatId, threadId } = currentMessageList;
|
const { chatId, threadId } = currentMessageList;
|
||||||
const chat = selectChat(global, chatId)!;
|
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);
|
const editingId = selectEditingId(global, chatId, threadId);
|
||||||
if (editingId && messageIds.includes(editingId)) {
|
if (editingId && messageIds.includes(editingId)) {
|
||||||
|
|||||||
@ -894,7 +894,7 @@ function findLastMessage<T extends GlobalState>(global: T, chatId: string) {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteMessages<T extends GlobalState>(
|
export function deleteMessages<T extends GlobalState>(
|
||||||
global: T, chatId: string | undefined, ids: number[], actions: RequiredGlobalActions,
|
global: T, chatId: string | undefined, ids: number[], actions: RequiredGlobalActions,
|
||||||
) {
|
) {
|
||||||
// Channel update
|
// Channel update
|
||||||
|
|||||||
@ -197,6 +197,10 @@ export function isMessageLocal(message: ApiMessage) {
|
|||||||
return isLocalMessageId(message.id);
|
return isLocalMessageId(message.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isMessageFailed(message: ApiMessage) {
|
||||||
|
return message.sendingState === 'messageSendingStateFailed';
|
||||||
|
}
|
||||||
|
|
||||||
export function isLocalMessageId(id: number) {
|
export function isLocalMessageId(id: number) {
|
||||||
return !Number.isInteger(id);
|
return !Number.isInteger(id);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,7 +50,7 @@ import {
|
|||||||
isUserRightBanned,
|
isUserRightBanned,
|
||||||
canSendReaction,
|
canSendReaction,
|
||||||
getAllowedAttachmentOptions,
|
getAllowedAttachmentOptions,
|
||||||
isLocalMessageId,
|
isLocalMessageId, isMessageFailed,
|
||||||
} from '../helpers';
|
} from '../helpers';
|
||||||
import { findLast } from '../../util/iteratees';
|
import { findLast } from '../../util/iteratees';
|
||||||
import { selectIsStickerFavorite } from './symbols';
|
import { selectIsStickerFavorite } from './symbols';
|
||||||
@ -538,6 +538,7 @@ export function selectAllowedMessageActions<T extends GlobalState>(global: T, me
|
|||||||
const isChannel = isChatChannel(chat);
|
const isChannel = isChatChannel(chat);
|
||||||
const isBotChat = Boolean(selectBot(global, chat.id));
|
const isBotChat = Boolean(selectBot(global, chat.id));
|
||||||
const isLocal = isMessageLocal(message);
|
const isLocal = isMessageLocal(message);
|
||||||
|
const isFailed = isMessageFailed(message);
|
||||||
const isServiceNotification = isServiceNotificationMessage(message);
|
const isServiceNotification = isServiceNotificationMessage(message);
|
||||||
const isOwn = isOwnMessage(message);
|
const isOwn = isOwnMessage(message);
|
||||||
const isAction = isActionMessage(message);
|
const isAction = isActionMessage(message);
|
||||||
@ -582,7 +583,7 @@ export function selectAllowedMessageActions<T extends GlobalState>(global: T, me
|
|||||||
canPin = !canUnpin;
|
canPin = !canUnpin;
|
||||||
}
|
}
|
||||||
|
|
||||||
const canDelete = !isLocal && !isServiceNotification && (
|
const canDelete = (!isLocal || isFailed) && !isServiceNotification && (
|
||||||
isPrivate
|
isPrivate
|
||||||
|| isOwn
|
|| isOwn
|
||||||
|| isBasicGroup
|
|| isBasicGroup
|
||||||
@ -614,8 +615,8 @@ export function selectAllowedMessageActions<T extends GlobalState>(global: T, me
|
|||||||
const canFaveSticker = !isAction && hasSticker && !hasFavoriteSticker;
|
const canFaveSticker = !isAction && hasSticker && !hasFavoriteSticker;
|
||||||
const canUnfaveSticker = !isAction && hasFavoriteSticker;
|
const canUnfaveSticker = !isAction && hasFavoriteSticker;
|
||||||
const canCopy = !isAction;
|
const canCopy = !isAction;
|
||||||
const canCopyLink = !isAction && (isChannel || isSuperGroup);
|
const canCopyLink = !isLocal && !isAction && (isChannel || isSuperGroup);
|
||||||
const canSelect = !isAction;
|
const canSelect = !isLocal && !isAction;
|
||||||
|
|
||||||
const canDownload = Boolean(content.webPage?.document || content.webPage?.video || content.webPage?.photo
|
const canDownload = Boolean(content.webPage?.document || content.webPage?.video || content.webPage?.photo
|
||||||
|| content.audio || content.voice || content.photo || content.video || content.document || content.sticker);
|
|| content.audio || content.voice || content.photo || content.video || content.document || content.sticker);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user