Service Notifications: Support forwarding

This commit is contained in:
Alexander Zinchuk 2021-10-22 14:33:10 +03:00
parent b3f5ebffcb
commit 6390e45c51
2 changed files with 42 additions and 29 deletions

View File

@ -16,6 +16,7 @@ import {
import { LoadMoreDirection } from '../../../types';
import { MAX_MEDIA_FILES_FOR_ALBUM, MESSAGE_LIST_SLICE, SERVICE_NOTIFICATIONS_USER_ID } from '../../../config';
import { IS_IOS } from '../../../util/environment';
import { callApi, cancelApiProgress } from '../../../api/gramjs';
import { areSortedArraysIntersecting, buildCollectionByKey, split } from '../../../util/iteratees';
import {
@ -54,7 +55,7 @@ import {
selectFirstUnreadId,
} from '../../selectors';
import { debounce, rafPromise } from '../../../util/schedulers';
import { IS_IOS } from '../../../util/environment';
import { isServiceNotificationMessage } from '../../helpers';
const uploadProgressCallbacks = new Map<number, ApiOnProgress>();
@ -553,9 +554,39 @@ addReducer('forwardMessages', (global) => {
.map((id) => selectChatMessage(global, fromChatId, id)).filter<ApiMessage>(Boolean as any)
: undefined;
if (fromChat && toChat && messages && messages.length) {
void forwardMessages(fromChat, toChat, messages);
if (!fromChat || !toChat || !messages) {
return;
}
const realMessages = messages.filter((m) => !isServiceNotificationMessage(m));
if (realMessages.length) {
void callApi('forwardMessages', {
fromChat,
toChat,
messages: realMessages,
serverTimeOffset: getGlobal().serverTimeOffset,
});
}
messages
.filter((m) => isServiceNotificationMessage(m))
.forEach((message) => {
const { text, entities } = message.content.text || {};
const { sticker, poll } = message.content;
void sendMessage({
chat: toChat,
text,
entities,
sticker,
poll,
});
});
setGlobal({
...getGlobal(),
forwardMessages: {},
});
});
addReducer('loadScheduledHistory', (global, actions, payload) => {
@ -781,13 +812,13 @@ function getViewportSlice(
async function sendMessage(params: {
chat: ApiChat;
text: string;
entities: ApiMessageEntity[];
replyingTo: number;
attachment: ApiAttachment;
sticker: ApiSticker;
gif: ApiVideo;
poll: ApiNewPoll;
text?: string;
entities?: ApiMessageEntity[];
replyingTo?: number;
attachment?: ApiAttachment;
sticker?: ApiSticker;
gif?: ApiVideo;
poll?: ApiNewPoll;
serverTimeOffset?: number;
}) {
let localId: number | undefined;
@ -834,24 +865,6 @@ async function sendMessage(params: {
}
}
function forwardMessages(
fromChat: ApiChat,
toChat: ApiChat,
messages: ApiMessage[],
) {
callApi('forwardMessages', {
fromChat,
toChat,
messages,
serverTimeOffset: getGlobal().serverTimeOffset,
});
setGlobal({
...getGlobal(),
forwardMessages: {},
});
}
async function loadPollOptionResults(
chat: ApiChat,
messageId: number,

View File

@ -409,7 +409,7 @@ export function selectAllowedMessageActions(global: GlobalState, message: ApiMes
|| (isChannel && (chat.isCreator || getHasAdminRight(chat, 'editMessages')))
);
const canForward = !isLocal && !isServiceNotification && !isAction;
const canForward = !isLocal && !isAction;
const hasSticker = Boolean(message.content.sticker);
const hasFavoriteSticker = hasSticker && selectIsStickerFavorite(global, message.content.sticker!);