From 64badee6f24507ee41ad2dbd898e1d67ca67aeb9 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 13 Jun 2023 13:46:12 +0300 Subject: [PATCH] Add get_message_content_min_user_ids and register story sender. --- td/telegram/MessageContent.cpp | 145 ++++++++++++++++++++++++++++++-- td/telegram/MessageContent.h | 2 +- td/telegram/MessagesManager.cpp | 12 +-- 3 files changed, 142 insertions(+), 17 deletions(-) diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index aaeb91f92..8c452835e 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -3301,13 +3301,148 @@ std::pair get_message_content_group_call_info(const Mess return {m->input_group_call_id, m->duration >= 0}; } -UserId get_message_content_contact_user_id(const MessageContent *content) { - switch (content->get_type()) { - case MessageContentType::Contact: - return static_cast(content)->contact.get_user_id(); +vector get_message_content_min_user_ids(const MessageContent *message_content) { + switch (message_content->get_type()) { + case MessageContentType::Text: { + // const auto *content = static_cast(message_content); + break; + } + case MessageContentType::Animation: + break; + case MessageContentType::Audio: + break; + case MessageContentType::Contact: { + const auto *content = static_cast(message_content); + return {content->contact.get_user_id()}; + } + case MessageContentType::Document: + break; + case MessageContentType::Game: { + // not supported + // const auto *content = static_cast(message_content); + // return {content->game.get_bot_user_id())}; + } + case MessageContentType::Invoice: + break; + case MessageContentType::LiveLocation: + break; + case MessageContentType::Location: + break; + case MessageContentType::Photo: + break; + case MessageContentType::Sticker: + break; + case MessageContentType::Venue: + break; + case MessageContentType::Video: + break; + case MessageContentType::VideoNote: + break; + case MessageContentType::VoiceNote: + break; + case MessageContentType::ChatCreate: { + const auto *content = static_cast(message_content); + return content->participant_user_ids; + } + case MessageContentType::ChatChangeTitle: + break; + case MessageContentType::ChatChangePhoto: + break; + case MessageContentType::ChatDeletePhoto: + break; + case MessageContentType::ChatDeleteHistory: + break; + case MessageContentType::ChatAddUsers: { + const auto *content = static_cast(message_content); + return content->user_ids; + } + case MessageContentType::ChatJoinedByLink: + break; + case MessageContentType::ChatDeleteUser: { + const auto *content = static_cast(message_content); + return {content->user_id}; + } + case MessageContentType::ChatMigrateTo: + break; + case MessageContentType::ChannelCreate: + break; + case MessageContentType::ChannelMigrateFrom: + break; + case MessageContentType::PinMessage: + break; + case MessageContentType::GameScore: + break; + case MessageContentType::ScreenshotTaken: + break; + case MessageContentType::ChatSetTtl: + // the content->from_user_id user can't be min + break; + case MessageContentType::Unsupported: + break; + case MessageContentType::Call: + break; + case MessageContentType::PaymentSuccessful: + break; + case MessageContentType::ContactRegistered: + break; + case MessageContentType::ExpiredPhoto: + break; + case MessageContentType::ExpiredVideo: + break; + case MessageContentType::CustomServiceAction: + break; + case MessageContentType::WebsiteConnected: + break; + case MessageContentType::PassportDataSent: + break; + case MessageContentType::PassportDataReceived: + break; + case MessageContentType::Poll: + break; + case MessageContentType::Dice: + break; + case MessageContentType::ProximityAlertTriggered: + break; + case MessageContentType::GroupCall: + break; + case MessageContentType::InviteToGroupCall: { + const auto *content = static_cast(message_content); + return content->user_ids; + } + case MessageContentType::ChatSetTheme: + break; + case MessageContentType::WebViewDataSent: + break; + case MessageContentType::WebViewDataReceived: + break; + case MessageContentType::GiftPremium: + break; + case MessageContentType::TopicCreate: + break; + case MessageContentType::TopicEdit: + break; + case MessageContentType::SuggestProfilePhoto: + break; + case MessageContentType::WriteAccessAllowed: + break; + case MessageContentType::RequestedDialog: + break; + case MessageContentType::WebViewWriteAccessAllowed: + break; + case MessageContentType::SetBackground: + break; + case MessageContentType::Story: { + const auto *content = static_cast(message_content); + if (content->story_full_id.get_dialog_id().get_type() == DialogType::User) { + return {content->story_full_id.get_dialog_id().get_user_id()}; + } + break; + } default: - return UserId(); + UNREACHABLE(); + break; } + return {}; } vector get_message_content_added_user_ids(const MessageContent *content) { diff --git a/td/telegram/MessageContent.h b/td/telegram/MessageContent.h index c97a09d09..6a677e16a 100644 --- a/td/telegram/MessageContent.h +++ b/td/telegram/MessageContent.h @@ -144,7 +144,7 @@ FullMessageId get_message_content_replied_message_id(DialogId dialog_id, const M std::pair get_message_content_group_call_info(const MessageContent *content); -UserId get_message_content_contact_user_id(const MessageContent *content); +vector get_message_content_min_user_ids(const MessageContent *message_content); vector get_message_content_added_user_ids(const MessageContent *content); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 375d65b27..181141e04 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -13209,17 +13209,7 @@ vector MessagesManager::get_message_user_ids(const Message *m) { if (m->forward_info != nullptr && m->forward_info->sender_user_id.is_valid()) { user_ids.push_back(m->forward_info->sender_user_id); } - if (m->content->get_type() == MessageContentType::ChatAddUsers) { - append(user_ids, get_message_content_added_user_ids(m->content.get())); - } - auto deleted_user_id = get_message_content_deleted_user_id(m->content.get()); - if (deleted_user_id.is_valid()) { - user_ids.push_back(deleted_user_id); - } - auto contact_user_id = get_message_content_contact_user_id(m->content.get()); - if (contact_user_id.is_valid()) { - user_ids.push_back(contact_user_id); - } + append(user_ids, get_message_content_min_user_ids(m->content.get())); return user_ids; }