From 5e3734d7bf45dd2f5c91479f17bc8c2586628c72 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 7 Jun 2019 14:32:58 +0300 Subject: [PATCH] ReportSpamPanel -> HistoryView::ContactStatus. --- Telegram/Resources/langs/lang.strings | 5 +- Telegram/SourceFiles/apiwrap.cpp | 25 +- Telegram/SourceFiles/apiwrap.h | 2 + Telegram/SourceFiles/app.cpp | 37 +-- Telegram/SourceFiles/core/utils.h | 9 - Telegram/SourceFiles/data/data_peer.h | 28 ++ Telegram/SourceFiles/data/data_session.cpp | 1 - Telegram/SourceFiles/data/data_user.cpp | 35 +-- Telegram/SourceFiles/data/data_user.h | 14 +- Telegram/SourceFiles/history/history.style | 17 - .../SourceFiles/history/history_widget.cpp | 290 +----------------- Telegram/SourceFiles/history/history_widget.h | 45 +-- .../view/history_view_contact_status.cpp | 251 +++++++++++++++ .../view/history_view_contact_status.h | 72 +++++ Telegram/SourceFiles/mainwidget.cpp | 13 +- Telegram/SourceFiles/settings.cpp | 2 - Telegram/SourceFiles/settings.h | 4 - .../settings/settings_privacy_controllers.cpp | 2 +- Telegram/SourceFiles/storage/localstorage.cpp | 83 +---- Telegram/SourceFiles/storage/localstorage.h | 2 - Telegram/gyp/telegram_sources.txt | 2 + 21 files changed, 438 insertions(+), 501 deletions(-) create mode 100644 Telegram/SourceFiles/history/view/history_view_contact_status.cpp create mode 100644 Telegram/SourceFiles/history/view/history_view_contact_status.h diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index d39981913..29c102382 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1189,12 +1189,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_ban_user" = "Ban User"; "lng_delete_all_from" = "Delete all from this user"; "lng_report_spam" = "Report Spam"; -"lng_report_spam_hide" = "Hide"; -"lng_report_spam_thanks" = "Thank you for your report!"; "lng_report_spam_sure" = "Are you sure you want to report spam from this user?"; "lng_report_spam_sure_group" = "Are you sure you want to report spam in this group?"; "lng_report_spam_sure_channel" = "Are you sure you want to report spam in this channel?"; "lng_report_spam_ok" = "Report"; +"lng_new_contact_block" = "Block user"; +"lng_new_contact_add" = "Add contact"; +"lng_new_contact_share" = "Share my phone number"; "lng_cant_send_to_not_contact" = "Sorry, you can only send messages to\nmutual contacts at the moment.\n{more_info}"; "lng_cant_invite_not_contact" = "Sorry, you can only add mutual contacts\nto groups at the moment.\n{more_info}"; "lng_cant_more_info" = "More info ยป"; diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index dc2ba4d92..8552963c8 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -1316,6 +1316,22 @@ void ApiWrap::requestPeer(not_null peer) { _peerRequests.insert(peer, requestId); } +void ApiWrap::requestPeerSettings(not_null peer) { + if (!_requestedPeerSettings.emplace(peer).second) { + return; + } + request(MTPmessages_GetPeerSettings( + peer->input + )).done([=](const MTPPeerSettings &result) { + peer->setSettings(result.match([&](const MTPDpeerSettings &data) { + return data.vflags.v; + })); + _requestedPeerSettings.erase(peer); + }).fail([=](const RPCError &error) { + _requestedPeerSettings.erase(peer); + }).send(); +} + void ApiWrap::migrateChat( not_null chat, FnMut)> done, @@ -2191,7 +2207,7 @@ void ApiWrap::blockUser(not_null user) { } else if (_blockRequests.find(user) == end(_blockRequests)) { const auto requestId = request(MTPcontacts_Block(user->inputUser)).done([this, user](const MTPBool &result) { _blockRequests.erase(user); - user->setBlockStatus(UserData::BlockStatus::Blocked); + user->setIsBlocked(true); if (_blockedUsersSlice) { _blockedUsersSlice->list.insert( _blockedUsersSlice->list.begin(), @@ -2217,7 +2233,7 @@ void ApiWrap::unblockUser(not_null user) { user->inputUser )).done([=](const MTPBool &result) { _blockRequests.erase(user); - user->setBlockStatus(UserData::BlockStatus::NotBlocked); + user->setIsBlocked(false); if (_blockedUsersSlice) { auto &list = _blockedUsersSlice->list; for (auto i = list.begin(); i != list.end(); ++i) { @@ -2513,9 +2529,6 @@ void ApiWrap::deleteHistory(not_null peer, bool justClear, bool revok const auto offset = applyAffectedHistory(peer, result); if (offset > 0) { deleteHistory(peer, justClear, revoke); - } else if (!justClear && cReportSpamStatuses().contains(peer->id)) { - cRefReportSpamStatuses().remove(peer->id); - Local::writeReportSpamStatuses(); } }).send(); } @@ -5793,7 +5806,7 @@ void ApiWrap::reloadBlockedUsers() { const auto user = _session->data().userLoaded( data.vuser_id.v); if (user) { - user->setBlockStatus(UserData::BlockStatus::Blocked); + user->setIsBlocked(true); slice.list.push_back({ user, data.vdate.v }); } }); diff --git a/Telegram/SourceFiles/apiwrap.h b/Telegram/SourceFiles/apiwrap.h index 84bbf63c0..3feeccf07 100644 --- a/Telegram/SourceFiles/apiwrap.h +++ b/Telegram/SourceFiles/apiwrap.h @@ -150,6 +150,7 @@ public: void requestFullPeer(not_null peer); void requestPeer(not_null peer); void requestPeers(const QList &peers); + void requestPeerSettings(not_null peer); void requestLastParticipants(not_null channel); void requestBots(not_null channel); void requestAdmins(not_null channel); @@ -689,6 +690,7 @@ private: using PeerRequests = QMap; PeerRequests _fullPeerRequests; PeerRequests _peerRequests; + base::flat_set> _requestedPeerSettings; PeerRequests _participantsRequests; PeerRequests _botsRequests; diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index 577d5f11f..a223271e8 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -142,48 +142,13 @@ namespace App { } } - //void feedUserLink(MTPint userId, const MTPContactLink &myLink, const MTPContactLink &foreignLink) { - // if (const auto user = Auth().data().userLoaded(userId.v)) { - // const auto wasShowPhone = (user->contactStatus() == UserData::ContactStatus::CanAdd); - // switch (myLink.type()) { - // case mtpc_contactLinkContact: - // user->setContactStatus(UserData::ContactStatus::Contact); - // break; - // case mtpc_contactLinkNone: - // case mtpc_contactLinkUnknown: - // user->setContactStatus(UserData::ContactStatus::PhoneUnknown); - // break; - // } - // if (user->contactStatus() == UserData::ContactStatus::PhoneUnknown - // && !user->phone().isEmpty() - // && user->id != Auth().userPeerId()) { - // user->setContactStatus(UserData::ContactStatus::CanAdd); - // } - - // const auto showPhone = !user->isServiceUser() - // && !user->isSelf() - // && user->contactStatus() == UserData::ContactStatus::CanAdd; - // const auto showPhoneChanged = !user->isServiceUser() - // && !user->isSelf() - // && (showPhone != wasShowPhone); - // if (showPhoneChanged) { - // user->setName( - // TextUtilities::SingleLine(user->firstName), - // TextUtilities::SingleLine(user->lastName), - // showPhone - // ? App::formatPhone(user->phone()) - // : QString(), - // TextUtilities::SingleLine(user->username)); - // } - // } - //} - QString peerName(const PeerData *peer, bool forDialogs) { return peer ? ((forDialogs && peer->isUser() && !peer->asUser()->nameOrPhone.isEmpty()) ? peer->asUser()->nameOrPhone : peer->name) : lang(lng_deleted); } void prepareCorners(RoundCorners index, int32 radius, const QBrush &brush, const style::color *shadow = nullptr, QImage *cors = nullptr) { Expects(::corners.size() > index); + int32 r = radius * cIntRetinaFactor(), s = st::msgShadow * cIntRetinaFactor(); QImage rect(r * 3, r * 3 + (shadow ? s : 0), QImage::Format_ARGB32_Premultiplied), localCors[4]; { diff --git a/Telegram/SourceFiles/core/utils.h b/Telegram/SourceFiles/core/utils.h index c5df62cb8..9911c4dd8 100644 --- a/Telegram/SourceFiles/core/utils.h +++ b/Telegram/SourceFiles/core/utils.h @@ -341,15 +341,6 @@ QNetworkProxy ToNetworkProxy(const ProxyData &proxy); static const int MatrixRowShift = 40000; -enum DBIPeerReportSpamStatus { - dbiprsNoButton = 0, // hidden, but not in the cloud settings yet - dbiprsUnknown = 1, // contacts not loaded yet - dbiprsShowButton = 2, // show report spam button, each show peer request setting from cloud - dbiprsReportSent = 3, // report sent, but the report spam panel is not hidden yet - dbiprsHidden = 4, // hidden in the cloud or not needed (bots, contacts, etc), no more requests - dbiprsRequesting = 5, // requesting the cloud setting right now -}; - inline int rowscount(int fullCount, int countPerRow) { return (fullCount + countPerRow - 1) / countPerRow; } diff --git a/Telegram/SourceFiles/data/data_peer.h b/Telegram/SourceFiles/data/data_peer.h index 33ce8f3b3..adbec3df7 100644 --- a/Telegram/SourceFiles/data/data_peer.h +++ b/Telegram/SourceFiles/data/data_peer.h @@ -109,6 +109,15 @@ protected: PeerData &operator=(const PeerData &other) = delete; public: + static constexpr auto kEssentialSettings = 0 + | MTPDpeerSettings::Flag::f_report_spam + | MTPDpeerSettings::Flag::f_add_contact + | MTPDpeerSettings::Flag::f_block_contact + | MTPDpeerSettings::Flag::f_share_contact; + using Settings = Data::Flags< + MTPDpeerSettings::Flags, + kEssentialSettings.value()>; + virtual ~PeerData(); static constexpr auto kServiceNotificationsId = peerFromUser(777000); @@ -289,6 +298,20 @@ public: void checkFolder(FolderId folderId); + void setSettings(MTPDpeerSettings::Flags which) { + _settings.set(which); + } + auto settings() const { + return (_settings.current() & kSettingsUnknown) + ? std::nullopt + : std::make_optional(_settings.current()); + } + auto settingsValue() const { + return (_settings.current() & kSettingsUnknown) + ? _settings.changes() + : _settings.value(); + } + enum LoadedStatus { NotLoaded = 0x00, MinimalLoaded = 0x01, @@ -342,6 +365,11 @@ private: crl::time _lastFullUpdate = 0; MsgId _pinnedMessageId = 0; + static constexpr auto kSettingsUnknown = MTPDpeerSettings::Flag(1U << 9); + static_assert(!(kEssentialSettings & kSettingsUnknown)); + + Settings _settings = { kSettingsUnknown }; + QString _about; }; diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index b4b678461..3b8f4888f 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -216,7 +216,6 @@ void Session::clear() { _sentMessagesData.clear(); cSetRecentInlineBots(RecentInlineBots()); cSetRecentStickers(RecentStickerPack()); - cSetReportSpamStatuses(ReportSpamStatuses()); App::clearMousedItems(); _histories.clear(); } diff --git a/Telegram/SourceFiles/data/data_user.cpp b/Telegram/SourceFiles/data/data_user.cpp index 348fab06d..dcf9e122a 100644 --- a/Telegram/SourceFiles/data/data_user.cpp +++ b/Telegram/SourceFiles/data/data_user.cpp @@ -59,17 +59,15 @@ bool UserData::canShareThisContact() const { } void UserData::setIsContact(bool is) { - if (_isContact != is) { - _isContact = is; + const auto status = is + ? ContactStatus::Contact + : ContactStatus::NotContact; + if (_contactStatus != status) { + _contactStatus = status; Notify::peerUpdatedDelayed( this, Notify::PeerUpdate::Flag::UserIsContact); } - if (_isContact - && cReportSpamStatuses().value(id, dbiprsHidden) != dbiprsHidden) { - cRefReportSpamStatuses().insert(id, dbiprsHidden); - Local::writeReportSpamStatuses(); - } } // see Local::readPeer as well @@ -231,9 +229,12 @@ void UserData::setAccessHash(uint64 accessHash) { } } -void UserData::setBlockStatus(BlockStatus blockStatus) { - if (blockStatus != _blockStatus) { - _blockStatus = blockStatus; +void UserData::setIsBlocked(bool is) { + const auto status = is + ? BlockStatus::Blocked + : BlockStatus::NotBlocked; + if (_blockStatus != status) { + _blockStatus = status; Notify::peerUpdatedDelayed(this, UpdateFlag::UserIsBlocked); } } @@ -257,13 +258,11 @@ void ApplyUserUpdate(not_null user, const MTPDuserFull &update) { if (update.has_profile_photo()) { user->owner().processPhoto(update.vprofile_photo); } - update.vsettings.match([&](const MTPDpeerSettings &data) { - //user->owner().processUserSettings(data); - //App::feedUserLink( - // MTP_int(peerToUser(user->id)), - // link.vmy_link, - // link.vforeign_link); + const auto settings = update.vsettings.match([&]( + const MTPDpeerSettings &data) { + return data.vflags.v; }); + user->setSettings(settings); user->session().api().applyNotifySettings( MTP_inputNotifyPeer(user->input), update.vnotify_settings); @@ -279,9 +278,7 @@ void ApplyUserUpdate(not_null user, const MTPDuserFull &update) { user->clearPinnedMessage(); } user->setFullFlags(update.vflags.v); - user->setBlockStatus(update.is_blocked() - ? UserData::BlockStatus::Blocked - : UserData::BlockStatus::NotBlocked); + user->setIsBlocked(update.is_blocked()); user->setCallsStatus(update.is_phone_calls_private() ? UserData::CallsStatus::Private : update.is_phone_calls_available() diff --git a/Telegram/SourceFiles/data/data_user.h b/Telegram/SourceFiles/data/data_user.h index fa47fe739..331b2b0eb 100644 --- a/Telegram/SourceFiles/data/data_user.h +++ b/Telegram/SourceFiles/data/data_user.h @@ -163,8 +163,16 @@ public: Text phoneText; TimeId onlineTill = 0; + enum class ContactStatus : char { + Unknown, + Contact, + NotContact, + }; + [[nodiscard]] ContactStatus contactStatus() const { + return _contactStatus; + } [[nodiscard]] bool isContact() const { - return _isContact; + return (contactStatus() == ContactStatus::Contact); } void setIsContact(bool is); @@ -179,7 +187,7 @@ public: bool isBlocked() const { return (blockStatus() == BlockStatus::Blocked); } - void setBlockStatus(BlockStatus blockStatus); + void setIsBlocked(bool is); enum class CallsStatus : char { Unknown, @@ -209,7 +217,7 @@ private: QString _unavailableReason; QString _phone; - bool _isContact = false; + ContactStatus _contactStatus = ContactStatus::Unknown; BlockStatus _blockStatus = BlockStatus::Unknown; CallsStatus _callsStatus = CallsStatus::Unknown; int _commonChatsCount = 0; diff --git a/Telegram/SourceFiles/history/history.style b/Telegram/SourceFiles/history/history.style index dbaa95c68..d3083a9b8 100644 --- a/Telegram/SourceFiles/history/history.style +++ b/Telegram/SourceFiles/history/history.style @@ -302,23 +302,6 @@ historyReplyCancel: IconButton { } } -reportSpamHide: FlatButton { - color: windowActiveTextFg; - overColor: windowActiveTextFg; - - bgColor: transparent; - overBgColor: transparent; - - width: -40px; - height: 46px; - - textTop: 15px; - - font: font(fsize); - overFont: font(fsize underline); -} -reportSpamSeparator: 30px; - msgBotKbDuration: 200; msgBotKbFont: semiboldFont; msgBotKbIconPadding: 2px; diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 490570dfe..b0e72e256 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -65,6 +65,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/application.h" #include "apiwrap.h" #include "history/view/history_view_top_bar_widget.h" +#include "history/view/history_view_contact_status.h" #include "observer_peer.h" #include "base/qthelp_regex.h" #include "ui/widgets/popup_menu.h" @@ -238,49 +239,6 @@ object_ptr SetupDiscussButton( } // namespace -ReportSpamPanel::ReportSpamPanel(QWidget *parent) : TWidget(parent), -_report(this, lang(lng_report_spam), st::reportSpamHide), -_hide(this, lang(lng_report_spam_hide), st::reportSpamHide), -_clear(this, lang(lng_profile_delete_conversation)) { - resize(parent->width(), _hide->height() + st::lineWidth); - - connect(_report, SIGNAL(clicked()), this, SIGNAL(reportClicked())); - connect(_hide, SIGNAL(clicked()), this, SIGNAL(hideClicked())); - connect(_clear, SIGNAL(clicked()), this, SIGNAL(clearClicked())); - - _clear->hide(); -} - -void ReportSpamPanel::resizeEvent(QResizeEvent *e) { - _report->resize(width() - (_hide->width() + st::reportSpamSeparator) * 2, _report->height()); - _report->moveToLeft(_hide->width() + st::reportSpamSeparator, 0); - _hide->moveToRight(0, 0); - _clear->move((width() - _clear->width()) / 2, height() - _clear->height() - ((height() - st::msgFont->height - _clear->height()) / 2)); -} - -void ReportSpamPanel::paintEvent(QPaintEvent *e) { - Painter p(this); - p.fillRect(QRect(0, 0, width(), height() - st::lineWidth), st::historyPinnedBg); - p.fillRect(Adaptive::OneColumn() ? 0 : st::lineWidth, height() - st::lineWidth, width() - (Adaptive::OneColumn() ? 0 : st::lineWidth), st::lineWidth, st::shadowFg); - if (!_clear->isHidden()) { - p.setPen(st::historyComposeAreaFg); - p.setFont(st::msgFont); - p.drawText(QRect(_report->x(), (_clear->y() - st::msgFont->height) / 2, _report->width(), st::msgFont->height), lang(lng_report_spam_thanks), style::al_top); - } -} - -void ReportSpamPanel::setReported(bool reported, PeerData *onPeer) { - if (reported) { - _report->hide(); - _clear->setText(lang(onPeer->isChannel() ? (onPeer->isMegagroup() ? lng_profile_leave_group : lng_profile_leave_channel) : lng_profile_delete_conversation)); - _clear->show(); - } else { - _report->show(); - _clear->hide(); - } - update(); -} - HistoryWidget::HistoryWidget( QWidget *parent, not_null controller) @@ -520,14 +478,6 @@ HistoryWidget::HistoryWidget( } }, lifetime()); - session().data().contactsLoaded().changes( - ) | rpl::start_with_next([=] { - if (_peer) { - updateReportSpamStatus(); - updateControlsVisibility(); - } - }, lifetime()); - subscribe(Media::Player::instance()->switchToNextNotifier(), [this](const Media::Player::Instance::Switch &pair) { if (pair.from.type() == AudioMsgId::Type::Voice) { scrollToCurrentVoiceMessage(pair.from.contextId(), pair.to); @@ -1058,8 +1008,8 @@ void HistoryWidget::applyInlineBotQuery(UserData *bot, const QString &query) { } void HistoryWidget::orderWidgets() { - if (_reportSpamPanel) { - _reportSpamPanel->raise(); + if (_contactStatus) { + _contactStatus->raise(); } if (_pinnedBar) { _pinnedBar->shadow->raise(); @@ -1082,26 +1032,6 @@ void HistoryWidget::orderWidgets() { _attachDragPhoto->raise(); } -void HistoryWidget::setReportSpamStatus(DBIPeerReportSpamStatus status) { - if (_reportSpamStatus == status) { - return; - } - _reportSpamStatus = status; - if (_reportSpamStatus == dbiprsShowButton || _reportSpamStatus == dbiprsReportSent) { - Assert(_peer != nullptr); - _reportSpamPanel.create(this); - connect(_reportSpamPanel, SIGNAL(reportClicked()), this, SLOT(onReportSpamClicked())); - connect(_reportSpamPanel, SIGNAL(hideClicked()), this, SLOT(onReportSpamHide())); - connect(_reportSpamPanel, SIGNAL(clearClicked()), this, SLOT(onReportSpamClear())); - _reportSpamPanel->setReported(_reportSpamStatus == dbiprsReportSent, _peer); - _reportSpamPanel->show(); - orderWidgets(); - updateControlsGeometry(); - } else { - _reportSpamPanel.destroy(); - } -} - void HistoryWidget::updateStickersByEmoji() { if (!_history) { return; @@ -1753,6 +1683,11 @@ void HistoryWidget::showHistory( _channel = peerToChannel(_peer->id); _canSendMessages = _peer->canWrite(); _tabbedSelector->setCurrentPeer(_peer); + _contactStatus = std::make_unique( + this, + _peer); + } else { + _contactStatus = nullptr; } if (_peer) { @@ -1769,12 +1704,6 @@ void HistoryWidget::showHistory( } } - _reportSpamRequest = 0; - if (_reportSpamSettingRequestId > 0) { - MTP::cancel(_reportSpamSettingRequestId); - } - _reportSpamSettingRequestId = ReportSpamRequestNeeded; - noSelectingScroll(); _nonEmptySelection = false; @@ -1941,117 +1870,6 @@ bool HistoryWidget::contentOverlapped(const QRect &globalRect) { || (_inlineResults && _inlineResults->overlaps(globalRect))); } -void HistoryWidget::updateReportSpamStatus() { - if (!_peer - || (_peer->id == session().userPeerId()) - || _peer->isServiceUser() - || (_peer->isUser() && _peer->asUser()->isBot())) { - setReportSpamStatus(dbiprsHidden); - return; - } else if (!_firstLoadRequest && _history->isEmpty()) { - setReportSpamStatus(dbiprsNoButton); - if (cReportSpamStatuses().contains(_peer->id)) { - cRefReportSpamStatuses().remove(_peer->id); - Local::writeReportSpamStatuses(); - } - return; - } else { - auto i = cReportSpamStatuses().constFind(_peer->id); - if (i != cReportSpamStatuses().cend()) { - if (i.value() == dbiprsNoButton) { - setReportSpamStatus(dbiprsHidden); - if (!_peer->isUser() || !_peer->asUser()->isContact()) { - MTP::send(MTPmessages_HidePeerSettingsBar(_peer->input)); - } - - cRefReportSpamStatuses().insert(_peer->id, _reportSpamStatus); - Local::writeReportSpamStatuses(); - } else { - setReportSpamStatus(i.value()); - if (_reportSpamStatus == dbiprsShowButton) { - requestReportSpamSetting(); - } - } - return; - } else if (_peer->migrateFrom()) { // migrate report status - i = cReportSpamStatuses().constFind(_peer->migrateFrom()->id); - if (i != cReportSpamStatuses().cend()) { - if (i.value() == dbiprsNoButton) { - setReportSpamStatus(dbiprsHidden); - if (!_peer->isUser() || !_peer->asUser()->isContact()) { - MTP::send(MTPmessages_HidePeerSettingsBar(_peer->input)); - } - } else { - setReportSpamStatus(i.value()); - if (_reportSpamStatus == dbiprsShowButton) { - requestReportSpamSetting(); - } - } - cRefReportSpamStatuses().insert(_peer->id, _reportSpamStatus); - Local::writeReportSpamStatuses(); - return; - } - } - } - auto status = dbiprsRequesting; - if (!session().data().contactsLoaded().current() || _firstLoadRequest) { - status = dbiprsUnknown; - } else if (_peer->isUser() && _peer->asUser()->isContact()) { - status = dbiprsHidden; - } else { - requestReportSpamSetting(); - } - setReportSpamStatus(status); - if (_reportSpamStatus == dbiprsHidden) { - cRefReportSpamStatuses().insert(_peer->id, _reportSpamStatus); - Local::writeReportSpamStatuses(); - } -} - -void HistoryWidget::requestReportSpamSetting() { - if (_reportSpamSettingRequestId >= 0 || !_peer) { - return; - } - - _reportSpamSettingRequestId = MTP::send( - MTPmessages_GetPeerSettings(_peer->input), - rpcDone(&HistoryWidget::reportSpamSettingDone), - rpcFail(&HistoryWidget::reportSpamSettingFail)); -} - -void HistoryWidget::reportSpamSettingDone(const MTPPeerSettings &result, mtpRequestId req) { - if (req != _reportSpamSettingRequestId) { - return; - } - - _reportSpamSettingRequestId = 0; - result.match([&](const MTPDpeerSettings &data) { - const auto status = data.is_report_spam() - ? dbiprsShowButton - : dbiprsHidden; - if (status != _reportSpamStatus) { - setReportSpamStatus(status); - if (_reportSpamPanel) { - _reportSpamPanel->setReported(false, _peer); - } - - cRefReportSpamStatuses().insert(_peer->id, _reportSpamStatus); - Local::writeReportSpamStatuses(); - - updateControlsVisibility(); - } - }); -} - -bool HistoryWidget::reportSpamSettingFail(const RPCError &error, mtpRequestId req) { - if (MTP::isDefaultHandledError(error)) return false; - - if (req == _reportSpamSettingRequestId) { - req = 0; - } - return true; -} - bool HistoryWidget::canWriteMessage() const { if (!_history || !_canSendMessages) return false; if (isBlocked() || isJoinChannel() || isMuteUnmute() || isBotStart()) return false; @@ -2085,8 +1903,8 @@ void HistoryWidget::updateControlsVisibility() { } else if (!_firstLoadRequest && _scroll->isHidden()) { _scroll->show(); } - if (_reportSpamPanel) { - _reportSpamPanel->show(); + if (_contactStatus) { + _contactStatus->show(); } refreshAboutProxyPromotion(); if (!editingMessage() && (isBlocked() || isJoinChannel() || isMuteUnmute() || isBotStart())) { @@ -2445,10 +2263,6 @@ void HistoryWidget::messagesReceived(PeerData *peer, const MTPmessages_Messages addMessagesToFront(peer, *histList); _preloadRequest = 0; preloadHistoryIfNeeded(); - if (_reportSpamStatus == dbiprsUnknown) { - updateReportSpamStatus(); - if (_reportSpamStatus != dbiprsUnknown) updateControlsVisibility(); - } } else if (_preloadDownRequest == requestId) { auto to = toMigrated ? _migrated : _history; addMessagesToBack(peer, *histList); @@ -3138,7 +2952,6 @@ void HistoryWidget::animationCallback() { void HistoryWidget::doneShow() { _topBar->setAnimatingMode(false); - updateReportSpamStatus(); updateBotKeyboard(); updateControlsVisibility(); if (!_historyInited) { @@ -4663,73 +4476,6 @@ void HistoryWidget::documentFailed(const FullMsgId &newId) { } } -void HistoryWidget::onReportSpamClicked() { - auto text = lang(_peer->isUser() ? lng_report_spam_sure : ((_peer->isChat() || _peer->isMegagroup()) ? lng_report_spam_sure_group : lng_report_spam_sure_channel)); - Ui::show(Box(text, lang(lng_report_spam_ok), st::attentionBoxButton, crl::guard(this, [this, peer = _peer] { - if (_reportSpamRequest) return; - - Ui::hideLayer(); - _reportSpamRequest = MTP::send( - MTPmessages_ReportSpam(peer->input), - rpcDone(&HistoryWidget::reportSpamDone, peer), - rpcFail(&HistoryWidget::reportSpamFail), 0, 5); - if (const auto user = peer->asUser()) { - session().api().blockUser(user); - } - }))); -} - -void HistoryWidget::reportSpamDone(PeerData *peer, const MTPBool &result, mtpRequestId req) { - Expects(peer != nullptr); - - if (req == _reportSpamRequest) { - _reportSpamRequest = 0; - } - cRefReportSpamStatuses().insert(peer->id, dbiprsReportSent); - Local::writeReportSpamStatuses(); - if (_peer == peer) { - setReportSpamStatus(dbiprsReportSent); - if (_reportSpamPanel) { - _reportSpamPanel->setReported(_reportSpamStatus == dbiprsReportSent, peer); - } - } -} - -bool HistoryWidget::reportSpamFail(const RPCError &error, mtpRequestId req) { - if (MTP::isDefaultHandledError(error)) return false; - - if (req == _reportSpamRequest) { - _reportSpamRequest = 0; - } - return false; -} - -void HistoryWidget::onReportSpamHide() { - if (_peer) { - cRefReportSpamStatuses().insert(_peer->id, dbiprsHidden); - Local::writeReportSpamStatuses(); - - MTP::send(MTPmessages_HidePeerSettingsBar(_peer->input)); - } - setReportSpamStatus(dbiprsHidden); - updateControlsVisibility(); -} - -void HistoryWidget::onReportSpamClear() { - Expects(_peer != nullptr); - - InvokeQueued(App::main(), [peer = _peer] { - Ui::showChatsList(); - if (const auto from = peer->migrateFrom()) { - peer->session().api().deleteConversation(from, false); - } - peer->session().api().deleteConversation(peer, false); - }); - - // Invalidates _peer. - controller()->showBackFromStack(); -} - void HistoryWidget::handleHistoryChange(not_null history) { if (_list && (_history == history || _migrated == history)) { handlePendingHistoryUpdate(); @@ -4824,11 +4570,11 @@ void HistoryWidget::updateControlsGeometry() { _pinnedBar->cancel->moveToLeft(width() - _pinnedBar->cancel->width(), pinnedBarTop); _pinnedBar->shadow->setGeometryToLeft(0, pinnedBarTop + st::historyReplyHeight, width(), st::lineWidth); } - const auto reportSpamTop = pinnedBarTop + (_pinnedBar ? st::historyReplyHeight : 0); - if (_reportSpamPanel) { - _reportSpamPanel->setGeometryToLeft(0, reportSpamTop, width(), _reportSpamPanel->height()); + const auto contactStatusTop = pinnedBarTop + (_pinnedBar ? st::historyReplyHeight : 0); + if (_contactStatus) { + _contactStatus->move(0, contactStatusTop); } - const auto scrollAreaTop = reportSpamTop + (_reportSpamPanel ? (_reportSpamPanel->height() - st::lineWidth) : 0); + const auto scrollAreaTop = contactStatusTop + (_contactStatus ? _contactStatus->height() : 0); if (_scroll->y() != scrollAreaTop) { _scroll->moveToLeft(0, scrollAreaTop); _fieldAutocomplete->setBoundings(_scroll->geometry()); @@ -4983,8 +4729,8 @@ void HistoryWidget::updateHistoryGeometry(bool initial, bool loadedDown, const S if (_pinnedBar) { newScrollHeight -= st::historyReplyHeight; } - if (_reportSpamPanel) { - newScrollHeight -= _reportSpamPanel->height() - st::lineWidth; + if (_contactStatus) { + newScrollHeight -= _contactStatus->height() - st::lineWidth; } if (!editingMessage() && (isBlocked() || isBotStart() || isJoinChannel() || isMuteUnmute())) { newScrollHeight -= _unblock->height(); @@ -5255,7 +5001,7 @@ void HistoryWidget::updateBotKeyboard(History *h, bool force) { int HistoryWidget::computeMaxFieldHeight() const { const auto available = height() - _topBar->height() - - (_reportSpamPanel ? _reportSpamPanel->height() - st::lineWidth : 0) + - (_contactStatus ? _contactStatus->height() : 0) - (_pinnedBar ? st::historyReplyHeight : 0) - ((_editMsgId || replyToId() @@ -6266,7 +6012,6 @@ void HistoryWidget::fullPeerUpdated(PeerData *peer) { refresh = true; } onCheckFieldAutocomplete(); - updateReportSpamStatus(); _list->updateBotInfo(); handlePeerUpdate(); @@ -6285,7 +6030,6 @@ void HistoryWidget::fullPeerUpdated(PeerData *peer) { void HistoryWidget::handlePeerUpdate() { bool resize = false; updateHistoryGeometry(); - if (_peer->isChannel()) updateReportSpamStatus(); if (_peer->isChat() && _peer->asChat()->noParticipantInfo()) { session().api().requestFullPeer(_peer); } else if (_peer->isUser() && (_peer->asUser()->blockStatus() == UserData::BlockStatus::Unknown || _peer->asUser()->callsStatus() == UserData::CallsStatus::Unknown)) { diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index 3e82809fb..b13e40204 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -78,6 +78,7 @@ struct UploadedThumbDocument; namespace HistoryView { class TopBarWidget; +class ContactStatus; } // namespace HistoryView class DragArea; @@ -87,30 +88,6 @@ class MessageField; class HistoryInner; struct HistoryMessageMarkupButton; -class ReportSpamPanel : public TWidget { - Q_OBJECT - -public: - ReportSpamPanel(QWidget *parent); - - void setReported(bool reported, PeerData *onPeer); - -signals: - void hideClicked(); - void reportClicked(); - void clearClicked(); - -protected: - void resizeEvent(QResizeEvent *e) override; - void paintEvent(QPaintEvent *e) override; - -private: - object_ptr _report; - object_ptr _hide; - object_ptr _clear; - -}; - class HistoryWidget final : public Window::AbstractSectionWidget, public RPCSender { Q_OBJECT @@ -302,10 +279,6 @@ signals: void cancelled(); public slots: - void onReportSpamClicked(); - void onReportSpamHide(); - void onReportSpamClear(); - void onScroll(); void onBroadcastSilentChange(); @@ -358,7 +331,6 @@ private: void toggleTabbedSelectorMode(); void returnTabbedSelector(object_ptr selector); void recountChatWidth(); - void setReportSpamStatus(DBIPeerReportSpamStatus status); void historyDownClicked(); void showNextUnreadMention(); void handlePeerUpdate(); @@ -572,19 +544,10 @@ private: void saveEditMsgDone(History *history, const MTPUpdates &updates, mtpRequestId req); bool saveEditMsgFail(History *history, const RPCError &error, mtpRequestId req); - void updateReportSpamStatus(); - void requestReportSpamSetting(); - void reportSpamSettingDone(const MTPPeerSettings &result, mtpRequestId req); - bool reportSpamSettingFail(const RPCError &error, mtpRequestId req); - void checkPreview(); void requestPreview(); void gotPreview(QString links, const MTPMessageMedia &media, mtpRequestId req); - static const mtpRequestId ReportSpamRequestNeeded = -1; - DBIPeerReportSpamStatus _reportSpamStatus = dbiprsUnknown; - mtpRequestId _reportSpamSettingRequestId = ReportSpamRequestNeeded; - QStringList _parsedLinks; QString _previewLinks; WebPageData *_previewData = nullptr; @@ -645,9 +608,6 @@ private: // This one is syntetic. void synteticScrollToY(int y); - void reportSpamDone(PeerData *peer, const MTPBool &result, mtpRequestId request); - bool reportSpamFail(const RPCError &error, mtpRequestId request); - void countHistoryShowFrom(); enum class TextUpdateEvent { @@ -749,7 +709,7 @@ private: bool showInlineBotCancel() const; void refreshSilentToggle(); - object_ptr _reportSpamPanel = { nullptr }; + std::unique_ptr _contactStatus; object_ptr _send; object_ptr _unblock; @@ -758,7 +718,6 @@ private: object_ptr _muteUnmute; object_ptr _discuss; object_ptr _aboutProxyPromotion = { nullptr }; - mtpRequestId _reportSpamRequest = 0; object_ptr _attachToggle; object_ptr _tabbedSelectorToggle; object_ptr _tabbedSelectorToggleTooltip = { nullptr }; diff --git a/Telegram/SourceFiles/history/view/history_view_contact_status.cpp b/Telegram/SourceFiles/history/view/history_view_contact_status.cpp new file mode 100644 index 000000000..116c5f4b2 --- /dev/null +++ b/Telegram/SourceFiles/history/view/history_view_contact_status.cpp @@ -0,0 +1,251 @@ +/* +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 "history/view/history_view_contact_status.h" + +#include "lang/lang_keys.h" +#include "ui/widgets/buttons.h" +#include "data/data_peer.h" +#include "data/data_user.h" +#include "data/data_chat.h" +#include "data/data_channel.h" +#include "apiwrap.h" +#include "auth_session.h" +#include "styles/style_history.h" +#include "styles/style_info.h" + +namespace HistoryView { +namespace { + +bool BarCurrentlyHidden(not_null peer) { + const auto settings = peer->settings(); + if (!settings) { + return false; + } else if (!(*settings)) { + return true; + } + using Setting = MTPDpeerSettings::Flag; + if (const auto user = peer->asUser()) { + if (user->isContact() + && !((*settings) & Setting::f_share_contact)) { + return true; + } + } else if (!((*settings) & Setting::f_report_spam)) { + return true; + } + return false; +} + +} // namespace +// +//void HistoryWidget::onReportSpamClicked() { +// auto text = lang(_peer->isUser() ? lng_report_spam_sure : ((_peer->isChat() || _peer->isMegagroup()) ? lng_report_spam_sure_group : lng_report_spam_sure_channel)); +// Ui::show(Box(text, lang(lng_report_spam_ok), st::attentionBoxButton, crl::guard(this, [this, peer = _peer] { +// if (_reportSpamRequest) return; +// +// Ui::hideLayer(); +// _reportSpamRequest = MTP::send( +// MTPmessages_ReportSpam(peer->input), +// rpcDone(&HistoryWidget::reportSpamDone, peer), +// rpcFail(&HistoryWidget::reportSpamFail), 0, 5); +// if (const auto user = peer->asUser()) { +// session().api().blockUser(user); +// } +// }))); +//} +// +//void HistoryWidget::reportSpamDone(PeerData *peer, const MTPBool &result, mtpRequestId req) { +// Expects(peer != nullptr); +// +// if (req == _reportSpamRequest) { +// _reportSpamRequest = 0; +// } +// cRefReportSpamStatuses().insert(peer->id, dbiprsReportSent); +// Local::writeReportSpamStatuses(); +// if (_peer == peer) { +// setReportSpamStatus(dbiprsReportSent); +// if (_reportSpamPanel) { +// _reportSpamPanel->setReported(_reportSpamStatus == dbiprsReportSent, peer); +// } +// } +//} +// +//bool HistoryWidget::reportSpamFail(const RPCError &error, mtpRequestId req) { +// if (MTP::isDefaultHandledError(error)) return false; +// +// if (req == _reportSpamRequest) { +// _reportSpamRequest = 0; +// } +// return false; +//} +// +//void HistoryWidget::onReportSpamHide() { +// if (_peer) { +// cRefReportSpamStatuses().insert(_peer->id, dbiprsHidden); +// Local::writeReportSpamStatuses(); +// +// MTP::send(MTPmessages_HidePeerSettingsBar(_peer->input)); +// } +// setReportSpamStatus(dbiprsHidden); +// updateControlsVisibility(); +//} +// +//void HistoryWidget::onReportSpamClear() { +// Expects(_peer != nullptr); +// +// InvokeQueued(App::main(), [peer = _peer] { +// Ui::showChatsList(); +// if (const auto from = peer->migrateFrom()) { +// peer->session().api().deleteConversation(from, false); +// } +// peer->session().api().deleteConversation(peer, false); +// }); +// +// // Invalidates _peer. +// controller()->showBackFromStack(); +//} + +ContactStatus::Bar::Bar(QWidget *parent) +: RpWidget(parent) +, _block(this, lang(lng_new_contact_block), st::historyUnblock) +, _add(this, lang(lng_new_contact_add), st::historyComposeButton) +, _share(this, lang(lng_new_contact_share), st::historyComposeButton) +, _report(this, lang(lng_report_spam), st::historyUnblock) +, _close(this, st::infoTopBarClose) { + resize(_close->size()); +} + +void ContactStatus::Bar::showState(State state) { + _add->setVisible(state == State::BlockOrAdd); + _block->setVisible(state == State::BlockOrAdd); + _share->setVisible(state == State::SharePhoneNumber); + _report->setVisible(state == State::ReportSpam); +} + +void ContactStatus::Bar::resizeEvent(QResizeEvent *e) { + _close->moveToRight(0, 0); + _add->setGeometry(0, 0, width() / 2, height()); + _block->setGeometry(width() / 2, 0, width() - (width() / 2), height()); + _share->setGeometry(rect()); + _report->setGeometry(rect()); +} + +ContactStatus::ContactStatus(not_null parent, not_null peer) +: _bar(parent, object_ptr(parent)) +, _shadow(parent) { + setupWidgets(parent); + setupState(peer); +} + +void ContactStatus::setupWidgets(not_null parent) { + parent->widthValue( + ) | rpl::start_with_next([=](int width) { + _bar.resizeToWidth(width); + }, _bar.lifetime()); + + _bar.geometryValue( + ) | rpl::start_with_next([=](QRect geometry) { + _shadow.setGeometry( + geometry.x(), + geometry.y() + geometry.height(), + geometry.width(), + st::lineWidth); + }, _shadow.lifetime()); + + _bar.shownValue( + ) | rpl::start_with_next([=](bool shown) { + _shadow.setVisible(shown); + }, _shadow.lifetime()); +} + +auto ContactStatus::PeerState(not_null peer) +-> rpl::producer { + using SettingsChange = PeerData::Settings::Change; + using Settings = MTPDpeerSettings::Flags; + using Setting = MTPDpeerSettings::Flag; + if (const auto user = peer->asUser()) { + using FlagsChange = UserData::Flags::Change; + using Flags = MTPDuser::Flags; + using Flag = MTPDuser::Flag; + + auto isContactChanges = user->flagsValue( + ) | rpl::filter([](FlagsChange flags) { + return flags.diff + & (Flag::f_contact | Flag::f_mutual_contact); + }); + return rpl::combine( + std::move(isContactChanges), + user->settingsValue() + ) | rpl::map([=](FlagsChange flags, SettingsChange settings) { + if (!settings.value) { + return State::None; + } else if (user->isContact()) { + if (settings.value & Setting::f_share_contact) { + return State::SharePhoneNumber; + } else { + return State::None; + } + } + return State::BlockOrAdd; + }); + } + + return peer->settingsValue( + ) | rpl::map([=](SettingsChange settings) { + return (settings.value & Setting::f_report_spam) + ? State::ReportSpam + : State::None; + }); +} + +void ContactStatus::setupState(not_null peer) { + if (!BarCurrentlyHidden(peer)) { + peer->session().api().requestPeerSettings(peer); + } + PeerState( + peer + ) | rpl::start_with_next([=](State state) { + if (state == State::None) { + _bar.hide(anim::type::normal); + } else { + _bar.entity()->showState(state); + _bar.show(anim::type::normal); + } + }, _bar.lifetime()); +} + +void ContactStatus::show() { + if (_shown) { + return; + } + _shown = true; + const auto visible = (_state != State::None); + if (visible) { + _bar.entity()->showState(_state); + } + _bar.toggle(visible, anim::type::instant); +} + +void ContactStatus::raise() { + _bar.raise(); + _shadow.raise(); +} + +void ContactStatus::move(int x, int y) { + _bar.move(x, y); + _shadow.move(x, y + _bar.height()); +} + +int ContactStatus::height() const { + return _bar.height(); +} + +rpl::producer ContactStatus::heightValue() const { + return _bar.heightValue(); +} + +} // namespace HistoryView diff --git a/Telegram/SourceFiles/history/view/history_view_contact_status.h b/Telegram/SourceFiles/history/view/history_view_contact_status.h new file mode 100644 index 000000000..53f24ad06 --- /dev/null +++ b/Telegram/SourceFiles/history/view/history_view_contact_status.h @@ -0,0 +1,72 @@ +/* +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 "ui/rp_widget.h" +#include "ui/wrap/slide_wrap.h" +#include "ui/widgets/shadow.h" + +namespace Ui { +class FlatButton; +class IconButton; +} // namespace Ui + +namespace HistoryView { + +class ContactStatus final { +public: + ContactStatus(not_null parent, not_null peer); + + void show(); + void raise(); + + void move(int x, int y); + int height() const; + rpl::producer heightValue() const; + +private: + enum class State { + None, + ReportSpam, + BlockOrAdd, + SharePhoneNumber, + }; + + class Bar : public Ui::RpWidget { + public: + explicit Bar(QWidget *parent); + + void showState(State state); + + protected: + void resizeEvent(QResizeEvent *e) override; + + private: + object_ptr _block; + object_ptr _add; + object_ptr _share; + object_ptr _report; + object_ptr _close; + + }; + + void setupWidgets(not_null parent); + void setupState(not_null peer); + + static rpl::producer PeerState(not_null peer); + + State _state = State::None; + Ui::SlideWrap _bar; + Ui::PlainShadow _shadow; + bool _shown = false; + + rpl::lifetime _lifetime; + +}; + +} // namespace HistoryView diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index c84cece7b..9677a3ef8 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -4215,8 +4215,11 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { } break; case mtpc_updatePeerSettings: { - //const auto &d = update.c_updateContactLink(); - //App::feedUserLink(d.vuser_id, d.vmy_link, d.vforeign_link); + const auto &d = update.c_updatePeerSettings(); + const auto peerId = peerFromMTP(d.vpeer); + if (const auto peer = session().data().peerLoaded(peerId)) { + //peer->updateSettings(d.vsettings); + } } break; case mtpc_updateNotifySettings: { @@ -4278,9 +4281,9 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { } break; case mtpc_updateUserBlocked: { - auto &d = update.c_updateUserBlocked(); - if (auto user = session().data().userLoaded(d.vuser_id.v)) { - user->setBlockStatus(mtpIsTrue(d.vblocked) ? UserData::BlockStatus::Blocked : UserData::BlockStatus::NotBlocked); + const auto &d = update.c_updateUserBlocked(); + if (const auto user = session().data().userLoaded(d.vuser_id.v)) { + user->setIsBlocked(mtpIsTrue(d.vblocked)); } } break; diff --git a/Telegram/SourceFiles/settings.cpp b/Telegram/SourceFiles/settings.cpp index bd1ab24f0..de09e96a1 100644 --- a/Telegram/SourceFiles/settings.cpp +++ b/Telegram/SourceFiles/settings.cpp @@ -69,8 +69,6 @@ int32 gIntRetinaFactor = 1; int gOtherOnline = 0; -ReportSpamStatuses gReportSpamStatuses; - int32 gAutoDownloadPhoto = 0; // all auto download int32 gAutoDownloadAudio = 0; int32 gAutoDownloadGif = 0; diff --git a/Telegram/SourceFiles/settings.h b/Telegram/SourceFiles/settings.h index 3f59dd514..75aa3657b 100644 --- a/Telegram/SourceFiles/settings.h +++ b/Telegram/SourceFiles/settings.h @@ -158,10 +158,6 @@ DeclareSetting(float64, RetinaFactor); DeclareSetting(int32, IntRetinaFactor); DeclareSetting(int, OtherOnline); - -typedef QMap ReportSpamStatuses; -DeclareRefSetting(ReportSpamStatuses, ReportSpamStatuses); - DeclareSetting(bool, AutoPlayGif); constexpr auto kInterfaceScaleAuto = 0; diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp index 473231e58..81a92a9b9 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp @@ -234,7 +234,7 @@ void BlockedBoxController::receivedUsers(const QVector &resul item.match([&](const MTPDcontactBlocked &data) { if (const auto user = Auth().data().userLoaded(data.vuser_id.v)) { appendRow(user); - user->setBlockStatus(UserData::BlockStatus::Blocked); + user->setIsBlocked(true); } }); } diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp index 54bdc9d20..0fbd6e8f8 100644 --- a/Telegram/SourceFiles/storage/localstorage.cpp +++ b/Telegram/SourceFiles/storage/localstorage.cpp @@ -518,7 +518,7 @@ enum { // Local Storage Keys lskRecentHashtagsAndBots = 0x0a, // no data lskStickersOld = 0x0b, // no data lskSavedPeersOld = 0x0c, // no data - lskReportSpamStatuses = 0x0d, // no data + lskReportSpamStatusesOld = 0x0d, // no data lskSavedGifsOld = 0x0e, // no data lskSavedGifs = 0x0f, // no data lskStickersKeys = 0x10, // no data @@ -645,7 +645,7 @@ typedef QMap FileLocationPairs; FileLocationPairs _fileLocationPairs; typedef QMap FileLocationAliases; FileLocationAliases _fileLocationAliases; -FileKey _locationsKey = 0, _reportSpamStatusesKey = 0, _trustedBotsKey = 0; +FileKey _locationsKey = 0, _trustedBotsKey = 0; using TrustedBots = OrderedSet; TrustedBots _trustedBots; @@ -838,63 +838,6 @@ void _readLocations() { } } -void _writeReportSpamStatuses() { - if (!_working()) return; - - if (cReportSpamStatuses().isEmpty()) { - if (_reportSpamStatusesKey) { - clearKey(_reportSpamStatusesKey); - _reportSpamStatusesKey = 0; - _mapChanged = true; - _writeMap(); - } - } else { - if (!_reportSpamStatusesKey) { - _reportSpamStatusesKey = genKey(); - _mapChanged = true; - _writeMap(WriteMapWhen::Fast); - } - const ReportSpamStatuses &statuses(cReportSpamStatuses()); - - quint32 size = sizeof(qint32); - for (ReportSpamStatuses::const_iterator i = statuses.cbegin(), e = statuses.cend(); i != e; ++i) { - // peer + status - size += sizeof(quint64) + sizeof(qint32); - } - - EncryptedDescriptor data(size); - data.stream << qint32(statuses.size()); - for (ReportSpamStatuses::const_iterator i = statuses.cbegin(), e = statuses.cend(); i != e; ++i) { - data.stream << quint64(i.key()) << qint32(i.value()); - } - - FileWriteDescriptor file(_reportSpamStatusesKey); - file.writeEncrypted(data); - } -} - -void _readReportSpamStatuses() { - FileReadDescriptor statuses; - if (!readEncryptedFile(statuses, _reportSpamStatusesKey)) { - clearKey(_reportSpamStatusesKey); - _reportSpamStatusesKey = 0; - _writeMap(); - return; - } - - ReportSpamStatuses &map(cRefReportSpamStatuses()); - map.clear(); - - qint32 size = 0; - statuses.stream >> size; - for (int32 i = 0; i < size; ++i) { - quint64 peer = 0; - qint32 status = 0; - statuses.stream >> peer >> status; - map.insert(peer, DBIPeerReportSpamStatus(status)); - } -} - struct ReadSettingsContext { int legacyLanguageId = Lang::kLegacyLanguageNone; QString legacyLanguageFile; @@ -2352,8 +2295,9 @@ ReadMapState _readMap(const QByteArray &pass) { case lskLocations: { map.stream >> locationsKey; } break; - case lskReportSpamStatuses: { + case lskReportSpamStatusesOld: { map.stream >> reportSpamStatusesKey; + clearKey(reportSpamStatusesKey); } break; case lskTrustedBots: { map.stream >> trustedBotsKey; @@ -2412,7 +2356,6 @@ ReadMapState _readMap(const QByteArray &pass) { _draftsNotReadMap = draftsNotReadMap; _locationsKey = locationsKey; - _reportSpamStatusesKey = reportSpamStatusesKey; _trustedBotsKey = trustedBotsKey; _recentStickersKeyOld = recentStickersKeyOld; _installedStickersKey = installedStickersKey; @@ -2437,9 +2380,6 @@ ReadMapState _readMap(const QByteArray &pass) { if (_locationsKey) { _readLocations(); } - if (_reportSpamStatusesKey) { - _readReportSpamStatuses(); - } _readUserSettings(); _readMtpData(); @@ -2516,7 +2456,6 @@ void _writeMap(WriteMapWhen when) { if (!_draftsMap.isEmpty()) mapSize += sizeof(quint32) * 2 + _draftsMap.size() * sizeof(quint64) * 2; if (!_draftCursorsMap.isEmpty()) mapSize += sizeof(quint32) * 2 + _draftCursorsMap.size() * sizeof(quint64) * 2; if (_locationsKey) mapSize += sizeof(quint32) + sizeof(quint64); - if (_reportSpamStatusesKey) mapSize += sizeof(quint32) + sizeof(quint64); if (_trustedBotsKey) mapSize += sizeof(quint32) + sizeof(quint64); if (_recentStickersKeyOld) mapSize += sizeof(quint32) + sizeof(quint64); if (_installedStickersKey || _featuredStickersKey || _recentStickersKey || _archivedStickersKey) { @@ -2548,9 +2487,6 @@ void _writeMap(WriteMapWhen when) { if (_locationsKey) { mapData.stream << quint32(lskLocations) << quint64(_locationsKey); } - if (_reportSpamStatusesKey) { - mapData.stream << quint32(lskReportSpamStatuses) << quint64(_reportSpamStatusesKey); - } if (_trustedBotsKey) { mapData.stream << quint32(lskTrustedBots) << quint64(_trustedBotsKey); } @@ -2837,7 +2773,7 @@ void reset() { _fileLocationPairs.clear(); _fileLocationAliases.clear(); _draftsNotReadMap.clear(); - _locationsKey = _reportSpamStatusesKey = _trustedBotsKey = 0; + _locationsKey = _trustedBotsKey = 0; _recentStickersKeyOld = 0; _installedStickersKey = _featuredStickersKey = _recentStickersKey = _favedStickersKey = _archivedStickersKey = 0; _savedGifsKey = 0; @@ -2879,7 +2815,6 @@ void setPasscode(const QByteArray &passcode) { base::flat_set CollectGoodNames() { const auto keys = { _locationsKey, - _reportSpamStatusesKey, _userSettingsKey, _installedStickersKey, _featuredStickersKey, @@ -4838,10 +4773,6 @@ Export::Settings ReadExportSettings() { : Export::Settings(); } -void writeReportSpamStatuses() { - _writeReportSpamStatuses(); -} - void writeSelf() { _mapChanged = true; _writeMap(); @@ -4976,10 +4907,6 @@ bool ClearManager::addTask(int task) { _locationsKey = 0; _mapChanged = true; } - if (_reportSpamStatusesKey) { - _reportSpamStatusesKey = 0; - _mapChanged = true; - } if (_trustedBotsKey) { _trustedBotsKey = 0; _mapChanged = true; diff --git a/Telegram/SourceFiles/storage/localstorage.h b/Telegram/SourceFiles/storage/localstorage.h index 5a54c5bea..135632536 100644 --- a/Telegram/SourceFiles/storage/localstorage.h +++ b/Telegram/SourceFiles/storage/localstorage.h @@ -169,8 +169,6 @@ void saveRecentSearchHashtags(const QString &text); void WriteExportSettings(const Export::Settings &settings); Export::Settings ReadExportSettings(); -void writeReportSpamStatuses(); - void writeSelf(); void readSelf(const QByteArray &serialized, int32 streamVersion); diff --git a/Telegram/gyp/telegram_sources.txt b/Telegram/gyp/telegram_sources.txt index 08d6d5484..5f01d4f20 100644 --- a/Telegram/gyp/telegram_sources.txt +++ b/Telegram/gyp/telegram_sources.txt @@ -296,6 +296,8 @@ <(src_loc)/history/media/history_media_wall_paper.cpp <(src_loc)/history/media/history_media_web_page.h <(src_loc)/history/media/history_media_web_page.cpp +<(src_loc)/history/view/history_view_contact_status.cpp +<(src_loc)/history/view/history_view_contact_status.h <(src_loc)/history/view/history_view_context_menu.cpp <(src_loc)/history/view/history_view_context_menu.h <(src_loc)/history/view/history_view_cursor_state.cpp