diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 6659383633..0adff412d1 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -3270,7 +3270,7 @@ void ApiWrap::toggleSavedGif( )).done([=](const MTPBool &result) { if (mtpIsTrue(result)) { if (saved) { - App::addSavedGif(document); + session().data().addSavedGif(document); } } }).fail([=](const RPCError &error) { diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index 8dcdccfc28..e8db570212 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -115,33 +115,6 @@ namespace App { return nullptr; } - void addSavedGif(DocumentData *doc) { - auto &saved = Auth().data().savedGifsRef(); - int32 index = saved.indexOf(doc); - if (index) { - if (index > 0) saved.remove(index); - saved.push_front(doc); - if (saved.size() > Global::SavedGifsLimit()) saved.pop_back(); - Local::writeSavedGifs(); - - Auth().data().notifySavedGifsUpdated(); - Auth().data().setLastSavedGifsUpdate(0); - Auth().api().updateStickers(); - } - } - - void checkSavedGif(HistoryItem *item) { - if (!item->Has() && (item->out() || item->history()->peer == Auth().user())) { - if (const auto media = item->media()) { - if (const auto document = media->document()) { - if (document->isGifv()) { - addSavedGif(document); - } - } - } - } - } - QString peerName(const PeerData *peer, bool forDialogs) { return peer ? ((forDialogs && peer->isUser() && !peer->asUser()->nameOrPhone.isEmpty()) ? peer->asUser()->nameOrPhone : peer->name) : tr::lng_deleted(tr::now); } diff --git a/Telegram/SourceFiles/app.h b/Telegram/SourceFiles/app.h index d861427392..19b969270f 100644 --- a/Telegram/SourceFiles/app.h +++ b/Telegram/SourceFiles/app.h @@ -65,8 +65,6 @@ namespace App { QString formatPhone(QString phone); - void addSavedGif(DocumentData *doc); - void checkSavedGif(HistoryItem *item); [[nodiscard]] QString peerName(const PeerData *peer, bool forDialogs = false); void hoveredItem(HistoryView::Element *item); diff --git a/Telegram/SourceFiles/boxes/add_contact_box.cpp b/Telegram/SourceFiles/boxes/add_contact_box.cpp index 0d67fc3088..7c0a1dd5f6 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/add_contact_box.cpp @@ -154,7 +154,10 @@ void ShowAddParticipantsError( class RevokePublicLinkBox::Inner : public TWidget, private MTP::Sender { public: - Inner(QWidget *parent, Fn revokeCallback); + Inner( + QWidget *parent, + not_null session, + Fn revokeCallback); protected: void mouseMoveEvent(QMouseEvent *e) override; @@ -173,6 +176,8 @@ private: void paintChat(Painter &p, const ChatRow &row, bool selected) const; void updateSelected(); + const not_null _session; + PeerData *_selected = nullptr; PeerData *_pressed = nullptr; @@ -188,8 +193,20 @@ private: }; -AddContactBox::AddContactBox(QWidget*, QString fname, QString lname, QString phone) -: _first(this, st::defaultInputField, tr::lng_signup_firstname(), fname) +AddContactBox::AddContactBox( + QWidget*, + not_null session) +: AddContactBox(nullptr, session, QString(), QString(), QString()) { +} + +AddContactBox::AddContactBox( + QWidget*, + not_null session, + QString fname, + QString lname, + QString phone) +: _session(session) +, _first(this, st::defaultInputField, tr::lng_signup_firstname(), fname) , _last(this, st::defaultInputField, tr::lng_signup_lastname(), lname) , _phone(this, st::defaultInputField, tr::lng_contact_phone(), phone) , _invertOrder(langFirstNameGoesSecond()) { @@ -198,28 +215,15 @@ AddContactBox::AddContactBox(QWidget*, QString fname, QString lname, QString pho } } -AddContactBox::AddContactBox(QWidget*, UserData *user) -: _user(user) -, _first(this, st::defaultInputField, tr::lng_signup_firstname(), user->firstName) -, _last(this, st::defaultInputField, tr::lng_signup_lastname(), user->lastName) -, _phone(this, st::defaultInputField, tr::lng_contact_phone(), user->phone()) -, _invertOrder(langFirstNameGoesSecond()) { - _phone->setDisabled(true); -} - void AddContactBox::prepare() { if (_invertOrder) { setTabOrder(_last, _first); } - if (_user) { - setTitle(tr::lng_edit_contact_title()); - } else { - const auto readyToAdd = !_phone->getLastText().isEmpty() - && (!_first->getLastText().isEmpty() || !_last->getLastText().isEmpty()); - setTitle(readyToAdd - ? tr::lng_confirm_contact_data() - : tr::lng_enter_contact_data()); - } + const auto readyToAdd = !_phone->getLastText().isEmpty() + && (!_first->getLastText().isEmpty() || !_last->getLastText().isEmpty()); + setTitle(readyToAdd + ? tr::lng_confirm_contact_data() + : tr::lng_enter_contact_data()); updateButtons(); connect(_first, &Ui::InputField::submitted, [=] { submit(); }); @@ -307,7 +311,7 @@ void AddContactBox::save() { _first->showError(); } return; - } else if (!_user && !IsValidPhone(phone)) { + } else if (!IsValidPhone(phone)) { _phone->setFocus(); _phone->showError(); return; @@ -317,49 +321,31 @@ void AddContactBox::save() { lastName = QString(); } _sentName = firstName; - if (_user) { - _contactId = rand_value(); - QVector v(1, MTP_inputPhoneContact(MTP_long(_contactId), MTP_string(_user->phone()), MTP_string(firstName), MTP_string(lastName))); - _addRequest = MTP::send(MTPcontacts_ImportContacts(MTP_vector(v)), rpcDone(&AddContactBox::onSaveUserDone), rpcFail(&AddContactBox::onSaveUserFail)); - } else { - _contactId = rand_value(); - QVector v(1, MTP_inputPhoneContact(MTP_long(_contactId), MTP_string(phone), MTP_string(firstName), MTP_string(lastName))); - _addRequest = MTP::send(MTPcontacts_ImportContacts(MTP_vector(v)), rpcDone(&AddContactBox::onImportDone)); - } + _contactId = rand_value(); + _addRequest = _session->api().request(MTPcontacts_ImportContacts( + MTP_vector( + 1, + MTP_inputPhoneContact( + MTP_long(_contactId), + MTP_string(phone), + MTP_string(firstName), + MTP_string(lastName))) + )).done(crl::guard(this, [=](const MTPcontacts_ImportedContacts &res) { + })).send(); } -bool AddContactBox::onSaveUserFail(const RPCError &error) { - if (MTP::isDefaultHandledError(error)) return false; - - _addRequest = 0; - const auto &err = error.type(); - const auto firstName = _first->getLastText().trimmed(); - const auto lastName = _last->getLastText().trimmed(); - if (err == "CHAT_TITLE_NOT_MODIFIED") { - _user->setName(firstName, lastName, _user->nameOrPhone, _user->username); - closeBox(); - return true; - } else if (err == "NO_CHAT_TITLE") { - _first->setFocus(); - _first->showError(); - return true; - } - _first->setFocus(); - return true; -} - -void AddContactBox::onImportDone(const MTPcontacts_ImportedContacts &res) { +void AddContactBox::importDone(const MTPcontacts_ImportedContacts &result) { if (!isBoxShown() || !App::main()) return; - const auto &d = res.c_contacts_importedContacts(); - Auth().data().processUsers(d.vusers()); + const auto &d = result.c_contacts_importedContacts(); + _session->data().processUsers(d.vusers()); const auto &v = d.vimported().v; const auto user = [&]() -> UserData* { if (!v.isEmpty()) { auto &c = v.front().c_importedContact(); if (c.vclient_id().v == _contactId) { - return Auth().data().userLoaded(c.vuser_id().v); + return _session->data().userLoaded(c.vuser_id().v); } } return nullptr; @@ -377,12 +363,6 @@ void AddContactBox::onImportDone(const MTPcontacts_ImportedContacts &res) { } } -void AddContactBox::onSaveUserDone(const MTPcontacts_ImportedContacts &res) { - auto &d = res.c_contacts_importedContacts(); - Auth().data().processUsers(d.vusers()); - closeBox(); -} - void AddContactBox::retry() { _addRequest = 0; _contactId = 0; @@ -402,19 +382,19 @@ void AddContactBox::updateButtons() { if (_retrying) { addButton(tr::lng_try_other_contact(), [=] { retry(); }); } else { - addButton( - _user ? tr::lng_settings_save() : tr::lng_add_contact(), - [=] { save(); }); + addButton(tr::lng_add_contact(), [=] { save(); }); addButton(tr::lng_cancel(), [=] { closeBox(); }); } } GroupInfoBox::GroupInfoBox( QWidget*, + not_null session, Type type, const QString &title, Fn)> channelDone) -: _type(type) +: _session(session) +, _type(type) , _initialTitle(title) , _channelDone(std::move(channelDone)) { } @@ -537,7 +517,7 @@ void GroupInfoBox::createGroup( auto image = _photo->takeResultImage(); Ui::hideLayer(); - Auth().api().applyUpdates(result); + _session->api().applyUpdates(result); auto success = base::make_optional(&result) | [](auto updates) -> std::optional*> { @@ -557,8 +537,8 @@ void GroupInfoBox::createGroup( ? base::make_optional(chats) : std::nullopt; } - | [](auto chats) { - return Auth().data().chat(chats->front().c_chat().vid().v); + | [&](auto chats) { + return _session->data().chat(chats->front().c_chat().vid().v); } | [&](not_null chat) { if (!image.isNull()) { @@ -646,7 +626,7 @@ void GroupInfoBox::createChannel(const QString &title, const QString &descriptio MTPInputGeoPoint(), // geo_point MTPstring() // address )).done([=](const MTPUpdates &result) { - Auth().api().applyUpdates(result); + _session->api().applyUpdates(result); const auto success = base::make_optional(&result) | [](auto updates) -> std::optional*> { @@ -664,8 +644,8 @@ void GroupInfoBox::createChannel(const QString &title, const QString &descriptio ? base::make_optional(chats) : std::nullopt; } - | [](auto chats) { - return Auth().data().channel(chats->front().c_channel().vid().v); + | [&](auto chats) { + return _session->data().channel(chats->front().c_channel().vid().v); } | [&](not_null channel) { auto image = _photo->takeResultImage(); @@ -729,10 +709,14 @@ void GroupInfoBox::updateMaxHeight() { setDimensions(st::boxWideWidth, newHeight); } -SetupChannelBox::SetupChannelBox(QWidget*, ChannelData *channel, bool existing) +SetupChannelBox::SetupChannelBox( + QWidget*, + not_null channel, + bool existing) : _channel(channel) , _existing(existing) -, _privacyGroup(std::make_shared>(Privacy::Public)) +, _privacyGroup( + std::make_shared>(Privacy::Public)) , _public( this, _privacyGroup, @@ -749,7 +733,12 @@ SetupChannelBox::SetupChannelBox(QWidget*, ChannelData *channel, bool existing) ? tr::lng_create_private_group_title : tr::lng_create_private_channel_title)(tr::now), st::defaultBoxCheckbox) -, _aboutPublicWidth(st::boxWideWidth - st::boxPadding.left() - st::boxButtonPadding.right() - st::newGroupPadding.left() - st::defaultRadio.diameter - st::defaultBoxCheckbox.textPosition.x()) +, _aboutPublicWidth(st::boxWideWidth + - st::boxPadding.left() + - st::boxButtonPadding.right() + - st::newGroupPadding.left() + - st::defaultRadio.diameter + - st::defaultBoxCheckbox.textPosition.x()) , _aboutPublic( st::defaultTextStyle, (channel->isMegagroup() @@ -1003,11 +992,16 @@ void SetupChannelBox::privacyChanged(Privacy value) { if (value == Privacy::Public) { if (_tooMuchUsernames) { _privacyGroup->setValue(Privacy::Private); - Ui::show(Box(crl::guard(this, [this] { + const auto callback = crl::guard(this, [=] { _tooMuchUsernames = false; _privacyGroup->setValue(Privacy::Public); check(); - })), LayerOption::KeepOther); + }); + Ui::show( + Box( + &_channel->session(), + callback), + LayerOption::KeepOther); return; } _link->show(); @@ -1096,23 +1090,30 @@ bool SetupChannelBox::onCheckFail(const RPCError &error) { } void SetupChannelBox::showRevokePublicLinkBoxForEdit() { - closeBox(); - Ui::show(Box([channel = _channel, existing = _existing]() { + const auto channel = _channel; + const auto existing = _existing; + const auto callback = [=] { Ui::show( Box(channel, existing), LayerOption::KeepOther); - }), LayerOption::KeepOther); + }; + closeBox(); + Ui::show( + Box( + &channel->session(), + callback), + LayerOption::KeepOther); } bool SetupChannelBox::onFirstCheckFail(const RPCError &error) { if (MTP::isDefaultHandledError(error)) return false; _checkRequestId = 0; - QString err(error.type()); - if (err == qstr("CHANNEL_PUBLIC_GROUP_NA")) { + const auto &type = error.type(); + if (type == qstr("CHANNEL_PUBLIC_GROUP_NA")) { Ui::hideLayer(); return true; - } else if (err == qstr("CHANNELS_ADMIN_PUBLIC_TOO_MUCH")) { + } else if (type == qstr("CHANNELS_ADMIN_PUBLIC_TOO_MUCH")) { if (_existing) { showRevokePublicLinkBoxForEdit(); } else { @@ -1248,7 +1249,12 @@ bool EditNameBox::saveSelfFail(const RPCError &error) { return true; } -RevokePublicLinkBox::Inner::Inner(QWidget *parent, Fn revokeCallback) : TWidget(parent) +RevokePublicLinkBox::Inner::Inner( + QWidget *parent, + not_null session, + Fn revokeCallback) +: TWidget(parent) +, _session(session) , _rowHeight(st::contactsPadding.top() + st::contactsPhotoSize + st::contactsPadding.bottom()) , _revokeWidth(st::normalFont->width(tr::lng_channels_too_much_public_revoke(tr::now))) , _revokeCallback(std::move(revokeCallback)) { @@ -1263,7 +1269,7 @@ RevokePublicLinkBox::Inner::Inner(QWidget *parent, Fn revokeCallback) : return data.vchats().v; }); for (const auto &chat : chats) { - if (const auto peer = Auth().data().processChat(chat)) { + if (const auto peer = _session->data().processChat(chat)) { if (!peer->isChannel() || peer->userName().isEmpty()) { continue; } @@ -1289,8 +1295,10 @@ RevokePublicLinkBox::Inner::Inner(QWidget *parent, Fn revokeCallback) : RevokePublicLinkBox::RevokePublicLinkBox( QWidget*, + not_null session, Fn revokeCallback) -: _aboutRevoke( +: _session(session) +, _aboutRevoke( this, tr::lng_channels_too_much_public_about(tr::now), st::aboutRevokePublicLabel) @@ -1299,7 +1307,7 @@ RevokePublicLinkBox::RevokePublicLinkBox( void RevokePublicLinkBox::prepare() { _innerTop = st::boxPadding.top() + _aboutRevoke->height() + st::boxPadding.top(); - _inner = setInnerWidget(object_ptr(this, [=] { + _inner = setInnerWidget(object_ptr(this, _session, [=] { const auto callback = _revokeCallback; closeBox(); if (callback) { @@ -1309,7 +1317,7 @@ void RevokePublicLinkBox::prepare() { addButton(tr::lng_cancel(), [=] { closeBox(); }); - subscribe(Auth().downloaderTaskFinished(), [=] { update(); }); + subscribe(_session->downloaderTaskFinished(), [=] { update(); }); _inner->resizeToWidth(st::boxWideWidth); setDimensions(st::boxWideWidth, _innerTop + _inner->height()); @@ -1323,7 +1331,7 @@ void RevokePublicLinkBox::Inner::updateSelected() { auto point = mapFromGlobal(QCursor::pos()); PeerData *selected = nullptr; auto top = _rowsTop; - for_const (auto &row, _rows) { + for (const auto &row : _rows) { auto revokeLink = rtlrect(width() - st::contactsPadding.right() - st::contactsCheckPosition.x() - _revokeWidth, top + st::contactsPadding.top() + (st::contactsPhotoSize - st::normalFont->height) / 2, _revokeWidth, st::normalFont->height, width()); if (revokeLink.contains(point)) { selected = row.peer; diff --git a/Telegram/SourceFiles/boxes/add_contact_box.h b/Telegram/SourceFiles/boxes/add_contact_box.h index 10aec92c66..fc0af49fa6 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.h +++ b/Telegram/SourceFiles/boxes/add_contact_box.h @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL class ConfirmBox; class PeerListBox; +class AuthSession; constexpr auto kMaxBioLength = 70; @@ -43,10 +44,15 @@ void ShowAddParticipantsError( not_null chat, const std::vector> &users); -class AddContactBox : public BoxContent, public RPCSender { +class AddContactBox : public BoxContent { public: - AddContactBox(QWidget*, QString fname = QString(), QString lname = QString(), QString phone = QString()); - AddContactBox(QWidget*, UserData *user); + AddContactBox(QWidget*, not_null session); + AddContactBox( + QWidget*, + not_null session, + QString fname, + QString lname, + QString phone); protected: void prepare() override; @@ -61,12 +67,9 @@ private: void retry(); void save(); void updateButtons(); - void onImportDone(const MTPcontacts_ImportedContacts &res); + void importDone(const MTPcontacts_ImportedContacts &result); - void onSaveUserDone(const MTPcontacts_ImportedContacts &res); - bool onSaveUserFail(const RPCError &e); - - UserData *_user = nullptr; + const not_null _session; object_ptr _first; object_ptr _last; @@ -91,6 +94,7 @@ public: }; GroupInfoBox( QWidget*, + not_null session, Type type, const QString &title = QString(), Fn)> channelDone = nullptr); @@ -110,6 +114,8 @@ private: void descriptionResized(); void updateMaxHeight(); + const not_null _session; + Type _type = Type::Group; QString _initialTitle; Fn)> _channelDone; @@ -126,7 +132,10 @@ private: class SetupChannelBox : public BoxContent, public RPCSender { public: - SetupChannelBox(QWidget*, ChannelData *channel, bool existing = false); + SetupChannelBox( + QWidget*, + not_null channel, + bool existing = false); void setInnerFocus() override; @@ -162,7 +171,8 @@ private: void showRevokePublicLinkBoxForEdit(); - ChannelData *_channel = nullptr; + const not_null _channel; + bool _existing = false; std::shared_ptr> _privacyGroup; @@ -215,7 +225,10 @@ private: class RevokePublicLinkBox : public BoxContent, public RPCSender { public: - RevokePublicLinkBox(QWidget*, Fn revokeCallback); + RevokePublicLinkBox( + QWidget*, + not_null session, + Fn revokeCallback); protected: void prepare() override; @@ -223,6 +236,8 @@ protected: void resizeEvent(QResizeEvent *e) override; private: + const not_null _session; + object_ptr _aboutRevoke; class Inner; diff --git a/Telegram/SourceFiles/boxes/peers/edit_linked_chat_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_linked_chat_box.cpp index 49e0a768e4..5618eeb17c 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_linked_chat_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_linked_chat_box.cpp @@ -245,6 +245,7 @@ object_ptr SetupCreateGroup( const auto guarded = crl::guard(parent, callback); Ui::show( Box( + &channel->session(), GroupInfoBox::Type::Megagroup, channel->name + " Chat", guarded), diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp index c717f48a2c..37fa9b9212 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp @@ -464,7 +464,9 @@ void Controller::askUsernameRevoke() { checkUsernameAvailability(); }); Ui::show( - Box(std::move(revokeCallback)), + Box( + &_peer->session(), + std::move(revokeCallback)), LayerOption::KeepOther); } diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index 18c2c906e1..9688a32e25 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -217,7 +217,7 @@ StickersListWidget::Footer::Footer(not_null parent) _iconsLeft = _iconsRight = st::emojiCategorySkip + st::stickerIconWidth; - subscribe(Auth().downloaderTaskFinished(), [this] { + subscribe(_pan->session().downloaderTaskFinished(), [=] { update(); }); } @@ -689,7 +689,7 @@ void StickersListWidget::Footer::paintSearchIcon(Painter &p) const { } void StickersListWidget::Footer::paintFeaturedStickerSetsBadge(Painter &p, int iconLeft) const { - if (auto unread = Auth().data().featuredStickerSetsUnreadCount()) { + if (const auto unread = _pan->session().data().featuredStickerSetsUnreadCount()) { Dialogs::Layout::UnreadBadgeStyle unreadSt; unreadSt.sizeId = Dialogs::Layout::UnreadBadgeInStickersPanel; unreadSt.size = st::stickersSettingsUnreadSize; @@ -837,7 +837,7 @@ StickersListWidget::StickersListWidget( Ui::show(Box(StickersBox::Section::Installed)); }); - subscribe(Auth().downloaderTaskFinished(), [=] { + subscribe(session().downloaderTaskFinished(), [=] { if (isVisible()) { update(); readVisibleFeatured(getVisibleTop(), getVisibleBottom()); @@ -850,6 +850,10 @@ StickersListWidget::StickersListWidget( })); } +AuthSession &StickersListWidget::session() const { + return controller()->session(); +} + rpl::producer> StickersListWidget::chosen() const { return _chosen.events(); } @@ -923,7 +927,7 @@ void StickersListWidget::readVisibleFeatured( } } if (loaded == count) { - Auth().api().readFeaturedSetDelayed(set.id); + session().api().readFeaturedSetDelayed(set.id); } } } @@ -1178,7 +1182,7 @@ void StickersListWidget::fillLocalSearchRows(const QString &query) { return true; }; - const auto &sets = Auth().data().stickerSets(); + const auto &sets = session().data().stickerSets(); for (const auto &[setId, titleWords] : _searchIndex) { if (allSearchWordsInTitle(titleWords)) { if (const auto it = sets.find(setId); it != sets.end()) { @@ -1190,7 +1194,7 @@ void StickersListWidget::fillLocalSearchRows(const QString &query) { void StickersListWidget::fillCloudSearchRows( const std::vector &cloudSets) { - const auto &sets = Auth().data().stickerSets(); + const auto &sets = session().data().stickerSets(); for (const auto setId : cloudSets) { if (const auto it = sets.find(setId); it != sets.end()) { addSearchRow(&*it); @@ -1266,7 +1270,7 @@ void StickersListWidget::searchResultsDone( setData = &d.vset().c_stickerSet(); } for (const auto &cover : d.vcovers().v) { - const auto document = Auth().data().processDocument(cover); + const auto document = session().data().processDocument(cover); if (document->sticker()) { covers.push_back(document); } @@ -1932,7 +1936,7 @@ void StickersListWidget::removeRecentSticker(int section, int index) { break; } } - auto &sets = Auth().data().stickerSetsRef(); + auto &sets = session().data().stickerSetsRef(); auto it = sets.find(Stickers::CustomSetId); if (it != sets.cend()) { for (int i = 0, l = it->stickers.size(); i < l; ++i) { @@ -1965,7 +1969,7 @@ void StickersListWidget::removeFavedSticker(int section, int index) { const auto &sticker = _mySets[section].stickers[index]; const auto document = sticker.document; Stickers::SetFaved(document, false); - Auth().api().toggleFavedSticker( + session().api().toggleFavedSticker( document, Data::FileOriginStickerSet(Stickers::FavedSetId, 0), false); @@ -2077,12 +2081,12 @@ void StickersListWidget::refreshStickers() { void StickersListWidget::refreshMySets() { _mySets.clear(); _favedStickersMap.clear(); - _mySets.reserve(Auth().data().stickerSetsOrder().size() + 3); + _mySets.reserve(session().data().stickerSetsOrder().size() + 3); refreshFavedStickers(); refreshRecentStickers(false); refreshMegagroupStickers(GroupStickersPlace::Visible); - for (const auto setId : Auth().data().stickerSetsOrder()) { + for (const auto setId : session().data().stickerSetsOrder()) { const auto externalLayout = false; appendSet(_mySets, setId, externalLayout, AppendSkip::Archived); } @@ -2091,9 +2095,9 @@ void StickersListWidget::refreshMySets() { void StickersListWidget::refreshFeaturedSets() { _featuredSets.clear(); - _featuredSets.reserve(Auth().data().featuredStickerSetsOrder().size()); + _featuredSets.reserve(session().data().featuredStickerSetsOrder().size()); - for (const auto setId : Auth().data().featuredStickerSetsOrder()) { + for (const auto setId : session().data().featuredStickerSetsOrder()) { const auto externalLayout = true; appendSet(_featuredSets, setId, externalLayout, AppendSkip::Installed); } @@ -2102,7 +2106,7 @@ void StickersListWidget::refreshFeaturedSets() { void StickersListWidget::refreshSearchSets() { refreshSearchIndex(); - const auto &sets = Auth().data().stickerSets(); + const auto &sets = session().data().stickerSets(); for (auto &set : _searchSets) { if (const auto it = sets.find(set.id); it != sets.end()) { set.flags = it->flags; @@ -2226,7 +2230,7 @@ void StickersListWidget::appendSet( uint64 setId, bool externalLayout, AppendSkip skip) { - auto &sets = Auth().data().stickerSets(); + auto &sets = session().data().stickerSets(); auto it = sets.constFind(setId); if (it == sets.cend() || it->stickers.isEmpty()) { return; @@ -2267,7 +2271,7 @@ auto StickersListWidget::collectRecentStickers() -> std::vector { _custom.clear(); auto result = std::vector(); - const auto &sets = Auth().data().stickerSets(); + const auto &sets = session().data().stickerSets(); const auto &recent = Stickers::GetRecentPack(); const auto customIt = sets.constFind(Stickers::CustomSetId); const auto cloudIt = sets.constFind(Stickers::CloudRecentSetId); @@ -2353,7 +2357,7 @@ void StickersListWidget::refreshRecentStickers(bool performResize) { void StickersListWidget::refreshFavedStickers() { clearSelection(); - auto &sets = Auth().data().stickerSets(); + auto &sets = session().data().stickerSets(); auto it = sets.constFind(Stickers::FavedSetId); if (it == sets.cend() || it->stickers.isEmpty()) { return; @@ -2384,7 +2388,7 @@ void StickersListWidget::refreshMegagroupStickers(GroupStickersPlace place) { }; if (_megagroupSet->mgInfo->stickerSet.type() == mtpc_inputStickerSetEmpty) { if (canEdit) { - auto hidden = Auth().settings().isGroupStickersSectionHidden(_megagroupSet->id); + auto hidden = session().settings().isGroupStickersSectionHidden(_megagroupSet->id); if (isShownHere(hidden)) { const auto shortName = QString(); const auto thumbnail = ImagePtr(); @@ -2402,10 +2406,10 @@ void StickersListWidget::refreshMegagroupStickers(GroupStickersPlace place) { } return; } - auto hidden = Auth().settings().isGroupStickersSectionHidden(_megagroupSet->id); + auto hidden = session().settings().isGroupStickersSectionHidden(_megagroupSet->id); auto removeHiddenForGroup = [this, &hidden] { if (hidden) { - Auth().settings().removeGroupStickersSectionHidden(_megagroupSet->id); + session().settings().removeGroupStickersSectionHidden(_megagroupSet->id); Local::writeUserSettings(); hidden = false; } @@ -2417,7 +2421,7 @@ void StickersListWidget::refreshMegagroupStickers(GroupStickersPlace place) { return; } auto &set = _megagroupSet->mgInfo->stickerSet.c_inputStickerSetID(); - auto &sets = Auth().data().stickerSets(); + auto &sets = session().data().stickerSets(); auto it = sets.constFind(set.vid().v); if (it != sets.cend()) { auto isInstalled = (it->flags & MTPDstickerSet::Flag::f_installed_date) @@ -2461,7 +2465,7 @@ void StickersListWidget::refreshMegagroupStickers(GroupStickersPlace place) { void StickersListWidget::fillIcons(QList &icons) { icons.clear(); icons.reserve(_mySets.size() + 1); - if (Auth().data().featuredStickerSetsUnreadCount() + if (session().data().featuredStickerSetsUnreadCount() && !_featuredSets.empty()) { icons.push_back(StickerIcon(Stickers::FeaturedSetId)); } @@ -2510,7 +2514,7 @@ void StickersListWidget::fillIcons(QList &icons) { pixh)); } - if (!Auth().data().featuredStickerSetsUnreadCount() + if (!session().data().featuredStickerSetsUnreadCount() && !_featuredSets.empty()) { icons.push_back(StickerIcon(Stickers::FeaturedSetId)); } @@ -2761,7 +2765,7 @@ void StickersListWidget::displaySet(uint64 setId) { return; } } - auto &sets = Auth().data().stickerSets(); + auto &sets = session().data().stickerSets(); auto it = sets.constFind(setId); if (it != sets.cend()) { _displayingSetId = setId; @@ -2776,7 +2780,7 @@ void StickersListWidget::displaySet(uint64 setId) { } void StickersListWidget::installSet(uint64 setId) { - auto &sets = Auth().data().stickerSets(); + auto &sets = session().data().stickerSets(); auto it = sets.constFind(setId); if (it != sets.cend()) { const auto input = Stickers::inputSetId(*it); @@ -2815,7 +2819,7 @@ void StickersListWidget::sendInstallRequest( void StickersListWidget::removeMegagroupSet(bool locally) { if (locally) { - Auth().settings().setGroupStickersSectionHidden(_megagroupSet->id); + session().settings().setGroupStickersSectionHidden(_megagroupSet->id); Local::writeUserSettings(); refreshStickers(); return; @@ -2825,7 +2829,7 @@ void StickersListWidget::removeMegagroupSet(bool locally) { Expects(group->mgInfo != nullptr); if (group->mgInfo->stickerSet.type() != mtpc_inputStickerSetEmpty) { - Auth().api().setGroupStickerSet(group, MTP_inputStickerSetEmpty()); + session().api().setGroupStickerSet(group, MTP_inputStickerSetEmpty()); } Ui::hideLayer(); _removingSetId = 0; @@ -2837,14 +2841,14 @@ void StickersListWidget::removeMegagroupSet(bool locally) { } void StickersListWidget::removeSet(uint64 setId) { - auto &sets = Auth().data().stickerSets(); + auto &sets = session().data().stickerSets(); auto it = sets.constFind(setId); if (it != sets.cend()) { _removingSetId = it->id; auto text = tr::lng_stickers_remove_pack(tr::now, lt_sticker_pack, it->title); Ui::show(Box(text, tr::lng_stickers_remove_pack_confirm(tr::now), crl::guard(this, [=] { Ui::hideLayer(); - auto &sets = Auth().data().stickerSetsRef(); + auto &sets = session().data().stickerSetsRef(); auto it = sets.find(_removingSetId); if (it != sets.cend()) { if (it->id && it->access) { @@ -2871,8 +2875,8 @@ void StickersListWidget::removeSet(uint64 setId) { // && !(it->flags & MTPDstickerSet_ClientFlag::f_special)) { // sets.erase(it); //} - int removeIndex = Auth().data().stickerSetsOrder().indexOf(_removingSetId); - if (removeIndex >= 0) Auth().data().stickerSetsOrderRef().removeAt(removeIndex); + int removeIndex = session().data().stickerSetsOrder().indexOf(_removingSetId); + if (removeIndex >= 0) session().data().stickerSetsOrderRef().removeAt(removeIndex); refreshStickers(); Local::writeInstalledStickers(); if (writeRecent) Local::writeUserSettings(); diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h index 220855eed4..835a615299 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h @@ -12,6 +12,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/variant.h" #include "base/timer.h" +class AuthSession; + namespace Window { class SessionController; } // namespace Window @@ -40,6 +42,8 @@ public: QWidget *parent, not_null controller); + AuthSession &session() const; + rpl::producer> chosen() const; rpl::producer<> scrollUpdated() const; rpl::producer<> checkForHide() const; diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp index 0ed13b29a8..57724bbf4f 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp @@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/discrete_sliders.h" #include "ui/widgets/scroll_area.h" #include "ui/image/image_prepare.h" +#include "window/window_session_controller.h" #include "storage/localstorage.h" #include "data/data_channel.h" #include "lang/lang_keys.h" @@ -279,17 +280,18 @@ TabbedSelector::TabbedSelector( not_null controller, Mode mode) : RpWidget(parent) +, _controller(controller) , _mode(mode) , _topShadow(full() ? object_ptr(this) : nullptr) , _bottomShadow(this) , _scroll(this, st::emojiScroll) , _tabs { { - createTab(SelectorTab::Emoji, controller), - createTab(SelectorTab::Stickers, controller), - createTab(SelectorTab::Gifs, controller), + createTab(SelectorTab::Emoji), + createTab(SelectorTab::Stickers), + createTab(SelectorTab::Gifs), } } , _currentTabType(full() - ? Auth().settings().selectorTab() + ? session().settings().selectorTab() : SelectorTab::Emoji) { resize(st::emojiPanWidth, st::emojiPanMaxHeight); @@ -355,7 +357,7 @@ TabbedSelector::TabbedSelector( Notify::PeerUpdate::Flag::RightsChanged, handleUpdate)); - Auth().api().stickerSetInstalled( + session().api().stickerSetInstalled( ) | rpl::start_with_next([this](uint64 setId) { _tabsSlider->setActiveSection( static_cast(SelectorTab::Stickers)); @@ -368,22 +370,28 @@ TabbedSelector::TabbedSelector( showAll(); } -TabbedSelector::Tab TabbedSelector::createTab(SelectorTab type, not_null controller) { -auto createWidget = [&]() -> object_ptr { - if (!full() && type != SelectorTab::Emoji) { - return { nullptr }; - } - switch (type) { - case SelectorTab::Emoji: - return object_ptr(this, controller); - case SelectorTab::Stickers: - return object_ptr(this, controller); - case SelectorTab::Gifs: - return object_ptr(this, controller); - } - Unexpected("Type in TabbedSelector::createTab."); -}; -return Tab{ type, createWidget() }; +TabbedSelector::~TabbedSelector() = default; + +AuthSession &TabbedSelector::session() const { + return _controller->session(); +} + +TabbedSelector::Tab TabbedSelector::createTab(SelectorTab type) { + auto createWidget = [&]() -> object_ptr { + if (!full() && type != SelectorTab::Emoji) { + return { nullptr }; + } + switch (type) { + case SelectorTab::Emoji: + return object_ptr(this, _controller); + case SelectorTab::Stickers: + return object_ptr(this, _controller); + case SelectorTab::Gifs: + return object_ptr(this, _controller); + } + Unexpected("Type in TabbedSelector::createTab."); + }; + return Tab{ type, createWidget() }; } bool TabbedSelector::full() const { @@ -602,8 +610,6 @@ QRect TabbedSelector::rectForFloatPlayer() const { return mapToGlobal(_scroll->geometry()); } -TabbedSelector::~TabbedSelector() = default; - void TabbedSelector::hideFinished() { for (auto &tab : _tabs) { if (!tab.widget()) { @@ -617,7 +623,7 @@ void TabbedSelector::hideFinished() { void TabbedSelector::showStarted() { if (full()) { - Auth().api().updateStickers(); + session().api().updateStickers(); } currentTab()->widget()->refreshRecent(); currentTab()->widget()->preloadImages(); @@ -818,8 +824,8 @@ void TabbedSelector::switchTab() { update(); if (full()) { - Auth().settings().setSelectorTab(_currentTabType); - Auth().saveSettingsDelayed(); + session().settings().setSelectorTab(_currentTabType); + session().saveSettingsDelayed(); } } diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h index e0b9266d8c..a497ad6aed 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h @@ -55,6 +55,9 @@ public: QWidget *parent, not_null controller, Mode mode = Mode::Full); + ~TabbedSelector(); + + AuthSession &session() const; rpl::producer emojiChosen() const; rpl::producer> fileChosen() const; @@ -99,8 +102,6 @@ public: return _showRequests.events(); } - ~TabbedSelector(); - class Inner; class InnerFooter; @@ -146,9 +147,7 @@ private: }; bool full() const; - Tab createTab( - SelectorTab type, - not_null controller); + Tab createTab(SelectorTab type); void paintSlideFrame(Painter &p); void paintContent(Painter &p); @@ -185,6 +184,8 @@ private: not_null stickers() const; not_null gifs() const; + const not_null _controller; + Mode _mode = Mode::Full; int _roundRadius = 0; int _footerTop = 0; diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index 88f9e9e137..ec4ffd4bdf 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -737,11 +737,11 @@ void DocumentData::automaticLoad( const auto shouldLoadFromCloud = !Data::IsExecutableName(filename) && (item ? Data::AutoDownload::Should( - Auth().settings().autoDownload(), + session().settings().autoDownload(), item->history()->peer, this) : Data::AutoDownload::Should( - Auth().settings().autoDownload(), + session().settings().autoDownload(), this)); const auto loadFromCloud = shouldLoadFromCloud ? LoadFromCloudOrLocal diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index fec417e576..0ed4e39775 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -1645,7 +1645,7 @@ bool Session::checkEntitiesAndViewsUpdate(const MTPDmessage &data) { } requestItemTextRefresh(existing); if (existing->mainView()) { - App::checkSavedGif(existing); + checkSavedGif(existing); return true; } return false; @@ -1653,6 +1653,40 @@ bool Session::checkEntitiesAndViewsUpdate(const MTPDmessage &data) { return false; } +void Session::addSavedGif(not_null document) { + const auto index = _savedGifs.indexOf(document); + if (!index) { + return; + } + if (index > 0) { + _savedGifs.remove(index); + } + _savedGifs.push_front(document); + if (_savedGifs.size() > Global::SavedGifsLimit()) { + _savedGifs.pop_back(); + } + Local::writeSavedGifs(); + + notifySavedGifsUpdated(); + setLastSavedGifsUpdate(0); + session().api().updateStickers(); +} + +void Session::checkSavedGif(not_null item) { + if (item->Has() + || (!item->out() + && item->history()->peer != session().user())) { + return; + } + if (const auto media = item->media()) { + if (const auto document = media->document()) { + if (document->isGifv()) { + addSavedGif(document); + } + } + } +} + void Session::updateEditedMessage(const MTPMessage &data) { const auto existing = data.match([](const MTPDmessageEmpty &) -> HistoryItem* { diff --git a/Telegram/SourceFiles/data/data_session.h b/Telegram/SourceFiles/data/data_session.h index 7cc8a67c5d..119424e811 100644 --- a/Telegram/SourceFiles/data/data_session.h +++ b/Telegram/SourceFiles/data/data_session.h @@ -309,6 +309,9 @@ public: return _savedGifs; } + void addSavedGif(not_null document); + void checkSavedGif(not_null item); + HistoryItemsList idsToItems(const MessageIdsList &ids) const; MessageIdsList itemsToIds(const HistoryItemsList &items) const; MessageIdsList itemOrItsGroup(not_null item) const; diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index fc61c06338..7c41a1aec8 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -115,7 +115,9 @@ void activateBotCommand( Ui::showPeerHistory(history, ShowAtTheEndMsgId); auto options = ApiWrap::SendOptions(history); options.replyTo = msgId; - history->session().api().shareContact(Auth().user(), options); + history->session().api().shareContact( + history->session().user(), + options); })); } break; 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 ab1104453d..3ecb283c99 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -227,25 +227,25 @@ InnerWidget::InnerWidget( , _idManager(_history->adminLogIdManager()) { setMouseTracking(true); _scrollDateHideTimer.setCallback([this] { scrollDateHideByTimer(); }); - Auth().data().viewRepaintRequest( + session().data().viewRepaintRequest( ) | rpl::start_with_next([this](auto view) { if (view->delegate() == this) { repaintItem(view); } }, lifetime()); - Auth().data().viewResizeRequest( + session().data().viewResizeRequest( ) | rpl::start_with_next([this](auto view) { if (view->delegate() == this) { resizeItem(view); } }, lifetime()); - Auth().data().itemViewRefreshRequest( + session().data().itemViewRefreshRequest( ) | rpl::start_with_next([this](auto item) { if (const auto view = viewForItem(item)) { refreshItem(view); } }, lifetime()); - Auth().data().viewLayoutChanged( + session().data().viewLayoutChanged( ) | rpl::start_with_next([this](auto view) { if (view->delegate() == this) { if (view->isUnderCursor()) { @@ -253,7 +253,7 @@ InnerWidget::InnerWidget( } } }, lifetime()); - Auth().data().animationPlayInlineRequest( + session().data().animationPlayInlineRequest( ) | rpl::start_with_next([this](auto item) { if (const auto view = viewForItem(item)) { if (const auto media = view->media()) { @@ -261,7 +261,7 @@ InnerWidget::InnerWidget( } } }, lifetime()); - subscribe(Auth().data().queryItemVisibility(), [this](const Data::Session::ItemVisibilityQuery &query) { + subscribe(session().data().queryItemVisibility(), [this](const Data::Session::ItemVisibilityQuery &query) { if (_history != query.item->history() || !query.item->isLogEntry() || !isVisible()) { return; } @@ -277,6 +277,10 @@ InnerWidget::InnerWidget( requestAdmins(); } +AuthSession &InnerWidget::session() const { + return _controller->session(); +} + void InnerWidget::visibleTopBottomUpdated( int visibleTop, int visibleBottom) { @@ -389,7 +393,7 @@ void InnerWidget::requestAdmins() { MTP_int(kMaxChannelAdmins), MTP_int(participantsHash) )).done([this](const MTPchannels_ChannelParticipants &result) { - Auth().api().parseChannelParticipants(_channel, result, [&]( + session().api().parseChannelParticipants(_channel, result, [&]( int availableCount, const QVector &list) { auto filtered = ( @@ -407,7 +411,7 @@ void InnerWidget::requestAdmins() { return std::make_pair(userId, canEdit); }) | ranges::view::transform([&](auto &&pair) { return std::make_pair( - Auth().data().userLoaded(pair.first), + session().data().userLoaded(pair.first), pair.second); }) | ranges::view::filter([&](auto &&pair) { return (pair.first != nullptr); @@ -421,7 +425,7 @@ void InnerWidget::requestAdmins() { } }); if (_admins.empty()) { - _admins.push_back(Auth().user()); + _admins.push_back(session().user()); } if (_showFilterCallback) { showFilter(std::move(_showFilterCallback)); @@ -514,7 +518,7 @@ bool InnerWidget::elementUnderCursor( void InnerWidget::elementAnimationAutoplayAsync( not_null view) { crl::on_main(this, [this, msgId = view->data()->fullId()] { - if (const auto item = Auth().data().message(msgId)) { + if (const auto item = session().data().message(msgId)) { if (const auto view = viewForItem(item)) { if (const auto media = view->media()) { media->autoplayAnimation(); @@ -1144,7 +1148,7 @@ void InnerWidget::showContextInFolder(not_null document) { } void InnerWidget::openContextGif(FullMsgId itemId) { - if (const auto item = Auth().data().message(itemId)) { + if (const auto item = session().data().message(itemId)) { if (const auto media = item->media()) { if (const auto document = media->document()) { Core::App().showDocument(document, item); @@ -1154,7 +1158,7 @@ void InnerWidget::openContextGif(FullMsgId itemId) { } void InnerWidget::copyContextText(FullMsgId itemId) { - if (const auto item = Auth().data().message(itemId)) { + if (const auto item = session().data().message(itemId)) { SetClipboardText(HistoryItemText(item)); } } @@ -1612,7 +1616,7 @@ void InnerWidget::performDrag() { // if (uponSelected && !Adaptive::OneColumn()) { // auto selectedState = getSelectionState(); // if (selectedState.count > 0 && selectedState.count == selectedState.canForwardCount) { - // Auth().data().setMimeForwardIds(getSelectedItems()); + // session().data().setMimeForwardIds(getSelectedItems()); // mimeData->setData(qsl("application/x-td-forward"), "1"); // } // } @@ -1626,8 +1630,8 @@ void InnerWidget::performDrag() { // if (_mouseCursorState == CursorState::Date // || (pressedMedia && pressedMedia->dragItem())) { // forwardMimeType = qsl("application/x-td-forward"); - // Auth().data().setMimeForwardIds( - // Auth().data().itemOrItsGroup(pressedItem->data())); + // session().data().setMimeForwardIds( + // session().data().itemOrItsGroup(pressedItem->data())); // } // } // if (auto pressedLnkItem = App::pressedLinkItem()) { @@ -1635,7 +1639,7 @@ void InnerWidget::performDrag() { // if (forwardMimeType.isEmpty() // && pressedMedia->dragItemByHandler(pressedHandler)) { // forwardMimeType = qsl("application/x-td-forward"); - // Auth().data().setMimeForwardIds( + // session().data().setMimeForwardIds( // { 1, pressedLnkItem->fullId() }); // } // } diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h index e0100add38..5f34d59fee 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h @@ -16,6 +16,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mtproto/sender.h" #include "base/timer.h" +class AuthSession; + namespace HistoryView { class Element; struct TextState; @@ -48,6 +50,8 @@ public: not_null controller, not_null channel); + AuthSession &session() const; + base::Observable showSearchSignal; base::Observable scrollToSignal; base::Observable cancelledSignal; diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index 231cf31cac..5e7f434895 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -1005,7 +1005,7 @@ void History::applyMessageChanges( if (data.type() == mtpc_messageService) { applyServiceChanges(item, data.c_messageService()); } - App::checkSavedGif(item); + owner().checkSavedGif(item); } void History::applyServiceChanges( diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 7c94a14053..5ecab7403e 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -153,31 +153,31 @@ HistoryInner::HistoryInner( subscribe(_controller->window()->dragFinished(), [this] { mouseActionUpdate(QCursor::pos()); }); - Auth().data().itemRemoved( + session().data().itemRemoved( ) | rpl::start_with_next( [this](auto item) { itemRemoved(item); }, lifetime()); - Auth().data().viewRemoved( + session().data().viewRemoved( ) | rpl::start_with_next( [this](auto view) { viewRemoved(view); }, lifetime()); - Auth().data().itemViewRefreshRequest( + session().data().itemViewRefreshRequest( ) | rpl::start_with_next( [this](auto item) { refreshView(item); }, lifetime()); rpl::merge( - Auth().data().historyUnloaded(), - Auth().data().historyCleared() + session().data().historyUnloaded(), + session().data().historyCleared() ) | rpl::filter([this](not_null history) { return (_history == history); }) | rpl::start_with_next([this] { mouseActionCancel(); }, lifetime()); - Auth().data().viewRepaintRequest( + session().data().viewRepaintRequest( ) | rpl::start_with_next([this](not_null view) { repaintItem(view); }, lifetime()); - Auth().data().viewLayoutChanged( + session().data().viewLayoutChanged( ) | rpl::filter([](not_null view) { return (view == view->data()->mainView()) && view->isUnderCursor(); }) | rpl::start_with_next([this](not_null view) { @@ -185,6 +185,10 @@ HistoryInner::HistoryInner( }, lifetime()); } +AuthSession &HistoryInner::session() const { + return _controller->session(); +} + void HistoryInner::messagesReceived( PeerData *peer, const QVector &messages) { @@ -493,7 +497,7 @@ TextSelection HistoryInner::computeRenderSelection( if (result != TextSelection() && result != FullSelection) { return result; } - if (const auto group = Auth().data().groups().find(item)) { + if (const auto group = session().data().groups().find(item)) { auto parts = TextSelection(); auto allFullSelected = true; const auto count = int(group->items.size()); @@ -681,7 +685,7 @@ void HistoryInner::paintEvent(QPaintEvent *e) { } if (!readMentions.empty() && App::wnd()->doWeReadMentions()) { - Auth().api().markMediaRead(readMentions); + session().api().markMediaRead(readMentions); } if (mtop >= 0 || htop >= 0) { @@ -1183,7 +1187,7 @@ std::unique_ptr HistoryInner::prepareDrag() { if (uponSelected && !Adaptive::OneColumn()) { auto selectedState = getSelectionState(); if (selectedState.count > 0 && selectedState.count == selectedState.canForwardCount) { - Auth().data().setMimeForwardIds(getSelectedItems()); + session().data().setMimeForwardIds(getSelectedItems()); mimeData->setData(qsl("application/x-td-forward"), "1"); } } @@ -1195,7 +1199,7 @@ std::unique_ptr HistoryInner::prepareDrag() { } auto forwardIds = MessageIdsList(); if (_mouseCursorState == CursorState::Date) { - forwardIds = Auth().data().itemOrItsGroup(_dragStateItem); + forwardIds = session().data().itemOrItsGroup(_dragStateItem); } else if (view->isHiddenByGroup() && pressedHandler) { forwardIds = MessageIdsList(1, _dragStateItem->fullId()); } else if (const auto media = view->media()) { @@ -1207,7 +1211,7 @@ std::unique_ptr HistoryInner::prepareDrag() { if (forwardIds.empty()) { return nullptr; } - Auth().data().setMimeForwardIds(std::move(forwardIds)); + session().data().setMimeForwardIds(std::move(forwardIds)); auto result = std::make_unique(); result->setData(qsl("application/x-td-forward"), "1"); if (const auto media = view->media()) { @@ -1534,7 +1538,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { }); if (photo->hasSticker) { _menu->addAction(tr::lng_context_attached_stickers(tr::now), [=] { - Auth().api().requestAttachedStickerSets(photo); + session().api().requestAttachedStickerSets(photo); }); } }; @@ -1628,7 +1632,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { } if (IsServerMsgId(item->id) && !item->serviceMsg()) { _menu->addAction(tr::lng_context_select_msg(tr::now), [=] { - if (const auto item = Auth().data().message(itemId)) { + if (const auto item = session().data().message(itemId)) { if (const auto view = item->mainView()) { changeSelection(&_selected, item, SelectAction::Select); repaintItem(item); @@ -1645,7 +1649,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { : App::hoveredLinkItem() ? App::hoveredLinkItem()->data().get() : nullptr) { - if (const auto group = Auth().data().groups().find(result)) { + if (const auto group = session().data().groups().find(result)) { return group->items.front(); } return result; @@ -1680,7 +1684,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { showStickerPackInfo(document); }); _menu->addAction(Stickers::IsFaved(document) ? tr::lng_faved_stickers_remove(tr::now) : tr::lng_faved_stickers_add(tr::now), [=] { - Auth().api().toggleFavedSticker( + session().api().toggleFavedSticker( document, itemId, !Stickers::IsFaved(document)); @@ -1696,7 +1700,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { if (!poll->closed) { if (poll->voted()) { _menu->addAction(tr::lng_polls_retract(tr::now), [=] { - Auth().api().sendPollVotes(itemId, {}); + session().api().sendPollVotes(itemId, {}); }); } if (item->canStopPoll()) { @@ -1768,7 +1772,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { } if (item->id > 0 && !item->serviceMsg()) { _menu->addAction(tr::lng_context_select_msg(tr::now), [=] { - if (const auto item = Auth().data().message(itemId)) { + if (const auto item = session().data().message(itemId)) { if (const auto view = item->mainView()) { changeSelectionAsGroup(&_selected, item, SelectAction::Select); repaintItem(view); @@ -1783,7 +1787,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { && !App::mousedItem()->data()->serviceMsg()) { const auto itemId = App::mousedItem()->data()->fullId(); _menu->addAction(tr::lng_context_select_msg(tr::now), [=] { - if (const auto item = Auth().data().message(itemId)) { + if (const auto item = session().data().message(itemId)) { if (const auto view = item->mainView()) { changeSelectionAsGroup(&_selected, item, SelectAction::Select); repaintItem(item); @@ -1857,7 +1861,7 @@ void HistoryInner::saveDocumentToFile( } void HistoryInner::openContextGif(FullMsgId itemId) { - if (const auto item = Auth().data().message(itemId)) { + if (const auto item = session().data().message(itemId)) { if (const auto media = item->media()) { if (const auto document = media->document()) { Core::App().showDocument(document, item); @@ -1867,18 +1871,18 @@ void HistoryInner::openContextGif(FullMsgId itemId) { } void HistoryInner::saveContextGif(FullMsgId itemId) { - if (const auto item = Auth().data().message(itemId)) { + if (const auto item = session().data().message(itemId)) { if (const auto media = item->media()) { if (const auto document = media->document()) { - Auth().api().toggleSavedGif(document, item->fullId(), true); + session().api().toggleSavedGif(document, item->fullId(), true); } } } } void HistoryInner::copyContextText(FullMsgId itemId) { - if (const auto item = Auth().data().message(itemId)) { - if (const auto group = Auth().data().groups().find(item)) { + if (const auto item = session().data().message(itemId)) { + if (const auto group = session().data().groups().find(item)) { SetClipboardText(HistoryGroupText(group)); } else { SetClipboardText(HistoryItemText(item)); @@ -1937,7 +1941,7 @@ TextForMimeData HistoryInner::getSelectedText() const { }; for (const auto [item, selection] : selected) { - if (const auto group = Auth().data().groups().find(item)) { + if (const auto group = session().data().groups().find(item)) { if (groups.contains(group)) { continue; } @@ -2149,7 +2153,7 @@ void HistoryInner::visibleAreaUpdated(int top, int bottom) { const auto pages = kUnloadHeavyPartsPages; const auto from = _visibleAreaTop - pages * visibleAreaHeight; const auto till = _visibleAreaBottom + pages * visibleAreaHeight; - Auth().data().unloadHeavyViewParts(ElementDelegate(), from, till); + session().data().unloadHeavyViewParts(ElementDelegate(), from, till); } bool HistoryInner::displayScrollDate() const { @@ -2494,7 +2498,7 @@ void HistoryInner::mouseActionUpdate() { dragState = TextState(nullptr, _botAbout->info->text.getState( point - _botAbout->rect.topLeft() - QPoint(st::msgPadding.left(), st::msgPadding.top() + st::botDescSkip + st::msgNameFont->height), _botAbout->width)); - _dragStateItem = Auth().data().message(dragState.itemId); + _dragStateItem = session().data().message(dragState.itemId); lnkhost = _botAbout.get(); } } else if (item) { @@ -2552,7 +2556,7 @@ void HistoryInner::mouseActionUpdate() { dragState = TextState( nullptr, _scrollDateLink); - _dragStateItem = Auth().data().message(dragState.itemId); + _dragStateItem = session().data().message(dragState.itemId); lnkhost = view; } } @@ -2568,7 +2572,7 @@ void HistoryInner::mouseActionUpdate() { selectingText = false; } dragState = view->textState(m, request); - _dragStateItem = Auth().data().message(dragState.itemId); + _dragStateItem = session().data().message(dragState.itemId); lnkhost = view; if (!dragState.link && m.x() >= st::historyPhotoLeft && m.x() < st::historyPhotoLeft + st::msgPhotoSize) { if (auto msg = item->toHistoryMessage()) { @@ -2588,7 +2592,7 @@ void HistoryInner::mouseActionUpdate() { dragState = TextState(nullptr, from ? from->openLink() : hiddenUserpicLink(message->fullId())); - _dragStateItem = Auth().data().message(dragState.itemId); + _dragStateItem = session().data().message(dragState.itemId); lnkhost = view; return false; } @@ -2826,7 +2830,7 @@ void HistoryInner::notifyIsBotChanged() { if (newinfo) { _botAbout = std::make_unique(this, newinfo); if (newinfo && !newinfo->inited) { - Auth().api().requestFullPeer(_peer); + session().api().requestFullPeer(_peer); } } else { _botAbout = nullptr; @@ -2877,7 +2881,7 @@ bool HistoryInner::isSelectedGroup( bool HistoryInner::isSelectedAsGroup( not_null toItems, not_null item) const { - if (const auto group = Auth().data().groups().find(item)) { + if (const auto group = session().data().groups().find(item)) { return isSelectedGroup(toItems, group); } return isSelected(toItems, item); @@ -2940,7 +2944,7 @@ void HistoryInner::changeSelectionAsGroup( not_null toItems, not_null item, SelectAction action) const { - const auto group = Auth().data().groups().find(item); + const auto group = session().data().groups().find(item); if (!group) { return changeSelection(toItems, item, action); } @@ -2974,13 +2978,13 @@ void HistoryInner::forwardItem(FullMsgId itemId) { } void HistoryInner::forwardAsGroup(FullMsgId itemId) { - if (const auto item = Auth().data().message(itemId)) { - Window::ShowForwardMessagesBox(Auth().data().itemOrItsGroup(item)); + if (const auto item = session().data().message(itemId)) { + Window::ShowForwardMessagesBox(session().data().itemOrItsGroup(item)); } } void HistoryInner::deleteItem(FullMsgId itemId) { - if (const auto item = Auth().data().message(itemId)) { + if (const auto item = session().data().message(itemId)) { deleteItem(item); } } @@ -3002,13 +3006,13 @@ bool HistoryInner::hasPendingResizedItems() const { } void HistoryInner::deleteAsGroup(FullMsgId itemId) { - if (const auto item = Auth().data().message(itemId)) { - const auto group = Auth().data().groups().find(item); + if (const auto item = session().data().message(itemId)) { + const auto group = session().data().groups().find(item); if (!group) { return deleteItem(item); } Ui::show(Box( - Auth().data().itemsToIds(group->items))); + session().data().itemsToIds(group->items))); } } @@ -3017,14 +3021,14 @@ void HistoryInner::reportItem(FullMsgId itemId) { } void HistoryInner::reportAsGroup(FullMsgId itemId) { - if (const auto item = Auth().data().message(itemId)) { - const auto group = Auth().data().groups().find(item); + if (const auto item = session().data().message(itemId)) { + const auto group = session().data().groups().find(item); if (!group) { return reportItem(itemId); } Ui::show(Box( _peer, - Auth().data().itemsToIds(group->items))); + session().data().itemsToIds(group->items))); } } diff --git a/Telegram/SourceFiles/history/history_inner_widget.h b/Telegram/SourceFiles/history/history_inner_widget.h index bb35cc2f6d..2b64352212 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.h +++ b/Telegram/SourceFiles/history/history_inner_widget.h @@ -52,6 +52,8 @@ public: Ui::ScrollArea *scroll, not_null history); + AuthSession &session() const; + void messagesReceived(PeerData *peer, const QVector &messages); void messagesReceivedDown(PeerData *peer, const QVector &messages); diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 80e0837334..a7116b535d 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -184,17 +184,18 @@ void FastShareMessage(not_null item) { base::flat_set requests; }; const auto history = item->history(); + const auto owner = &history->owner(); const auto data = std::make_shared( history->peer, - history->owner().itemOrItsGroup(item)); - const auto isGroup = (history->owner().groups().find(item) != nullptr); + owner->itemOrItsGroup(item)); + const auto isGroup = (owner->groups().find(item) != nullptr); const auto isGame = item->getMessageBot() && item->media() && (item->media()->game() != nullptr); const auto canCopyLink = item->hasDirectLink() || isGame; auto copyCallback = [=]() { - if (auto item = Auth().data().message(data->msgIds[0])) { + if (const auto item = owner->message(data->msgIds[0])) { if (item->hasDirectLink()) { HistoryView::CopyPostLink(item->fullId()); } else if (const auto bot = item->getMessageBot()) { @@ -321,7 +322,7 @@ void FastShareMessage(not_null item) { Fn HistoryDependentItemCallback( const FullMsgId &msgId) { return [dependent = msgId](ChannelData *channel, MsgId msgId) { - if (auto item = Auth().data().message(dependent)) { + if (const auto item = Auth().data().message(dependent)) { item->updateDependencyItem(); } }; diff --git a/Telegram/SourceFiles/history/media/history_media_contact.cpp b/Telegram/SourceFiles/history/media/history_media_contact.cpp index bdde268f6f..67580c8ecf 100644 --- a/Telegram/SourceFiles/history/media/history_media_contact.cpp +++ b/Telegram/SourceFiles/history/media/history_media_contact.cpp @@ -42,11 +42,14 @@ ClickHandlerPtr sendMessageClickHandler(PeerData *peer) { } ClickHandlerPtr addContactClickHandler(not_null item) { - return std::make_shared([fullId = item->fullId()] { - if (const auto item = Auth().data().message(fullId)) { + const auto session = &item->history()->session(); + const auto fullId = item->fullId(); + return std::make_shared([=] { + if (const auto item = session->data().message(fullId)) { if (const auto media = item->media()) { if (const auto contact = media->sharedContact()) { Ui::show(Box( + session, contact->firstName, contact->lastName, contact->phoneNumber)); diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp index 49c385f4bd..97505bfd3a 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp @@ -64,7 +64,7 @@ void SavePhotoToFile(not_null photo) { tr::lng_save_photo(tr::now), qsl("JPEG Image (*.jpg);;") + FileDialog::AllFilesFilter(), filedialogDefaultName(qsl("photo"), qsl(".jpg")), - crl::guard(&Auth(), [=](const QString &result) { + crl::guard(&photo->session(), [=](const QString &result) { if (!result.isEmpty()) { photo->large()->original().save(result, "JPG"); } @@ -86,7 +86,7 @@ void ShowStickerPackInfo(not_null document) { void ToggleFavedSticker( not_null document, FullMsgId contextId) { - Auth().api().toggleFavedSticker( + document->session().api().toggleFavedSticker( document, contextId, !Stickers::IsFaved(document)); @@ -99,7 +99,7 @@ void AddPhotoActions( tr::lng_context_save_image(tr::now), App::LambdaDelayed( st::defaultDropdownMenu.menu.ripple.hideDuration, - &Auth(), + &photo->session(), [=] { SavePhotoToFile(photo); })); menu->addAction(tr::lng_context_copy_image(tr::now), [=] { CopyImage(photo); @@ -147,7 +147,7 @@ void AddSaveDocumentAction( : tr::lng_context_save_file(tr::now))))), App::LambdaDelayed( st::defaultDropdownMenu.menu.ripple.hideDuration, - &Auth(), + &document->session(), save)); } @@ -255,9 +255,10 @@ bool AddForwardMessageAction( } else if (!item || !item->allowsForward()) { return false; } + const auto owner = &item->history()->owner(); const auto asGroup = (request.pointState != PointState::GroupPart); if (asGroup) { - if (const auto group = Auth().data().groups().find(item)) { + if (const auto group = owner->groups().find(item)) { if (ranges::find_if(group->items, [](auto item) { return !item->allowsForward(); }) != end(group->items)) { @@ -267,9 +268,9 @@ bool AddForwardMessageAction( } const auto itemId = item->fullId(); menu->addAction(tr::lng_context_forward_msg(tr::now), [=] { - if (const auto item = Auth().data().message(itemId)) { + if (const auto item = owner->message(itemId)) { Window::ShowForwardMessagesBox(asGroup - ? Auth().data().itemOrItsGroup(item) + ? owner->itemOrItsGroup(item) : MessageIdsList{ 1, itemId }); } }); @@ -320,9 +321,10 @@ bool AddDeleteMessageAction( } else if (!item || !item->canDelete()) { return false; } + const auto owner = &item->history()->owner(); const auto asGroup = (request.pointState != PointState::GroupPart); if (asGroup) { - if (const auto group = Auth().data().groups().find(item)) { + if (const auto group = owner->groups().find(item)) { if (ranges::find_if(group->items, [](auto item) { return !IsServerMsgId(item->id) || !item->canDelete(); }) != end(group->items)) { @@ -332,11 +334,11 @@ bool AddDeleteMessageAction( } const auto itemId = item->fullId(); menu->addAction(tr::lng_context_delete_msg(tr::now), [=] { - if (const auto item = Auth().data().message(itemId)) { + if (const auto item = owner->message(itemId)) { if (asGroup) { - if (const auto group = Auth().data().groups().find(item)) { + if (const auto group = owner->groups().find(item)) { Ui::show(Box( - Auth().data().itemsToIds(group->items))); + owner->itemsToIds(group->items))); return; } } @@ -385,10 +387,11 @@ bool AddSelectMessageAction( } else if (!item || !IsServerMsgId(item->id) || item->serviceMsg()) { return false; } + const auto owner = &item->history()->owner(); const auto itemId = item->fullId(); const auto asGroup = (request.pointState != PointState::GroupPart); menu->addAction(tr::lng_context_select_msg(tr::now), [=] { - if (const auto item = Auth().data().message(itemId)) { + if (const auto item = owner->message(itemId)) { if (asGroup) { list->selectItemAsGroup(item); } else { @@ -485,6 +488,7 @@ base::unique_qptr FillContextMenu( // AddToggleGroupingAction(result, linkPeer->peer()); // } } else if (!request.overSelection && view && !hasSelection) { + const auto owner = &view->data()->history()->owner(); const auto media = view->media(); const auto mediaHasTextForCopy = media && media->hasTextForCopy(); if (const auto document = media ? media->getDocument() : nullptr) { @@ -493,9 +497,9 @@ base::unique_qptr FillContextMenu( if (!link && (view->hasVisibleText() || mediaHasTextForCopy)) { const auto asGroup = (request.pointState != PointState::GroupPart); result->addAction(tr::lng_context_copy_text(tr::now), [=] { - if (const auto item = Auth().data().message(itemId)) { + if (const auto item = owner->message(itemId)) { if (asGroup) { - if (const auto group = Auth().data().groups().find(item)) { + if (const auto group = owner->groups().find(item)) { SetClipboardText(HistoryGroupText(group)); return; } diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 1599ab3c4e..bcfe1ef252 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -245,25 +245,25 @@ ListWidget::ListWidget( , _highlightTimer([this] { updateHighlightedMessage(); }) { setMouseTracking(true); _scrollDateHideTimer.setCallback([this] { scrollDateHideByTimer(); }); - Auth().data().viewRepaintRequest( + session().data().viewRepaintRequest( ) | rpl::start_with_next([this](auto view) { if (view->delegate() == this) { repaintItem(view); } }, lifetime()); - Auth().data().viewResizeRequest( + session().data().viewResizeRequest( ) | rpl::start_with_next([this](auto view) { if (view->delegate() == this) { resizeItem(view); } }, lifetime()); - Auth().data().itemViewRefreshRequest( + session().data().itemViewRefreshRequest( ) | rpl::start_with_next([this](auto item) { if (const auto view = viewForItem(item)) { refreshItem(view); } }, lifetime()); - Auth().data().viewLayoutChanged( + session().data().viewLayoutChanged( ) | rpl::start_with_next([this](auto view) { if (view->delegate() == this) { if (view->isUnderCursor()) { @@ -271,7 +271,7 @@ ListWidget::ListWidget( } } }, lifetime()); - Auth().data().animationPlayInlineRequest( + session().data().animationPlayInlineRequest( ) | rpl::start_with_next([this](auto item) { if (const auto view = viewForItem(item)) { if (const auto media = view->media()) { @@ -279,11 +279,11 @@ ListWidget::ListWidget( } } }, lifetime()); - Auth().data().itemRemoved( + session().data().itemRemoved( ) | rpl::start_with_next( [this](auto item) { itemRemoved(item); }, lifetime()); - subscribe(Auth().data().queryItemVisibility(), [this](const Data::Session::ItemVisibilityQuery &query) { + subscribe(session().data().queryItemVisibility(), [this](const Data::Session::ItemVisibilityQuery &query) { if (const auto view = viewForItem(query.item)) { const auto top = itemTop(view); if (top >= 0 @@ -295,6 +295,10 @@ ListWidget::ListWidget( }); } +AuthSession &ListWidget::session() const { + return _controller->session(); +} + not_null ListWidget::delegate() const { return _delegate; } @@ -317,7 +321,7 @@ void ListWidget::refreshRows() { _items.clear(); _items.reserve(_slice.ids.size()); for (const auto &fullId : _slice.ids) { - if (const auto item = Auth().data().message(fullId)) { + if (const auto item = session().data().message(fullId)) { _items.push_back(enforceViewForItem(item)); } } @@ -350,7 +354,7 @@ std::optional ListWidget::scrollTopForPosition( std::optional ListWidget::scrollTopForView( not_null view) const { if (view->isHiddenByGroup()) { - if (const auto group = Auth().data().groups().find(view->data())) { + if (const auto group = session().data().groups().find(view->data())) { if (const auto leader = viewForItem(group->items.back())) { if (!leader->isHiddenByGroup()) { return scrollTopForView(leader); @@ -398,7 +402,7 @@ void ListWidget::animatedScrollTo( void ListWidget::scrollToAnimationCallback( FullMsgId attachToId, int relativeTo) { - const auto attachTo = Auth().data().message(attachToId); + const auto attachTo = session().data().message(attachToId); const auto attachToView = viewForItem(attachTo); if (!attachToView) { _scrollToAnimation.stop(); @@ -424,7 +428,7 @@ bool ListWidget::isBelowPosition(Data::MessagePosition position) const { } void ListWidget::highlightMessage(FullMsgId itemId) { - if (const auto item = Auth().data().message(itemId)) { + if (const auto item = session().data().message(itemId)) { if (const auto view = viewForItem(item)) { _highlightStart = crl::now(); _highlightedMessageId = itemId; @@ -436,7 +440,7 @@ void ListWidget::highlightMessage(FullMsgId itemId) { } void ListWidget::updateHighlightedMessage() { - if (const auto item = Auth().data().message(_highlightedMessageId)) { + if (const auto item = session().data().message(_highlightedMessageId)) { if (const auto view = viewForItem(item)) { repaintItem(view); auto duration = st::activeFadeInDuration + st::activeFadeOutDuration; @@ -488,7 +492,7 @@ void ListWidget::restoreScrollState() { } Element *ListWidget::viewForItem(FullMsgId itemId) const { - if (const auto item = Auth().data().message(itemId)) { + if (const auto item = session().data().message(itemId)) { return viewForItem(item); } return nullptr; @@ -736,7 +740,7 @@ bool ListWidget::isSelectedGroup( bool ListWidget::isSelectedAsGroup( const SelectedMap &applyTo, not_null item) const { - if (const auto group = Auth().data().groups().find(item)) { + if (const auto group = session().data().groups().find(item)) { return isSelectedGroup(applyTo, group); } return applyTo.contains(item->fullId()); @@ -803,7 +807,7 @@ void ListWidget::changeSelectionAsGroup( SelectedMap &applyTo, not_null item, SelectAction action) const { - const auto group = Auth().data().groups().find(item); + const auto group = session().data().groups().find(item); if (!group) { return changeSelection(applyTo, item, action); } @@ -1228,7 +1232,7 @@ TextSelection ListWidget::computeRenderSelection( return TextSelection(); }; const auto item = view->data(); - if (const auto group = Auth().data().groups().find(item)) { + if (const auto group = session().data().groups().find(item)) { if (group->items.back() != item) { return TextSelection(); } @@ -1393,7 +1397,7 @@ void ListWidget::applyDragSelection(SelectedMap &applyTo) const { if (applyTo.size() >= MaxSelectedItems) { break; } else if (!applyTo.contains(itemId)) { - if (const auto item = Auth().data().message(itemId)) { + if (const auto item = session().data().message(itemId)) { addToSelection(applyTo, item); } } @@ -1451,8 +1455,8 @@ TextForMimeData ListWidget::getSelectedText() const { }; for (const auto [itemId, data] : selected) { - if (const auto item = Auth().data().message(itemId)) { - if (const auto group = Auth().data().groups().find(item)) { + if (const auto item = session().data().message(itemId)) { + if (const auto group = session().data().groups().find(item)) { if (groups.contains(group)) { continue; } @@ -1694,7 +1698,7 @@ void ListWidget::updateDragSelection() { } else if (_items.empty() || !_overElement || !_selectEnabled) { return; } - const auto pressItem = Auth().data().message(_pressState.itemId); + const auto pressItem = session().data().message(_pressState.itemId); if (!pressItem) { return; } @@ -1792,7 +1796,7 @@ void ListWidget::updateDragSelection( std::vector>::const_iterator till) { Expects(from < till); - const auto &groups = Auth().data().groups(); + const auto &groups = session().data().groups(); const auto changeItem = [&](not_null item, bool add) { const auto itemId = item->fullId(); if (add) { @@ -2011,7 +2015,7 @@ void ListWidget::mouseActionFinish( return; } if (needItemSelectionToggle) { - if (const auto item = Auth().data().message(pressState.itemId)) { + if (const auto item = session().data().message(pressState.itemId)) { clearTextSelection(); if (pressState.pointState == PointState::GroupPart) { changeSelection( @@ -2144,7 +2148,7 @@ void ListWidget::mouseActionUpdate() { dragState = TextState( nullptr, _scrollDateLink); - _overItemExact = Auth().data().message(dragState.itemId); + _overItemExact = session().data().message(dragState.itemId); lnkhost = view; } } @@ -2154,7 +2158,7 @@ void ListWidget::mouseActionUpdate() { }); if (!dragState.link) { dragState = view->textState(itemPoint, request); - _overItemExact = Auth().data().message(dragState.itemId); + _overItemExact = session().data().message(dragState.itemId); lnkhost = view; if (!dragState.link && itemPoint.x() >= st::historyPhotoLeft @@ -2175,7 +2179,7 @@ void ListWidget::mouseActionUpdate() { dragState = TextState(nullptr, from ? from->openLink() : hiddenUserpicLink(message->fullId())); - _overItemExact = Auth().data().message(dragState.itemId); + _overItemExact = session().data().message(dragState.itemId); lnkhost = view; return false; } @@ -2231,7 +2235,7 @@ void ListWidget::mouseActionUpdate() { // Voice message seek support. if (_pressState.pointState != PointState::Outside && ClickHandler::getPressed()) { - if (const auto item = Auth().data().message(_pressState.itemId)) { + if (const auto item = session().data().message(_pressState.itemId)) { if (const auto view = viewForItem(item)) { auto adjustedPoint = mapPointToItem(point, view); view->updatePressed(adjustedPoint); @@ -2272,7 +2276,7 @@ std::unique_ptr ListWidget::prepareDrag() { return nullptr; } - const auto pressedItem = Auth().data().message(_pressState.itemId); + const auto pressedItem = session().data().message(_pressState.itemId); const auto pressedView = viewForItem(pressedItem); const auto uponSelected = pressedView && isInsideSelection( pressedView, @@ -2311,7 +2315,7 @@ std::unique_ptr ListWidget::prepareDrag() { ? getSelectedItems() : MessageIdsList(); if (!items.empty()) { - Auth().data().setMimeForwardIds(std::move(items)); + session().data().setMimeForwardIds(std::move(items)); mimeData->setData(qsl("application/x-td-forward"), "1"); } } @@ -2322,7 +2326,7 @@ std::unique_ptr ListWidget::prepareDrag() { ? _pressItemExact : pressedItem; if (_mouseCursorState == CursorState::Date) { - forwardIds = Auth().data().itemOrItsGroup(_overElement->data()); + forwardIds = session().data().itemOrItsGroup(_overElement->data()); } else if (_pressState.pointState == PointState::GroupPart) { forwardIds = MessageIdsList(1, exactItem->fullId()); } else if (const auto media = pressedView->media()) { @@ -2334,7 +2338,7 @@ std::unique_ptr ListWidget::prepareDrag() { if (forwardIds.empty()) { return nullptr; } - Auth().data().setMimeForwardIds(std::move(forwardIds)); + session().data().setMimeForwardIds(std::move(forwardIds)); auto result = std::make_unique(); result->setData(qsl("application/x-td-forward"), "1"); if (const auto media = pressedView->media()) { diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.h b/Telegram/SourceFiles/history/view/history_view_list_widget.h index 701d61b75f..df13214c18 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.h @@ -15,6 +15,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_messages.h" #include "history/view/history_view_element.h" +class AuthSession; + namespace Ui { class PopupMenu; } // namespace Ui @@ -128,6 +130,8 @@ public: not_null controller, not_null delegate); + AuthSession &session() const; + not_null delegate() const; // Set the correct scroll position after being resized. diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 82c83ed7a8..779c433cfd 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -1457,12 +1457,13 @@ void Message::drawRightAction( ClickHandlerPtr Message::rightActionLink() const { if (!_rightActionLink) { + const auto owner = &data()->history()->owner(); const auto itemId = data()->fullId(); const auto forwarded = data()->Get(); const auto savedFromPeer = forwarded ? forwarded->savedFromPeer : nullptr; const auto savedFromMsgId = forwarded ? forwarded->savedFromMsgId : 0; _rightActionLink = std::make_shared([=] { - if (const auto item = Auth().data().message(itemId)) { + if (const auto item = owner->message(itemId)) { if (savedFromPeer && savedFromMsgId) { App::wnd()->sessionController()->showPeerHistory( savedFromPeer, @@ -1479,9 +1480,10 @@ ClickHandlerPtr Message::rightActionLink() const { ClickHandlerPtr Message::fastReplyLink() const { if (!_fastReplyLink) { + const auto owner = &data()->history()->owner(); const auto itemId = data()->fullId(); _fastReplyLink = std::make_shared([=] { - if (const auto item = Auth().data().message(itemId)) { + if (const auto item = owner->message(itemId)) { if (const auto main = App::main()) { main->replyToItem(item); } 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 9d168ff1b0..8cdc983d5d 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -59,7 +59,7 @@ TopBarWidget::TopBarWidget( , _infoToggle(this, st::topBarInfo) , _menuToggle(this, st::topBarMenuToggle) , _titlePeerText(st::windowMinWidth / 3) -, _onlineUpdater([this] { updateOnlineDisplay(); }) { +, _onlineUpdater([=] { updateOnlineDisplay(); }) { subscribe(Lang::Current().updated(), [this] { refreshLang(); }); setAttribute(Qt::WA_OpaquePaintEvent); @@ -100,7 +100,7 @@ TopBarWidget::TopBarWidget( refreshUnreadBadge(); { using AnimationUpdate = Data::Session::SendActionAnimationUpdate; - Auth().data().sendActionAnimationUpdated( + session().data().sendActionAnimationUpdated( ) | rpl::filter([=](const AnimationUpdate &update) { return (update.history == _activeChat.history()); }) | rpl::start_with_next([=] { @@ -127,8 +127,8 @@ TopBarWidget::TopBarWidget( }); rpl::combine( - Auth().settings().thirdSectionInfoEnabledValue(), - Auth().settings().tabbedReplacedWithInfoValue() + session().settings().thirdSectionInfoEnabledValue(), + session().settings().tabbedReplacedWithInfoValue() ) | rpl::start_with_next( [this] { updateInfoToggleActive(); }, lifetime()); @@ -143,6 +143,12 @@ TopBarWidget::TopBarWidget( updateControlsVisibility(); } +TopBarWidget::~TopBarWidget() = default; + +AuthSession &TopBarWidget::session() const { + return _controller->session(); +} + void TopBarWidget::updateConnectingState() { const auto mtp = MTP::dcstate(); if (mtp == MTP::ConnectedState) { @@ -236,13 +242,13 @@ void TopBarWidget::showMenu() { void TopBarWidget::toggleInfoSection() { if (Adaptive::ThreeColumn() - && (Auth().settings().thirdSectionInfoEnabled() - || Auth().settings().tabbedReplacedWithInfo())) { + && (session().settings().thirdSectionInfoEnabled() + || session().settings().tabbedReplacedWithInfo())) { _controller->closeThirdSection(); } else if (_activeChat.peer()) { if (_controller->canShowThirdSection()) { - Auth().settings().setThirdSectionInfoEnabled(true); - Auth().saveSettingsDelayed(); + session().settings().setThirdSectionInfoEnabled(true); + session().saveSettingsDelayed(); if (Adaptive::ThreeColumn()) { _controller->showSection( Info::Memento::Default(_activeChat.peer()), @@ -745,8 +751,8 @@ void TopBarWidget::refreshUnreadBadge() { void TopBarWidget::updateUnreadBadge() { if (!_unreadBadge) return; - const auto muted = Auth().data().unreadBadgeMutedIgnoreOne(_activeChat); - const auto counter = Auth().data().unreadBadgeIgnoreOne(_activeChat); + const auto muted = session().data().unreadBadgeMutedIgnoreOne(_activeChat); + const auto counter = session().data().unreadBadgeIgnoreOne(_activeChat); const auto text = [&] { if (!counter) { return QString(); @@ -760,8 +766,8 @@ void TopBarWidget::updateUnreadBadge() { void TopBarWidget::updateInfoToggleActive() { auto infoThirdActive = Adaptive::ThreeColumn() - && (Auth().settings().thirdSectionInfoEnabled() - || Auth().settings().tabbedReplacedWithInfo()); + && (session().settings().thirdSectionInfoEnabled() + || session().settings().tabbedReplacedWithInfo()); auto iconOverride = infoThirdActive ? &st::topBarInfoActive : nullptr; @@ -779,8 +785,8 @@ void TopBarWidget::updateOnlineDisplay() { const auto now = base::unixtime::now(); bool titlePeerTextOnline = false; if (const auto user = _activeChat.peer()->asUser()) { - if (Auth().supportMode() - && !Auth().supportHelper().infoCurrent(user).text.empty()) { + if (session().supportMode() + && !session().supportHelper().infoCurrent(user).text.empty()) { text = QString::fromUtf8("\xe2\x9a\xa0\xef\xb8\x8f check info"); titlePeerTextOnline = false; } else { @@ -799,7 +805,7 @@ void TopBarWidget::updateOnlineDisplay() { text = tr::lng_chat_status_members(tr::now, lt_count_decimal, chat->count); } } else { - const auto self = Auth().user(); + const auto self = session().user(); auto online = 0; auto onlyMe = true; for (const auto user : chat->participants) { @@ -821,9 +827,9 @@ void TopBarWidget::updateOnlineDisplay() { } else if (const auto channel = _activeChat.peer()->asChannel()) { if (channel->isMegagroup() && channel->membersCount() > 0 && channel->membersCount() <= Global::ChatSizeMax()) { if (channel->mgInfo->lastParticipants.empty() || channel->lastParticipantsCountOutdated()) { - Auth().api().requestLastParticipants(channel); + session().api().requestLastParticipants(channel); } - const auto self = Auth().user(); + const auto self = session().user(); auto online = 0; auto onlyMe = true; for (auto &participant : std::as_const(channel->mgInfo->lastParticipants)) { @@ -883,6 +889,4 @@ void TopBarWidget::updateOnlineDisplayIn(crl::time timeout) { _onlineUpdater.callOnce(timeout); } -TopBarWidget::~TopBarWidget() = default; - } // namespace HistoryView diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h index 2b5e5c9e15..c2f9f4962e 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h @@ -12,6 +12,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/timer.h" #include "dialogs/dialogs_key.h" +class AuthSession; + namespace Ui { class AbstractButton; class RoundButton; @@ -29,10 +31,6 @@ namespace HistoryView { class TopBarWidget : public Ui::RpWidget, private base::Subscriber { public: - TopBarWidget( - QWidget *parent, - not_null controller); - struct SelectedState { bool textSelected = false; int count = 0; @@ -40,8 +38,13 @@ public: int canForwardCount = 0; }; + TopBarWidget( + QWidget *parent, + not_null controller); ~TopBarWidget(); + AuthSession &session() const; + void updateControlsVisibility(); void finishAnimating(); void showSelected(SelectedState state); diff --git a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp index 70c61a9497..a96bea911f 100644 --- a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp +++ b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp @@ -554,6 +554,10 @@ ListWidget::ListWidget( start(); } +AuthSession &ListWidget::session() const { + return _controller->session(); +} + void ListWidget::start() { _controller->setSearchEnabledByContent(false); ObservableViewer( @@ -564,17 +568,17 @@ void ListWidget::start() { } }, lifetime()); ObservableViewer( - Auth().downloader().taskFinished() + session().downloader().taskFinished() ) | rpl::start_with_next([this] { update(); }, lifetime()); - Auth().data().itemLayoutChanged( + session().data().itemLayoutChanged( ) | rpl::start_with_next([this](auto item) { itemLayoutChanged(item); }, lifetime()); - Auth().data().itemRemoved( + session().data().itemRemoved( ) | rpl::start_with_next([this](auto item) { itemRemoved(item); }, lifetime()); - Auth().data().itemRepaintRequest( + session().data().itemRepaintRequest( ) | rpl::start_with_next([this](auto item) { repaintItem(item); }, lifetime()); @@ -839,7 +843,7 @@ BaseLayout *ListWidget::getExistingLayout( std::unique_ptr ListWidget::createLayout( UniversalMsgId universalId, Type type) { - auto item = Auth().data().message(computeFullId(universalId)); + auto item = session().data().message(computeFullId(universalId)); if (!item) { return nullptr; } @@ -1180,7 +1184,7 @@ void ListWidget::showContextMenu( mouseActionUpdate(e->globalPos()); } - auto item = Auth().data().message(computeFullId(_overState.itemId)); + auto item = session().data().message(computeFullId(_overState.itemId)); if (!item || !_overState.inside) { return; } @@ -1225,11 +1229,12 @@ void ListWidget::showContextMenu( auto link = ClickHandler::getActive(); const auto itemFullId = item->fullId(); + const auto owner = &session().data(); _contextMenu = base::make_unique_q(this); _contextMenu->addAction( tr::lng_context_to_msg(tr::now), - [itemFullId] { - if (auto item = Auth().data().message(itemFullId)) { + [=] { + if (const auto item = owner->message(itemFullId)) { Ui::showPeerHistoryAtItem(item); } }); @@ -1381,7 +1386,7 @@ void ListWidget::forwardSelected() { } void ListWidget::forwardItem(UniversalMsgId universalId) { - if (const auto item = Auth().data().message(computeFullId(universalId))) { + if (const auto item = session().data().message(computeFullId(universalId))) { forwardItems({ 1, item->fullId() }); } } @@ -1409,7 +1414,7 @@ void ListWidget::deleteSelected() { } void ListWidget::deleteItem(UniversalMsgId universalId) { - if (const auto item = Auth().data().message(computeFullId(universalId))) { + if (const auto item = session().data().message(computeFullId(universalId))) { deleteItems({ 1, item->fullId() }); } } @@ -1513,7 +1518,7 @@ bool ListWidget::changeItemSelection( universalId, selection); if (ok) { - auto item = Auth().data().message(computeFullId(universalId)); + auto item = session().data().message(computeFullId(universalId)); if (!item) { selected.erase(iterator); return false; @@ -1932,7 +1937,7 @@ void ListWidget::performDrag() { // if (uponSelected && !Adaptive::OneColumn()) { // auto selectedState = getSelectionState(); // if (selectedState.count > 0 && selectedState.count == selectedState.canForwardCount) { - // Auth().data().setMimeForwardIds(collectSelectedIds()); + // session().data().setMimeForwardIds(collectSelectedIds()); // mimeData->setData(qsl("application/x-td-forward"), "1"); // } // } @@ -1944,14 +1949,14 @@ void ListWidget::performDrag() { // if (auto pressedItem = _pressState.layout) { // pressedMedia = pressedItem->getMedia(); // if (_mouseCursorState == CursorState::Date || (pressedMedia && pressedMedia->dragItem())) { - // Auth().data().setMimeForwardIds(Auth().data().itemOrItsGroup(pressedItem)); + // session().data().setMimeForwardIds(session().data().itemOrItsGroup(pressedItem)); // forwardMimeType = qsl("application/x-td-forward"); // } // } // if (auto pressedLnkItem = App::pressedLinkItem()) { // if ((pressedMedia = pressedLnkItem->getMedia())) { // if (forwardMimeType.isEmpty() && pressedMedia->dragItemByHandler(pressedHandler)) { - // Auth().data().setMimeForwardIds({ 1, pressedLnkItem->fullId() }); + // session().data().setMimeForwardIds({ 1, pressedLnkItem->fullId() }); // forwardMimeType = qsl("application/x-td-forward"); // } // } diff --git a/Telegram/SourceFiles/info/media/info_media_list_widget.h b/Telegram/SourceFiles/info/media/info_media_list_widget.h index e1b272974f..0995a01171 100644 --- a/Telegram/SourceFiles/info/media/info_media_list_widget.h +++ b/Telegram/SourceFiles/info/media/info_media_list_widget.h @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_shared_media.h" class DeleteMessagesBox; +class AuthSession; namespace HistoryView { struct TextState; @@ -49,6 +50,8 @@ public: QWidget *parent, not_null controller); + AuthSession &session() const; + void restart(); rpl::producer scrollToRequests() const; diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index 0c14bff012..cc23349bf5 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -351,10 +351,10 @@ object_ptr DetailsFiller::setupMuteToggle() { result->toggleOn( NotificationsEnabledValue(peer) )->addClickHandler([=] { - const auto muteForSeconds = Auth().data().notifyIsMuted(peer) + const auto muteForSeconds = peer->owner().notifyIsMuted(peer) ? 0 : Data::NotifySettings::kDefaultMutePeriod; - Auth().data().updateNotifySettings(peer, muteForSeconds); + peer->owner().updateNotifySettings(peer, muteForSeconds); }); object_ptr( result, @@ -653,7 +653,7 @@ void ActionsFiller::addJoinChannelAction( _wrap, tr::lng_profile_join_channel(), rpl::duplicate(joinVisible), - [channel] { Auth().api().joinChannel(channel); }); + [=] { channel->session().api().joinChannel(channel); }); _wrap->add(object_ptr>( _wrap, CreateSkipWidget( @@ -749,19 +749,20 @@ object_ptr ActionsFiller::fill() { // //object_ptr FeedDetailsFiller::setupDefaultToggle() { // using namespace rpl::mappers; -// const auto feedId = _feed->id(); +// const auto feed = _feed; +// const auto feedId = feed->id(); // auto result = object_ptr