Support reportMessageDelivery (#5440)
This commit is contained in:
parent
d0633cb419
commit
e97ec38930
@ -267,6 +267,7 @@ export function buildApiMessageWithChatId(
|
||||
effectId: mtpMessage.effect?.toString(),
|
||||
isInvertedMedia,
|
||||
isVideoProcessingPending,
|
||||
reportDeliveryUntilDate: mtpMessage.reportDeliveryUntilDate,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -1121,6 +1121,18 @@ export function fetchPaidReactionPrivacy() {
|
||||
return invokeRequest(new GramJs.messages.GetPaidReactionPrivacy(), { shouldReturnTrue: true });
|
||||
}
|
||||
|
||||
export function reportMessagesDelivery({
|
||||
chat, messageIds,
|
||||
}: {
|
||||
chat: ApiChat;
|
||||
messageIds: number[];
|
||||
}) {
|
||||
return invokeRequest(new GramJs.messages.ReportMessagesDelivery({
|
||||
peer: buildInputPeer(chat.id, chat.accessHash),
|
||||
id: messageIds,
|
||||
}));
|
||||
}
|
||||
|
||||
export async function fetchDiscussionMessage({
|
||||
chat, messageId,
|
||||
}: {
|
||||
|
||||
@ -773,6 +773,7 @@ export interface ApiMessage {
|
||||
isInvertedMedia?: true;
|
||||
isVideoProcessingPending?: true;
|
||||
areReactionsPossible?: true;
|
||||
reportDeliveryUntilDate?: number;
|
||||
}
|
||||
|
||||
export interface ApiReactions {
|
||||
|
||||
@ -2284,6 +2284,31 @@ addActionHandler('copyMessageLink', async (global, actions, payload): Promise<vo
|
||||
);
|
||||
});
|
||||
|
||||
const MESSAGES_TO_REPORT_DELIVERY = new Map<string, number[]>();
|
||||
let reportDeliveryTimeout: number | undefined;
|
||||
addActionHandler('reportMessageDelivery', (global, actions, payload): ActionReturnType => {
|
||||
const { chatId, messageId } = payload;
|
||||
const currentIds = MESSAGES_TO_REPORT_DELIVERY.get(chatId) || [];
|
||||
currentIds.push(messageId);
|
||||
MESSAGES_TO_REPORT_DELIVERY.set(chatId, currentIds);
|
||||
|
||||
if (!reportDeliveryTimeout) {
|
||||
// Slightly unsafe in the multitab environment, but there is no better way to do it now.
|
||||
// Not critical if user manages to close the tab in a show window before the report is sent.
|
||||
reportDeliveryTimeout = window.setTimeout(() => {
|
||||
reportDeliveryTimeout = undefined;
|
||||
|
||||
MESSAGES_TO_REPORT_DELIVERY.forEach((messageIds, cId) => {
|
||||
const chat = selectChat(global, cId);
|
||||
if (!chat) return;
|
||||
|
||||
callApi('reportMessagesDelivery', { chat, messageIds });
|
||||
});
|
||||
MESSAGES_TO_REPORT_DELIVERY.clear();
|
||||
}, 500);
|
||||
}
|
||||
});
|
||||
|
||||
function countSortedIds(ids: number[], from: number, to: number) {
|
||||
// If ids are outside viewport, we cannot get correct count
|
||||
if (ids.length === 0 || from < ids[0] || to > ids[ids.length - 1]) return undefined;
|
||||
|
||||
@ -18,6 +18,7 @@ import {
|
||||
import { getMessageKey, isLocalMessageId } from '../../../util/keys/messageKey';
|
||||
import { notifyAboutMessage } from '../../../util/notifications';
|
||||
import { onTickEnd } from '../../../util/schedulers';
|
||||
import { getServerTime } from '../../../util/serverTime';
|
||||
import {
|
||||
addPaidReaction,
|
||||
checkIfHasUnreadReactions, getIsSavedDialog, getMessageContent, getMessageText, isActionMessage,
|
||||
@ -163,6 +164,10 @@ addActionHandler('apiUpdate', (global, actions, update): ActionReturnType => {
|
||||
global = updatePoll(global, poll.id, poll);
|
||||
}
|
||||
|
||||
if (message.reportDeliveryUntilDate && message.reportDeliveryUntilDate > getServerTime()) {
|
||||
actions.reportMessageDelivery({ chatId, messageId: id });
|
||||
}
|
||||
|
||||
setGlobal(global);
|
||||
|
||||
// Reload dialogs if chat is not present in the list
|
||||
|
||||
@ -2443,6 +2443,11 @@ export interface ActionPayloads {
|
||||
botId: string;
|
||||
isAccessGranted: boolean;
|
||||
};
|
||||
|
||||
reportMessageDelivery: {
|
||||
chatId: string;
|
||||
messageId: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface RequiredActionPayloads {
|
||||
|
||||
@ -1616,6 +1616,7 @@ messages.viewSponsoredMessage#673ad8f1 peer:InputPeer random_id:bytes = Bool;
|
||||
messages.clickSponsoredMessage#f093465 flags:# media:flags.0?true fullscreen:flags.1?true peer:InputPeer random_id:bytes = Bool;
|
||||
messages.reportSponsoredMessage#1af3dbb8 peer:InputPeer random_id:bytes option:bytes = channels.SponsoredMessageReportResult;
|
||||
messages.getSponsoredMessages#9bd2f439 peer:InputPeer = messages.SponsoredMessages;
|
||||
messages.reportMessagesDelivery#5a6d7395 flags:# push:flags.0?true peer:InputPeer id:Vector<int> = Bool;
|
||||
updates.getState#edd4882a = updates.State;
|
||||
updates.getDifference#19c2f763 flags:# pts:int pts_limit:flags.1?int pts_total_limit:flags.0?int date:int qts:int qts_limit:flags.2?int = updates.Difference;
|
||||
updates.getChannelDifference#3173d78 flags:# force:flags.0?true channel:InputChannel filter:ChannelMessagesFilter pts:int limit:int = updates.ChannelDifference;
|
||||
@ -1685,8 +1686,8 @@ bots.allowSendMessage#f132e3ef bot:InputUser = Updates;
|
||||
bots.invokeWebViewCustomMethod#87fc5e7 bot:InputUser custom_method:string params:DataJSON = DataJSON;
|
||||
bots.getPopularAppBots#c2510192 offset:string limit:int = bots.PopularAppBots;
|
||||
bots.getPreviewMedias#a2a5594d bot:InputUser = Vector<BotPreviewMedia>;
|
||||
bots.checkDownloadFileParams#50077589 bot:InputUser file_name:string url:string = Bool;
|
||||
bots.toggleUserEmojiStatusPermission#6de6392 bot:InputUser enabled:Bool = Bool;
|
||||
bots.checkDownloadFileParams#50077589 bot:InputUser file_name:string url:string = Bool;
|
||||
payments.getPaymentForm#37148dbb flags:# invoice:InputInvoice theme_params:flags.0?DataJSON = payments.PaymentForm;
|
||||
payments.getPaymentReceipt#2478d1cc peer:InputPeer msg_id:int = payments.PaymentReceipt;
|
||||
payments.validateRequestedInfo#b6c8f12b flags:# save:flags.0?true invoice:InputInvoice info:PaymentRequestedInfo = payments.ValidatedRequestedInfo;
|
||||
@ -1777,4 +1778,4 @@ premium.getBoostsList#60f67660 flags:# gifts:flags.0?true peer:InputPeer offset:
|
||||
premium.getMyBoosts#be77b4a = premium.MyBoosts;
|
||||
premium.applyBoost#6b7da746 flags:# slots:flags.0?Vector<int> peer:InputPeer = premium.MyBoosts;
|
||||
premium.getBoostsStatus#42f1f61 peer:InputPeer = premium.BoostsStatus;
|
||||
fragment.getCollectibleInfo#be1e85ba collectible:InputCollectible = fragment.CollectibleInfo;`;
|
||||
fragment.getCollectibleInfo#be1e85ba collectible:InputCollectible = fragment.CollectibleInfo;`;
|
||||
@ -217,6 +217,7 @@
|
||||
"messages.clickSponsoredMessage",
|
||||
"messages.reportSponsoredMessage",
|
||||
"messages.getSponsoredMessages",
|
||||
"messages.reportMessagesDelivery",
|
||||
"updates.getState",
|
||||
"updates.getDifference",
|
||||
"updates.getChannelDifference",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user