diff --git a/src/api/gramjs/apiBuilders/messages.ts b/src/api/gramjs/apiBuilders/messages.ts index 03764276..a5abe5e5 100644 --- a/src/api/gramjs/apiBuilders/messages.ts +++ b/src/api/gramjs/apiBuilders/messages.ts @@ -849,10 +849,11 @@ export function buildLocalMessage( }; } -export function buildForwardedMessage( +export function buildLocalForwardedMessage( toChat: ApiChat, message: ApiMessage, serverTimeOffset: number, + scheduledAt?: number, ): ApiMessage { const localId = localMessageCounter++; const { @@ -873,10 +874,12 @@ export function buildForwardedMessage( id: localId, chatId: toChat.id, content, - date: Math.round(Date.now() / 1000) + serverTimeOffset, + date: scheduledAt || Math.round(Date.now() / 1000) + serverTimeOffset, isOutgoing: !asIncomingInChatWithSelf && toChat.type !== 'chatTypeChannel', senderId: currentUserId, sendingState: 'messageSendingStatePending', + groupedId, + isInAlbum, // Forward info doesn't get added when users forwards his own messages, also when forwarding audio ...(senderId !== currentUserId && !isAudio && { forwardInfo: { @@ -886,8 +889,7 @@ export function buildForwardedMessage( senderUserId: senderId, }, }), - groupedId, - isInAlbum, + ...(scheduledAt && { isScheduled: true }), }; } diff --git a/src/api/gramjs/methods/messages.ts b/src/api/gramjs/methods/messages.ts index 8cce8492..025746d9 100644 --- a/src/api/gramjs/methods/messages.ts +++ b/src/api/gramjs/methods/messages.ts @@ -30,7 +30,7 @@ import { buildApiMessage, buildLocalMessage, buildWebPage, - buildForwardedMessage, + buildLocalForwardedMessage, } from '../apiBuilders/messages'; import { buildApiUser } from '../apiBuilders/users'; import { @@ -1024,21 +1024,25 @@ export async function forwardMessages({ toChat, messages, serverTimeOffset, + isSilent, + scheduledAt, }: { fromChat: ApiChat; toChat: ApiChat; messages: ApiMessage[]; serverTimeOffset: number; + isSilent?: boolean; + scheduledAt?: number; }) { const messageIds = messages.map(({ id }) => id); const randomIds = messages.map(generateRandomBigInt); messages.forEach((message, index) => { - const localMessage = buildForwardedMessage(toChat, message, serverTimeOffset); + const localMessage = buildLocalForwardedMessage(toChat, message, serverTimeOffset, scheduledAt); localDb.localMessages[String(randomIds[index])] = localMessage; onUpdate({ - '@type': 'newMessage', + '@type': localMessage.isScheduled ? 'newScheduledMessage' : 'newMessage', id: localMessage.id, chatId: toChat.id, message: localMessage, @@ -1050,6 +1054,8 @@ export async function forwardMessages({ toPeer: buildInputPeer(toChat.id, toChat.accessHash), randomId: randomIds, id: messageIds, + ...(isSilent && { sil2ent: isSilent }), + ...(scheduledAt && { scheduleDate: scheduledAt }), }), true); } diff --git a/src/components/middle/composer/Composer.tsx b/src/components/middle/composer/Composer.tsx index 7b137e63..84f0e64a 100644 --- a/src/components/middle/composer/Composer.tsx +++ b/src/components/middle/composer/Composer.tsx @@ -526,8 +526,12 @@ const Composer: FC = ({ isSilent, }); } + if (isForwarding) { - forwardMessages(); + forwardMessages({ + scheduledAt, + isSilent, + }); } lastMessageSendTimeSeconds.current = getServerTime(serverTimeOffset); diff --git a/src/components/middle/message/Message.tsx b/src/components/middle/message/Message.tsx index 40817cea..b90a1925 100644 --- a/src/components/middle/message/Message.tsx +++ b/src/components/middle/message/Message.tsx @@ -270,7 +270,9 @@ const Message: FC = ({ const hasReply = isReplyMessage(message) && !shouldHideReply; const hasThread = Boolean(threadInfo) && messageListType === 'thread'; const { forwardInfo, viaBotId } = message; - const asForwarded = forwardInfo && !isChatWithSelf && !isRepliesChat && !forwardInfo.isLinkedChannelPost; + const asForwarded = ( + forwardInfo && (!isChatWithSelf || isScheduled) && !isRepliesChat && !forwardInfo.isLinkedChannelPost + ); const isInDocumentGroup = Boolean(message.groupedId) && !message.isInAlbum; const isAlbum = Boolean(album) && album!.messages.length > 1; const { diff --git a/src/modules/actions/api/messages.ts b/src/modules/actions/api/messages.ts index ce28216d..70d93f67 100644 --- a/src/modules/actions/api/messages.ts +++ b/src/modules/actions/api/messages.ts @@ -555,7 +555,7 @@ addReducer('loadPollOptionResults', (global, actions, payload) => { void loadPollOptionResults(chat, messageId, option, offset, limit, shouldResetVoters); }); -addReducer('forwardMessages', (global) => { +addReducer('forwardMessages', (global, action, payload) => { const { fromChatId, messageIds, toChatId } = global.forwardMessages; const fromChat = fromChatId ? selectChat(global, fromChatId) : undefined; const toChat = toChatId ? selectChat(global, toChatId) : undefined; @@ -569,6 +569,8 @@ addReducer('forwardMessages', (global) => { return; } + const { isSilent, scheduledAt } = payload; + const realMessages = messages.filter((m) => !isServiceNotificationMessage(m)); if (realMessages.length) { void callApi('forwardMessages', { @@ -576,6 +578,8 @@ addReducer('forwardMessages', (global) => { toChat, messages: realMessages, serverTimeOffset: getGlobal().serverTimeOffset, + isSilent, + scheduledAt, }); } @@ -591,6 +595,8 @@ addReducer('forwardMessages', (global) => { entities, sticker, poll, + isSilent, + scheduledAt, }); }); @@ -829,6 +835,8 @@ async function sendMessage(params: { gif?: ApiVideo; poll?: ApiNewPoll; serverTimeOffset?: number; + isSilent?: boolean; + scheduledAt?: number; }) { let localId: number | undefined; const progressCallback = params.attachment ? (progress: number, messageLocalId: number) => {