mirror of
https://github.com/danog/telegram-tt.git
synced 2025-01-21 21:01:29 +01:00
Composer: Support scheduling forwarded messages
This commit is contained in:
parent
becfab6fe7
commit
f17277aad9
@ -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 }),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -526,8 +526,12 @@ const Composer: FC<OwnProps & StateProps & DispatchProps> = ({
|
||||
isSilent,
|
||||
});
|
||||
}
|
||||
|
||||
if (isForwarding) {
|
||||
forwardMessages();
|
||||
forwardMessages({
|
||||
scheduledAt,
|
||||
isSilent,
|
||||
});
|
||||
}
|
||||
|
||||
lastMessageSendTimeSeconds.current = getServerTime(serverTimeOffset);
|
||||
|
@ -270,7 +270,9 @@ const Message: FC<OwnProps & StateProps & DispatchProps> = ({
|
||||
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 {
|
||||
|
@ -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) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user