From c5a41e1f550d528be5b54b6d815fee5857e2132f Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 4 Jan 2019 15:09:48 +0400 Subject: [PATCH] Divide data/data_peer and remove from PCH. --- Telegram/SourceFiles/apiwrap.cpp | 7 +- Telegram/SourceFiles/apiwrap.h | 8 +- Telegram/SourceFiles/app.cpp | 15 + Telegram/SourceFiles/app.h | 16 +- Telegram/SourceFiles/auth_session.cpp | 9 + Telegram/SourceFiles/auth_session.h | 8 +- .../SourceFiles/boxes/add_contact_box.cpp | 3 + Telegram/SourceFiles/boxes/confirm_box.cpp | 3 + .../SourceFiles/boxes/edit_caption_box.cpp | 1 + .../boxes/edit_participant_box.cpp | 6 + .../SourceFiles/boxes/edit_participant_box.h | 4 +- .../SourceFiles/boxes/edit_privacy_box.cpp | 1 + Telegram/SourceFiles/boxes/peer_list_box.cpp | 15 + Telegram/SourceFiles/boxes/peer_list_box.h | 13 +- .../boxes/peer_list_controllers.cpp | 7 +- .../boxes/peers/edit_peer_info_box.cpp | 3 + .../boxes/peers/manage_peer_box.cpp | 1 + Telegram/SourceFiles/boxes/report_box.cpp | 5 +- Telegram/SourceFiles/boxes/share_box.cpp | 2 + Telegram/SourceFiles/boxes/stickers_box.cpp | 1 + Telegram/SourceFiles/boxes/username_box.cpp | 3 +- Telegram/SourceFiles/calls/calls_call.cpp | 1 + Telegram/SourceFiles/calls/calls_instance.cpp | 3 +- Telegram/SourceFiles/calls/calls_panel.cpp | 1 + Telegram/SourceFiles/calls/calls_top_bar.cpp | 5 +- .../SourceFiles/chat_helpers/bot_keyboard.cpp | 1 + .../chat_helpers/field_autocomplete.cpp | 7 +- .../chat_helpers/gifs_list_widget.cpp | 1 + .../chat_helpers/message_field.cpp | 1 + .../chat_helpers/stickers_list_widget.cpp | 1 + .../chat_helpers/tabbed_selector.cpp | 1 + .../SourceFiles/core/click_handler_types.cpp | 1 + Telegram/SourceFiles/data/data_channel.cpp | 474 +++++++++ Telegram/SourceFiles/data/data_channel.h | 364 +++++++ .../SourceFiles/data/data_channel_admins.cpp | 1 + Telegram/SourceFiles/data/data_chat.cpp | 65 ++ Telegram/SourceFiles/data/data_chat.h | 108 ++ .../data/data_document_good_thumbnail.cpp | 1 + Telegram/SourceFiles/data/data_feed.cpp | 1 + .../SourceFiles/data/data_file_origin.cpp | 4 +- Telegram/SourceFiles/data/data_file_origin.h | 39 +- .../SourceFiles/data/data_media_types.cpp | 1 + Telegram/SourceFiles/data/data_peer.cpp | 949 ++---------------- Telegram/SourceFiles/data/data_peer.h | 913 +---------------- .../SourceFiles/data/data_peer_values.cpp | 3 + Telegram/SourceFiles/data/data_photo.cpp | 1 + Telegram/SourceFiles/data/data_pts_waiter.cpp | 159 +++ Telegram/SourceFiles/data/data_pts_waiter.h | 95 ++ .../data/data_search_controller.cpp | 1 + Telegram/SourceFiles/data/data_session.cpp | 4 + Telegram/SourceFiles/data/data_session.h | 1 + Telegram/SourceFiles/data/data_types.h | 6 + Telegram/SourceFiles/data/data_user.cpp | 260 +++++ Telegram/SourceFiles/data/data_user.h | 229 +++++ .../dialogs/dialogs_inner_widget.cpp | 3 + .../SourceFiles/dialogs/dialogs_layout.cpp | 2 + .../dialogs_search_from_controllers.cpp | 2 + .../SourceFiles/dialogs/dialogs_widget.cpp | 3 + Telegram/SourceFiles/facades.cpp | 9 + Telegram/SourceFiles/facades.h | 12 +- .../admin_log/history_admin_log_filter.cpp | 4 +- .../admin_log/history_admin_log_inner.cpp | 2 + .../admin_log/history_admin_log_item.cpp | 23 +- .../admin_log/history_admin_log_section.cpp | 1 + Telegram/SourceFiles/history/history.cpp | 3 + .../history/history_inner_widget.cpp | 1 + Telegram/SourceFiles/history/history_item.cpp | 7 +- .../history/history_item_components.cpp | 2 + .../SourceFiles/history/history_item_text.cpp | 1 + .../history/history_location_manager.cpp | 1 + .../SourceFiles/history/history_message.cpp | 2 + .../SourceFiles/history/history_service.cpp | 10 + .../SourceFiles/history/history_service.h | 8 +- .../SourceFiles/history/history_widget.cpp | 3 + .../history/media/history_media_contact.cpp | 1 + .../history/media/history_media_contact.h | 4 + .../history/media/history_media_location.cpp | 1 + .../history/media/history_media_photo.cpp | 1 + .../history/media/history_media_video.cpp | 1 + .../history/media/history_media_web_page.cpp | 1 + .../view/history_view_context_menu.cpp | 1 + .../history/view/history_view_list_widget.cpp | 1 + .../history/view/history_view_message.cpp | 1 + .../view/history_view_top_bar_widget.cpp | 3 + .../info_common_groups_inner_widget.cpp | 5 +- .../info_common_groups_widget.cpp | 1 + .../feed/info_feed_channels_controllers.cpp | 1 + Telegram/SourceFiles/info/info_controller.cpp | 19 +- Telegram/SourceFiles/info/info_controller.h | 14 +- Telegram/SourceFiles/info/info_memento.cpp | 2 + Telegram/SourceFiles/info/info_top_bar.cpp | 4 +- .../SourceFiles/info/info_wrap_widget.cpp | 1 + .../info/media/info_media_buttons.h | 2 + .../info/profile/info_profile_actions.cpp | 2 + .../info/profile/info_profile_cover.cpp | 2 + .../info/profile/info_profile_members.cpp | 7 +- .../info_profile_members_controllers.cpp | 6 + .../info_profile_members_controllers.h | 4 +- .../info/profile/info_profile_values.cpp | 3 + .../inline_bots/inline_bot_layout_item.cpp | 14 +- .../inline_bots/inline_bot_layout_item.h | 4 +- .../inline_bots/inline_bot_send_data.cpp | 1 + .../inline_bots/inline_results_widget.cpp | 2 + Telegram/SourceFiles/intro/introwidget.cpp | 1 + Telegram/SourceFiles/mainwidget.cpp | 3 + Telegram/SourceFiles/mainwidget.h | 1 + Telegram/SourceFiles/media/media_audio.cpp | 1 + .../media/player/media_player_instance.cpp | 1 + .../media/player/media_player_panel.cpp | 2 + .../media/view/media_view_group_thumbs.cpp | 1 + Telegram/SourceFiles/mediaview.cpp | 3 + Telegram/SourceFiles/messenger.cpp | 1 + .../SourceFiles/overview/overview_layout.cpp | 1 + .../passport/passport_form_controller.cpp | 3 +- .../passport/passport_panel_details_row.cpp | 1 + .../passport/passport_panel_form.cpp | 1 + .../passport/passport_panel_password.cpp | 1 + .../profile/profile_block_group_members.cpp | 13 + .../profile/profile_block_group_members.h | 8 +- .../profile/profile_block_peer_list.cpp | 3 +- .../profile/profile_channel_controllers.cpp | 2 + .../settings/settings_information.cpp | 1 + .../SourceFiles/settings/settings_main.cpp | 1 + .../settings/settings_privacy_controllers.cpp | 1 + .../SourceFiles/storage/file_download.cpp | 14 +- Telegram/SourceFiles/storage/file_download.h | 6 +- Telegram/SourceFiles/storage/localstorage.cpp | 1 + .../SourceFiles/storage/serialize_common.cpp | 3 + .../SourceFiles/support/support_helper.cpp | 1 + Telegram/SourceFiles/ui/image/image.cpp | 22 + Telegram/SourceFiles/ui/image/image.h | 26 +- .../SourceFiles/ui/image/image_source.cpp | 3 +- Telegram/SourceFiles/ui/special_buttons.cpp | 1 + Telegram/SourceFiles/ui/text/text_entity.cpp | 1 + Telegram/SourceFiles/ui/text_options.cpp | 3 + .../SourceFiles/ui/widgets/input_fields.cpp | 1 + Telegram/SourceFiles/window/layer_widget.h | 1 + .../window/notifications_manager.cpp | 1 + .../window/notifications_utilities.cpp | 1 + .../SourceFiles/window/window_controller.cpp | 2 + .../SourceFiles/window/window_main_menu.cpp | 1 + .../SourceFiles/window/window_peer_menu.cpp | 3 + Telegram/gyp/telegram_sources.txt | 8 + 143 files changed, 2291 insertions(+), 1899 deletions(-) create mode 100644 Telegram/SourceFiles/data/data_channel.cpp create mode 100644 Telegram/SourceFiles/data/data_channel.h create mode 100644 Telegram/SourceFiles/data/data_chat.cpp create mode 100644 Telegram/SourceFiles/data/data_chat.h create mode 100644 Telegram/SourceFiles/data/data_pts_waiter.cpp create mode 100644 Telegram/SourceFiles/data/data_pts_waiter.h create mode 100644 Telegram/SourceFiles/data/data_user.cpp create mode 100644 Telegram/SourceFiles/data/data_user.h diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index f6228ac03..125c72714 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -17,6 +17,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_search_controller.h" #include "data/data_channel_admins.h" #include "data/data_session.h" +#include "data/data_channel.h" +#include "data/data_chat.h" +#include "data/data_user.h" #include "dialogs/dialogs_key.h" #include "core/tl_help.h" #include "core/core_cloud_password.h" @@ -2604,7 +2607,7 @@ void ApiWrap::requestFileReference( request(std::move(data)).done([=](const auto &result) { const auto parsed = Data::GetFileReferences(result); - for (const auto &p : parsed) { + for (const auto &p : parsed.data) { // Unpack here the parsed pair by hand to workaround a GCC bug. // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87122 const auto &origin = p.first; @@ -2669,7 +2672,7 @@ void ApiWrap::refreshFileReference( const auto fail = [&] { handler(Data::UpdatedFileReferences()); }; - origin.match([&](Data::FileOriginMessage data) { + origin.data.match([&](Data::FileOriginMessage data) { if (const auto item = App::histItemById(data)) { if (const auto channel = item->history()->peer->asChannel()) { request(MTPchannels_GetMessages( diff --git a/Telegram/SourceFiles/apiwrap.h b/Telegram/SourceFiles/apiwrap.h index 9aa711e4b..220a09114 100644 --- a/Telegram/SourceFiles/apiwrap.h +++ b/Telegram/SourceFiles/apiwrap.h @@ -24,6 +24,10 @@ enum class SendMediaType; struct FileLoadTo; class mtpFileLoader; +namespace Data { +struct UpdatedFileReferences; +} // namespace Data + namespace InlineBots { class Result; } // namespace InlineBots @@ -408,10 +412,6 @@ private: TimeMs received = 0; }; - using SimpleFileLocationId = Data::SimpleFileLocationId; - using DocumentFileLocationId = Data::DocumentFileLocationId; - using FileLocationId = Data::FileLocationId; - void updatesReceived(const MTPUpdates &updates); void checkQuitPreventFinished(); diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index f297be69a..c4a8b63fc 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -14,6 +14,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_boxes.h" #include "lang/lang_keys.h" #include "boxes/confirm_box.h" +#include "data/data_channel.h" +#include "data/data_chat.h" +#include "data/data_user.h" #include "data/data_abstract_structure.h" #include "data/data_media_types.h" #include "data/data_session.h" @@ -700,6 +703,14 @@ namespace App { return Auth().data().historyLoaded(peer); } + not_null history(not_null peer) { + return history(peer->id); + } + + History *historyLoaded(const PeerData *peer) { + return peer ? historyLoaded(peer->id) : nullptr; + } + HistoryItem *histItemById(ChannelId channelId, MsgId itemId) { if (!itemId) return nullptr; @@ -713,6 +724,10 @@ namespace App { return nullptr; } + HistoryItem *histItemById(const ChannelData *channel, MsgId itemId) { + return histItemById(channel ? peerToChannel(channel->id) : 0, itemId); + } + void historyRegItem(not_null item) { const auto data = fetchMsgsData(item->channelId()); const auto i = data->constFind(item->id); diff --git a/Telegram/SourceFiles/app.h b/Telegram/SourceFiles/app.h index 18e2a87b5..5d729dd38 100644 --- a/Telegram/SourceFiles/app.h +++ b/Telegram/SourceFiles/app.h @@ -8,7 +8,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "data/data_types.h" -#include "data/data_peer.h" enum NewMessageType : char; enum class ImageRoundRadius; @@ -102,16 +101,11 @@ namespace App { [[nodiscard]] not_null history(PeerId peer); [[nodiscard]] History *historyLoaded(PeerId peer); [[nodiscard]] HistoryItem *histItemById(ChannelId channelId, MsgId itemId); - [[nodiscard]] inline not_null history(const PeerData *peer) { - Assert(peer != nullptr); - return history(peer->id); - } - [[nodiscard]] inline History *historyLoaded(const PeerData *peer) { - return peer ? historyLoaded(peer->id) : nullptr; - } - [[nodiscard]] inline HistoryItem *histItemById(const ChannelData *channel, MsgId itemId) { - return histItemById(channel ? peerToChannel(channel->id) : 0, itemId); - } + [[nodiscard]] not_null history(not_null peer); + [[nodiscard]] History *historyLoaded(const PeerData *peer); + [[nodiscard]] HistoryItem *histItemById( + const ChannelData *channel, + MsgId itemId); [[nodiscard]] inline HistoryItem *histItemById(const FullMsgId &msgId) { return histItemById(msgId.channel, msgId.msg); } diff --git a/Telegram/SourceFiles/auth_session.cpp b/Telegram/SourceFiles/auth_session.cpp index 27d3544c4..10a87f4a9 100644 --- a/Telegram/SourceFiles/auth_session.cpp +++ b/Telegram/SourceFiles/auth_session.cpp @@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/storage_facade.h" #include "storage/serialize_common.h" #include "data/data_session.h" +#include "data/data_user.h" #include "window/notifications_manager.h" #include "window/themes/window_theme.h" #include "platform/platform_specific.h" @@ -438,6 +439,14 @@ base::Observable &AuthSession::downloaderTaskFinished() { return downloader().taskFinished(); } +UserId AuthSession::userId() const { + return _user->bareId(); +} + +PeerId AuthSession::userPeerId() const { + return _user->id; +} + bool AuthSession::validateSelf(const MTPUser &user) { if (user.type() != mtpc_user || !user.c_user().is_self()) { LOG(("API Error: bad self user received.")); diff --git a/Telegram/SourceFiles/auth_session.h b/Telegram/SourceFiles/auth_session.h index cd723d9e8..ec67993bd 100644 --- a/Telegram/SourceFiles/auth_session.h +++ b/Telegram/SourceFiles/auth_session.h @@ -282,12 +282,8 @@ public: static bool Exists(); - UserId userId() const { - return _user->bareId(); - } - PeerId userPeerId() const { - return _user->id; - } + UserId userId() const; + PeerId userPeerId() const; not_null user() const { return _user; } diff --git a/Telegram/SourceFiles/boxes/add_contact_box.cpp b/Telegram/SourceFiles/boxes/add_contact_box.cpp index 57f7b0eb8..4a9f7e8aa 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/add_contact_box.cpp @@ -27,6 +27,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/toast/toast.h" #include "ui/special_buttons.h" #include "ui/text_options.h" +#include "data/data_channel.h" +#include "data/data_chat.h" +#include "data/data_user.h" #include "mainwidget.h" #include "mainwindow.h" #include "apiwrap.h" diff --git a/Telegram/SourceFiles/boxes/confirm_box.cpp b/Telegram/SourceFiles/boxes/confirm_box.cpp index 9c9413d1d..9c6d6886c 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.cpp +++ b/Telegram/SourceFiles/boxes/confirm_box.cpp @@ -25,6 +25,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/click_handler_types.h" #include "storage/localstorage.h" #include "data/data_session.h" +#include "data/data_channel.h" +#include "data/data_chat.h" +#include "data/data_user.h" #include "auth_session.h" #include "observer_peer.h" diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp index 0f0b05878..c673854f2 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp @@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_media_types.h" #include "data/data_photo.h" #include "data/data_document.h" +#include "data/data_user.h" #include "lang/lang_keys.h" #include "core/event_filter.h" #include "chat_helpers/message_field.h" diff --git a/Telegram/SourceFiles/boxes/edit_participant_box.cpp b/Telegram/SourceFiles/boxes/edit_participant_box.cpp index 6b74398c1..396598386 100644 --- a/Telegram/SourceFiles/boxes/edit_participant_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_participant_box.cpp @@ -15,6 +15,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/special_buttons.h" #include "boxes/calendar_box.h" #include "data/data_peer_values.h" +#include "data/data_channel.h" +#include "data/data_user.h" #include "styles/style_boxes.h" namespace { @@ -446,6 +448,10 @@ void EditRestrictedBox::setRestrictUntil(TimeId until) { resizeToContent(); } +bool EditRestrictedBox::isUntilForever() const { + return ChannelData::IsRestrictedForever(_until); +} + void EditRestrictedBox::clearVariants() { for (auto &&widget : base::take(_untilVariants)) { removeControl(widget.data()); diff --git a/Telegram/SourceFiles/boxes/edit_participant_box.h b/Telegram/SourceFiles/boxes/edit_participant_box.h index 0700e4da7..55aa156e0 100644 --- a/Telegram/SourceFiles/boxes/edit_participant_box.h +++ b/Telegram/SourceFiles/boxes/edit_participant_box.h @@ -112,9 +112,7 @@ private: void applyDependencies(QPointer changed); void showRestrictUntil(); void setRestrictUntil(TimeId until); - bool isUntilForever() { - return ChannelData::IsRestrictedForever(_until); - } + bool isUntilForever() const; void clearVariants(); void createUntilGroup(); void createUntilVariants(); diff --git a/Telegram/SourceFiles/boxes/edit_privacy_box.cpp b/Telegram/SourceFiles/boxes/edit_privacy_box.cpp index 6e0545c48..ab550ef1e 100644 --- a/Telegram/SourceFiles/boxes/edit_privacy_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_privacy_box.cpp @@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "apiwrap.h" #include "auth_session.h" +#include "data/data_user.h" #include "styles/style_settings.h" #include "styles/style_boxes.h" diff --git a/Telegram/SourceFiles/boxes/peer_list_box.cpp b/Telegram/SourceFiles/boxes/peer_list_box.cpp index c296a5a2d..dc62d189a 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_box.cpp @@ -26,8 +26,23 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "observer_peer.h" #include "storage/file_download.h" #include "data/data_peer_values.h" +#include "data/data_chat.h" #include "window/themes/window_theme.h" +auto PaintUserpicCallback( + not_null peer, + bool respectSavedMessagesChat) +-> Fn { + if (respectSavedMessagesChat && peer->isSelf()) { + return [](Painter &p, int x, int y, int outerWidth, int size) { + Ui::EmptyUserpic::PaintSavedMessages(p, x, y, outerWidth, size); + }; + } + return [=](Painter &p, int x, int y, int outerWidth, int size) { + peer->paintUserpicLeft(p, x, y, outerWidth, size); + }; +} + PeerListBox::PeerListBox( QWidget*, std::unique_ptr controller, diff --git a/Telegram/SourceFiles/boxes/peer_list_box.h b/Telegram/SourceFiles/boxes/peer_list_box.h index 64634e4e0..04fa47de0 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.h +++ b/Telegram/SourceFiles/boxes/peer_list_box.h @@ -34,19 +34,10 @@ namespace Notify { struct PeerUpdate; } // namespace Notify -inline auto PaintUserpicCallback( +auto PaintUserpicCallback( not_null peer, bool respectSavedMessagesChat) -->Fn { - if (respectSavedMessagesChat && peer->isSelf()) { - return [](Painter &p, int x, int y, int outerWidth, int size) { - Ui::EmptyUserpic::PaintSavedMessages(p, x, y, outerWidth, size); - }; - } - return [peer](Painter &p, int x, int y, int outerWidth, int size) { - peer->paintUserpicLeft(p, x, y, outerWidth, size); - }; -} +-> Fn; using PeerListRowId = uint64; class PeerListRow { diff --git a/Telegram/SourceFiles/boxes/peer_list_controllers.cpp b/Telegram/SourceFiles/boxes/peer_list_controllers.cpp index ace376085..1cd51759c 100644 --- a/Telegram/SourceFiles/boxes/peer_list_controllers.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_controllers.cpp @@ -7,18 +7,21 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "boxes/peer_list_controllers.h" -#include "styles/style_boxes.h" -#include "styles/style_profile.h" #include "boxes/confirm_box.h" #include "observer_peer.h" #include "ui/widgets/checkbox.h" #include "auth_session.h" #include "data/data_session.h" +#include "data/data_channel.h" +#include "data/data_chat.h" +#include "data/data_user.h" #include "apiwrap.h" #include "mainwidget.h" #include "lang/lang_keys.h" #include "history/history.h" #include "dialogs/dialogs_indexed_list.h" +#include "styles/style_boxes.h" +#include "styles/style_profile.h" namespace { diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp index 6e33c23da..900f4b33d 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp @@ -23,6 +23,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/add_contact_box.h" #include "boxes/stickers_box.h" #include "boxes/peer_list_controllers.h" +#include "data/data_peer.h" +#include "data/data_chat.h" +#include "data/data_channel.h" #include "chat_helpers/emoji_suggestions_widget.h" #include "mtproto/sender.h" #include "lang/lang_keys.h" diff --git a/Telegram/SourceFiles/boxes/peers/manage_peer_box.cpp b/Telegram/SourceFiles/boxes/peers/manage_peer_box.cpp index 54abd18d1..2beadf1f3 100644 --- a/Telegram/SourceFiles/boxes/peers/manage_peer_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/manage_peer_box.cpp @@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/profile/info_profile_button.h" #include "info/profile/info_profile_icon.h" #include "info/profile/info_profile_values.h" +#include "data/data_channel.h" #include "styles/style_boxes.h" #include "styles/style_info.h" diff --git a/Telegram/SourceFiles/boxes/report_box.cpp b/Telegram/SourceFiles/boxes/report_box.cpp index cd3947418..f0486ab5d 100644 --- a/Telegram/SourceFiles/boxes/report_box.cpp +++ b/Telegram/SourceFiles/boxes/report_box.cpp @@ -8,14 +8,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/report_box.h" #include "lang/lang_keys.h" -#include "styles/style_boxes.h" -#include "styles/style_profile.h" +#include "data/data_peer.h" #include "boxes/confirm_box.h" #include "ui/widgets/checkbox.h" #include "ui/widgets/buttons.h" #include "ui/widgets/input_fields.h" #include "ui/toast/toast.h" #include "mainwindow.h" +#include "styles/style_boxes.h" +#include "styles/style_profile.h" namespace { diff --git a/Telegram/SourceFiles/boxes/share_box.cpp b/Telegram/SourceFiles/boxes/share_box.cpp index 99a530a1d..7c86dd227 100644 --- a/Telegram/SourceFiles/boxes/share_box.cpp +++ b/Telegram/SourceFiles/boxes/share_box.cpp @@ -29,6 +29,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/themes/window_theme.h" #include "boxes/peer_list_box.h" #include "chat_helpers/emoji_suggestions_widget.h" +#include "data/data_channel.h" +#include "data/data_user.h" #include "auth_session.h" #include "messenger.h" #include "styles/style_boxes.h" diff --git a/Telegram/SourceFiles/boxes/stickers_box.cpp b/Telegram/SourceFiles/boxes/stickers_box.cpp index fc854be17..e2c978a7e 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.cpp +++ b/Telegram/SourceFiles/boxes/stickers_box.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_document.h" #include "data/data_session.h" +#include "data/data_channel.h" #include "lang/lang_keys.h" #include "mainwidget.h" #include "chat_helpers/stickers.h" diff --git a/Telegram/SourceFiles/boxes/username_box.cpp b/Telegram/SourceFiles/boxes/username_box.cpp index e94347319..bc8af847a 100644 --- a/Telegram/SourceFiles/boxes/username_box.cpp +++ b/Telegram/SourceFiles/boxes/username_box.cpp @@ -14,9 +14,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/buttons.h" #include "ui/widgets/input_fields.h" #include "ui/toast/toast.h" -#include "styles/style_boxes.h" #include "messenger.h" #include "auth_session.h" +#include "data/data_user.h" +#include "styles/style_boxes.h" namespace { diff --git a/Telegram/SourceFiles/calls/calls_call.cpp b/Telegram/SourceFiles/calls/calls_call.cpp index 3d0b4bf9b..2be4c5bbd 100644 --- a/Telegram/SourceFiles/calls/calls_call.cpp +++ b/Telegram/SourceFiles/calls/calls_call.cpp @@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mtproto/connection.h" #include "media/media_audio_track.h" #include "calls/calls_panel.h" +#include "data/data_user.h" #ifdef slots #undef slots diff --git a/Telegram/SourceFiles/calls/calls_instance.cpp b/Telegram/SourceFiles/calls/calls_instance.cpp index 83de10a7c..1b5fed1de 100644 --- a/Telegram/SourceFiles/calls/calls_instance.cpp +++ b/Telegram/SourceFiles/calls/calls_instance.cpp @@ -15,11 +15,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/confirm_box.h" #include "calls/calls_call.h" #include "calls/calls_panel.h" +#include "data/data_user.h" #include "media/media_audio_track.h" #include "platform/platform_specific.h" #include "mainwidget.h" - #include "boxes/rate_call_box.h" + namespace Calls { namespace { diff --git a/Telegram/SourceFiles/calls/calls_panel.cpp b/Telegram/SourceFiles/calls/calls_panel.cpp index 3fd4c4680..8fb88355f 100644 --- a/Telegram/SourceFiles/calls/calls_panel.cpp +++ b/Telegram/SourceFiles/calls/calls_panel.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_photo.h" #include "data/data_session.h" +#include "data/data_user.h" #include "calls/calls_emoji_fingerprint.h" #include "styles/style_calls.h" #include "styles/style_history.h" diff --git a/Telegram/SourceFiles/calls/calls_top_bar.cpp b/Telegram/SourceFiles/calls/calls_top_bar.cpp index 4c7eb2819..bca48a200 100644 --- a/Telegram/SourceFiles/calls/calls_top_bar.cpp +++ b/Telegram/SourceFiles/calls/calls_top_bar.cpp @@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "calls/calls_top_bar.h" -#include "styles/style_calls.h" #include "ui/widgets/buttons.h" #include "ui/widgets/labels.h" #include "ui/wrap/padding_wrap.h" @@ -15,11 +14,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "calls/calls_call.h" #include "calls/calls_instance.h" #include "calls/calls_panel.h" -#include "styles/style_boxes.h" +#include "data/data_user.h" #include "observer_peer.h" #include "boxes/abstract_box.h" #include "base/timer.h" #include "layout.h" +#include "styles/style_calls.h" +#include "styles/style_boxes.h" namespace Calls { namespace { diff --git a/Telegram/SourceFiles/chat_helpers/bot_keyboard.cpp b/Telegram/SourceFiles/chat_helpers/bot_keyboard.cpp index 207ee94b7..abab8920b 100644 --- a/Telegram/SourceFiles/chat_helpers/bot_keyboard.cpp +++ b/Telegram/SourceFiles/chat_helpers/bot_keyboard.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history.h" #include "history/history_item_components.h" +#include "data/data_user.h" #include "styles/style_widgets.h" #include "styles/style_history.h" diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp index 2066f4585..da032df64 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp @@ -8,17 +8,20 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "chat_helpers/field_autocomplete.h" #include "data/data_document.h" +#include "data/data_channel.h" +#include "data/data_chat.h" +#include "data/data_user.h" #include "data/data_peer_values.h" #include "mainwindow.h" #include "apiwrap.h" #include "storage/localstorage.h" #include "ui/widgets/scroll_area.h" #include "ui/image/image.h" +#include "auth_session.h" +#include "chat_helpers/stickers.h" #include "styles/style_history.h" #include "styles/style_widgets.h" #include "styles/style_chat_helpers.h" -#include "auth_session.h" -#include "chat_helpers/stickers.h" FieldAutocomplete::FieldAutocomplete(QWidget *parent) : TWidget(parent) , _scroll(this, st::mentionScroll) { diff --git a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp index 804296fbb..4cc593a56 100644 --- a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_photo.h" #include "data/data_document.h" #include "data/data_session.h" +#include "data/data_user.h" #include "styles/style_chat_helpers.h" #include "ui/widgets/buttons.h" #include "ui/widgets/input_fields.h" diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index 43d8a8758..d719e57e7 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/abstract_box.h" #include "ui/wrap/vertical_layout.h" #include "data/data_session.h" +#include "data/data_user.h" #include "chat_helpers/emoji_suggestions_widget.h" #include "window/window_controller.h" #include "lang/lang_keys.h" diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index fc0f1c8ad..661d17ca3 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_document.h" #include "data/data_session.h" +#include "data/data_channel.h" #include "ui/widgets/buttons.h" #include "ui/effects/ripple_animation.h" #include "ui/image/image.h" diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp index ce0437e83..7c967f09d 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp @@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/scroll_area.h" #include "ui/image/image_prepare.h" #include "storage/localstorage.h" +#include "data/data_channel.h" #include "lang/lang_keys.h" #include "mainwindow.h" #include "observer_peer.h" diff --git a/Telegram/SourceFiles/core/click_handler_types.cpp b/Telegram/SourceFiles/core/click_handler_types.cpp index a18d57937..86c0b6ada 100644 --- a/Telegram/SourceFiles/core/click_handler_types.cpp +++ b/Telegram/SourceFiles/core/click_handler_types.cpp @@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/localstorage.h" #include "ui/widgets/tooltip.h" #include "core/file_utilities.h" +#include "data/data_user.h" namespace { diff --git a/Telegram/SourceFiles/data/data_channel.cpp b/Telegram/SourceFiles/data/data_channel.cpp new file mode 100644 index 000000000..c5e3d88a6 --- /dev/null +++ b/Telegram/SourceFiles/data/data_channel.cpp @@ -0,0 +1,474 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "data/data_channel.h" + +#include "data/data_peer_values.h" +#include "data/data_channel_admins.h" +#include "data/data_user.h" +#include "data/data_session.h" +#include "data/data_feed.h" +#include "observer_peer.h" +#include "auth_session.h" + +namespace { + +using UpdateFlag = Notify::PeerUpdate::Flag; + +} // namespace + +ChannelData::ChannelData(not_null owner, PeerId id) +: PeerData(owner, id) +, inputChannel(MTP_inputChannel(MTP_int(bareId()), MTP_long(0))) { + Data::PeerFlagValue( + this, + MTPDchannel::Flag::f_megagroup + ) | rpl::start_with_next([this](bool megagroup) { + if (megagroup) { + if (!mgInfo) { + mgInfo = std::make_unique(); + } + } else if (mgInfo) { + mgInfo = nullptr; + } + }, _lifetime); +} + +void ChannelData::setPhoto(const MTPChatPhoto &photo) { + setPhoto(userpicPhotoId(), photo); +} + +void ChannelData::setPhoto(PhotoId photoId, const MTPChatPhoto &photo) { + if (photo.type() == mtpc_chatPhoto) { + const auto &data = photo.c_chatPhoto(); + updateUserpic(photoId, data.vphoto_small); + } else { + clearUserpic(); + } +} + +void ChannelData::setName(const QString &newName, const QString &newUsername) { + updateNameDelayed(newName.isEmpty() ? name : newName, QString(), newUsername); +} + +bool ChannelData::setAbout(const QString &newAbout) { + if (_about == newAbout) { + return false; + } + _about = newAbout; + Notify::peerUpdatedDelayed(this, UpdateFlag::AboutChanged); + return true; +} + +void ChannelData::setInviteLink(const QString &newInviteLink) { + if (newInviteLink != _inviteLink) { + _inviteLink = newInviteLink; + Notify::peerUpdatedDelayed(this, UpdateFlag::InviteLinkChanged); + } +} + +QString ChannelData::inviteLink() const { + return _inviteLink; +} + +bool ChannelData::canHaveInviteLink() const { + return (adminRights() & AdminRight::f_invite_users) + || amCreator(); +} + +void ChannelData::setMembersCount(int newMembersCount) { + if (_membersCount != newMembersCount) { + if (isMegagroup() && !mgInfo->lastParticipants.empty()) { + mgInfo->lastParticipantsStatus |= MegagroupInfo::LastParticipantsCountOutdated; + mgInfo->lastParticipantsCount = membersCount(); + } + _membersCount = newMembersCount; + Notify::peerUpdatedDelayed(this, Notify::PeerUpdate::Flag::MembersChanged); + } +} + +void ChannelData::setAdminsCount(int newAdminsCount) { + if (_adminsCount != newAdminsCount) { + _adminsCount = newAdminsCount; + Notify::peerUpdatedDelayed(this, Notify::PeerUpdate::Flag::AdminsChanged); + } +} + +void ChannelData::setRestrictedCount(int newRestrictedCount) { + if (_restrictedCount != newRestrictedCount) { + _restrictedCount = newRestrictedCount; + Notify::peerUpdatedDelayed(this, Notify::PeerUpdate::Flag::BannedUsersChanged); + } +} + +void ChannelData::setKickedCount(int newKickedCount) { + if (_kickedCount != newKickedCount) { + _kickedCount = newKickedCount; + Notify::peerUpdatedDelayed(this, Notify::PeerUpdate::Flag::BannedUsersChanged); + } +} + +MTPChatBannedRights ChannelData::KickedRestrictedRights() { + using Flag = MTPDchatBannedRights::Flag; + auto flags = Flag::f_view_messages | Flag::f_send_messages | Flag::f_send_media | Flag::f_embed_links | Flag::f_send_stickers | Flag::f_send_gifs | Flag::f_send_games | Flag::f_send_inline; + return MTP_chatBannedRights(MTP_flags(flags), MTP_int(std::numeric_limits::max())); +} + +void ChannelData::applyEditAdmin(not_null user, const MTPChatAdminRights &oldRights, const MTPChatAdminRights &newRights) { + auto flags = Notify::PeerUpdate::Flag::AdminsChanged | Notify::PeerUpdate::Flag::None; + if (mgInfo) { + // If rights are empty - still add participant? TODO check + if (!base::contains(mgInfo->lastParticipants, user)) { + mgInfo->lastParticipants.push_front(user); + setMembersCount(membersCount() + 1); + if (user->botInfo && !mgInfo->bots.contains(user)) { + mgInfo->bots.insert(user); + if (mgInfo->botStatus != 0 && mgInfo->botStatus < 2) { + mgInfo->botStatus = 2; + } + } + } + // If rights are empty - still remove restrictions? TODO check + if (mgInfo->lastRestricted.contains(user)) { + mgInfo->lastRestricted.remove(user); + if (restrictedCount() > 0) { + setRestrictedCount(restrictedCount() - 1); + } + } + + auto userId = peerToUser(user->id); + auto it = mgInfo->lastAdmins.find(user); + if (newRights.c_chatAdminRights().vflags.v != 0) { + auto lastAdmin = MegagroupInfo::Admin { newRights }; + lastAdmin.canEdit = true; + if (it == mgInfo->lastAdmins.cend()) { + mgInfo->lastAdmins.emplace(user, lastAdmin); + setAdminsCount(adminsCount() + 1); + } else { + it->second = lastAdmin; + } + Data::ChannelAdminChanges(this).feed(userId, true); + } else { + if (it != mgInfo->lastAdmins.cend()) { + mgInfo->lastAdmins.erase(it); + if (adminsCount() > 0) { + setAdminsCount(adminsCount() - 1); + } + } + Data::ChannelAdminChanges(this).feed(userId, false); + } + } + if (oldRights.c_chatAdminRights().vflags.v && !newRights.c_chatAdminRights().vflags.v) { + // We removed an admin. + if (adminsCount() > 1) { + setAdminsCount(adminsCount() - 1); + } + if (!isMegagroup() && user->botInfo && membersCount() > 1) { + // Removing bot admin removes it from channel. + setMembersCount(membersCount() - 1); + } + } else if (!oldRights.c_chatAdminRights().vflags.v && newRights.c_chatAdminRights().vflags.v) { + // We added an admin. + setAdminsCount(adminsCount() + 1); + updateFullForced(); + } + Notify::peerUpdatedDelayed(this, flags); +} + +void ChannelData::applyEditBanned(not_null user, const MTPChatBannedRights &oldRights, const MTPChatBannedRights &newRights) { + auto flags = Notify::PeerUpdate::Flag::BannedUsersChanged | Notify::PeerUpdate::Flag::None; + auto isKicked = (newRights.c_chatBannedRights().vflags.v & MTPDchatBannedRights::Flag::f_view_messages); + auto isRestricted = !isKicked && (newRights.c_chatBannedRights().vflags.v != 0); + if (mgInfo) { + // If rights are empty - still remove admin? TODO check + if (mgInfo->lastAdmins.contains(user)) { + mgInfo->lastAdmins.remove(user); + if (adminsCount() > 1) { + setAdminsCount(adminsCount() - 1); + } else { + flags |= Notify::PeerUpdate::Flag::AdminsChanged; + } + } + auto it = mgInfo->lastRestricted.find(user); + if (isRestricted) { + if (it == mgInfo->lastRestricted.cend()) { + mgInfo->lastRestricted.emplace(user, MegagroupInfo::Restricted { newRights }); + setRestrictedCount(restrictedCount() + 1); + } else { + it->second.rights = newRights; + } + } else { + if (it != mgInfo->lastRestricted.cend()) { + mgInfo->lastRestricted.erase(it); + if (restrictedCount() > 0) { + setRestrictedCount(restrictedCount() - 1); + } + } + if (isKicked) { + auto i = ranges::find(mgInfo->lastParticipants, user); + if (i != mgInfo->lastParticipants.end()) { + mgInfo->lastParticipants.erase(i); + } + if (membersCount() > 1) { + setMembersCount(membersCount() - 1); + } else { + mgInfo->lastParticipantsStatus |= MegagroupInfo::LastParticipantsCountOutdated; + mgInfo->lastParticipantsCount = 0; + } + setKickedCount(kickedCount() + 1); + if (mgInfo->bots.contains(user)) { + mgInfo->bots.remove(user); + if (mgInfo->bots.empty() && mgInfo->botStatus > 0) { + mgInfo->botStatus = -1; + } + } + flags |= Notify::PeerUpdate::Flag::MembersChanged; + owner().removeMegagroupParticipant(this, user); + } + } + Data::ChannelAdminChanges(this).feed(peerToUser(user->id), false); + } else { + if (isKicked) { + if (membersCount() > 1) { + setMembersCount(membersCount() - 1); + flags |= Notify::PeerUpdate::Flag::MembersChanged; + } + setKickedCount(kickedCount() + 1); + } + } + Notify::peerUpdatedDelayed(this, flags); +} + +bool ChannelData::isGroupAdmin(not_null user) const { + if (auto info = mgInfo.get()) { + return info->admins.contains(peerToUser(user->id)); + } + return false; +} + +QString ChannelData::unavailableReason() const { + return _unavailableReason; +} + +void ChannelData::setUnavailableReason(const QString &text) { + if (_unavailableReason != text) { + _unavailableReason = text; + Notify::peerUpdatedDelayed( + this, + Notify::PeerUpdate::Flag::UnavailableReasonChanged); + } +} + +void ChannelData::setAvailableMinId(MsgId availableMinId) { + if (_availableMinId != availableMinId) { + _availableMinId = availableMinId; + if (pinnedMessageId() <= _availableMinId) { + clearPinnedMessage(); + } + } +} + +void ChannelData::setFeed(not_null feed) { + setFeedPointer(feed); +} + +void ChannelData::clearFeed() { + setFeedPointer(nullptr); +} + +void ChannelData::setFeedPointer(Data::Feed *feed) { + if (_feed != feed) { + const auto was = _feed; + _feed = feed; + if (was) { + was->unregisterOne(this); + } + if (_feed) { + _feed->registerOne(this); + } + } +} + +bool ChannelData::canBanMembers() const { + return (adminRights() & AdminRight::f_ban_users) + || amCreator(); +} + +bool ChannelData::canEditMessages() const { + return (adminRights() & AdminRight::f_edit_messages) + || amCreator(); +} + +bool ChannelData::canDeleteMessages() const { + return (adminRights() & AdminRight::f_delete_messages) + || amCreator(); +} + +bool ChannelData::anyoneCanAddMembers() const { + // #TODO groups + return false;// (flags() & MTPDchannel::Flag::f_democracy); +} + +bool ChannelData::hiddenPreHistory() const { + return (fullFlags() & MTPDchannelFull::Flag::f_hidden_prehistory); +} + +bool ChannelData::canAddMembers() const { + return (adminRights() & AdminRight::f_invite_users) + || amCreator() + || (anyoneCanAddMembers() + && amIn() + && !hasRestrictions()); +} + +bool ChannelData::canAddAdmins() const { + return (adminRights() & AdminRight::f_add_admins) + || amCreator(); +} + +bool ChannelData::canPublish() const { + return (adminRights() & AdminRight::f_post_messages) + || amCreator(); +} + +bool ChannelData::canWrite() const { + // Duplicated in Data::CanWriteValue(). + return amIn() + && (canPublish() + || (!isBroadcast() + && !restricted(Restriction::f_send_messages))); +} + +bool ChannelData::canViewMembers() const { + return fullFlags() + & MTPDchannelFull::Flag::f_can_view_participants; +} + +bool ChannelData::canViewAdmins() const { + return (isMegagroup() || hasAdminRights() || amCreator()); +} + +bool ChannelData::canViewBanned() const { + return (hasAdminRights() || amCreator()); +} + +bool ChannelData::canEditInformation() const { + return (adminRights() & AdminRight::f_change_info) + || amCreator(); +} + +bool ChannelData::canEditInvites() const { + return canEditInformation(); +} + +bool ChannelData::canEditSignatures() const { + return canEditInformation(); +} + +bool ChannelData::canEditPreHistoryHidden() const { + return canEditInformation(); +} + +bool ChannelData::canEditUsername() const { + return amCreator() + && (fullFlags() + & MTPDchannelFull::Flag::f_can_set_username); +} + +bool ChannelData::canEditStickers() const { + return (fullFlags() + & MTPDchannelFull::Flag::f_can_set_stickers); +} + +bool ChannelData::canDelete() const { + constexpr auto kDeleteChannelMembersLimit = 1000; + return amCreator() + && (membersCount() <= kDeleteChannelMembersLimit); +} + +bool ChannelData::canEditLastAdmin(not_null user) const { + // Duplicated in ParticipantsBoxController::canEditAdmin :( + if (mgInfo) { + auto i = mgInfo->lastAdmins.find(user); + if (i != mgInfo->lastAdmins.cend()) { + return i->second.canEdit; + } + return (user != mgInfo->creator); + } + return false; +} + +bool ChannelData::canEditAdmin(not_null user) const { + // Duplicated in ParticipantsBoxController::canEditAdmin :( + if (user->isSelf()) { + return false; + } else if (amCreator()) { + return true; + } else if (!canEditLastAdmin(user)) { + return false; + } + return adminRights() & AdminRight::f_add_admins; +} + +bool ChannelData::canRestrictUser(not_null user) const { + // Duplicated in ParticipantsBoxController::canRestrictUser :( + if (user->isSelf()) { + return false; + } else if (amCreator()) { + return true; + } else if (!canEditLastAdmin(user)) { + return false; + } + return adminRights() & AdminRight::f_ban_users; +} + +void ChannelData::setAdminRights(const MTPChatAdminRights &rights) { + if (rights.c_chatAdminRights().vflags.v == adminRights()) { + return; + } + _adminRights.set(rights.c_chatAdminRights().vflags.v); + if (isMegagroup()) { + const auto self = session().user(); + if (hasAdminRights()) { + if (!amCreator()) { + auto me = MegagroupInfo::Admin { rights }; + me.canEdit = false; + mgInfo->lastAdmins.emplace(self, me); + } + mgInfo->lastRestricted.remove(self); + } else { + mgInfo->lastAdmins.remove(self); + } + + auto amAdmin = hasAdminRights() || amCreator(); + Data::ChannelAdminChanges(this).feed(session().userId(), amAdmin); + } + Notify::peerUpdatedDelayed(this, UpdateFlag::ChannelRightsChanged | UpdateFlag::AdminsChanged | UpdateFlag::BannedUsersChanged); +} + +void ChannelData::setRestrictedRights(const MTPChatBannedRights &rights) { + if (rights.c_chatBannedRights().vflags.v == restrictions() + && rights.c_chatBannedRights().vuntil_date.v == _restrictedUntill) { + return; + } + _restrictedUntill = rights.c_chatBannedRights().vuntil_date.v; + _restrictions.set(rights.c_chatBannedRights().vflags.v); + if (isMegagroup()) { + const auto self = session().user(); + if (hasRestrictions()) { + if (!amCreator()) { + auto me = MegagroupInfo::Restricted { rights }; + mgInfo->lastRestricted.emplace(self, me); + } + mgInfo->lastAdmins.remove(self); + Data::ChannelAdminChanges(this).feed(session().userId(), false); + } else { + mgInfo->lastRestricted.remove(self); + } + } + Notify::peerUpdatedDelayed(this, UpdateFlag::ChannelRightsChanged | UpdateFlag::AdminsChanged | UpdateFlag::BannedUsersChanged); +} diff --git a/Telegram/SourceFiles/data/data_channel.h b/Telegram/SourceFiles/data/data_channel.h new file mode 100644 index 000000000..81b7e2644 --- /dev/null +++ b/Telegram/SourceFiles/data/data_channel.h @@ -0,0 +1,364 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +#include "data/data_peer.h" +#include "data/data_pts_waiter.h" + +struct MegagroupInfo { + struct Admin { + explicit Admin(MTPChatAdminRights rights) + : rights(rights) { + } + Admin(MTPChatAdminRights rights, bool canEdit) + : rights(rights) + , canEdit(canEdit) { + } + MTPChatAdminRights rights; + bool canEdit = false; + }; + struct Restricted { + explicit Restricted(MTPChatBannedRights rights) + : rights(rights) { + } + MTPChatBannedRights rights; + }; + std::deque> lastParticipants; + base::flat_map, Admin> lastAdmins; + base::flat_map, Restricted> lastRestricted; + base::flat_set> markupSenders; + base::flat_set> bots; + + // For admin badges, full admins list. + base::flat_set admins; + + UserData *creator = nullptr; // nullptr means unknown + int botStatus = 0; // -1 - no bots, 0 - unknown, 1 - one bot, that sees all history, 2 - other + bool joinedMessageFound = false; + MTPInputStickerSet stickerSet = MTP_inputStickerSetEmpty(); + + enum LastParticipantsStatus { + LastParticipantsUpToDate = 0x00, + LastParticipantsCountOutdated = 0x02, + }; + mutable int lastParticipantsStatus = LastParticipantsUpToDate; + int lastParticipantsCount = 0; + + ChatData *migrateFromPtr = nullptr; + +}; + +class ChannelData : public PeerData { +public: + static constexpr auto kEssentialFlags = 0 + | MTPDchannel::Flag::f_creator + | MTPDchannel::Flag::f_left + | MTPDchannel::Flag::f_broadcast + | MTPDchannel::Flag::f_verified + | MTPDchannel::Flag::f_megagroup + | MTPDchannel::Flag::f_restricted + | MTPDchannel::Flag::f_signatures + | MTPDchannel::Flag::f_username; + using Flags = Data::Flags< + MTPDchannel::Flags, + kEssentialFlags>; + + static constexpr auto kEssentialFullFlags = 0 + | MTPDchannelFull::Flag::f_can_view_participants + | MTPDchannelFull::Flag::f_can_set_username + | MTPDchannelFull::Flag::f_can_set_stickers; + using FullFlags = Data::Flags< + MTPDchannelFull::Flags, + kEssentialFullFlags>; + + ChannelData(not_null owner, PeerId id); + + void setPhoto(const MTPChatPhoto &photo); + void setPhoto(PhotoId photoId, const MTPChatPhoto &photo); + + void setName(const QString &name, const QString &username); + + void setFlags(MTPDchannel::Flags which) { + _flags.set(which); + } + void addFlags(MTPDchannel::Flags which) { + _flags.add(which); + } + void removeFlags(MTPDchannel::Flags which) { + _flags.remove(which); + } + auto flags() const { + return _flags.current(); + } + auto flagsValue() const { + return _flags.value(); + } + + void setFullFlags(MTPDchannelFull::Flags which) { + _fullFlags.set(which); + } + void addFullFlags(MTPDchannelFull::Flags which) { + _fullFlags.add(which); + } + void removeFullFlags(MTPDchannelFull::Flags which) { + _fullFlags.remove(which); + } + auto fullFlags() const { + return _fullFlags.current(); + } + auto fullFlagsValue() const { + return _fullFlags.value(); + } + + uint64 access = 0; + + MTPinputChannel inputChannel; + + QString username; + + // Returns true if about text was changed. + bool setAbout(const QString &newAbout); + const QString &about() const { + return _about; + } + + int membersCount() const { + return _membersCount; + } + void setMembersCount(int newMembersCount); + + int adminsCount() const { + return _adminsCount; + } + void setAdminsCount(int newAdminsCount); + + int restrictedCount() const { + return _restrictedCount; + } + void setRestrictedCount(int newRestrictedCount); + + int kickedCount() const { + return _kickedCount; + } + void setKickedCount(int newKickedCount); + + bool haveLeft() const { + return flags() & MTPDchannel::Flag::f_left; + } + bool amIn() const { + return !isForbidden() && !haveLeft(); + } + bool addsSignature() const { + return flags() & MTPDchannel::Flag::f_signatures; + } + bool isForbidden() const { + return flags() & MTPDchannel_ClientFlag::f_forbidden; + } + bool isVerified() const { + return flags() & MTPDchannel::Flag::f_verified; + } + + static MTPChatBannedRights KickedRestrictedRights(); + static constexpr auto kRestrictUntilForever = TimeId(INT_MAX); + static bool IsRestrictedForever(TimeId until) { + return !until || (until == kRestrictUntilForever); + } + void applyEditAdmin( + not_null user, + const MTPChatAdminRights &oldRights, + const MTPChatAdminRights &newRights); + void applyEditBanned( + not_null user, + const MTPChatBannedRights &oldRights, + const MTPChatBannedRights &newRights); + + bool isGroupAdmin(not_null user) const; + + int32 date = 0; + int version = 0; + std::unique_ptr mgInfo; + bool lastParticipantsCountOutdated() const { + if (!mgInfo + || !(mgInfo->lastParticipantsStatus + & MegagroupInfo::LastParticipantsCountOutdated)) { + return false; + } + if (mgInfo->lastParticipantsCount == membersCount()) { + mgInfo->lastParticipantsStatus + &= ~MegagroupInfo::LastParticipantsCountOutdated; + return false; + } + return true; + } + bool isMegagroup() const { + return flags() & MTPDchannel::Flag::f_megagroup; + } + bool isBroadcast() const { + return flags() & MTPDchannel::Flag::f_broadcast; + } + bool isPublic() const { + return flags() & MTPDchannel::Flag::f_username; + } + bool amCreator() const { + return flags() & MTPDchannel::Flag::f_creator; + } + + using AdminRight = ChatAdminRight; + using Restriction = ChatRestriction; + using AdminRights = ChatAdminRights; + using Restrictions = ChatRestrictions; + using AdminRightFlags = Data::Flags; + using RestrictionFlags = Data::Flags; + auto adminRights() const { + return _adminRights.current(); + } + auto adminRightsValue() const { + return _adminRights.value(); + } + void setAdminRights(const MTPChatAdminRights &rights); + bool hasAdminRights() const { + return (adminRights() != 0); + } + auto restrictions() const { + return _restrictions.current(); + } + auto restrictionsValue() const { + return _restrictions.value(); + } + bool restricted(Restriction right) const { + return restrictions() & right; + } + TimeId restrictedUntil() const { + return _restrictedUntill; + } + void setRestrictedRights(const MTPChatBannedRights &rights); + bool hasRestrictions() const { + return (restrictions() != 0); + } + bool hasRestrictions(TimeId now) const { + return hasRestrictions() + && (restrictedUntil() > now); + } + bool canBanMembers() const; + bool canEditMessages() const; + bool canDeleteMessages() const; + bool anyoneCanAddMembers() const; + bool hiddenPreHistory() const; + bool canAddMembers() const; + bool canAddAdmins() const; + bool canPublish() const; + bool canWrite() const; + bool canViewMembers() const; + bool canViewAdmins() const; + bool canViewBanned() const; + bool canEditInformation() const; + bool canEditInvites() const; + bool canEditSignatures() const; + bool canEditPreHistoryHidden() const; + bool canEditUsername() const; + bool canEditStickers() const; + bool canDelete() const; + bool canEditAdmin(not_null user) const; + bool canRestrictUser(not_null user) const; + + void setInviteLink(const QString &newInviteLink); + QString inviteLink() const; + bool canHaveInviteLink() const; + + UserId inviter = 0; // > 0 - user who invited me to channel, < 0 - not in channel + TimeId inviteDate = 0; + + void ptsInit(int32 pts) { + _ptsWaiter.init(pts); + } + void ptsReceived(int32 pts) { + _ptsWaiter.updateAndApply(this, pts, 0); + } + bool ptsUpdateAndApply(int32 pts, int32 count) { + return _ptsWaiter.updateAndApply(this, pts, count); + } + bool ptsUpdateAndApply( + int32 pts, + int32 count, + const MTPUpdate &update) { + return _ptsWaiter.updateAndApply(this, pts, count, update); + } + bool ptsUpdateAndApply( + int32 pts, + int32 count, + const MTPUpdates &updates) { + return _ptsWaiter.updateAndApply(this, pts, count, updates); + } + int32 pts() const { + return _ptsWaiter.current(); + } + bool ptsInited() const { + return _ptsWaiter.inited(); + } + bool ptsRequesting() const { + return _ptsWaiter.requesting(); + } + void ptsSetRequesting(bool isRequesting) { + return _ptsWaiter.setRequesting(isRequesting); + } + void ptsWaitingForShortPoll(int32 ms) { // < 0 - not waiting + return _ptsWaiter.setWaitingForShortPoll(this, ms); + } + bool ptsWaitingForSkipped() const { + return _ptsWaiter.waitingForSkipped(); + } + bool ptsWaitingForShortPoll() const { + return _ptsWaiter.waitingForShortPoll(); + } + + QString unavailableReason() const override; + void setUnavailableReason(const QString &reason); + + MsgId availableMinId() const { + return _availableMinId; + } + void setAvailableMinId(MsgId availableMinId); + + void setFeed(not_null feed); + void clearFeed(); + + Data::Feed *feed() const { + return _feed; + } + +private: + void flagsUpdated(MTPDchannel::Flags diff); + void fullFlagsUpdated(MTPDchannelFull::Flags diff); + + bool canEditLastAdmin(not_null user) const; + void setFeedPointer(Data::Feed *feed); + + Flags _flags = Flags(MTPDchannel_ClientFlag::f_forbidden | 0); + FullFlags _fullFlags; + + PtsWaiter _ptsWaiter; + + int _membersCount = 1; + int _adminsCount = 1; + int _restrictedCount = 0; + int _kickedCount = 0; + MsgId _availableMinId = 0; + + AdminRightFlags _adminRights; + RestrictionFlags _restrictions; + TimeId _restrictedUntill; + + QString _unavailableReason; + QString _about; + + QString _inviteLink; + Data::Feed *_feed = nullptr; + + rpl::lifetime _lifetime; + +}; diff --git a/Telegram/SourceFiles/data/data_channel_admins.cpp b/Telegram/SourceFiles/data/data_channel_admins.cpp index cc3ab3a7d..9583871c6 100644 --- a/Telegram/SourceFiles/data/data_channel_admins.cpp +++ b/Telegram/SourceFiles/data/data_channel_admins.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_channel_admins.h" #include "history/history.h" +#include "data/data_channel.h" namespace Data { diff --git a/Telegram/SourceFiles/data/data_chat.cpp b/Telegram/SourceFiles/data/data_chat.cpp new file mode 100644 index 000000000..0c858a228 --- /dev/null +++ b/Telegram/SourceFiles/data/data_chat.cpp @@ -0,0 +1,65 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "data/data_chat.h" + +#include "observer_peer.h" + +namespace { + +using UpdateFlag = Notify::PeerUpdate::Flag; + +} // namespace + +ChatData::ChatData(not_null owner, PeerId id) +: PeerData(owner, id) +, inputChat(MTP_int(bareId())) { +} + +void ChatData::setPhoto(const MTPChatPhoto &photo) { + setPhoto(userpicPhotoId(), photo); +} + +void ChatData::setPhoto(PhotoId photoId, const MTPChatPhoto &photo) { + if (photo.type() == mtpc_chatPhoto) { + const auto &data = photo.c_chatPhoto(); + updateUserpic(photoId, data.vphoto_small); + } else { + clearUserpic(); + } +} + +bool ChatData::canEditInformation() const { + // #TODO groups + return !isDeactivated() + /*&& ((adminRights() & AdminRight::f_change_info) || amCreator())*/; +} + +void ChatData::setName(const QString &newName) { + updateNameDelayed(newName.isEmpty() ? name : newName, QString(), QString()); +} + +void ChatData::invalidateParticipants() { + // #TODO groups + auto wasCanEdit = canEditInformation(); + participants.clear(); + admins.clear(); + //removeFlags(MTPDchat::Flag::f_admin); + invitedByMe.clear(); + botStatus = 0; + if (wasCanEdit != canEditInformation()) { + Notify::peerUpdatedDelayed(this, Notify::PeerUpdate::Flag::ChatCanEdit); + } + Notify::peerUpdatedDelayed(this, Notify::PeerUpdate::Flag::MembersChanged | Notify::PeerUpdate::Flag::AdminsChanged); +} + +void ChatData::setInviteLink(const QString &newInviteLink) { + if (newInviteLink != _inviteLink) { + _inviteLink = newInviteLink; + Notify::peerUpdatedDelayed(this, UpdateFlag::InviteLinkChanged); + } +} diff --git a/Telegram/SourceFiles/data/data_chat.h b/Telegram/SourceFiles/data/data_chat.h new file mode 100644 index 000000000..fe84b4900 --- /dev/null +++ b/Telegram/SourceFiles/data/data_chat.h @@ -0,0 +1,108 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +#include "data/data_peer.h" + +class ChatData : public PeerData { +public: + static constexpr auto kEssentialFlags = 0 + | MTPDchat::Flag::f_creator + | MTPDchat::Flag::f_kicked + | MTPDchat::Flag::f_left + | MTPDchat::Flag::f_deactivated + | MTPDchat::Flag::f_migrated_to + | MTPDchat::Flag::f_admin_rights + | MTPDchat::Flag::f_default_banned_rights; + using Flags = Data::Flags< + MTPDchat::Flags, + kEssentialFlags>; + + ChatData(not_null owner, PeerId id); + + void setPhoto(const MTPChatPhoto &photo); + void setPhoto(PhotoId photoId, const MTPChatPhoto &photo); + + void setName(const QString &newName); + + void invalidateParticipants(); + bool noParticipantInfo() const { + return (count > 0 || amIn()) && participants.empty(); + } + + MTPint inputChat; + + ChannelData *migrateToPtr = nullptr; + + int count = 0; + TimeId date = 0; + int version = 0; + UserId creator = 0; + + void setFlags(MTPDchat::Flags which) { + _flags.set(which); + } + void addFlags(MTPDchat::Flags which) { + _flags.add(which); + } + void removeFlags(MTPDchat::Flags which) { + _flags.remove(which); + } + auto flags() const { + return _flags.current(); + } + auto flagsValue() const { + return _flags.value(); + } + + bool isForbidden() const { + return flags() & MTPDchat_ClientFlag::f_forbidden; + } + bool amIn() const { + return !isForbidden() && !haveLeft() && !wasKicked(); + } + bool canEditInformation() const; + bool canWrite() const { + // Duplicated in Data::CanWriteValue(). + return !isDeactivated() && amIn(); + } + bool haveLeft() const { + return flags() & MTPDchat::Flag::f_left; + } + bool wasKicked() const { + return flags() & MTPDchat::Flag::f_kicked; + } + bool amCreator() const { + return flags() & MTPDchat::Flag::f_creator; + } + bool isDeactivated() const { + return flags() & MTPDchat::Flag::f_deactivated; + } + bool isMigrated() const { + return flags() & MTPDchat::Flag::f_migrated_to; + } + base::flat_map, int> participants; + base::flat_set> invitedByMe; + base::flat_set> admins; + std::deque> lastAuthors; + base::flat_set> markupSenders; + int botStatus = 0; // -1 - no bots, 0 - unknown, 1 - one bot, that sees all history, 2 - other +// ImagePtr photoFull; + + void setInviteLink(const QString &newInviteLink); + QString inviteLink() const { + return _inviteLink; + } + +private: + void flagsUpdated(MTPDchat::Flags diff); + + Flags _flags; + QString _inviteLink; + +}; diff --git a/Telegram/SourceFiles/data/data_document_good_thumbnail.cpp b/Telegram/SourceFiles/data/data_document_good_thumbnail.cpp index b8925768e..806e1ea75 100644 --- a/Telegram/SourceFiles/data/data_document_good_thumbnail.cpp +++ b/Telegram/SourceFiles/data/data_document_good_thumbnail.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "data/data_document.h" +#include "data/data_file_origin.h" #include "media/media_clip_reader.h" #include "auth_session.h" diff --git a/Telegram/SourceFiles/data/data_feed.cpp b/Telegram/SourceFiles/data/data_feed.cpp index 713544562..cff371824 100644 --- a/Telegram/SourceFiles/data/data_feed.cpp +++ b/Telegram/SourceFiles/data/data_feed.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_feed.h" #include "data/data_session.h" +#include "data/data_channel.h" #include "dialogs/dialogs_key.h" #include "history/history.h" #include "history/history_item.h" diff --git a/Telegram/SourceFiles/data/data_file_origin.cpp b/Telegram/SourceFiles/data/data_file_origin.cpp index 81217e1e9..6f96e9295 100644 --- a/Telegram/SourceFiles/data/data_file_origin.cpp +++ b/Telegram/SourceFiles/data/data_file_origin.cpp @@ -19,7 +19,7 @@ struct FileReferenceAccumulator { } void push(const MTPFileLocation &data) { data.match([&](const MTPDfileLocation &data) { - result.emplace(SimpleFileLocationId( + result.data.emplace(SimpleFileLocationId( data.vvolume_id.v, data.vdc_id.v, data.vlocal_id.v), data.vfile_reference.v); @@ -46,7 +46,7 @@ struct FileReferenceAccumulator { for (const auto &thumb : data.vthumbs.v) { push(thumb); } - result.emplace( + result.data.emplace( DocumentFileLocationId(data.vid.v), data.vfile_reference.v); }, [](const MTPDdocumentEmpty &data) { diff --git a/Telegram/SourceFiles/data/data_file_origin.h b/Telegram/SourceFiles/data/data_file_origin.h index 27a214055..6e50114f3 100644 --- a/Telegram/SourceFiles/data/data_file_origin.h +++ b/Telegram/SourceFiles/data/data_file_origin.h @@ -60,12 +60,35 @@ struct FileOriginSavedGifs { } }; -using FileOrigin = base::optional_variant< - FileOriginMessage, - FileOriginUserPhoto, - FileOriginPeerPhoto, - FileOriginStickerSet, - FileOriginSavedGifs>; +struct FileOrigin { + using Variant = base::optional_variant< + FileOriginMessage, + FileOriginUserPhoto, + FileOriginPeerPhoto, + FileOriginStickerSet, + FileOriginSavedGifs>; + + FileOrigin() = default; + FileOrigin(FileOriginMessage data) : data(data) { + } + FileOrigin(FileOriginUserPhoto data) : data(data) { + } + FileOrigin(FileOriginPeerPhoto data) : data(data) { + } + FileOrigin(FileOriginStickerSet data) : data(data) { + } + FileOrigin(FileOriginSavedGifs data) : data(data) { + } + + explicit operator bool() const { + return data.has_value(); + } + inline bool operator<(const FileOrigin &other) const { + return data < other.data; + } + + Variant data; +}; // Volume_id, dc_id, local_id. struct SimpleFileLocationId { @@ -84,7 +107,9 @@ using DocumentFileLocationId = uint64; using FileLocationId = base::variant< SimpleFileLocationId, DocumentFileLocationId>; -using UpdatedFileReferences = std::map; +struct UpdatedFileReferences { + std::map data; +}; UpdatedFileReferences GetFileReferences(const MTPmessages_Messages &data); UpdatedFileReferences GetFileReferences(const MTPphotos_Photos &data); diff --git a/Telegram/SourceFiles/data/data_media_types.cpp b/Telegram/SourceFiles/data/data_media_types.cpp index e79252c3e..3b2594073 100644 --- a/Telegram/SourceFiles/data/data_media_types.cpp +++ b/Telegram/SourceFiles/data/data_media_types.cpp @@ -35,6 +35,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_game.h" #include "data/data_web_page.h" #include "data/data_poll.h" +#include "data/data_channel.h" #include "lang/lang_keys.h" #include "layout.h" diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp index 8a7b898ed..213403e69 100644 --- a/Telegram/SourceFiles/data/data_peer.cpp +++ b/Telegram/SourceFiles/data/data_peer.cpp @@ -9,23 +9,20 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include -#include "data/data_peer_values.h" -#include "data/data_channel_admins.h" +#include "data/data_user.h" +#include "data/data_chat.h" +#include "data/data_channel.h" #include "data/data_photo.h" #include "data/data_feed.h" #include "data/data_session.h" -#include "history/history.h" #include "lang/lang_keys.h" #include "observer_peer.h" -#include "mainwidget.h" #include "apiwrap.h" #include "boxes/confirm_box.h" -#include "styles/style_history.h" #include "auth_session.h" #include "messenger.h" #include "mainwindow.h" #include "window/window_controller.h" -#include "storage/localstorage.h" #include "ui/image/image.h" #include "ui/empty_userpic.h" #include "ui/text_options.h" @@ -35,6 +32,8 @@ namespace { constexpr auto kUpdateFullPeerTimeout = TimeMs(5000); // Not more than once in 5 seconds. constexpr auto kUserpicSize = 160; +using UpdateFlag = Notify::PeerUpdate::Flag; + } // namespace namespace Data { @@ -65,8 +64,6 @@ style::color PeerUserpicColor(PeerId peerId) { } // namespace Data -using UpdateFlag = Notify::PeerUpdate::Flag; - PeerClickHandler::PeerClickHandler(not_null peer) : _peer(peer) { } @@ -294,6 +291,16 @@ QPixmap PeerData::genUserpicRounded(int size) const { return App::pixmapFromImageInPlace(std::move(result)); } +Data::FileOrigin PeerData::userpicOrigin() const { + return Data::FileOriginPeerPhoto(id); +} + +Data::FileOrigin PeerData::userpicPhotoOrigin() const { + return (isUser() && userpicPhotoId()) + ? Data::FileOriginUserPhoto(bareId(), userpicPhotoId()) + : Data::FileOrigin(); +} + void PeerData::updateUserpic( PhotoId photoId, const MTPFileLocation &location) { @@ -418,313 +425,6 @@ void PeerData::fillNames() { PeerData::~PeerData() = default; -const Text &BotCommand::descriptionText() const { - if (_descriptionText.isEmpty() && !_description.isEmpty()) { - _descriptionText.setText( - st::defaultTextStyle, - _description, - Ui::NameTextOptions()); - } - return _descriptionText; -} - -UserData::UserData(not_null owner, PeerId id) -: PeerData(owner, id) { -} - -bool UserData::canShareThisContact() const { - return canShareThisContactFast() - || !owner().findContactPhone(peerToUser(id)).isEmpty(); -} - -void UserData::setContactStatus(ContactStatus status) { - if (_contactStatus != status) { - const auto changed = (_contactStatus == ContactStatus::Contact) - != (status == ContactStatus::Contact); - _contactStatus = status; - if (changed) { - Notify::peerUpdatedDelayed( - this, - Notify::PeerUpdate::Flag::UserIsContact); - } - } - if (_contactStatus == ContactStatus::Contact - && cReportSpamStatuses().value(id, dbiprsHidden) != dbiprsHidden) { - cRefReportSpamStatuses().insert(id, dbiprsHidden); - Local::writeReportSpamStatuses(); - } -} - -// see Local::readPeer as well -void UserData::setPhoto(const MTPUserProfilePhoto &photo) { - if (photo.type() == mtpc_userProfilePhoto) { - const auto &data = photo.c_userProfilePhoto(); - updateUserpic(data.vphoto_id.v, data.vphoto_small); - } else { - clearUserpic(); - } -} - -bool UserData::setAbout(const QString &newAbout) { - if (_about == newAbout) { - return false; - } - _about = newAbout; - Notify::peerUpdatedDelayed(this, UpdateFlag::AboutChanged); - return true; -} - -QString UserData::unavailableReason() const { - return _unavailableReason; -} - -void UserData::setUnavailableReason(const QString &text) { - if (_unavailableReason != text) { - _unavailableReason = text; - Notify::peerUpdatedDelayed( - this, - Notify::PeerUpdate::Flag::UnavailableReasonChanged); - } -} - -void UserData::setCommonChatsCount(int count) { - if (_commonChatsCount != count) { - _commonChatsCount = count; - Notify::peerUpdatedDelayed(this, UpdateFlag::UserCommonChatsChanged); - } -} - -void UserData::setName(const QString &newFirstName, const QString &newLastName, const QString &newPhoneName, const QString &newUsername) { - bool changeName = !newFirstName.isEmpty() || !newLastName.isEmpty(); - - QString newFullName; - if (changeName && newFirstName.trimmed().isEmpty()) { - firstName = newLastName; - lastName = QString(); - newFullName = firstName; - } else { - if (changeName) { - firstName = newFirstName; - lastName = newLastName; - } - newFullName = lastName.isEmpty() ? firstName : lng_full_name(lt_first_name, firstName, lt_last_name, lastName); - } - updateNameDelayed(newFullName, newPhoneName, newUsername); -} - -void UserData::setPhone(const QString &newPhone) { - if (_phone != newPhone) { - _phone = newPhone; - } -} - -void UserData::setBotInfoVersion(int version) { - if (version < 0) { - if (botInfo) { - if (!botInfo->commands.isEmpty()) { - botInfo->commands.clear(); - Notify::botCommandsChanged(this); - } - botInfo = nullptr; - Notify::userIsBotChanged(this); - } - } else if (!botInfo) { - botInfo = std::make_unique(); - botInfo->version = version; - Notify::userIsBotChanged(this); - } else if (botInfo->version < version) { - if (!botInfo->commands.isEmpty()) { - botInfo->commands.clear(); - Notify::botCommandsChanged(this); - } - botInfo->description.clear(); - botInfo->version = version; - botInfo->inited = false; - } -} - -void UserData::setBotInfo(const MTPBotInfo &info) { - switch (info.type()) { - case mtpc_botInfo: { - const auto &d(info.c_botInfo()); - if (peerFromUser(d.vuser_id.v) != id || !botInfo) return; - - QString desc = qs(d.vdescription); - if (botInfo->description != desc) { - botInfo->description = desc; - botInfo->text = Text(st::msgMinWidth); - } - - auto &v = d.vcommands.v; - botInfo->commands.reserve(v.size()); - auto changedCommands = false; - int32 j = 0; - for (int32 i = 0, l = v.size(); i < l; ++i) { - if (v.at(i).type() != mtpc_botCommand) continue; - - QString cmd = qs(v.at(i).c_botCommand().vcommand), desc = qs(v.at(i).c_botCommand().vdescription); - if (botInfo->commands.size() <= j) { - botInfo->commands.push_back(BotCommand(cmd, desc)); - changedCommands = true; - } else { - if (botInfo->commands[j].command != cmd) { - botInfo->commands[j].command = cmd; - changedCommands = true; - } - if (botInfo->commands[j].setDescription(desc)) { - changedCommands = true; - } - } - ++j; - } - while (j < botInfo->commands.size()) { - botInfo->commands.pop_back(); - changedCommands = true; - } - - botInfo->inited = true; - - if (changedCommands) { - Notify::botCommandsChanged(this); - } - } break; - } -} - -void UserData::setNameOrPhone(const QString &newNameOrPhone) { - if (nameOrPhone != newNameOrPhone) { - nameOrPhone = newNameOrPhone; - phoneText.setText( - st::msgNameStyle, - nameOrPhone, - Ui::NameTextOptions()); - } -} - -void UserData::madeAction(TimeId when) { - if (botInfo || isServiceUser(id) || when <= 0) return; - - if (onlineTill <= 0 && -onlineTill < when) { - onlineTill = -when - SetOnlineAfterActivity; - Notify::peerUpdatedDelayed(this, Notify::PeerUpdate::Flag::UserOnlineChanged); - } else if (onlineTill > 0 && onlineTill < when + 1) { - onlineTill = when + SetOnlineAfterActivity; - Notify::peerUpdatedDelayed(this, Notify::PeerUpdate::Flag::UserOnlineChanged); - } -} - -void UserData::setAccessHash(uint64 accessHash) { - if (accessHash == kInaccessibleAccessHashOld) { - _accessHash = 0; -// _flags.add(MTPDuser_ClientFlag::f_inaccessible | 0); - _flags.add(MTPDuser::Flag::f_deleted); - } else { - _accessHash = accessHash; - } -} - -void UserData::setBlockStatus(BlockStatus blockStatus) { - if (blockStatus != _blockStatus) { - _blockStatus = blockStatus; - Notify::peerUpdatedDelayed(this, UpdateFlag::UserIsBlocked); - } -} - -void UserData::setCallsStatus(CallsStatus callsStatus) { - if (callsStatus != _callsStatus) { - _callsStatus = callsStatus; - Notify::peerUpdatedDelayed(this, UpdateFlag::UserHasCalls); - } -} - -bool UserData::hasCalls() const { - return (callsStatus() != CallsStatus::Disabled) - && (callsStatus() != CallsStatus::Unknown); -} - -ChatData::ChatData(not_null owner, PeerId id) -: PeerData(owner, id) -, inputChat(MTP_int(bareId())) { -} - -void ChatData::setPhoto(const MTPChatPhoto &photo) { - setPhoto(userpicPhotoId(), photo); -} - -void ChatData::setPhoto(PhotoId photoId, const MTPChatPhoto &photo) { - if (photo.type() == mtpc_chatPhoto) { - const auto &data = photo.c_chatPhoto(); - updateUserpic(photoId, data.vphoto_small); - } else { - clearUserpic(); - } -} - -bool ChatData::canEditInformation() const { - // #TODO groups - return !isDeactivated() - /*&& ((adminRights() & AdminRight::f_change_info) || amCreator())*/; -} - -void ChatData::setName(const QString &newName) { - updateNameDelayed(newName.isEmpty() ? name : newName, QString(), QString()); -} - -void ChatData::invalidateParticipants() { - // #TODO groups - auto wasCanEdit = canEditInformation(); - participants.clear(); - admins.clear(); - //removeFlags(MTPDchat::Flag::f_admin); - invitedByMe.clear(); - botStatus = 0; - if (wasCanEdit != canEditInformation()) { - Notify::peerUpdatedDelayed(this, Notify::PeerUpdate::Flag::ChatCanEdit); - } - Notify::peerUpdatedDelayed(this, Notify::PeerUpdate::Flag::MembersChanged | Notify::PeerUpdate::Flag::AdminsChanged); -} - -void ChatData::setInviteLink(const QString &newInviteLink) { - if (newInviteLink != _inviteLink) { - _inviteLink = newInviteLink; - Notify::peerUpdatedDelayed(this, UpdateFlag::InviteLinkChanged); - } -} - -ChannelData::ChannelData(not_null owner, PeerId id) -: PeerData(owner, id) -, inputChannel(MTP_inputChannel(MTP_int(bareId()), MTP_long(0))) { - Data::PeerFlagValue( - this, - MTPDchannel::Flag::f_megagroup - ) | rpl::start_with_next([this](bool megagroup) { - if (megagroup) { - if (!mgInfo) { - mgInfo = std::make_unique(); - } - } else if (mgInfo) { - mgInfo = nullptr; - } - }, _lifetime); -} - -void ChannelData::setPhoto(const MTPChatPhoto &photo) { - setPhoto(userpicPhotoId(), photo); -} - -void ChannelData::setPhoto(PhotoId photoId, const MTPChatPhoto &photo) { - if (photo.type() == mtpc_chatPhoto) { - const auto &data = photo.c_chatPhoto(); - updateUserpic(photoId, data.vphoto_small); - } else { - clearUserpic(); - } -} - -void ChannelData::setName(const QString &newName, const QString &newUsername) { - updateNameDelayed(newName.isEmpty() ? name : newName, QString(), newUsername); -} - void PeerData::updateFull() { if (!_lastFullUpdate || getms(true) > _lastFullUpdate + kUpdateFullPeerTimeout) { updateFullForced(); @@ -744,558 +444,105 @@ void PeerData::fullUpdated() { _lastFullUpdate = getms(true); } -bool ChannelData::setAbout(const QString &newAbout) { - if (_about == newAbout) { - return false; +UserData *PeerData::asUser() { + return isUser() ? static_cast(this) : nullptr; +} + +const UserData *PeerData::asUser() const { + return isUser() ? static_cast(this) : nullptr; +} + +ChatData *PeerData::asChat() { + return isChat() ? static_cast(this) : nullptr; +} + +const ChatData *PeerData::asChat() const { + return isChat() ? static_cast(this) : nullptr; +} + +ChannelData *PeerData::asChannel() { + return isChannel() ? static_cast(this) : nullptr; +} + +const ChannelData *PeerData::asChannel() const { + return isChannel() + ? static_cast(this) + : nullptr; +} + +ChannelData *PeerData::asMegagroup() { + return isMegagroup() ? static_cast(this) : nullptr; +} + +const ChannelData *PeerData::asMegagroup() const { + return isMegagroup() + ? static_cast(this) + : nullptr; +} + +ChatData *PeerData::migrateFrom() const { + if (const auto megagroup = asMegagroup()) { + return megagroup->amIn() + ? megagroup->mgInfo->migrateFromPtr + : nullptr; } - _about = newAbout; - Notify::peerUpdatedDelayed(this, UpdateFlag::AboutChanged); - return true; + return nullptr; } -void ChannelData::setInviteLink(const QString &newInviteLink) { - if (newInviteLink != _inviteLink) { - _inviteLink = newInviteLink; - Notify::peerUpdatedDelayed(this, UpdateFlag::InviteLinkChanged); - } -} - -void ChannelData::setMembersCount(int newMembersCount) { - if (_membersCount != newMembersCount) { - if (isMegagroup() && !mgInfo->lastParticipants.empty()) { - mgInfo->lastParticipantsStatus |= MegagroupInfo::LastParticipantsCountOutdated; - mgInfo->lastParticipantsCount = membersCount(); - } - _membersCount = newMembersCount; - Notify::peerUpdatedDelayed(this, Notify::PeerUpdate::Flag::MembersChanged); - } -} - -void ChannelData::setAdminsCount(int newAdminsCount) { - if (_adminsCount != newAdminsCount) { - _adminsCount = newAdminsCount; - Notify::peerUpdatedDelayed(this, Notify::PeerUpdate::Flag::AdminsChanged); - } -} - -void ChannelData::setRestrictedCount(int newRestrictedCount) { - if (_restrictedCount != newRestrictedCount) { - _restrictedCount = newRestrictedCount; - Notify::peerUpdatedDelayed(this, Notify::PeerUpdate::Flag::BannedUsersChanged); - } -} - -void ChannelData::setKickedCount(int newKickedCount) { - if (_kickedCount != newKickedCount) { - _kickedCount = newKickedCount; - Notify::peerUpdatedDelayed(this, Notify::PeerUpdate::Flag::BannedUsersChanged); - } -} - -MTPChatBannedRights ChannelData::KickedRestrictedRights() { - using Flag = MTPDchatBannedRights::Flag; - auto flags = Flag::f_view_messages | Flag::f_send_messages | Flag::f_send_media | Flag::f_embed_links | Flag::f_send_stickers | Flag::f_send_gifs | Flag::f_send_games | Flag::f_send_inline; - return MTP_chatBannedRights(MTP_flags(flags), MTP_int(std::numeric_limits::max())); -} - -void ChannelData::applyEditAdmin(not_null user, const MTPChatAdminRights &oldRights, const MTPChatAdminRights &newRights) { - auto flags = Notify::PeerUpdate::Flag::AdminsChanged | Notify::PeerUpdate::Flag::None; - if (mgInfo) { - // If rights are empty - still add participant? TODO check - if (!base::contains(mgInfo->lastParticipants, user)) { - mgInfo->lastParticipants.push_front(user); - setMembersCount(membersCount() + 1); - if (user->botInfo && !mgInfo->bots.contains(user)) { - mgInfo->bots.insert(user); - if (mgInfo->botStatus != 0 && mgInfo->botStatus < 2) { - mgInfo->botStatus = 2; - } - } - } - // If rights are empty - still remove restrictions? TODO check - if (mgInfo->lastRestricted.contains(user)) { - mgInfo->lastRestricted.remove(user); - if (restrictedCount() > 0) { - setRestrictedCount(restrictedCount() - 1); - } - } - - auto userId = peerToUser(user->id); - auto it = mgInfo->lastAdmins.find(user); - if (newRights.c_chatAdminRights().vflags.v != 0) { - auto lastAdmin = MegagroupInfo::Admin { newRights }; - lastAdmin.canEdit = true; - if (it == mgInfo->lastAdmins.cend()) { - mgInfo->lastAdmins.emplace(user, lastAdmin); - setAdminsCount(adminsCount() + 1); - } else { - it->second = lastAdmin; - } - Data::ChannelAdminChanges(this).feed(userId, true); - } else { - if (it != mgInfo->lastAdmins.cend()) { - mgInfo->lastAdmins.erase(it); - if (adminsCount() > 0) { - setAdminsCount(adminsCount() - 1); - } - } - Data::ChannelAdminChanges(this).feed(userId, false); +ChannelData *PeerData::migrateTo() const { + if (const auto chat = asChat()) { + if (const auto migrateTo = chat->migrateToPtr) { + return migrateTo->amIn() ? migrateTo : nullptr; } } - if (oldRights.c_chatAdminRights().vflags.v && !newRights.c_chatAdminRights().vflags.v) { - // We removed an admin. - if (adminsCount() > 1) { - setAdminsCount(adminsCount() - 1); - } - if (!isMegagroup() && user->botInfo && membersCount() > 1) { - // Removing bot admin removes it from channel. - setMembersCount(membersCount() - 1); - } - } else if (!oldRights.c_chatAdminRights().vflags.v && newRights.c_chatAdminRights().vflags.v) { - // We added an admin. - setAdminsCount(adminsCount() + 1); - updateFullForced(); + return nullptr; +} + +Data::Feed *PeerData::feed() const { + if (const auto channel = asChannel()) { + return channel->feed(); } - Notify::peerUpdatedDelayed(this, flags); + return nullptr; } -void ChannelData::applyEditBanned(not_null user, const MTPChatBannedRights &oldRights, const MTPChatBannedRights &newRights) { - auto flags = Notify::PeerUpdate::Flag::BannedUsersChanged | Notify::PeerUpdate::Flag::None; - auto isKicked = (newRights.c_chatBannedRights().vflags.v & MTPDchatBannedRights::Flag::f_view_messages); - auto isRestricted = !isKicked && (newRights.c_chatBannedRights().vflags.v != 0); - if (mgInfo) { - // If rights are empty - still remove admin? TODO check - if (mgInfo->lastAdmins.contains(user)) { - mgInfo->lastAdmins.remove(user); - if (adminsCount() > 1) { - setAdminsCount(adminsCount() - 1); - } else { - flags |= Notify::PeerUpdate::Flag::AdminsChanged; - } - } - auto it = mgInfo->lastRestricted.find(user); - if (isRestricted) { - if (it == mgInfo->lastRestricted.cend()) { - mgInfo->lastRestricted.emplace(user, MegagroupInfo::Restricted { newRights }); - setRestrictedCount(restrictedCount() + 1); - } else { - it->second.rights = newRights; - } - } else { - if (it != mgInfo->lastRestricted.cend()) { - mgInfo->lastRestricted.erase(it); - if (restrictedCount() > 0) { - setRestrictedCount(restrictedCount() - 1); - } - } - if (isKicked) { - auto i = ranges::find(mgInfo->lastParticipants, user); - if (i != mgInfo->lastParticipants.end()) { - mgInfo->lastParticipants.erase(i); - } - if (membersCount() > 1) { - setMembersCount(membersCount() - 1); - } else { - mgInfo->lastParticipantsStatus |= MegagroupInfo::LastParticipantsCountOutdated; - mgInfo->lastParticipantsCount = 0; - } - setKickedCount(kickedCount() + 1); - if (mgInfo->bots.contains(user)) { - mgInfo->bots.remove(user); - if (mgInfo->bots.empty() && mgInfo->botStatus > 0) { - mgInfo->botStatus = -1; - } - } - flags |= Notify::PeerUpdate::Flag::MembersChanged; - owner().removeMegagroupParticipant(this, user); - } - } - Data::ChannelAdminChanges(this).feed(peerToUser(user->id), false); - } else { - if (isKicked) { - if (membersCount() > 1) { - setMembersCount(membersCount() - 1); - flags |= Notify::PeerUpdate::Flag::MembersChanged; - } - setKickedCount(kickedCount() + 1); - } - } - Notify::peerUpdatedDelayed(this, flags); +const Text &PeerData::dialogName() const { + return migrateTo() + ? migrateTo()->dialogName() + : (isUser() && !asUser()->phoneText.isEmpty()) + ? asUser()->phoneText + : nameText; } -bool ChannelData::isGroupAdmin(not_null user) const { - if (auto info = mgInfo.get()) { - return info->admins.contains(peerToUser(user->id)); - } - return false; +const QString &PeerData::shortName() const { + return isUser() ? asUser()->firstName : name; } -QString ChannelData::unavailableReason() const { - return _unavailableReason; +QString PeerData::userName() const { + return isUser() + ? asUser()->username + : isChannel() + ? asChannel()->username + : QString(); } -void ChannelData::setUnavailableReason(const QString &text) { - if (_unavailableReason != text) { - _unavailableReason = text; - Notify::peerUpdatedDelayed( - this, - Notify::PeerUpdate::Flag::UnavailableReasonChanged); - } +bool PeerData::isVerified() const { + return isUser() + ? asUser()->isVerified() + : isChannel() + ? asChannel()->isVerified() + : false; } -void ChannelData::setAvailableMinId(MsgId availableMinId) { - if (_availableMinId != availableMinId) { - _availableMinId = availableMinId; - if (pinnedMessageId() <= _availableMinId) { - clearPinnedMessage(); - } - } +bool PeerData::isMegagroup() const { + return isChannel() ? asChannel()->isMegagroup() : false; } -void ChannelData::setFeed(not_null feed) { - setFeedPointer(feed); -} - -void ChannelData::clearFeed() { - setFeedPointer(nullptr); -} - -void ChannelData::setFeedPointer(Data::Feed *feed) { - if (_feed != feed) { - const auto was = _feed; - _feed = feed; - if (was) { - was->unregisterOne(this); - } - if (_feed) { - _feed->registerOne(this); - } - } -} - -bool ChannelData::canBanMembers() const { - return (adminRights() & AdminRight::f_ban_users) - || amCreator(); -} - -bool ChannelData::canEditMessages() const { - return (adminRights() & AdminRight::f_edit_messages) - || amCreator(); -} - -bool ChannelData::canDeleteMessages() const { - return (adminRights() & AdminRight::f_delete_messages) - || amCreator(); -} - -bool ChannelData::anyoneCanAddMembers() const { - // #TODO groups - return false;// (flags() & MTPDchannel::Flag::f_democracy); -} - -bool ChannelData::hiddenPreHistory() const { - return (fullFlags() & MTPDchannelFull::Flag::f_hidden_prehistory); -} - -bool ChannelData::canAddMembers() const { - return (adminRights() & AdminRight::f_invite_users) - || amCreator() - || (anyoneCanAddMembers() - && amIn() - && !hasRestrictions()); -} - -bool ChannelData::canAddAdmins() const { - return (adminRights() & AdminRight::f_add_admins) - || amCreator(); -} - -bool ChannelData::canPublish() const { - return (adminRights() & AdminRight::f_post_messages) - || amCreator(); -} - -bool ChannelData::canWrite() const { - // Duplicated in Data::CanWriteValue(). - return amIn() - && (canPublish() - || (!isBroadcast() - && !restricted(Restriction::f_send_messages))); -} - -bool ChannelData::canViewMembers() const { - return fullFlags() - & MTPDchannelFull::Flag::f_can_view_participants; -} - -bool ChannelData::canViewAdmins() const { - return (isMegagroup() || hasAdminRights() || amCreator()); -} - -bool ChannelData::canViewBanned() const { - return (hasAdminRights() || amCreator()); -} - -bool ChannelData::canEditInformation() const { - return (adminRights() & AdminRight::f_change_info) - || amCreator(); -} - -bool ChannelData::canEditInvites() const { - return canEditInformation(); -} - -bool ChannelData::canEditSignatures() const { - return canEditInformation(); -} - -bool ChannelData::canEditPreHistoryHidden() const { - return canEditInformation(); -} - -bool ChannelData::canEditUsername() const { - return amCreator() - && (fullFlags() - & MTPDchannelFull::Flag::f_can_set_username); -} - -bool ChannelData::canEditStickers() const { - return (fullFlags() - & MTPDchannelFull::Flag::f_can_set_stickers); -} - -bool ChannelData::canDelete() const { - constexpr auto kDeleteChannelMembersLimit = 1000; - return amCreator() - && (membersCount() <= kDeleteChannelMembersLimit); -} - -bool ChannelData::canEditLastAdmin(not_null user) const { - // Duplicated in ParticipantsBoxController::canEditAdmin :( - if (mgInfo) { - auto i = mgInfo->lastAdmins.find(user); - if (i != mgInfo->lastAdmins.cend()) { - return i->second.canEdit; - } - return (user != mgInfo->creator); - } - return false; -} - -bool ChannelData::canEditAdmin(not_null user) const { - // Duplicated in ParticipantsBoxController::canEditAdmin :( - if (user->isSelf()) { - return false; - } else if (amCreator()) { - return true; - } else if (!canEditLastAdmin(user)) { - return false; - } - return adminRights() & AdminRight::f_add_admins; -} - -bool ChannelData::canRestrictUser(not_null user) const { - // Duplicated in ParticipantsBoxController::canRestrictUser :( - if (user->isSelf()) { - return false; - } else if (amCreator()) { - return true; - } else if (!canEditLastAdmin(user)) { - return false; - } - return adminRights() & AdminRight::f_ban_users; -} - -void ChannelData::setAdminRights(const MTPChatAdminRights &rights) { - if (rights.c_chatAdminRights().vflags.v == adminRights()) { - return; - } - _adminRights.set(rights.c_chatAdminRights().vflags.v); - if (isMegagroup()) { - const auto self = session().user(); - if (hasAdminRights()) { - if (!amCreator()) { - auto me = MegagroupInfo::Admin { rights }; - me.canEdit = false; - mgInfo->lastAdmins.emplace(self, me); - } - mgInfo->lastRestricted.remove(self); - } else { - mgInfo->lastAdmins.remove(self); - } - - auto amAdmin = hasAdminRights() || amCreator(); - Data::ChannelAdminChanges(this).feed(session().userId(), amAdmin); - } - Notify::peerUpdatedDelayed(this, UpdateFlag::ChannelRightsChanged | UpdateFlag::AdminsChanged | UpdateFlag::BannedUsersChanged); -} - -void ChannelData::setRestrictedRights(const MTPChatBannedRights &rights) { - if (rights.c_chatBannedRights().vflags.v == restrictions() - && rights.c_chatBannedRights().vuntil_date.v == _restrictedUntill) { - return; - } - _restrictedUntill = rights.c_chatBannedRights().vuntil_date.v; - _restrictions.set(rights.c_chatBannedRights().vflags.v); - if (isMegagroup()) { - const auto self = session().user(); - if (hasRestrictions()) { - if (!amCreator()) { - auto me = MegagroupInfo::Restricted { rights }; - mgInfo->lastRestricted.emplace(self, me); - } - mgInfo->lastAdmins.remove(self); - Data::ChannelAdminChanges(this).feed(session().userId(), false); - } else { - mgInfo->lastRestricted.remove(self); - } - } - Notify::peerUpdatedDelayed(this, UpdateFlag::ChannelRightsChanged | UpdateFlag::AdminsChanged | UpdateFlag::BannedUsersChanged); -} - -uint64 PtsWaiter::ptsKey(PtsSkippedQueue queue, int32 pts) { - return _queue.insert(uint64(uint32(pts)) << 32 | (++_skippedKey), queue).key(); -} - -void PtsWaiter::setWaitingForSkipped(ChannelData *channel, int32 ms) { - if (ms >= 0) { - if (App::main()) { - App::main()->ptsWaiterStartTimerFor(channel, ms); - } - _waitingForSkipped = true; - } else { - _waitingForSkipped = false; - checkForWaiting(channel); - } -} - -void PtsWaiter::setWaitingForShortPoll(ChannelData *channel, int32 ms) { - if (ms >= 0) { - if (App::main()) { - App::main()->ptsWaiterStartTimerFor(channel, ms); - } - _waitingForShortPoll = true; - } else { - _waitingForShortPoll = false; - checkForWaiting(channel); - } -} - -void PtsWaiter::checkForWaiting(ChannelData *channel) { - if (!_waitingForSkipped && !_waitingForShortPoll && App::main()) { - App::main()->ptsWaiterStartTimerFor(channel, -1); - } -} - -void PtsWaiter::applySkippedUpdates(ChannelData *channel) { - if (!_waitingForSkipped) return; - - setWaitingForSkipped(channel, -1); - - if (_queue.isEmpty()) return; - - ++_applySkippedLevel; - for (auto i = _queue.cbegin(), e = _queue.cend(); i != e; ++i) { - switch (i.value()) { - case SkippedUpdate: Auth().api().applyUpdateNoPtsCheck(_updateQueue.value(i.key())); break; - case SkippedUpdates: Auth().api().applyUpdatesNoPtsCheck(_updatesQueue.value(i.key())); break; - } - } - --_applySkippedLevel; - clearSkippedUpdates(); -} - -void PtsWaiter::clearSkippedUpdates() { - _queue.clear(); - _updateQueue.clear(); - _updatesQueue.clear(); - _applySkippedLevel = 0; -} - -bool PtsWaiter::updated(ChannelData *channel, int32 pts, int32 count, const MTPUpdates &updates) { - if (_requesting || _applySkippedLevel) { - return true; - } else if (pts <= _good && count > 0) { - return false; - } else if (check(channel, pts, count)) { - return true; - } - _updatesQueue.insert(ptsKey(SkippedUpdates, pts), updates); - return false; -} - -bool PtsWaiter::updated(ChannelData *channel, int32 pts, int32 count, const MTPUpdate &update) { - if (_requesting || _applySkippedLevel) { - return true; - } else if (pts <= _good && count > 0) { - return false; - } else if (check(channel, pts, count)) { - return true; - } - _updateQueue.insert(ptsKey(SkippedUpdate, pts), update); - return false; -} - -bool PtsWaiter::updated(ChannelData *channel, int32 pts, int32 count) { - if (_requesting || _applySkippedLevel) { - return true; - } else if (pts <= _good && count > 0) { - return false; - } - return check(channel, pts, count); -} - -bool PtsWaiter::updateAndApply(ChannelData *channel, int32 pts, int32 count, const MTPUpdates &updates) { - if (!updated(channel, pts, count, updates)) { - return false; - } - if (!_waitingForSkipped || _queue.isEmpty()) { - // Optimization - no need to put in queue and back. - Auth().api().applyUpdatesNoPtsCheck(updates); - } else { - _updatesQueue.insert(ptsKey(SkippedUpdates, pts), updates); - applySkippedUpdates(channel); - } - return true; -} - -bool PtsWaiter::updateAndApply(ChannelData *channel, int32 pts, int32 count, const MTPUpdate &update) { - if (!updated(channel, pts, count, update)) { - return false; - } - if (!_waitingForSkipped || _queue.isEmpty()) { - // Optimization - no need to put in queue and back. - Auth().api().applyUpdateNoPtsCheck(update); - } else { - _updateQueue.insert(ptsKey(SkippedUpdate, pts), update); - applySkippedUpdates(channel); - } - return true; -} - -bool PtsWaiter::updateAndApply(ChannelData *channel, int32 pts, int32 count) { - if (!updated(channel, pts, count)) { - return false; - } - applySkippedUpdates(channel); - return true; -} - -bool PtsWaiter::check(ChannelData *channel, int32 pts, int32 count) { // return false if need to save that update and apply later - if (!inited()) { - init(pts); - return true; - } - - _last = qMax(_last, pts); - _count += count; - if (_last == _count) { - _good = _last; - return true; - } else if (_last < _count) { - setWaitingForSkipped(channel, 1); - } else { - setWaitingForSkipped(channel, WaitForSkippedTimeout); - } - return !count; +bool PeerData::canWrite() const { + return isChannel() + ? asChannel()->canWrite() + : isChat() + ? asChat()->canWrite() + : isUser() + ? asUser()->canWrite() + : false; } diff --git a/Telegram/SourceFiles/data/data_peer.h b/Telegram/SourceFiles/data/data_peer.h index d12ed6e9e..53f913052 100644 --- a/Telegram/SourceFiles/data/data_peer.h +++ b/Telegram/SourceFiles/data/data_peer.h @@ -10,7 +10,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_types.h" #include "data/data_flags.h" #include "data/data_notify_settings.h" -#include "data/data_file_origin.h" namespace Ui { class EmptyUserpic; @@ -33,6 +32,11 @@ style::color PeerUserpicColor(PeerId peerId); } // namespace Data +using ChatAdminRight = MTPDchatAdminRights::Flag; +using ChatRestriction = MTPDchatBannedRights::Flag; +using ChatAdminRights = MTPDchatAdminRights::Flags; +using ChatRestrictions = MTPDchatBannedRights::Flags; + class PeerClickHandler : public ClickHandler { public: PeerClickHandler(not_null peer); @@ -188,14 +192,8 @@ public: PhotoId userpicPhotoId() const { return userpicPhotoUnknown() ? 0 : _userpicPhotoId; } - Data::FileOrigin userpicOrigin() const { - return Data::FileOrigin(Data::FileOriginPeerPhoto(id)); - } - Data::FileOrigin userpicPhotoOrigin() const { - return (isUser() && userpicPhotoId()) - ? Data::FileOriginUserPhoto(bareId(), userpicPhotoId()) - : Data::FileOrigin(); - } + Data::FileOrigin userpicOrigin() const; + Data::FileOrigin userpicPhotoOrigin() const; int nameVersion = 1; @@ -261,900 +259,3 @@ private: MsgId _pinnedMessageId = 0; }; - -class BotCommand { -public: - BotCommand( - const QString &command, - const QString &description) - : command(command) - , _description(description) { - } - QString command; - - bool setDescription(const QString &description) { - if (_description != description) { - _description = description; - _descriptionText = Text(); - return true; - } - return false; - } - - const Text &descriptionText() const; - -private: - QString _description; - mutable Text _descriptionText; - -}; - -struct BotInfo { - bool inited = false; - bool readsAllHistory = false; - bool cantJoinGroups = false; - int version = 0; - QString description, inlinePlaceholder; - QList commands; - Text text = Text{ int(st::msgMinWidth) }; // description - - QString startToken, startGroupToken, shareGameShortName; - PeerId inlineReturnPeerId = 0; -}; - -class UserData : public PeerData { -public: - static constexpr auto kEssentialFlags = 0 - | MTPDuser::Flag::f_self - | MTPDuser::Flag::f_contact - | MTPDuser::Flag::f_mutual_contact - | MTPDuser::Flag::f_deleted - | MTPDuser::Flag::f_bot - | MTPDuser::Flag::f_bot_chat_history - | MTPDuser::Flag::f_bot_nochats - | MTPDuser::Flag::f_verified - | MTPDuser::Flag::f_restricted - | MTPDuser::Flag::f_bot_inline_geo; - using Flags = Data::Flags< - MTPDuser::Flags, - kEssentialFlags.value()>; - - static constexpr auto kEssentialFullFlags = 0 - | MTPDuserFull::Flag::f_blocked - | MTPDuserFull::Flag::f_phone_calls_available - | MTPDuserFull::Flag::f_phone_calls_private; - using FullFlags = Data::Flags< - MTPDuserFull::Flags, - kEssentialFullFlags.value()>; - - UserData(not_null owner, PeerId id); - void setPhoto(const MTPUserProfilePhoto &photo); - - void setName( - const QString &newFirstName, - const QString &newLastName, - const QString &newPhoneName, - const QString &newUsername); - - void setPhone(const QString &newPhone); - void setBotInfoVersion(int version); - void setBotInfo(const MTPBotInfo &info); - - void setNameOrPhone(const QString &newNameOrPhone); - - void madeAction(TimeId when); // pseudo-online - - uint64 accessHash() const { - return _accessHash; - } - void setAccessHash(uint64 accessHash); - - void setFlags(MTPDuser::Flags which) { - _flags.set(which); - } - void addFlags(MTPDuser::Flags which) { - _flags.add(which); - } - void removeFlags(MTPDuser::Flags which) { - _flags.remove(which); - } - auto flags() const { - return _flags.current(); - } - auto flagsValue() const { - return _flags.value(); - } - - void setFullFlags(MTPDuserFull::Flags which) { - _fullFlags.set(which); - } - void addFullFlags(MTPDuserFull::Flags which) { - _fullFlags.add(which); - } - void removeFullFlags(MTPDuserFull::Flags which) { - _fullFlags.remove(which); - } - auto fullFlags() const { - return _fullFlags.current(); - } - auto fullFlagsValue() const { - return _fullFlags.value(); - } - - bool isVerified() const { - return flags() & MTPDuser::Flag::f_verified; - } - bool isBotInlineGeo() const { - return flags() & MTPDuser::Flag::f_bot_inline_geo; - } - bool isInaccessible() const { - constexpr auto inaccessible = 0 - | MTPDuser::Flag::f_deleted; -// | MTPDuser_ClientFlag::f_inaccessible; - return flags() & inaccessible; - } - bool canWrite() const { - // Duplicated in Data::CanWriteValue(). - return !isInaccessible(); - } - bool isContact() const { - return (_contactStatus == ContactStatus::Contact); - } - - bool canShareThisContact() const; - bool canAddContact() const { - return canShareThisContact() && !isContact(); - } - - // In feedUsers() we check only that. - // When actually trying to share contact we perform - // a full check by canShareThisContact() call. - bool canShareThisContactFast() const { - return !_phone.isEmpty(); - } - - MTPInputUser inputUser; - - QString firstName; - QString lastName; - QString username; - const QString &phone() const { - return _phone; - } - QString nameOrPhone; - Text phoneText; - TimeId onlineTill = 0; - - enum class ContactStatus : char { - PhoneUnknown, - CanAdd, - Contact, - }; - ContactStatus contactStatus() const { - return _contactStatus; - } - void setContactStatus(ContactStatus status); - - enum class BlockStatus : char { - Unknown, - Blocked, - NotBlocked, - }; - BlockStatus blockStatus() const { - return _blockStatus; - } - bool isBlocked() const { - return (blockStatus() == BlockStatus::Blocked); - } - void setBlockStatus(BlockStatus blockStatus); - - enum class CallsStatus : char { - Unknown, - Enabled, - Disabled, - Private, - }; - CallsStatus callsStatus() const { - return _callsStatus; - } - bool hasCalls() const; - void setCallsStatus(CallsStatus callsStatus); - - bool setAbout(const QString &newAbout); - const QString &about() const { - return _about; - } - - std::unique_ptr botInfo; - - QString unavailableReason() const override; - void setUnavailableReason(const QString &reason); - - int commonChatsCount() const { - return _commonChatsCount; - } - void setCommonChatsCount(int count); - -private: - Flags _flags; - FullFlags _fullFlags; - - QString _unavailableReason; - QString _about; - QString _phone; - ContactStatus _contactStatus = ContactStatus::PhoneUnknown; - BlockStatus _blockStatus = BlockStatus::Unknown; - CallsStatus _callsStatus = CallsStatus::Unknown; - int _commonChatsCount = 0; - - uint64 _accessHash = 0; - static constexpr auto kInaccessibleAccessHashOld - = 0xFFFFFFFFFFFFFFFFULL; - -}; - -using ChatAdminRight = MTPDchatAdminRights::Flag; -using ChatRestriction = MTPDchatBannedRights::Flag; -using ChatAdminRights = MTPDchatAdminRights::Flags; -using ChatRestrictions = MTPDchatBannedRights::Flags; - -class ChatData : public PeerData { -public: - static constexpr auto kEssentialFlags = 0 - | MTPDchat::Flag::f_creator - | MTPDchat::Flag::f_kicked - | MTPDchat::Flag::f_left - | MTPDchat::Flag::f_deactivated - | MTPDchat::Flag::f_migrated_to - | MTPDchat::Flag::f_admin_rights - | MTPDchat::Flag::f_default_banned_rights; - using Flags = Data::Flags< - MTPDchat::Flags, - kEssentialFlags>; - - ChatData(not_null owner, PeerId id); - - void setPhoto(const MTPChatPhoto &photo); - void setPhoto(PhotoId photoId, const MTPChatPhoto &photo); - - void setName(const QString &newName); - - void invalidateParticipants(); - bool noParticipantInfo() const { - return (count > 0 || amIn()) && participants.empty(); - } - - MTPint inputChat; - - ChannelData *migrateToPtr = nullptr; - - int count = 0; - TimeId date = 0; - int version = 0; - UserId creator = 0; - - void setFlags(MTPDchat::Flags which) { - _flags.set(which); - } - void addFlags(MTPDchat::Flags which) { - _flags.add(which); - } - void removeFlags(MTPDchat::Flags which) { - _flags.remove(which); - } - auto flags() const { - return _flags.current(); - } - auto flagsValue() const { - return _flags.value(); - } - - bool isForbidden() const { - return flags() & MTPDchat_ClientFlag::f_forbidden; - } - bool amIn() const { - return !isForbidden() && !haveLeft() && !wasKicked(); - } - bool canEditInformation() const; - bool canWrite() const { - // Duplicated in Data::CanWriteValue(). - return !isDeactivated() && amIn(); - } - bool haveLeft() const { - return flags() & MTPDchat::Flag::f_left; - } - bool wasKicked() const { - return flags() & MTPDchat::Flag::f_kicked; - } - bool amCreator() const { - return flags() & MTPDchat::Flag::f_creator; - } - bool isDeactivated() const { - return flags() & MTPDchat::Flag::f_deactivated; - } - bool isMigrated() const { - return flags() & MTPDchat::Flag::f_migrated_to; - } - base::flat_map, int> participants; - base::flat_set> invitedByMe; - base::flat_set> admins; - std::deque> lastAuthors; - base::flat_set> markupSenders; - int botStatus = 0; // -1 - no bots, 0 - unknown, 1 - one bot, that sees all history, 2 - other -// ImagePtr photoFull; - - void setInviteLink(const QString &newInviteLink); - QString inviteLink() const { - return _inviteLink; - } - -private: - void flagsUpdated(MTPDchat::Flags diff); - - Flags _flags; - QString _inviteLink; - -}; - -enum PtsSkippedQueue { - SkippedUpdate, - SkippedUpdates, -}; -class PtsWaiter { -public: - PtsWaiter() = default; - void init(int32 pts) { - _good = _last = _count = pts; - clearSkippedUpdates(); - } - bool inited() const { - return _good > 0; - } - void setRequesting(bool isRequesting) { - _requesting = isRequesting; - if (_requesting) { - clearSkippedUpdates(); - } - } - bool requesting() const { - return _requesting; - } - bool waitingForSkipped() const { - return _waitingForSkipped; - } - bool waitingForShortPoll() const { - return _waitingForShortPoll; - } - void setWaitingForSkipped(ChannelData *channel, int32 ms); // < 0 - not waiting - void setWaitingForShortPoll(ChannelData *channel, int32 ms); // < 0 - not waiting - int32 current() const{ - return _good; - } - bool updated( - ChannelData *channel, - int32 pts, - int32 count, - const MTPUpdates &updates); - bool updated( - ChannelData *channel, - int32 pts, - int32 count, - const MTPUpdate &update); - bool updated( - ChannelData *channel, - int32 pts, - int32 count); - bool updateAndApply( - ChannelData *channel, - int32 pts, - int32 count, - const MTPUpdates &updates); - bool updateAndApply( - ChannelData *channel, - int32 pts, - int32 count, - const MTPUpdate &update); - bool updateAndApply( - ChannelData *channel, - int32 pts, - int32 count); - void applySkippedUpdates(ChannelData *channel); - void clearSkippedUpdates(); - -private: - bool check(ChannelData *channel, int32 pts, int32 count); // return false if need to save that update and apply later - uint64 ptsKey(PtsSkippedQueue queue, int32 pts); - void checkForWaiting(ChannelData *channel); - QMap _queue; - QMap _updateQueue; - QMap _updatesQueue; - int32 _good = 0; - int32 _last = 0; - int32 _count = 0; - int32 _applySkippedLevel = 0; - bool _requesting = false; - bool _waitingForSkipped = false; - bool _waitingForShortPoll = false; - uint32 _skippedKey = 0; -}; - -struct MegagroupInfo { - struct Admin { - explicit Admin(MTPChatAdminRights rights) - : rights(rights) { - } - Admin(MTPChatAdminRights rights, bool canEdit) - : rights(rights) - , canEdit(canEdit) { - } - MTPChatAdminRights rights; - bool canEdit = false; - }; - struct Restricted { - explicit Restricted(MTPChatBannedRights rights) - : rights(rights) { - } - MTPChatBannedRights rights; - }; - std::deque> lastParticipants; - base::flat_map, Admin> lastAdmins; - base::flat_map, Restricted> lastRestricted; - base::flat_set> markupSenders; - base::flat_set> bots; - - // For admin badges, full admins list. - base::flat_set admins; - - UserData *creator = nullptr; // nullptr means unknown - int botStatus = 0; // -1 - no bots, 0 - unknown, 1 - one bot, that sees all history, 2 - other - bool joinedMessageFound = false; - MTPInputStickerSet stickerSet = MTP_inputStickerSetEmpty(); - - enum LastParticipantsStatus { - LastParticipantsUpToDate = 0x00, - LastParticipantsCountOutdated = 0x02, - }; - mutable int lastParticipantsStatus = LastParticipantsUpToDate; - int lastParticipantsCount = 0; - - ChatData *migrateFromPtr = nullptr; - -}; - -class ChannelData : public PeerData { -public: - static constexpr auto kEssentialFlags = 0 - | MTPDchannel::Flag::f_creator - | MTPDchannel::Flag::f_left - | MTPDchannel::Flag::f_broadcast - | MTPDchannel::Flag::f_verified - | MTPDchannel::Flag::f_megagroup - | MTPDchannel::Flag::f_restricted - | MTPDchannel::Flag::f_signatures - | MTPDchannel::Flag::f_username; - using Flags = Data::Flags< - MTPDchannel::Flags, - kEssentialFlags>; - - static constexpr auto kEssentialFullFlags = 0 - | MTPDchannelFull::Flag::f_can_view_participants - | MTPDchannelFull::Flag::f_can_set_username - | MTPDchannelFull::Flag::f_can_set_stickers; - using FullFlags = Data::Flags< - MTPDchannelFull::Flags, - kEssentialFullFlags>; - - ChannelData(not_null owner, PeerId id); - - void setPhoto(const MTPChatPhoto &photo); - void setPhoto(PhotoId photoId, const MTPChatPhoto &photo); - - void setName(const QString &name, const QString &username); - - void setFlags(MTPDchannel::Flags which) { - _flags.set(which); - } - void addFlags(MTPDchannel::Flags which) { - _flags.add(which); - } - void removeFlags(MTPDchannel::Flags which) { - _flags.remove(which); - } - auto flags() const { - return _flags.current(); - } - auto flagsValue() const { - return _flags.value(); - } - - void setFullFlags(MTPDchannelFull::Flags which) { - _fullFlags.set(which); - } - void addFullFlags(MTPDchannelFull::Flags which) { - _fullFlags.add(which); - } - void removeFullFlags(MTPDchannelFull::Flags which) { - _fullFlags.remove(which); - } - auto fullFlags() const { - return _fullFlags.current(); - } - auto fullFlagsValue() const { - return _fullFlags.value(); - } - - uint64 access = 0; - - MTPinputChannel inputChannel; - - QString username; - - // Returns true if about text was changed. - bool setAbout(const QString &newAbout); - const QString &about() const { - return _about; - } - - int membersCount() const { - return _membersCount; - } - void setMembersCount(int newMembersCount); - - int adminsCount() const { - return _adminsCount; - } - void setAdminsCount(int newAdminsCount); - - int restrictedCount() const { - return _restrictedCount; - } - void setRestrictedCount(int newRestrictedCount); - - int kickedCount() const { - return _kickedCount; - } - void setKickedCount(int newKickedCount); - - bool haveLeft() const { - return flags() & MTPDchannel::Flag::f_left; - } - bool amIn() const { - return !isForbidden() && !haveLeft(); - } - bool addsSignature() const { - return flags() & MTPDchannel::Flag::f_signatures; - } - bool isForbidden() const { - return flags() & MTPDchannel_ClientFlag::f_forbidden; - } - bool isVerified() const { - return flags() & MTPDchannel::Flag::f_verified; - } - - static MTPChatBannedRights KickedRestrictedRights(); - static constexpr auto kRestrictUntilForever = TimeId(INT_MAX); - static bool IsRestrictedForever(TimeId until) { - return !until || (until == kRestrictUntilForever); - } - void applyEditAdmin( - not_null user, - const MTPChatAdminRights &oldRights, - const MTPChatAdminRights &newRights); - void applyEditBanned( - not_null user, - const MTPChatBannedRights &oldRights, - const MTPChatBannedRights &newRights); - - bool isGroupAdmin(not_null user) const; - - int32 date = 0; - int version = 0; - std::unique_ptr mgInfo; - bool lastParticipantsCountOutdated() const { - if (!mgInfo - || !(mgInfo->lastParticipantsStatus - & MegagroupInfo::LastParticipantsCountOutdated)) { - return false; - } - if (mgInfo->lastParticipantsCount == membersCount()) { - mgInfo->lastParticipantsStatus - &= ~MegagroupInfo::LastParticipantsCountOutdated; - return false; - } - return true; - } - bool isMegagroup() const { - return flags() & MTPDchannel::Flag::f_megagroup; - } - bool isBroadcast() const { - return flags() & MTPDchannel::Flag::f_broadcast; - } - bool isPublic() const { - return flags() & MTPDchannel::Flag::f_username; - } - bool amCreator() const { - return flags() & MTPDchannel::Flag::f_creator; - } - - using AdminRight = ChatAdminRight; - using Restriction = ChatRestriction; - using AdminRights = ChatAdminRights; - using Restrictions = ChatRestrictions; - using AdminRightFlags = Data::Flags; - using RestrictionFlags = Data::Flags; - auto adminRights() const { - return _adminRights.current(); - } - auto adminRightsValue() const { - return _adminRights.value(); - } - void setAdminRights(const MTPChatAdminRights &rights); - bool hasAdminRights() const { - return (adminRights() != 0); - } - auto restrictions() const { - return _restrictions.current(); - } - auto restrictionsValue() const { - return _restrictions.value(); - } - bool restricted(Restriction right) const { - return restrictions() & right; - } - TimeId restrictedUntil() const { - return _restrictedUntill; - } - void setRestrictedRights(const MTPChatBannedRights &rights); - bool hasRestrictions() const { - return (restrictions() != 0); - } - bool hasRestrictions(TimeId now) const { - return hasRestrictions() - && (restrictedUntil() > now); - } - bool canBanMembers() const; - bool canEditMessages() const; - bool canDeleteMessages() const; - bool anyoneCanAddMembers() const; - bool hiddenPreHistory() const; - bool canAddMembers() const; - bool canAddAdmins() const; - bool canPublish() const; - bool canWrite() const; - bool canViewMembers() const; - bool canViewAdmins() const; - bool canViewBanned() const; - bool canEditInformation() const; - bool canEditInvites() const; - bool canEditSignatures() const; - bool canEditPreHistoryHidden() const; - bool canEditUsername() const; - bool canEditStickers() const; - bool canDelete() const; - bool canEditAdmin(not_null user) const; - bool canRestrictUser(not_null user) const; - - void setInviteLink(const QString &newInviteLink); - QString inviteLink() const { - return _inviteLink; - } - bool canHaveInviteLink() const { - return (adminRights() & AdminRight::f_invite_users) - || amCreator(); - } - - UserId inviter = 0; // > 0 - user who invited me to channel, < 0 - not in channel - TimeId inviteDate = 0; - - void ptsInit(int32 pts) { - _ptsWaiter.init(pts); - } - void ptsReceived(int32 pts) { - _ptsWaiter.updateAndApply(this, pts, 0); - } - bool ptsUpdateAndApply(int32 pts, int32 count) { - return _ptsWaiter.updateAndApply(this, pts, count); - } - bool ptsUpdateAndApply( - int32 pts, - int32 count, - const MTPUpdate &update) { - return _ptsWaiter.updateAndApply(this, pts, count, update); - } - bool ptsUpdateAndApply( - int32 pts, - int32 count, - const MTPUpdates &updates) { - return _ptsWaiter.updateAndApply(this, pts, count, updates); - } - int32 pts() const { - return _ptsWaiter.current(); - } - bool ptsInited() const { - return _ptsWaiter.inited(); - } - bool ptsRequesting() const { - return _ptsWaiter.requesting(); - } - void ptsSetRequesting(bool isRequesting) { - return _ptsWaiter.setRequesting(isRequesting); - } - void ptsWaitingForShortPoll(int32 ms) { // < 0 - not waiting - return _ptsWaiter.setWaitingForShortPoll(this, ms); - } - bool ptsWaitingForSkipped() const { - return _ptsWaiter.waitingForSkipped(); - } - bool ptsWaitingForShortPoll() const { - return _ptsWaiter.waitingForShortPoll(); - } - - QString unavailableReason() const override; - void setUnavailableReason(const QString &reason); - - MsgId availableMinId() const { - return _availableMinId; - } - void setAvailableMinId(MsgId availableMinId); - - void setFeed(not_null feed); - void clearFeed(); - - Data::Feed *feed() const { - return _feed; - } - -private: - void flagsUpdated(MTPDchannel::Flags diff); - void fullFlagsUpdated(MTPDchannelFull::Flags diff); - - bool canEditLastAdmin(not_null user) const; - void setFeedPointer(Data::Feed *feed); - - Flags _flags = Flags(MTPDchannel_ClientFlag::f_forbidden | 0); - FullFlags _fullFlags; - - PtsWaiter _ptsWaiter; - - int _membersCount = 1; - int _adminsCount = 1; - int _restrictedCount = 0; - int _kickedCount = 0; - MsgId _availableMinId = 0; - - AdminRightFlags _adminRights; - RestrictionFlags _restrictions; - TimeId _restrictedUntill; - - QString _unavailableReason; - QString _about; - - QString _inviteLink; - Data::Feed *_feed = nullptr; - - rpl::lifetime _lifetime; - -}; - -inline bool isUser(const PeerData *peer) { - return peer ? peer->isUser() : false; -} -inline UserData *PeerData::asUser() { - return isUser() ? static_cast(this) : nullptr; -} -inline UserData *asUser(PeerData *peer) { - return peer ? peer->asUser() : nullptr; -} -inline const UserData *PeerData::asUser() const { - return isUser() ? static_cast(this) : nullptr; -} -inline const UserData *asUser(const PeerData *peer) { - return peer ? peer->asUser() : nullptr; -} -inline bool isChat(const PeerData *peer) { - return peer ? peer->isChat() : false; -} -inline ChatData *PeerData::asChat() { - return isChat() ? static_cast(this) : nullptr; -} -inline ChatData *asChat(PeerData *peer) { - return peer ? peer->asChat() : nullptr; -} -inline const ChatData *PeerData::asChat() const { - return isChat() ? static_cast(this) : nullptr; -} -inline const ChatData *asChat(const PeerData *peer) { - return peer ? peer->asChat() : nullptr; -} -inline bool isChannel(const PeerData *peer) { - return peer ? peer->isChannel() : false; -} -inline ChannelData *PeerData::asChannel() { - return isChannel() ? static_cast(this) : nullptr; -} -inline ChannelData *asChannel(PeerData *peer) { - return peer ? peer->asChannel() : nullptr; -} -inline const ChannelData *PeerData::asChannel() const { - return isChannel() - ? static_cast(this) - : nullptr; -} -inline const ChannelData *asChannel(const PeerData *peer) { - return peer ? peer->asChannel() : nullptr; -} -inline ChannelData *PeerData::asMegagroup() { - return isMegagroup() ? static_cast(this) : nullptr; -} -inline ChannelData *asMegagroup(PeerData *peer) { - return peer ? peer->asMegagroup() : nullptr; -} -inline const ChannelData *PeerData::asMegagroup() const { - return isMegagroup() - ? static_cast(this) - : nullptr; -} -inline const ChannelData *asMegagroup(const PeerData *peer) { - return peer ? peer->asMegagroup() : nullptr; -} -inline bool isMegagroup(const PeerData *peer) { - return peer ? peer->isMegagroup() : false; -} -inline ChatData *PeerData::migrateFrom() const { - if (const auto megagroup = asMegagroup()) { - return megagroup->amIn() - ? megagroup->mgInfo->migrateFromPtr - : nullptr; - } - return nullptr; -} -inline ChannelData *PeerData::migrateTo() const { - if (const auto chat = asChat()) { - if (const auto migrateTo = chat->migrateToPtr) { - return migrateTo->amIn() ? migrateTo : nullptr; - } - } - return nullptr; -} -inline Data::Feed *PeerData::feed() const { - if (const auto channel = asChannel()) { - return channel->feed(); - } - return nullptr; -} -inline const Text &PeerData::dialogName() const { - return migrateTo() - ? migrateTo()->dialogName() - : (isUser() && !asUser()->phoneText.isEmpty()) - ? asUser()->phoneText - : nameText; -} -inline const QString &PeerData::shortName() const { - return isUser() ? asUser()->firstName : name; -} -inline QString PeerData::userName() const { - return isUser() - ? asUser()->username - : isChannel() - ? asChannel()->username - : QString(); -} -inline bool PeerData::isVerified() const { - return isUser() - ? asUser()->isVerified() - : isChannel() - ? asChannel()->isVerified() - : false; -} -inline bool PeerData::isMegagroup() const { - return isChannel() ? asChannel()->isMegagroup() : false; -} -inline bool PeerData::canWrite() const { - return isChannel() - ? asChannel()->canWrite() - : isChat() - ? asChat()->canWrite() - : isUser() - ? asUser()->canWrite() - : false; -} diff --git a/Telegram/SourceFiles/data/data_peer_values.cpp b/Telegram/SourceFiles/data/data_peer_values.cpp index f4a399442..acef0a326 100644 --- a/Telegram/SourceFiles/data/data_peer_values.cpp +++ b/Telegram/SourceFiles/data/data_peer_values.cpp @@ -8,6 +8,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_peer_values.h" #include "lang/lang_keys.h" +#include "data/data_channel.h" +#include "data/data_chat.h" +#include "data/data_user.h" namespace Data { namespace { diff --git a/Telegram/SourceFiles/data/data_photo.cpp b/Telegram/SourceFiles/data/data_photo.cpp index ecf8965da..505044977 100644 --- a/Telegram/SourceFiles/data/data_photo.cpp +++ b/Telegram/SourceFiles/data/data_photo.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_photo.h" #include "data/data_session.h" +#include "data/data_file_origin.h" #include "ui/image/image.h" #include "ui/image/image_source.h" #include "mainwidget.h" diff --git a/Telegram/SourceFiles/data/data_pts_waiter.cpp b/Telegram/SourceFiles/data/data_pts_waiter.cpp new file mode 100644 index 000000000..4ae9c6a81 --- /dev/null +++ b/Telegram/SourceFiles/data/data_pts_waiter.cpp @@ -0,0 +1,159 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "data/data_pts_waiter.h" + +#include "mainwidget.h" +#include "auth_session.h" +#include "apiwrap.h" + +uint64 PtsWaiter::ptsKey(PtsSkippedQueue queue, int32 pts) { + return _queue.insert(uint64(uint32(pts)) << 32 | (++_skippedKey), queue).key(); +} + +void PtsWaiter::setWaitingForSkipped(ChannelData *channel, int32 ms) { + if (ms >= 0) { + if (App::main()) { + App::main()->ptsWaiterStartTimerFor(channel, ms); + } + _waitingForSkipped = true; + } else { + _waitingForSkipped = false; + checkForWaiting(channel); + } +} + +void PtsWaiter::setWaitingForShortPoll(ChannelData *channel, int32 ms) { + if (ms >= 0) { + if (App::main()) { + App::main()->ptsWaiterStartTimerFor(channel, ms); + } + _waitingForShortPoll = true; + } else { + _waitingForShortPoll = false; + checkForWaiting(channel); + } +} + +void PtsWaiter::checkForWaiting(ChannelData *channel) { + if (!_waitingForSkipped && !_waitingForShortPoll && App::main()) { + App::main()->ptsWaiterStartTimerFor(channel, -1); + } +} + +void PtsWaiter::applySkippedUpdates(ChannelData *channel) { + if (!_waitingForSkipped) return; + + setWaitingForSkipped(channel, -1); + + if (_queue.isEmpty()) return; + + ++_applySkippedLevel; + for (auto i = _queue.cbegin(), e = _queue.cend(); i != e; ++i) { + switch (i.value()) { + case SkippedUpdate: Auth().api().applyUpdateNoPtsCheck(_updateQueue.value(i.key())); break; + case SkippedUpdates: Auth().api().applyUpdatesNoPtsCheck(_updatesQueue.value(i.key())); break; + } + } + --_applySkippedLevel; + clearSkippedUpdates(); +} + +void PtsWaiter::clearSkippedUpdates() { + _queue.clear(); + _updateQueue.clear(); + _updatesQueue.clear(); + _applySkippedLevel = 0; +} + +bool PtsWaiter::updated(ChannelData *channel, int32 pts, int32 count, const MTPUpdates &updates) { + if (_requesting || _applySkippedLevel) { + return true; + } else if (pts <= _good && count > 0) { + return false; + } else if (check(channel, pts, count)) { + return true; + } + _updatesQueue.insert(ptsKey(SkippedUpdates, pts), updates); + return false; +} + +bool PtsWaiter::updated(ChannelData *channel, int32 pts, int32 count, const MTPUpdate &update) { + if (_requesting || _applySkippedLevel) { + return true; + } else if (pts <= _good && count > 0) { + return false; + } else if (check(channel, pts, count)) { + return true; + } + _updateQueue.insert(ptsKey(SkippedUpdate, pts), update); + return false; +} + +bool PtsWaiter::updated(ChannelData *channel, int32 pts, int32 count) { + if (_requesting || _applySkippedLevel) { + return true; + } else if (pts <= _good && count > 0) { + return false; + } + return check(channel, pts, count); +} + +bool PtsWaiter::updateAndApply(ChannelData *channel, int32 pts, int32 count, const MTPUpdates &updates) { + if (!updated(channel, pts, count, updates)) { + return false; + } + if (!_waitingForSkipped || _queue.isEmpty()) { + // Optimization - no need to put in queue and back. + Auth().api().applyUpdatesNoPtsCheck(updates); + } else { + _updatesQueue.insert(ptsKey(SkippedUpdates, pts), updates); + applySkippedUpdates(channel); + } + return true; +} + +bool PtsWaiter::updateAndApply(ChannelData *channel, int32 pts, int32 count, const MTPUpdate &update) { + if (!updated(channel, pts, count, update)) { + return false; + } + if (!_waitingForSkipped || _queue.isEmpty()) { + // Optimization - no need to put in queue and back. + Auth().api().applyUpdateNoPtsCheck(update); + } else { + _updateQueue.insert(ptsKey(SkippedUpdate, pts), update); + applySkippedUpdates(channel); + } + return true; +} + +bool PtsWaiter::updateAndApply(ChannelData *channel, int32 pts, int32 count) { + if (!updated(channel, pts, count)) { + return false; + } + applySkippedUpdates(channel); + return true; +} + +bool PtsWaiter::check(ChannelData *channel, int32 pts, int32 count) { // return false if need to save that update and apply later + if (!inited()) { + init(pts); + return true; + } + + _last = qMax(_last, pts); + _count += count; + if (_last == _count) { + _good = _last; + return true; + } else if (_last < _count) { + setWaitingForSkipped(channel, 1); + } else { + setWaitingForSkipped(channel, WaitForSkippedTimeout); + } + return !count; +} diff --git a/Telegram/SourceFiles/data/data_pts_waiter.h b/Telegram/SourceFiles/data/data_pts_waiter.h new file mode 100644 index 000000000..771470474 --- /dev/null +++ b/Telegram/SourceFiles/data/data_pts_waiter.h @@ -0,0 +1,95 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +enum PtsSkippedQueue { + SkippedUpdate, + SkippedUpdates, +}; + +class PtsWaiter { +public: + PtsWaiter() = default; + void init(int32 pts) { + _good = _last = _count = pts; + clearSkippedUpdates(); + } + bool inited() const { + return _good > 0; + } + void setRequesting(bool isRequesting) { + _requesting = isRequesting; + if (_requesting) { + clearSkippedUpdates(); + } + } + bool requesting() const { + return _requesting; + } + bool waitingForSkipped() const { + return _waitingForSkipped; + } + bool waitingForShortPoll() const { + return _waitingForShortPoll; + } + void setWaitingForSkipped(ChannelData *channel, int32 ms); // < 0 - not waiting + void setWaitingForShortPoll(ChannelData *channel, int32 ms); // < 0 - not waiting + int32 current() const{ + return _good; + } + bool updated( + ChannelData *channel, + int32 pts, + int32 count, + const MTPUpdates &updates); + bool updated( + ChannelData *channel, + int32 pts, + int32 count, + const MTPUpdate &update); + bool updated( + ChannelData *channel, + int32 pts, + int32 count); + bool updateAndApply( + ChannelData *channel, + int32 pts, + int32 count, + const MTPUpdates &updates); + bool updateAndApply( + ChannelData *channel, + int32 pts, + int32 count, + const MTPUpdate &update); + bool updateAndApply( + ChannelData *channel, + int32 pts, + int32 count); + void applySkippedUpdates(ChannelData *channel); + void clearSkippedUpdates(); + +private: + // Return false if need to save that update and apply later. + bool check(ChannelData *channel, int32 pts, int32 count); + + uint64 ptsKey(PtsSkippedQueue queue, int32 pts); + void checkForWaiting(ChannelData *channel); + + QMap _queue; + QMap _updateQueue; + QMap _updatesQueue; + int32 _good = 0; + int32 _last = 0; + int32 _count = 0; + int32 _applySkippedLevel = 0; + bool _requesting = false; + bool _waitingForSkipped = false; + bool _waitingForShortPoll = false; + uint32 _skippedKey = 0; + +}; diff --git a/Telegram/SourceFiles/data/data_search_controller.cpp b/Telegram/SourceFiles/data/data_search_controller.cpp index e1de81f53..49aef7798 100644 --- a/Telegram/SourceFiles/data/data_search_controller.cpp +++ b/Telegram/SourceFiles/data/data_search_controller.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "auth_session.h" #include "data/data_session.h" #include "data/data_messages.h" +#include "data/data_channel.h" #include "history/history.h" #include "history/history_item.h" diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 9dd9d55cb..a2ae7879f 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -30,6 +30,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" // for lang(lng_deleted) in user name. #include "data/data_media_types.h" #include "data/data_feed.h" +#include "data/data_channel.h" +#include "data/data_chat.h" +#include "data/data_user.h" +#include "data/data_file_origin.h" #include "data/data_photo.h" #include "data/data_document.h" #include "data/data_web_page.h" diff --git a/Telegram/SourceFiles/data/data_session.h b/Telegram/SourceFiles/data/data_session.h index d05a1d890..b5fe9b616 100644 --- a/Telegram/SourceFiles/data/data_session.h +++ b/Telegram/SourceFiles/data/data_session.h @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "chat_helpers/stickers.h" #include "dialogs/dialogs_key.h" #include "data/data_groups.h" +#include "data/data_notify_settings.h" #include "history/history_location_manager.h" #include "base/timer.h" diff --git a/Telegram/SourceFiles/data/data_types.h b/Telegram/SourceFiles/data/data_types.h index 5a0b89d28..e325d8ff3 100644 --- a/Telegram/SourceFiles/data/data_types.h +++ b/Telegram/SourceFiles/data/data_types.h @@ -82,6 +82,12 @@ class PeerData; class UserData; class ChatData; class ChannelData; +class BotCommand; +struct BotInfo; + +namespace Data { +class Feed; +} // namespace Data using UserId = int32; using ChatId = int32; diff --git a/Telegram/SourceFiles/data/data_user.cpp b/Telegram/SourceFiles/data/data_user.cpp new file mode 100644 index 000000000..92b801df9 --- /dev/null +++ b/Telegram/SourceFiles/data/data_user.cpp @@ -0,0 +1,260 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "data/data_user.h" + +#include "observer_peer.h" +#include "storage/localstorage.h" +#include "data/data_session.h" +#include "ui/text_options.h" +#include "lang/lang_keys.h" + +namespace { + +using UpdateFlag = Notify::PeerUpdate::Flag; + +} // namespace + +BotCommand::BotCommand( + const QString &command, + const QString &description) +: command(command) +, _description(description) { +} + +bool BotCommand::setDescription(const QString &description) { + if (_description != description) { + _description = description; + _descriptionText = Text(); + return true; + } + return false; +} + +const Text &BotCommand::descriptionText() const { + if (_descriptionText.isEmpty() && !_description.isEmpty()) { + _descriptionText.setText( + st::defaultTextStyle, + _description, + Ui::NameTextOptions()); + } + return _descriptionText; +} + +UserData::UserData(not_null owner, PeerId id) +: PeerData(owner, id) { +} + +bool UserData::canShareThisContact() const { + return canShareThisContactFast() + || !owner().findContactPhone(peerToUser(id)).isEmpty(); +} + +void UserData::setContactStatus(ContactStatus status) { + if (_contactStatus != status) { + const auto changed = (_contactStatus == ContactStatus::Contact) + != (status == ContactStatus::Contact); + _contactStatus = status; + if (changed) { + Notify::peerUpdatedDelayed( + this, + Notify::PeerUpdate::Flag::UserIsContact); + } + } + if (_contactStatus == ContactStatus::Contact + && cReportSpamStatuses().value(id, dbiprsHidden) != dbiprsHidden) { + cRefReportSpamStatuses().insert(id, dbiprsHidden); + Local::writeReportSpamStatuses(); + } +} + +// see Local::readPeer as well +void UserData::setPhoto(const MTPUserProfilePhoto &photo) { + if (photo.type() == mtpc_userProfilePhoto) { + const auto &data = photo.c_userProfilePhoto(); + updateUserpic(data.vphoto_id.v, data.vphoto_small); + } else { + clearUserpic(); + } +} + +bool UserData::setAbout(const QString &newAbout) { + if (_about == newAbout) { + return false; + } + _about = newAbout; + Notify::peerUpdatedDelayed(this, UpdateFlag::AboutChanged); + return true; +} + +QString UserData::unavailableReason() const { + return _unavailableReason; +} + +void UserData::setUnavailableReason(const QString &text) { + if (_unavailableReason != text) { + _unavailableReason = text; + Notify::peerUpdatedDelayed( + this, + Notify::PeerUpdate::Flag::UnavailableReasonChanged); + } +} + +void UserData::setCommonChatsCount(int count) { + if (_commonChatsCount != count) { + _commonChatsCount = count; + Notify::peerUpdatedDelayed(this, UpdateFlag::UserCommonChatsChanged); + } +} + +void UserData::setName(const QString &newFirstName, const QString &newLastName, const QString &newPhoneName, const QString &newUsername) { + bool changeName = !newFirstName.isEmpty() || !newLastName.isEmpty(); + + QString newFullName; + if (changeName && newFirstName.trimmed().isEmpty()) { + firstName = newLastName; + lastName = QString(); + newFullName = firstName; + } else { + if (changeName) { + firstName = newFirstName; + lastName = newLastName; + } + newFullName = lastName.isEmpty() ? firstName : lng_full_name(lt_first_name, firstName, lt_last_name, lastName); + } + updateNameDelayed(newFullName, newPhoneName, newUsername); +} + +void UserData::setPhone(const QString &newPhone) { + if (_phone != newPhone) { + _phone = newPhone; + } +} + +void UserData::setBotInfoVersion(int version) { + if (version < 0) { + if (botInfo) { + if (!botInfo->commands.isEmpty()) { + botInfo->commands.clear(); + Notify::botCommandsChanged(this); + } + botInfo = nullptr; + Notify::userIsBotChanged(this); + } + } else if (!botInfo) { + botInfo = std::make_unique(); + botInfo->version = version; + Notify::userIsBotChanged(this); + } else if (botInfo->version < version) { + if (!botInfo->commands.isEmpty()) { + botInfo->commands.clear(); + Notify::botCommandsChanged(this); + } + botInfo->description.clear(); + botInfo->version = version; + botInfo->inited = false; + } +} + +void UserData::setBotInfo(const MTPBotInfo &info) { + switch (info.type()) { + case mtpc_botInfo: { + const auto &d(info.c_botInfo()); + if (peerFromUser(d.vuser_id.v) != id || !botInfo) return; + + QString desc = qs(d.vdescription); + if (botInfo->description != desc) { + botInfo->description = desc; + botInfo->text = Text(st::msgMinWidth); + } + + auto &v = d.vcommands.v; + botInfo->commands.reserve(v.size()); + auto changedCommands = false; + int32 j = 0; + for (int32 i = 0, l = v.size(); i < l; ++i) { + if (v.at(i).type() != mtpc_botCommand) continue; + + QString cmd = qs(v.at(i).c_botCommand().vcommand), desc = qs(v.at(i).c_botCommand().vdescription); + if (botInfo->commands.size() <= j) { + botInfo->commands.push_back(BotCommand(cmd, desc)); + changedCommands = true; + } else { + if (botInfo->commands[j].command != cmd) { + botInfo->commands[j].command = cmd; + changedCommands = true; + } + if (botInfo->commands[j].setDescription(desc)) { + changedCommands = true; + } + } + ++j; + } + while (j < botInfo->commands.size()) { + botInfo->commands.pop_back(); + changedCommands = true; + } + + botInfo->inited = true; + + if (changedCommands) { + Notify::botCommandsChanged(this); + } + } break; + } +} + +void UserData::setNameOrPhone(const QString &newNameOrPhone) { + if (nameOrPhone != newNameOrPhone) { + nameOrPhone = newNameOrPhone; + phoneText.setText( + st::msgNameStyle, + nameOrPhone, + Ui::NameTextOptions()); + } +} + +void UserData::madeAction(TimeId when) { + if (botInfo || isServiceUser(id) || when <= 0) return; + + if (onlineTill <= 0 && -onlineTill < when) { + onlineTill = -when - SetOnlineAfterActivity; + Notify::peerUpdatedDelayed(this, Notify::PeerUpdate::Flag::UserOnlineChanged); + } else if (onlineTill > 0 && onlineTill < when + 1) { + onlineTill = when + SetOnlineAfterActivity; + Notify::peerUpdatedDelayed(this, Notify::PeerUpdate::Flag::UserOnlineChanged); + } +} + +void UserData::setAccessHash(uint64 accessHash) { + if (accessHash == kInaccessibleAccessHashOld) { + _accessHash = 0; +// _flags.add(MTPDuser_ClientFlag::f_inaccessible | 0); + _flags.add(MTPDuser::Flag::f_deleted); + } else { + _accessHash = accessHash; + } +} + +void UserData::setBlockStatus(BlockStatus blockStatus) { + if (blockStatus != _blockStatus) { + _blockStatus = blockStatus; + Notify::peerUpdatedDelayed(this, UpdateFlag::UserIsBlocked); + } +} + +void UserData::setCallsStatus(CallsStatus callsStatus) { + if (callsStatus != _callsStatus) { + _callsStatus = callsStatus; + Notify::peerUpdatedDelayed(this, UpdateFlag::UserHasCalls); + } +} + +bool UserData::hasCalls() const { + return (callsStatus() != CallsStatus::Disabled) + && (callsStatus() != CallsStatus::Unknown); +} diff --git a/Telegram/SourceFiles/data/data_user.h b/Telegram/SourceFiles/data/data_user.h new file mode 100644 index 000000000..3f3a2ed71 --- /dev/null +++ b/Telegram/SourceFiles/data/data_user.h @@ -0,0 +1,229 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +#include "data/data_peer.h" + +class BotCommand { +public: + BotCommand(const QString &command, const QString &description); + + bool setDescription(const QString &description); + const Text &descriptionText() const; + + QString command; + +private: + QString _description; + mutable Text _descriptionText; + +}; + +struct BotInfo { + bool inited = false; + bool readsAllHistory = false; + bool cantJoinGroups = false; + int version = 0; + QString description, inlinePlaceholder; + QList commands; + Text text = Text{ int(st::msgMinWidth) }; // description + + QString startToken, startGroupToken, shareGameShortName; + PeerId inlineReturnPeerId = 0; +}; + +class UserData : public PeerData { +public: + static constexpr auto kEssentialFlags = 0 + | MTPDuser::Flag::f_self + | MTPDuser::Flag::f_contact + | MTPDuser::Flag::f_mutual_contact + | MTPDuser::Flag::f_deleted + | MTPDuser::Flag::f_bot + | MTPDuser::Flag::f_bot_chat_history + | MTPDuser::Flag::f_bot_nochats + | MTPDuser::Flag::f_verified + | MTPDuser::Flag::f_restricted + | MTPDuser::Flag::f_bot_inline_geo; + using Flags = Data::Flags< + MTPDuser::Flags, + kEssentialFlags.value()>; + + static constexpr auto kEssentialFullFlags = 0 + | MTPDuserFull::Flag::f_blocked + | MTPDuserFull::Flag::f_phone_calls_available + | MTPDuserFull::Flag::f_phone_calls_private; + using FullFlags = Data::Flags< + MTPDuserFull::Flags, + kEssentialFullFlags.value()>; + + UserData(not_null owner, PeerId id); + void setPhoto(const MTPUserProfilePhoto &photo); + + void setName( + const QString &newFirstName, + const QString &newLastName, + const QString &newPhoneName, + const QString &newUsername); + + void setPhone(const QString &newPhone); + void setBotInfoVersion(int version); + void setBotInfo(const MTPBotInfo &info); + + void setNameOrPhone(const QString &newNameOrPhone); + + void madeAction(TimeId when); // pseudo-online + + uint64 accessHash() const { + return _accessHash; + } + void setAccessHash(uint64 accessHash); + + void setFlags(MTPDuser::Flags which) { + _flags.set(which); + } + void addFlags(MTPDuser::Flags which) { + _flags.add(which); + } + void removeFlags(MTPDuser::Flags which) { + _flags.remove(which); + } + auto flags() const { + return _flags.current(); + } + auto flagsValue() const { + return _flags.value(); + } + + void setFullFlags(MTPDuserFull::Flags which) { + _fullFlags.set(which); + } + void addFullFlags(MTPDuserFull::Flags which) { + _fullFlags.add(which); + } + void removeFullFlags(MTPDuserFull::Flags which) { + _fullFlags.remove(which); + } + auto fullFlags() const { + return _fullFlags.current(); + } + auto fullFlagsValue() const { + return _fullFlags.value(); + } + + bool isVerified() const { + return flags() & MTPDuser::Flag::f_verified; + } + bool isBotInlineGeo() const { + return flags() & MTPDuser::Flag::f_bot_inline_geo; + } + bool isInaccessible() const { + constexpr auto inaccessible = 0 + | MTPDuser::Flag::f_deleted; +// | MTPDuser_ClientFlag::f_inaccessible; + return flags() & inaccessible; + } + bool canWrite() const { + // Duplicated in Data::CanWriteValue(). + return !isInaccessible(); + } + bool isContact() const { + return (_contactStatus == ContactStatus::Contact); + } + + bool canShareThisContact() const; + bool canAddContact() const { + return canShareThisContact() && !isContact(); + } + + // In feedUsers() we check only that. + // When actually trying to share contact we perform + // a full check by canShareThisContact() call. + bool canShareThisContactFast() const { + return !_phone.isEmpty(); + } + + MTPInputUser inputUser; + + QString firstName; + QString lastName; + QString username; + const QString &phone() const { + return _phone; + } + QString nameOrPhone; + Text phoneText; + TimeId onlineTill = 0; + + enum class ContactStatus : char { + PhoneUnknown, + CanAdd, + Contact, + }; + ContactStatus contactStatus() const { + return _contactStatus; + } + void setContactStatus(ContactStatus status); + + enum class BlockStatus : char { + Unknown, + Blocked, + NotBlocked, + }; + BlockStatus blockStatus() const { + return _blockStatus; + } + bool isBlocked() const { + return (blockStatus() == BlockStatus::Blocked); + } + void setBlockStatus(BlockStatus blockStatus); + + enum class CallsStatus : char { + Unknown, + Enabled, + Disabled, + Private, + }; + CallsStatus callsStatus() const { + return _callsStatus; + } + bool hasCalls() const; + void setCallsStatus(CallsStatus callsStatus); + + bool setAbout(const QString &newAbout); + const QString &about() const { + return _about; + } + + std::unique_ptr botInfo; + + QString unavailableReason() const override; + void setUnavailableReason(const QString &reason); + + int commonChatsCount() const { + return _commonChatsCount; + } + void setCommonChatsCount(int count); + +private: + Flags _flags; + FullFlags _fullFlags; + + QString _unavailableReason; + QString _about; + QString _phone; + ContactStatus _contactStatus = ContactStatus::PhoneUnknown; + BlockStatus _blockStatus = BlockStatus::Unknown; + CallsStatus _callsStatus = CallsStatus::Unknown; + int _commonChatsCount = 0; + + uint64 _accessHash = 0; + static constexpr auto kInaccessibleAccessHashOld + = 0xFFFFFFFFFFFFFFFFULL; + +}; diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index 92ac4f2f1..24f896ebc 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -20,6 +20,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_drafts.h" #include "data/data_feed.h" #include "data/data_session.h" +#include "data/data_channel.h" +#include "data/data_chat.h" +#include "data/data_user.h" #include "lang/lang_keys.h" #include "mainwindow.h" #include "mainwidget.h" diff --git a/Telegram/SourceFiles/dialogs/dialogs_layout.cpp b/Telegram/SourceFiles/dialogs/dialogs_layout.cpp index 94c5060ae..227248cca 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_layout.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_layout.cpp @@ -19,6 +19,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "support/support_helper.h" #include "history/history_item.h" #include "history/history.h" +#include "data/data_channel.h" +#include "data/data_user.h" namespace Dialogs { namespace Layout { diff --git a/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.cpp b/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.cpp index 3ea660de9..48a84478d 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.cpp @@ -9,6 +9,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "data/data_peer_values.h" +#include "data/data_chat.h" +#include "data/data_user.h" #include "observer_peer.h" #include "auth_session.h" #include "apiwrap.h" diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index 2f589ee36..be044276b 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -33,6 +33,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/storage_media_prepare.h" #include "storage/localstorage.h" #include "data/data_session.h" +#include "data/data_channel.h" +#include "data/data_chat.h" +#include "data/data_user.h" #include "styles/style_dialogs.h" #include "styles/style_window.h" diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index e057081ac..14a0ca443 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -12,6 +12,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "media/media_clip_reader.h" #include "window/window_controller.h" #include "history/history_item_components.h" +#include "data/data_peer.h" +#include "data/data_user.h" #include "observer_peer.h" #include "mainwindow.h" #include "mainwidget.h" @@ -236,6 +238,9 @@ void showPeerProfile(const PeerId &peer) { } } } +void showPeerProfile(const PeerData *peer) { + showPeerProfile(peer->id); +} void showPeerProfile(not_null history) { showPeerProfile(history->peer->id); @@ -261,6 +266,10 @@ void showPeerHistory(not_null history, MsgId msgId) { showPeerHistory(history->peer->id, msgId); } +void showPeerHistory(const PeerData *peer, MsgId msgId) { + showPeerHistory(peer->id, msgId); +} + PeerData *getPeerForMouseAction() { return Messenger::Instance().ui_getPeerForMouseAction(); } diff --git a/Telegram/SourceFiles/facades.h b/Telegram/SourceFiles/facades.h index f05d98b63..64a41ad72 100644 --- a/Telegram/SourceFiles/facades.h +++ b/Telegram/SourceFiles/facades.h @@ -12,6 +12,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL class BoxContent; +namespace Data { +struct FileOrigin; +} // namespace Data + namespace Dialogs { enum class Mode; } // namespace Dialogs @@ -113,17 +117,13 @@ void hideSettingsAndLayer(anim::type animated = anim::type::normal); bool isLayerShown(); void showPeerProfile(const PeerId &peer); -inline void showPeerProfile(const PeerData *peer) { - showPeerProfile(peer->id); -} +void showPeerProfile(const PeerData *peer); void showPeerProfile(not_null history); void showPeerHistory(const PeerId &peer, MsgId msgId); void showPeerHistoryAtItem(not_null item); -inline void showPeerHistory(const PeerData *peer, MsgId msgId) { - showPeerHistory(peer->id, msgId); -} +void showPeerHistory(const PeerData *peer, MsgId msgId); void showPeerHistory(not_null history, MsgId msgId); inline void showChatsList() { showPeerHistory(PeerId(0), 0); diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.cpp index 0a0099042..6ef5742a2 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.cpp @@ -7,11 +7,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "history/admin_log/history_admin_log_filter.h" -#include "styles/style_boxes.h" #include "ui/widgets/checkbox.h" #include "ui/effects/ripple_animation.h" #include "lang/lang_keys.h" #include "data/data_peer_values.h" +#include "data/data_channel.h" +#include "data/data_user.h" +#include "styles/style_boxes.h" namespace AdminLog { namespace { diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp index 9157596c8..48148434c 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -39,6 +39,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_photo.h" #include "data/data_document.h" #include "data/data_media_types.h" +#include "data/data_channel.h" +#include "data/data_user.h" namespace AdminLog { namespace { diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp index ac53147c4..a52d48b48 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp @@ -12,6 +12,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_service.h" #include "history/history_message.h" #include "history/history.h" +#include "data/data_channel.h" +#include "data/data_user.h" #include "data/data_session.h" #include "lang/lang_keys.h" #include "boxes/sticker_set_box.h" @@ -151,12 +153,17 @@ const auto CollectChanges = [](auto &phraseMap, auto plusFlags, auto minusFlags) return withPrefix(plusFlags & ~minusFlags, '+') + withPrefix(minusFlags & ~plusFlags, kMinus); }; -auto GenerateAdminChangeText(not_null channel, const TextWithEntities &user, const MTPChatAdminRights *newRights, const MTPChatAdminRights *prevRights) { +TextWithEntities GenerateAdminChangeText( + not_null channel, + const TextWithEntities &user, + const MTPChatAdminRights *newRights, + const MTPChatAdminRights *prevRights) { + Expects(!newRights || newRights->type() == mtpc_chatAdminRights); + Expects(!prevRights || prevRights->type() == mtpc_chatAdminRights); + using Flag = MTPDchatAdminRights::Flag; using Flags = MTPDchatAdminRights::Flags; - Expects(!newRights || newRights->type() == mtpc_chatAdminRights); - Expects(!prevRights || prevRights->type() == mtpc_chatAdminRights); auto newFlags = newRights ? newRights->c_chatAdminRights().vflags.v : MTPDchatAdminRights::Flags(0); auto prevFlags = prevRights ? prevRights->c_chatAdminRights().vflags.v : MTPDchatAdminRights::Flags(0); auto result = lng_admin_log_promoted__generic(lt_user, user); @@ -189,12 +196,16 @@ auto GenerateAdminChangeText(not_null channel, const TextWithEntit return result; }; -auto GenerateBannedChangeText(const TextWithEntities &user, const MTPChatBannedRights *newRights, const MTPChatBannedRights *prevRights) { +TextWithEntities GenerateBannedChangeText( + const TextWithEntities &user, + const MTPChatBannedRights *newRights, + const MTPChatBannedRights *prevRights) { + Expects(!newRights || newRights->type() == mtpc_chatBannedRights); + Expects(!prevRights || prevRights->type() == mtpc_chatBannedRights); + using Flag = MTPDchatBannedRights::Flag; using Flags = MTPDchatBannedRights::Flags; - Expects(!newRights || newRights->type() == mtpc_chatBannedRights); - Expects(!prevRights || prevRights->type() == mtpc_chatBannedRights); auto newFlags = newRights ? newRights->c_chatBannedRights().vflags.v : MTPDchatBannedRights::Flags(0); auto prevFlags = prevRights ? prevRights->c_chatBannedRights().vflags.v : MTPDchatBannedRights::Flags(0); auto newUntil = newRights ? newRights->c_chatBannedRights().vuntil_date.v : TimeId(0); diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp index 7d6df0621..0858cbad2 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp @@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/window_controller.h" #include "boxes/confirm_box.h" #include "base/timer.h" +#include "data/data_channel.h" #include "lang/lang_keys.h" #include "styles/style_history.h" #include "styles/style_window.h" diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index 0ed7cdaa8..503f7506a 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -33,6 +33,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_channel_admins.h" #include "data/data_feed.h" #include "data/data_photo.h" +#include "data/data_channel.h" +#include "data/data_chat.h" +#include "data/data_user.h" #include "ui/image/image.h" #include "ui/text_options.h" #include "core/crash_reports.h" diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 289a4f0da..5002e5217 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -45,6 +45,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_document.h" #include "data/data_poll.h" #include "data/data_photo.h" +#include "data/data_user.h" namespace { diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index b11b38ec9..2ee67ede7 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -18,8 +18,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_message.h" #include "history/history.h" #include "media/media_clip_reader.h" -#include "styles/style_dialogs.h" -#include "styles/style_history.h" #include "ui/effects/ripple_animation.h" #include "ui/text_options.h" #include "storage/file_upload.h" @@ -37,6 +35,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_messages.h" #include "data/data_media_types.h" #include "data/data_feed.h" +#include "data/data_channel.h" +#include "data/data_chat.h" +#include "data/data_user.h" +#include "styles/style_dialogs.h" +#include "styles/style_history.h" namespace { diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index a45fd312e..74a885ab6 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -19,6 +19,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "media/player/media_player_instance.h" #include "data/data_media_types.h" #include "data/data_session.h" +#include "data/data_user.h" +#include "data/data_file_origin.h" #include "styles/style_widgets.h" #include "styles/style_history.h" diff --git a/Telegram/SourceFiles/history/history_item_text.cpp b/Telegram/SourceFiles/history/history_item_text.cpp index 549caf765..a5c5bf9eb 100644 --- a/Telegram/SourceFiles/history/history_item_text.cpp +++ b/Telegram/SourceFiles/history/history_item_text.cpp @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_media_types.h" #include "data/data_web_page.h" #include "data/data_groups.h" +#include "data/data_peer.h" #include "lang/lang_keys.h" #include "ui/text_options.h" diff --git a/Telegram/SourceFiles/history/history_location_manager.cpp b/Telegram/SourceFiles/history/history_location_manager.cpp index d1c833c0f..8595ad2c2 100644 --- a/Telegram/SourceFiles/history/history_location_manager.cpp +++ b/Telegram/SourceFiles/history/history_location_manager.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwidget.h" #include "lang/lang_keys.h" #include "ui/image/image.h" +#include "data/data_file_origin.h" #include "platform/platform_specific.h" namespace { diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index fa28483ff..bcd296c12 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -30,6 +30,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "data/data_game.h" #include "data/data_media_types.h" +#include "data/data_channel.h" +#include "data/data_user.h" #include "styles/style_dialogs.h" #include "styles/style_widgets.h" #include "styles/style_history.h" diff --git a/Telegram/SourceFiles/history/history_service.cpp b/Telegram/SourceFiles/history/history_service.cpp index 4afafbe6b..14f7137e0 100644 --- a/Telegram/SourceFiles/history/history_service.cpp +++ b/Telegram/SourceFiles/history/history_service.cpp @@ -21,6 +21,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "data/data_media_types.h" #include "data/data_game.h" +#include "data/data_channel.h" +#include "data/data_user.h" #include "window/notifications_manager.h" #include "window/window_controller.h" #include "storage/storage_shared_media.h" @@ -524,6 +526,14 @@ std::unique_ptr HistoryService::createView( return delegate->elementCreate(this); } +QString HistoryService::fromLinkText() const { + return textcmdLink(1, _from->name); +} + +ClickHandlerPtr HistoryService::fromLink() const { + return _from->createOpenLink(); +} + void HistoryService::setServiceText(const PreparedText &prepared) { _text.setText( st::serviceTextStyle, diff --git a/Telegram/SourceFiles/history/history_service.h b/Telegram/SourceFiles/history/history_service.h index 2fae633c7..cfc7bd49b 100644 --- a/Telegram/SourceFiles/history/history_service.h +++ b/Telegram/SourceFiles/history/history_service.h @@ -111,12 +111,8 @@ protected: void setServiceText(const PreparedText &prepared); - QString fromLinkText() const { - return textcmdLink(1, _from->name); - }; - ClickHandlerPtr fromLink() const { - return _from->createOpenLink(); - }; + QString fromLinkText() const; + ClickHandlerPtr fromLink() const; void removeMedia(); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 2312a62d0..2fdd82166 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -30,6 +30,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_document.h" #include "data/data_photo.h" #include "data/data_media_types.h" +#include "data/data_channel.h" +#include "data/data_chat.h" +#include "data/data_user.h" #include "history/history.h" #include "history/history_item.h" #include "history/history_message.h" diff --git a/Telegram/SourceFiles/history/media/history_media_contact.cpp b/Telegram/SourceFiles/history/media/history_media_contact.cpp index 5ccd6fc45..54e18dcab 100644 --- a/Telegram/SourceFiles/history/media/history_media_contact.cpp +++ b/Telegram/SourceFiles/history/media/history_media_contact.cpp @@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/empty_userpic.h" #include "ui/text_options.h" #include "data/data_session.h" +#include "data/data_user.h" #include "data/data_media_types.h" #include "styles/style_history.h" diff --git a/Telegram/SourceFiles/history/media/history_media_contact.h b/Telegram/SourceFiles/history/media/history_media_contact.h index 98349120c..68be3de25 100644 --- a/Telegram/SourceFiles/history/media/history_media_contact.h +++ b/Telegram/SourceFiles/history/media/history_media_contact.h @@ -9,6 +9,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/media/history_media.h" +namespace Ui { +class EmptyUserpic; +} // namespace Ui + class HistoryContact : public HistoryMedia { public: HistoryContact( diff --git a/Telegram/SourceFiles/history/media/history_media_location.cpp b/Telegram/SourceFiles/history/media/history_media_location.cpp index 2055310d1..9d720ca3a 100644 --- a/Telegram/SourceFiles/history/media/history_media_location.cpp +++ b/Telegram/SourceFiles/history/media/history_media_location.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/history_view_cursor_state.h" #include "ui/image/image.h" #include "ui/text_options.h" +#include "data/data_file_origin.h" #include "styles/style_history.h" namespace { diff --git a/Telegram/SourceFiles/history/media/history_media_photo.cpp b/Telegram/SourceFiles/history/media/history_media_photo.cpp index 58496eb87..fdd762c6c 100644 --- a/Telegram/SourceFiles/history/media/history_media_photo.cpp +++ b/Telegram/SourceFiles/history/media/history_media_photo.cpp @@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/grouped_layout.h" #include "data/data_session.h" #include "data/data_photo.h" +#include "data/data_file_origin.h" #include "styles/style_history.h" namespace { diff --git a/Telegram/SourceFiles/history/media/history_media_video.cpp b/Telegram/SourceFiles/history/media/history_media_video.cpp index b34eaa0ba..32b495319 100644 --- a/Telegram/SourceFiles/history/media/history_media_video.cpp +++ b/Telegram/SourceFiles/history/media/history_media_video.cpp @@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/grouped_layout.h" #include "data/data_session.h" #include "data/data_document.h" +#include "data/data_file_origin.h" #include "styles/style_history.h" namespace { diff --git a/Telegram/SourceFiles/history/media/history_media_web_page.cpp b/Telegram/SourceFiles/history/media/history_media_web_page.cpp index b783d15ae..ff9570870 100644 --- a/Telegram/SourceFiles/history/media/history_media_web_page.cpp +++ b/Telegram/SourceFiles/history/media/history_media_web_page.cpp @@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_media_types.h" #include "data/data_web_page.h" #include "data/data_photo.h" +#include "data/data_file_origin.h" #include "styles/style_history.h" namespace { diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp index d953f5aaa..417e195d4 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp @@ -25,6 +25,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_media_types.h" #include "data/data_session.h" #include "data/data_groups.h" +#include "data/data_channel.h" #include "core/file_utilities.h" #include "window/window_peer_menu.h" #include "lang/lang_keys.h" diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 1eca6e6f3..46cb92432 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -35,6 +35,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_feed.h" #include "data/data_media_types.h" #include "data/data_document.h" +#include "data/data_peer.h" #include "styles/style_history.h" namespace HistoryView { diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 21476a187..dbfae468b 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/media/history_media_web_page.h" #include "history/history.h" #include "data/data_session.h" +#include "data/data_user.h" #include "lang/lang_keys.h" #include "mainwidget.h" #include "mainwindow.h" diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index 5c0ba0488..27a6369a3 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -31,6 +31,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_peer_values.h" #include "data/data_feed.h" #include "data/data_session.h" +#include "data/data_channel.h" +#include "data/data_chat.h" +#include "data/data_user.h" #include "support/support_helper.h" #include "observer_peer.h" #include "apiwrap.h" diff --git a/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.cpp b/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.cpp index c8f2645ac..81af9b51d 100644 --- a/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.cpp +++ b/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.cpp @@ -10,13 +10,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/common_groups/info_common_groups_widget.h" #include "info/info_controller.h" #include "lang/lang_keys.h" -#include "styles/style_info.h" -#include "styles/style_widgets.h" #include "mtproto/sender.h" #include "window/window_controller.h" #include "ui/widgets/scroll_area.h" #include "ui/search_field_controller.h" +#include "data/data_user.h" #include "apiwrap.h" +#include "styles/style_info.h" +#include "styles/style_widgets.h" namespace Info { namespace CommonGroups { diff --git a/Telegram/SourceFiles/info/common_groups/info_common_groups_widget.cpp b/Telegram/SourceFiles/info/common_groups/info_common_groups_widget.cpp index 07cf9cf82..6231d9a64 100644 --- a/Telegram/SourceFiles/info/common_groups/info_common_groups_widget.cpp +++ b/Telegram/SourceFiles/info/common_groups/info_common_groups_widget.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/info_controller.h" #include "ui/search_field_controller.h" #include "ui/widgets/scroll_area.h" +#include "data/data_user.h" #include "styles/style_info.h" namespace Info { diff --git a/Telegram/SourceFiles/info/feed/info_feed_channels_controllers.cpp b/Telegram/SourceFiles/info/feed/info_feed_channels_controllers.cpp index b605eec6f..58566f444 100644 --- a/Telegram/SourceFiles/info/feed/info_feed_channels_controllers.cpp +++ b/Telegram/SourceFiles/info/feed/info_feed_channels_controllers.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_feed.h" #include "data/data_session.h" +#include "data/data_channel.h" #include "info/info_controller.h" #include "lang/lang_keys.h" #include "history/history.h" diff --git a/Telegram/SourceFiles/info/info_controller.cpp b/Telegram/SourceFiles/info/info_controller.cpp index e47e4cb8f..58f244c71 100644 --- a/Telegram/SourceFiles/info/info_controller.cpp +++ b/Telegram/SourceFiles/info/info_controller.cpp @@ -15,6 +15,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/info_memento.h" #include "info/media/info_media_widget.h" #include "observer_peer.h" +#include "data/data_peer.h" +#include "data/data_channel.h" +#include "data/data_chat.h" #include "window/window_controller.h" namespace Info { @@ -24,7 +27,7 @@ not_null CorrectPeer(PeerId peerId) { Expects(peerId != 0); auto result = App::peer(peerId); - if (auto to = result->migrateTo()) { + if (const auto to = result->migrateTo()) { return to; } return result; @@ -81,6 +84,20 @@ rpl::producer AbstractController::mediaSourceQueryValue() const { return rpl::single(QString()); } +PeerId AbstractController::peerId() const { + if (const auto peer = key().peer()) { + return peer->id; + } + return PeerId(0); +} + +PeerId AbstractController::migratedPeerId() const { + if (const auto peer = migrated()) { + return peer->id; + } + return PeerId(0); +} + void AbstractController::showSection( Window::SectionMemento &&memento, const Window::SectionShow ¶ms) { diff --git a/Telegram/SourceFiles/info/info_controller.h b/Telegram/SourceFiles/info/info_controller.h index acab65a8a..09c1f9024 100644 --- a/Telegram/SourceFiles/info/info_controller.h +++ b/Telegram/SourceFiles/info/info_controller.h @@ -107,18 +107,8 @@ public: virtual PeerData *migrated() const = 0; virtual Section section() const = 0; - PeerId peerId() const { - if (const auto peer = key().peer()) { - return peer->id; - } - return PeerId(0); - } - PeerId migratedPeerId() const { - if (auto peer = migrated()) { - return peer->id; - } - return PeerId(0); - } + PeerId peerId() const; + PeerId migratedPeerId() const; Data::Feed *feed() const { return key().feed(); } diff --git a/Telegram/SourceFiles/info/info_memento.cpp b/Telegram/SourceFiles/info/info_memento.cpp index e94a18e8b..40671525b 100644 --- a/Telegram/SourceFiles/info/info_memento.cpp +++ b/Telegram/SourceFiles/info/info_memento.cpp @@ -18,6 +18,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/info_layer_widget.h" #include "info/info_controller.h" #include "boxes/peer_list_box.h" +#include "data/data_channel.h" +#include "data/data_chat.h" namespace Info { diff --git a/Telegram/SourceFiles/info/info_top_bar.cpp b/Telegram/SourceFiles/info/info_top_bar.cpp index dcf549d68..4bd695eed 100644 --- a/Telegram/SourceFiles/info/info_top_bar.cpp +++ b/Telegram/SourceFiles/info/info_top_bar.cpp @@ -9,7 +9,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include -#include "styles/style_info.h" #include "lang/lang_keys.h" #include "info/info_wrap_widget.h" #include "info/info_controller.h" @@ -26,6 +25,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/wrap/padding_wrap.h" #include "ui/search_field_controller.h" #include "window/window_peer_menu.h" +#include "data/data_channel.h" +#include "data/data_user.h" +#include "styles/style_info.h" namespace Info { diff --git a/Telegram/SourceFiles/info/info_wrap_widget.cpp b/Telegram/SourceFiles/info/info_wrap_widget.cpp index 8c2ff17ec..222650fbf 100644 --- a/Telegram/SourceFiles/info/info_wrap_widget.cpp +++ b/Telegram/SourceFiles/info/info_wrap_widget.cpp @@ -28,6 +28,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/confirm_box.h" #include "auth_session.h" #include "data/data_session.h" +#include "data/data_user.h" #include "mainwidget.h" #include "lang/lang_keys.h" #include "styles/style_info.h" diff --git a/Telegram/SourceFiles/info/media/info_media_buttons.h b/Telegram/SourceFiles/info/media/info_media_buttons.h index 812fae260..062a3e406 100644 --- a/Telegram/SourceFiles/info/media/info_media_buttons.h +++ b/Telegram/SourceFiles/info/media/info_media_buttons.h @@ -18,6 +18,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/wrap/slide_wrap.h" #include "ui/wrap/vertical_layout.h" #include "window/window_controller.h" +#include "data/data_channel.h" +#include "data/data_user.h" #include "styles/style_info.h" namespace Info { diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index 0bc6c850a..9f53d47c2 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -12,6 +12,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_peer_values.h" #include "data/data_session.h" #include "data/data_feed.h" +#include "data/data_channel.h" +#include "data/data_user.h" #include "ui/wrap/vertical_layout.h" #include "ui/wrap/padding_wrap.h" #include "ui/wrap/slide_wrap.h" diff --git a/Telegram/SourceFiles/info/profile/info_profile_cover.cpp b/Telegram/SourceFiles/info/profile/info_profile_cover.cpp index c56c2fdc1..6d69deebb 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_cover.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_cover.cpp @@ -11,6 +11,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include "data/data_photo.h" #include "data/data_peer_values.h" +#include "data/data_channel.h" +#include "data/data_chat.h" #include "info/profile/info_profile_values.h" #include "info/info_controller.h" #include "info/info_memento.h" diff --git a/Telegram/SourceFiles/info/profile/info_profile_members.cpp b/Telegram/SourceFiles/info/profile/info_profile_members.cpp index 175526386..274a3008e 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_members.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_members.cpp @@ -24,12 +24,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/scroll_area.h" #include "ui/wrap/padding_wrap.h" #include "ui/search_field_controller.h" -#include "styles/style_boxes.h" -#include "styles/style_info.h" #include "lang/lang_keys.h" #include "boxes/confirm_box.h" #include "boxes/peer_list_controllers.h" #include "window/window_controller.h" +#include "data/data_channel.h" +#include "data/data_chat.h" +#include "data/data_user.h" +#include "styles/style_boxes.h" +#include "styles/style_info.h" namespace Info { namespace Profile { diff --git a/Telegram/SourceFiles/info/profile/info_profile_members_controllers.cpp b/Telegram/SourceFiles/info/profile/info_profile_members_controllers.cpp index bee151e8d..fe8395fe5 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_members_controllers.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_members_controllers.cpp @@ -16,6 +16,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "auth_session.h" #include "mainwidget.h" #include "observer_peer.h" +#include "data/data_chat.h" +#include "data/data_user.h" #include "boxes/confirm_box.h" #include "window/window_controller.h" #include "styles/style_info.h" @@ -351,6 +353,10 @@ int MemberListRow::nameIconWidth() const { : 0; } +not_null MemberListRow::user() const { + return peer()->asUser(); +} + void MemberListRow::paintNameIcon( Painter &p, int x, diff --git a/Telegram/SourceFiles/info/profile/info_profile_members_controllers.h b/Telegram/SourceFiles/info/profile/info_profile_members_controllers.h index e3854ac7d..6c2260462 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_members_controllers.h +++ b/Telegram/SourceFiles/info/profile/info_profile_members_controllers.h @@ -48,9 +48,7 @@ public: int outerWidth, bool selected) override; - not_null user() const { - return peer()->asUser(); - } + not_null user() const; bool canRemove() const { return _type.canRemove; } diff --git a/Telegram/SourceFiles/info/profile/info_profile_values.cpp b/Telegram/SourceFiles/info/profile/info_profile_values.cpp index 5c46c4929..94ef73303 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_values.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_values.cpp @@ -18,6 +18,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_peer_values.h" #include "data/data_shared_media.h" #include "data/data_feed.h" +#include "data/data_channel.h" +#include "data/data_chat.h" +#include "data/data_user.h" #include "data/data_session.h" namespace Info { diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp index fd28b7d60..58999b72a 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_photo.h" #include "data/data_document.h" +#include "data/data_peer.h" #include "core/click_handler_types.h" #include "inline_bots/inline_bot_result.h" #include "inline_bots/inline_bot_layout_internal.h" @@ -19,6 +20,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace InlineBots { namespace Layout { +namespace { + +NeverFreedPointer documentItemsMap; + +} // namespace void ItemBase::setPosition(int32 position) { _position = position; @@ -211,11 +217,9 @@ QString ItemBase::getResultThumbLetter() const { return QString(); } -namespace { - -NeverFreedPointer documentItemsMap; - -} // namespace +Data::FileOrigin ItemBase::fileOrigin() const { + return _context->inlineItemFileOrigin(); +} const DocumentItems *documentItems() { return documentItemsMap.data(); diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.h b/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.h index 4fcac4ba4..e55156779 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.h +++ b/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.h @@ -106,9 +106,7 @@ protected: not_null context() const { return _context; } - Data::FileOrigin fileOrigin() const { - return _context->inlineItemFileOrigin(); - } + Data::FileOrigin fileOrigin() const; Result *_result = nullptr; DocumentData *_doc = nullptr; diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_send_data.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_send_data.cpp index ccf0aa9d0..12e5902cf 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_send_data.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_send_data.cpp @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/localstorage.h" #include "lang/lang_keys.h" #include "history/history.h" +#include "data/data_channel.h" namespace InlineBots { namespace internal { diff --git a/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp b/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp index 727d88846..843ec36f9 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp @@ -9,6 +9,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_photo.h" #include "data/data_document.h" +#include "data/data_channel.h" +#include "data/data_user.h" #include "styles/style_chat_helpers.h" #include "ui/widgets/buttons.h" #include "ui/widgets/shadow.h" diff --git a/Telegram/SourceFiles/intro/introwidget.cpp b/Telegram/SourceFiles/intro/introwidget.cpp index 0a25df48a..5176ff276 100644 --- a/Telegram/SourceFiles/intro/introwidget.cpp +++ b/Telegram/SourceFiles/intro/introwidget.cpp @@ -30,6 +30,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/window_slide_animation.h" #include "window/window_connecting_widget.h" #include "window/window_lock_widgets.h" +#include "data/data_user.h" #include "styles/style_boxes.h" #include "styles/style_intro.h" #include "styles/style_window.h" diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 66a615ce1..6453650bb 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -19,6 +19,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "data/data_media_types.h" #include "data/data_feed.h" +#include "data/data_channel.h" +#include "data/data_chat.h" +#include "data/data_user.h" #include "ui/special_buttons.h" #include "ui/widgets/buttons.h" #include "ui/widgets/shadow.h" diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index ac475f2ba..4948ff00c 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/weak_ptr.h" #include "ui/rp_widget.h" #include "media/player/media_player_float.h" +#include "data/data_pts_waiter.h" struct HistoryMessageMarkupButton; class MainWindow; diff --git a/Telegram/SourceFiles/media/media_audio.cpp b/Telegram/SourceFiles/media/media_audio.cpp index 0a954fe9e..2832e9af8 100644 --- a/Telegram/SourceFiles/media/media_audio.cpp +++ b/Telegram/SourceFiles/media/media_audio.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "media/media_audio.h" #include "data/data_document.h" +#include "data/data_file_origin.h" #include "media/media_audio_ffmpeg_loader.h" #include "media/media_child_ffmpeg_loader.h" #include "media/media_audio_loaders.h" diff --git a/Telegram/SourceFiles/media/player/media_player_instance.cpp b/Telegram/SourceFiles/media/player/media_player_instance.cpp index bd28ae83d..5ace3395a 100644 --- a/Telegram/SourceFiles/media/player/media_player_instance.cpp +++ b/Telegram/SourceFiles/media/player/media_player_instance.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history.h" #include "history/history_item.h" #include "data/data_media_types.h" +#include "data/data_file_origin.h" #include "window/window_controller.h" #include "core/shortcuts.h" #include "messenger.h" diff --git a/Telegram/SourceFiles/media/player/media_player_panel.cpp b/Telegram/SourceFiles/media/player/media_player_panel.cpp index 0711b77a1..87b2cc631 100644 --- a/Telegram/SourceFiles/media/player/media_player_panel.cpp +++ b/Telegram/SourceFiles/media/player/media_player_panel.cpp @@ -14,6 +14,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_item.h" #include "data/data_document.h" #include "data/data_media_types.h" +#include "data/data_channel.h" +#include "data/data_chat.h" #include "ui/widgets/shadow.h" #include "ui/widgets/scroll_area.h" #include "mainwindow.h" diff --git a/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp b/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp index 93626d00e..dc4cbf456 100644 --- a/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp +++ b/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp @@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_media_types.h" #include "data/data_session.h" #include "data/data_web_page.h" +#include "data/data_file_origin.h" #include "history/history.h" #include "history/media/history_media.h" #include "ui/image/image.h" diff --git a/Telegram/SourceFiles/mediaview.cpp b/Telegram/SourceFiles/mediaview.cpp index 62bb0a5d4..74e546fb1 100644 --- a/Telegram/SourceFiles/mediaview.cpp +++ b/Telegram/SourceFiles/mediaview.cpp @@ -25,6 +25,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_message.h" #include "data/data_media_types.h" #include "data/data_session.h" +#include "data/data_channel.h" +#include "data/data_chat.h" +#include "data/data_user.h" #include "window/themes/window_theme_preview.h" #include "window/window_peer_menu.h" #include "observer_peer.h" diff --git a/Telegram/SourceFiles/messenger.cpp b/Telegram/SourceFiles/messenger.cpp index 2ddc0374c..aa6521b50 100644 --- a/Telegram/SourceFiles/messenger.cpp +++ b/Telegram/SourceFiles/messenger.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_photo.h" #include "data/data_document.h" #include "data/data_session.h" +#include "data/data_user.h" #include "base/timer.h" #include "core/update_checker.h" #include "core/shortcuts.h" diff --git a/Telegram/SourceFiles/overview/overview_layout.cpp b/Telegram/SourceFiles/overview/overview_layout.cpp index 9f657a6d4..f4ca1fd82 100644 --- a/Telegram/SourceFiles/overview/overview_layout.cpp +++ b/Telegram/SourceFiles/overview/overview_layout.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "data/data_web_page.h" #include "data/data_media_types.h" +#include "data/data_peer.h" #include "styles/style_overview.h" #include "styles/style_history.h" #include "core/file_utilities.h" diff --git a/Telegram/SourceFiles/passport/passport_form_controller.cpp b/Telegram/SourceFiles/passport/passport_form_controller.cpp index 58d67e500..8df3166fe 100644 --- a/Telegram/SourceFiles/passport/passport_form_controller.cpp +++ b/Telegram/SourceFiles/passport/passport_form_controller.cpp @@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/openssl_help.h" #include "base/qthelp_url.h" #include "data/data_session.h" +#include "data/data_user.h" #include "mainwindow.h" #include "window/window_controller.h" #include "core/click_handler_types.h" @@ -1715,7 +1716,7 @@ void FormController::loadFile(File &file) { file.id, file.accessHash, QByteArray(), // file_reference - std::nullopt, // origin + Data::FileOrigin(), SecureFileLocation, QString(), file.size, diff --git a/Telegram/SourceFiles/passport/passport_panel_details_row.cpp b/Telegram/SourceFiles/passport/passport_panel_details_row.cpp index e10551810..98a0d028d 100644 --- a/Telegram/SourceFiles/passport/passport_panel_details_row.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_details_row.cpp @@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/wrap/slide_wrap.h" #include "ui/countryinput.h" #include "auth_session.h" +#include "data/data_user.h" #include "styles/style_boxes.h" #include "styles/style_passport.h" diff --git a/Telegram/SourceFiles/passport/passport_panel_form.cpp b/Telegram/SourceFiles/passport/passport_panel_form.cpp index 70b1bc95e..4eb8d126b 100644 --- a/Telegram/SourceFiles/passport/passport_panel_form.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_form.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "boxes/abstract_box.h" #include "core/click_handler_types.h" +#include "data/data_user.h" #include "ui/widgets/shadow.h" #include "ui/widgets/buttons.h" #include "ui/widgets/scroll_area.h" diff --git a/Telegram/SourceFiles/passport/passport_panel_password.cpp b/Telegram/SourceFiles/passport/passport_panel_password.cpp index 2484bdb3f..dc381e65a 100644 --- a/Telegram/SourceFiles/passport/passport_panel_password.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_password.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/wrap/padding_wrap.h" #include "ui/special_buttons.h" #include "boxes/passcode_box.h" +#include "data/data_user.h" #include "lang/lang_keys.h" #include "info/profile/info_profile_icon.h" #include "styles/style_passport.h" diff --git a/Telegram/SourceFiles/profile/profile_block_group_members.cpp b/Telegram/SourceFiles/profile/profile_block_group_members.cpp index 8baf280aa..4cb8d4a9c 100644 --- a/Telegram/SourceFiles/profile/profile_block_group_members.cpp +++ b/Telegram/SourceFiles/profile/profile_block_group_members.cpp @@ -14,6 +14,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "profile/profile_channel_controllers.h" #include "ui/widgets/popup_menu.h" #include "data/data_peer_values.h" +#include "data/data_channel.h" +#include "data/data_chat.h" +#include "data/data_user.h" #include "mainwidget.h" #include "apiwrap.h" #include "observer_peer.h" @@ -21,9 +24,19 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" namespace Profile { +namespace { using UpdateFlag = Notify::PeerUpdate::Flag; +} // namespace + +GroupMembersWidget::Member::Member(UserData *user) : Item(user) { +} + +UserData *GroupMembersWidget::Member::user() const { + return static_cast(peer); +} + GroupMembersWidget::GroupMembersWidget( QWidget *parent, PeerData *peer, diff --git a/Telegram/SourceFiles/profile/profile_block_group_members.h b/Telegram/SourceFiles/profile/profile_block_group_members.h index cc15e1476..80fcbc1bf 100644 --- a/Telegram/SourceFiles/profile/profile_block_group_members.h +++ b/Telegram/SourceFiles/profile/profile_block_group_members.h @@ -74,11 +74,9 @@ private: int getListTop() const override; struct Member : public Item { - explicit Member(UserData *user) : Item(user) { - } - UserData *user() const { - return static_cast(peer); - } + explicit Member(UserData *user); + UserData *user() const; + TimeId onlineTextTill = 0; TimeId onlineTill = 0; TimeId onlineForSort = 0; diff --git a/Telegram/SourceFiles/profile/profile_block_peer_list.cpp b/Telegram/SourceFiles/profile/profile_block_peer_list.cpp index 4e0465dd3..8f1af61de 100644 --- a/Telegram/SourceFiles/profile/profile_block_peer_list.cpp +++ b/Telegram/SourceFiles/profile/profile_block_peer_list.cpp @@ -10,9 +10,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/effects/ripple_animation.h" #include "ui/widgets/popup_menu.h" #include "ui/text_options.h" +#include "data/data_peer.h" +#include "auth_session.h" #include "styles/style_profile.h" #include "styles/style_widgets.h" -#include "auth_session.h" namespace Profile { diff --git a/Telegram/SourceFiles/profile/profile_channel_controllers.cpp b/Telegram/SourceFiles/profile/profile_channel_controllers.cpp index 691ce3d5a..d3ab1a98e 100644 --- a/Telegram/SourceFiles/profile/profile_channel_controllers.cpp +++ b/Telegram/SourceFiles/profile/profile_channel_controllers.cpp @@ -21,6 +21,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "dialogs/dialogs_indexed_list.h" #include "data/data_peer_values.h" #include "data/data_session.h" +#include "data/data_channel.h" +#include "data/data_user.h" #include "ui/widgets/popup_menu.h" #include "window/window_controller.h" #include "history/history.h" diff --git a/Telegram/SourceFiles/settings/settings_information.cpp b/Telegram/SourceFiles/settings/settings_information.cpp index b8212a34b..284d1aac0 100644 --- a/Telegram/SourceFiles/settings/settings_information.cpp +++ b/Telegram/SourceFiles/settings/settings_information.cpp @@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/change_phone_box.h" #include "boxes/photo_crop_box.h" #include "boxes/username_box.h" +#include "data/data_user.h" #include "info/profile/info_profile_values.h" #include "info/profile/info_profile_button.h" #include "lang/lang_keys.h" diff --git a/Telegram/SourceFiles/settings/settings_main.cpp b/Telegram/SourceFiles/settings/settings_main.cpp index a1d1874ae..49f57232e 100644 --- a/Telegram/SourceFiles/settings/settings_main.cpp +++ b/Telegram/SourceFiles/settings/settings_main.cpp @@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/discrete_sliders.h" #include "info/profile/info_profile_button.h" #include "info/profile/info_profile_cover.h" +#include "data/data_user.h" #include "lang/lang_keys.h" #include "storage/localstorage.h" #include "auth_session.h" diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp index 3ce3d6b21..37b4290a8 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp @@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwidget.h" #include "auth_session.h" #include "storage/localstorage.h" +#include "data/data_user.h" #include "history/history.h" #include "calls/calls_instance.h" #include "ui/widgets/checkbox.h" diff --git a/Telegram/SourceFiles/storage/file_download.cpp b/Telegram/SourceFiles/storage/file_download.cpp index 9f3bdced6..22682519b 100644 --- a/Telegram/SourceFiles/storage/file_download.cpp +++ b/Telegram/SourceFiles/storage/file_download.cpp @@ -168,6 +168,10 @@ void FileLoader::readImage(const QSize &shrinkBox) const { } } +Data::FileOrigin FileLoader::fileOrigin() const { + return Data::FileOrigin(); +} + float64 FileLoader::currentProgress() const { if (_finished) return 1.; if (!fullSize()) return 0.; @@ -592,19 +596,19 @@ Data::FileOrigin mtpFileLoader::fileOrigin() const { } void mtpFileLoader::refreshFileReferenceFrom( - const Data::UpdatedFileReferences &data, + const Data::UpdatedFileReferences &updates, int requestId, const QByteArray ¤t) { const auto updated = [&] { if (_location) { - const auto i = data.find(Data::SimpleFileLocationId( + const auto i = updates.data.find(Data::SimpleFileLocationId( _location->volume(), _location->dc(), _location->local())); - return (i == end(data)) ? QByteArray() : i->second; + return (i == end(updates.data)) ? QByteArray() : i->second; } - const auto i = data.find(_id); - return (i == end(data)) ? QByteArray() : i->second; + const auto i = updates.data.find(_id); + return (i == end(updates.data)) ? QByteArray() : i->second; }(); if (updated.isEmpty() || updated == current) { cancel(true); diff --git a/Telegram/SourceFiles/storage/file_download.h b/Telegram/SourceFiles/storage/file_download.h index e64b8f725..2c1a41023 100644 --- a/Telegram/SourceFiles/storage/file_download.h +++ b/Telegram/SourceFiles/storage/file_download.h @@ -94,9 +94,7 @@ public: QString fileName() const { return _filename; } - virtual Data::FileOrigin fileOrigin() const { - return Data::FileOrigin(); - } + virtual Data::FileOrigin fileOrigin() const; float64 currentProgress() const; virtual int32 currentOffset(bool includeSkipped = false) const = 0; int32 fullSize() const; @@ -240,7 +238,7 @@ public: rpcInvalidate(); } void refreshFileReferenceFrom( - const Data::UpdatedFileReferences &data, + const Data::UpdatedFileReferences &updates, int requestId, const QByteArray ¤t); diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp index 284e66513..55cf0b712 100644 --- a/Telegram/SourceFiles/storage/localstorage.cpp +++ b/Telegram/SourceFiles/storage/localstorage.cpp @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/storage_clear_legacy.h" #include "chat_helpers/stickers.h" #include "data/data_drafts.h" +#include "data/data_user.h" #include "boxes/send_files_box.h" #include "window/themes/window_theme.h" #include "ui/widgets/input_fields.h" diff --git a/Telegram/SourceFiles/storage/serialize_common.cpp b/Telegram/SourceFiles/storage/serialize_common.cpp index 39f3711bf..cae088d2b 100644 --- a/Telegram/SourceFiles/storage/serialize_common.cpp +++ b/Telegram/SourceFiles/storage/serialize_common.cpp @@ -8,6 +8,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/serialize_common.h" #include "auth_session.h" +#include "data/data_channel.h" +#include "data/data_chat.h" +#include "data/data_user.h" #include "ui/image/image.h" namespace Serialize { diff --git a/Telegram/SourceFiles/support/support_helper.cpp b/Telegram/SourceFiles/support/support_helper.cpp index febbcc5e3..d0be9b0da 100644 --- a/Telegram/SourceFiles/support/support_helper.cpp +++ b/Telegram/SourceFiles/support/support_helper.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "dialogs/dialogs_key.h" #include "data/data_drafts.h" +#include "data/data_user.h" #include "history/history.h" #include "boxes/abstract_box.h" #include "ui/toast/toast.h" diff --git a/Telegram/SourceFiles/ui/image/image.cpp b/Telegram/SourceFiles/ui/image/image.cpp index b12204bd2..ba3eb7d6d 100644 --- a/Telegram/SourceFiles/ui/image/image.cpp +++ b/Telegram/SourceFiles/ui/image/image.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/media_active_cache.h" #include "storage/cache/storage_cache_database.h" #include "data/data_session.h" +#include "data/data_file_origin.h" #include "auth_session.h" using namespace Images; @@ -749,6 +750,27 @@ QPixmap Image::pixBlurredColoredNoCache( return App::pixmapFromImageInPlace(prepareColored(add, img)); } +void Image::automaticLoad(Data::FileOrigin origin, const HistoryItem *item) { + if (!loaded()) { + _source->automaticLoad(origin, item); + } +} + +void Image::load(Data::FileOrigin origin, bool loadFirst, bool prior) { + if (!loaded()) { + _source->load(origin, loadFirst, prior); + } +} + +void Image::loadEvenCancelled( + Data::FileOrigin origin, + bool loadFirst, + bool prior) { + if (!loaded()) { + _source->loadEvenCancelled(origin, loadFirst, prior); + } +} + std::optional Image::cacheKey() const { return _source->cacheKey(); } diff --git a/Telegram/SourceFiles/ui/image/image.h b/Telegram/SourceFiles/ui/image/image.h index 6dff6f1fc..e954f175f 100644 --- a/Telegram/SourceFiles/ui/image/image.h +++ b/Telegram/SourceFiles/ui/image/image.h @@ -171,11 +171,7 @@ public: int32 w, int32 h = 0) const; - void automaticLoad(Data::FileOrigin origin, const HistoryItem *item) { - if (!loaded()) { - _source->automaticLoad(origin, item); - } - } + void automaticLoad(Data::FileOrigin origin, const HistoryItem *item); void automaticLoadSettingsChanged() { _source->automaticLoadSettingsChanged(); } @@ -207,21 +203,13 @@ public: _source->setInformation(size, width, height); } void load( - Data::FileOrigin origin, - bool loadFirst = false, - bool prior = true) { - if (!loaded()) { - _source->load(origin, loadFirst, prior); - } - } + Data::FileOrigin origin, + bool loadFirst = false, + bool prior = true); void loadEvenCancelled( - Data::FileOrigin origin, - bool loadFirst = false, - bool prior = true) { - if (!loaded()) { - _source->loadEvenCancelled(origin, loadFirst, prior); - } - } + Data::FileOrigin origin, + bool loadFirst = false, + bool prior = true); const StorageImageLocation &location() const { return _source->location(); } diff --git a/Telegram/SourceFiles/ui/image/image_source.cpp b/Telegram/SourceFiles/ui/image/image_source.cpp index 8910bb0bd..422829791 100644 --- a/Telegram/SourceFiles/ui/image/image_source.cpp +++ b/Telegram/SourceFiles/ui/image/image_source.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/file_download.h" #include "data/data_session.h" +#include "data/data_file_origin.h" #include "storage/cache/storage_cache_database.h" #include "history/history_item.h" #include "history/history.h" @@ -318,7 +319,7 @@ void RemoteSource::loadLocal() { return; } - _loader = createLoader(std::nullopt, LoadFromLocalOnly, true); + _loader = createLoader(Data::FileOrigin(), LoadFromLocalOnly, true); if (_loader) _loader->start(); } diff --git a/Telegram/SourceFiles/ui/special_buttons.cpp b/Telegram/SourceFiles/ui/special_buttons.cpp index 05dd6ac17..3a3e6282d 100644 --- a/Telegram/SourceFiles/ui/special_buttons.cpp +++ b/Telegram/SourceFiles/ui/special_buttons.cpp @@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_photo.h" #include "data/data_session.h" #include "data/data_feed.h" +#include "data/data_channel.h" #include "history/history.h" #include "core/file_utilities.h" #include "boxes/photo_crop_box.h" diff --git a/Telegram/SourceFiles/ui/text/text_entity.cpp b/Telegram/SourceFiles/ui/text/text_entity.cpp index 152db8733..7f38bf94e 100644 --- a/Telegram/SourceFiles/ui/text/text_entity.cpp +++ b/Telegram/SourceFiles/ui/text/text_entity.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_tag.h" #include "base/qthelp_url.h" #include "ui/emoji_config.h" +#include "data/data_user.h" namespace TextUtilities { namespace { diff --git a/Telegram/SourceFiles/ui/text_options.cpp b/Telegram/SourceFiles/ui/text_options.cpp index f052e78ed..03da7556f 100644 --- a/Telegram/SourceFiles/ui/text_options.cpp +++ b/Telegram/SourceFiles/ui/text_options.cpp @@ -9,6 +9,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history.h" #include "history/history_item.h" +#include "data/data_channel.h" +#include "data/data_chat.h" +#include "data/data_user.h" #include "styles/style_history.h" #include "styles/style_window.h" diff --git a/Telegram/SourceFiles/ui/widgets/input_fields.cpp b/Telegram/SourceFiles/ui/widgets/input_fields.cpp index 247594cda..b0229b043 100644 --- a/Telegram/SourceFiles/ui/widgets/input_fields.cpp +++ b/Telegram/SourceFiles/ui/widgets/input_fields.cpp @@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "chat_helpers/emoji_suggestions_helper.h" #include "window/themes/window_theme.h" #include "lang/lang_keys.h" +#include "data/data_user.h" #include "mainwindow.h" #include "numbers.h" #include "auth_session.h" diff --git a/Telegram/SourceFiles/window/layer_widget.h b/Telegram/SourceFiles/window/layer_widget.h index d55644427..838093e1b 100644 --- a/Telegram/SourceFiles/window/layer_widget.h +++ b/Telegram/SourceFiles/window/layer_widget.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "ui/rp_widget.h" +#include "data/data_file_origin.h" namespace Window { diff --git a/Telegram/SourceFiles/window/notifications_manager.cpp b/Telegram/SourceFiles/window/notifications_manager.cpp index eb04d15a0..479c6c9c4 100644 --- a/Telegram/SourceFiles/window/notifications_manager.cpp +++ b/Telegram/SourceFiles/window/notifications_manager.cpp @@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/feed/history_feed_section.h" #include "lang/lang_keys.h" #include "data/data_session.h" +#include "data/data_channel.h" #include "window/window_controller.h" #include "mainwindow.h" #include "mainwidget.h" diff --git a/Telegram/SourceFiles/window/notifications_utilities.cpp b/Telegram/SourceFiles/window/notifications_utilities.cpp index ed16bbb9d..18f9e61d0 100644 --- a/Telegram/SourceFiles/window/notifications_utilities.cpp +++ b/Telegram/SourceFiles/window/notifications_utilities.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/platform_specific.h" #include "messenger.h" +#include "data/data_peer.h" #include "styles/style_window.h" namespace Window { diff --git a/Telegram/SourceFiles/window/window_controller.cpp b/Telegram/SourceFiles/window/window_controller.cpp index fd650f37f..576a0fdea 100644 --- a/Telegram/SourceFiles/window/window_controller.cpp +++ b/Telegram/SourceFiles/window/window_controller.cpp @@ -17,6 +17,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "media/player/media_player_round_controller.h" #include "data/data_session.h" #include "data/data_feed.h" +#include "data/data_channel.h" +#include "data/data_chat.h" #include "passport/passport_form_controller.h" #include "core/shortcuts.h" #include "boxes/calendar_box.h" diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index 83a607718..234ed9c4d 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -25,6 +25,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/click_handler_types.h" #include "observer_peer.h" #include "auth_session.h" +#include "data/data_user.h" #include "mainwidget.h" #include "styles/style_window.h" #include "styles/style_dialogs.h" diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index b8858a0b3..a31d076a9 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -34,6 +34,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "data/data_feed.h" #include "data/data_poll.h" +#include "data/data_channel.h" +#include "data/data_chat.h" +#include "data/data_user.h" #include "dialogs/dialogs_key.h" namespace Window { diff --git a/Telegram/gyp/telegram_sources.txt b/Telegram/gyp/telegram_sources.txt index 9e6bc94d6..afecba5f2 100644 --- a/Telegram/gyp/telegram_sources.txt +++ b/Telegram/gyp/telegram_sources.txt @@ -146,6 +146,10 @@ <(src_loc)/data/data_abstract_structure.h <(src_loc)/data/data_auto_download.cpp <(src_loc)/data/data_auto_download.h +<(src_loc)/data/data_chat.cpp +<(src_loc)/data/data_chat.h +<(src_loc)/data/data_channel.cpp +<(src_loc)/data/data_channel.h <(src_loc)/data/data_channel_admins.cpp <(src_loc)/data/data_channel_admins.h <(src_loc)/data/data_document.cpp @@ -178,6 +182,8 @@ <(src_loc)/data/data_photo.h <(src_loc)/data/data_poll.cpp <(src_loc)/data/data_poll.h +<(src_loc)/data/data_pts_waiter.cpp +<(src_loc)/data/data_pts_waiter.h <(src_loc)/data/data_search_controller.cpp <(src_loc)/data/data_search_controller.h <(src_loc)/data/data_session.cpp @@ -188,6 +194,8 @@ <(src_loc)/data/data_sparse_ids.h <(src_loc)/data/data_types.cpp <(src_loc)/data/data_types.h +<(src_loc)/data/data_user.cpp +<(src_loc)/data/data_user.h <(src_loc)/data/data_user_photos.cpp <(src_loc)/data/data_user_photos.h <(src_loc)/data/data_web_page.cpp