Comments: Poll new counters periodically (#2747)
This commit is contained in:
parent
8696eb41ce
commit
53827859a2
@ -30,7 +30,7 @@ export {
|
||||
fetchPinnedMessages, fetchScheduledHistory, sendScheduledMessages, rescheduleMessage, deleteScheduledMessages,
|
||||
reportMessages, sendMessageAction, fetchSeenBy, fetchSponsoredMessages, viewSponsoredMessage, fetchSendAs,
|
||||
saveDefaultSendAs, fetchUnreadReactions, readAllReactions, fetchUnreadMentions, readAllMentions, transcribeAudio,
|
||||
closePoll, fetchExtendedMedia, translateText,
|
||||
closePoll, fetchExtendedMedia, translateText, fetchMessageViews,
|
||||
} from './messages';
|
||||
|
||||
export {
|
||||
|
||||
@ -871,6 +871,30 @@ export async function markMessagesRead({
|
||||
});
|
||||
}
|
||||
|
||||
export async function fetchMessageViews({
|
||||
chat, ids,
|
||||
}: {
|
||||
chat: ApiChat; ids: number[];
|
||||
}) {
|
||||
const result = await invokeRequest(new GramJs.messages.GetMessagesViews({
|
||||
peer: buildInputPeer(chat.id, chat.accessHash),
|
||||
id: ids,
|
||||
increment: false,
|
||||
}));
|
||||
|
||||
if (!result) return undefined;
|
||||
|
||||
return ids.map((id, index) => {
|
||||
const { views, forwards, replies } = result.views[index];
|
||||
return {
|
||||
id,
|
||||
views,
|
||||
forwards,
|
||||
messagesCount: replies?.replies,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export async function requestThreadInfoUpdate({
|
||||
chat, threadId, originChannelId,
|
||||
}: {
|
||||
|
||||
@ -114,6 +114,7 @@ type StateProps = {
|
||||
};
|
||||
|
||||
const MESSAGE_REACTIONS_POLLING_INTERVAL = 15 * 1000;
|
||||
const MESSAGE_COMMENTS_POLLING_INTERVAL = 15 * 1000;
|
||||
const BOTTOM_THRESHOLD = 50;
|
||||
const UNREAD_DIVIDER_TOP = 10;
|
||||
const UNREAD_DIVIDER_TOP_WITH_TOOLS = 60;
|
||||
@ -164,6 +165,7 @@ const MessageList: FC<OwnProps & StateProps> = ({
|
||||
}) => {
|
||||
const {
|
||||
loadViewportMessages, setScrollOffset, loadSponsoredMessages, loadMessageReactions, copyMessagesByIds,
|
||||
loadMessageViews,
|
||||
} = getActions();
|
||||
|
||||
// eslint-disable-next-line no-null/no-null
|
||||
@ -262,6 +264,17 @@ const MessageList: FC<OwnProps & StateProps> = ({
|
||||
loadMessageReactions({ chatId, ids });
|
||||
}, MESSAGE_REACTIONS_POLLING_INTERVAL);
|
||||
|
||||
useInterval(() => {
|
||||
if (!messageIds || !messagesById || threadId !== MAIN_THREAD_ID) {
|
||||
return;
|
||||
}
|
||||
const ids = messageIds.filter((id) => messagesById[id]?.repliesThreadInfo?.isComments);
|
||||
|
||||
if (!ids.length) return;
|
||||
|
||||
loadMessageViews({ chatId, ids });
|
||||
}, MESSAGE_COMMENTS_POLLING_INTERVAL);
|
||||
|
||||
const loadMoreAround = useMemo(() => {
|
||||
if (type !== 'thread') {
|
||||
return undefined;
|
||||
|
||||
@ -1459,6 +1459,41 @@ addActionHandler('translateMessages', (global, actions, payload): ActionReturnTy
|
||||
return global;
|
||||
});
|
||||
|
||||
addActionHandler('loadMessageViews', async (global, actions, payload): Promise<void> => {
|
||||
const { chatId, ids } = payload;
|
||||
|
||||
const chat = selectChat(global, chatId);
|
||||
if (!chat) return;
|
||||
|
||||
const result = await callApi('fetchMessageViews', {
|
||||
chat,
|
||||
ids,
|
||||
});
|
||||
|
||||
if (!result) return;
|
||||
|
||||
global = getGlobal();
|
||||
result.forEach((update) => {
|
||||
global = updateChatMessage(global, chatId, update.id, {
|
||||
views: update.views,
|
||||
forwards: update.forwards,
|
||||
});
|
||||
|
||||
const message = selectChatMessage(global, chatId, update.id);
|
||||
if (!message) return;
|
||||
|
||||
const repliesChatId = message.repliesThreadInfo?.chatId;
|
||||
const threadId = message.repliesThreadInfo?.threadId;
|
||||
if (!repliesChatId || !threadId) return;
|
||||
|
||||
global = updateThreadInfo(global, repliesChatId, threadId, {
|
||||
messagesCount: update.messagesCount,
|
||||
});
|
||||
});
|
||||
|
||||
setGlobal(global);
|
||||
});
|
||||
|
||||
function countSortedIds(ids: number[], from: number, to: number) {
|
||||
let count = 0;
|
||||
|
||||
|
||||
@ -1666,6 +1666,10 @@ export interface ActionPayloads {
|
||||
chatId: string;
|
||||
offsetId?: number;
|
||||
};
|
||||
loadMessageViews: {
|
||||
chatId: string;
|
||||
ids: number[];
|
||||
};
|
||||
animateUnreadReaction: {
|
||||
messageIds: number[];
|
||||
} & WithTabId;
|
||||
|
||||
@ -1196,6 +1196,7 @@ messages.getStickerSet#c8a0ec74 stickerset:InputStickerSet hash:int = messages.S
|
||||
messages.installStickerSet#c78fe460 stickerset:InputStickerSet archived:Bool = messages.StickerSetInstallResult;
|
||||
messages.uninstallStickerSet#f96e55de stickerset:InputStickerSet = Bool;
|
||||
messages.startBot#e6df7378 bot:InputUser peer:InputPeer random_id:long start_param:string = Updates;
|
||||
messages.getMessagesViews#5784d3e1 peer:InputPeer id:Vector<int> increment:Bool = messages.MessageViews;
|
||||
messages.migrateChat#a2875319 chat_id:long = Updates;
|
||||
messages.searchGlobal#4bc6589a flags:# folder_id:flags.0?int q:string filter:MessagesFilter min_date:int max_date:int offset_rate:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages;
|
||||
messages.getDocumentByHash#b1f2061f sha256:bytes size:long mime_type:string = Document;
|
||||
|
||||
@ -275,5 +275,6 @@
|
||||
"channels.updatePinnedForumTopic",
|
||||
"channels.deleteTopicHistory",
|
||||
"channels.toggleParticipantsHidden",
|
||||
"photos.uploadContactProfilePhoto"
|
||||
"photos.uploadContactProfilePhoto",
|
||||
"messages.getMessagesViews"
|
||||
]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user