2018-01-04 10:22:53 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "data/data_session.h"
|
|
|
|
|
|
|
|
#include "observer_peer.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2018-01-17 16:21:01 +00:00
|
|
|
#include "apiwrap.h"
|
2019-03-25 11:49:57 +00:00
|
|
|
#include "mainwidget.h"
|
2019-09-16 11:14:06 +00:00
|
|
|
#include "api/api_text_entities.h"
|
2019-01-21 13:42:21 +00:00
|
|
|
#include "core/application.h"
|
2020-01-07 10:41:13 +00:00
|
|
|
#include "core/mime_type.h" // Core::IsMimeSticker
|
2019-04-10 11:26:15 +00:00
|
|
|
#include "core/crash_reports.h" // CrashReports::SetAnnotation
|
2018-10-23 09:44:42 +00:00
|
|
|
#include "ui/image/image.h"
|
2019-04-10 11:26:15 +00:00
|
|
|
#include "ui/image/image_source.h" // Images::LocalFileSource
|
2020-04-16 12:37:26 +00:00
|
|
|
#include "ui/image/image_location_factory.h" // Images::FromPhotoSize
|
2018-06-20 00:02:36 +00:00
|
|
|
#include "export/export_controller.h"
|
|
|
|
#include "export/view/export_view_panel_controller.h"
|
2018-04-09 17:48:29 +00:00
|
|
|
#include "window/notifications_manager.h"
|
2018-01-18 11:46:45 +00:00
|
|
|
#include "history/history.h"
|
2018-01-04 10:22:53 +00:00
|
|
|
#include "history/history_item_components.h"
|
2019-08-02 13:21:09 +00:00
|
|
|
#include "history/view/media/history_view_media.h"
|
2018-01-14 16:02:25 +00:00
|
|
|
#include "history/view/history_view_element.h"
|
2018-01-17 16:21:01 +00:00
|
|
|
#include "inline_bots/inline_bot_layout_item.h"
|
|
|
|
#include "storage/localstorage.h"
|
2018-08-27 11:35:58 +00:00
|
|
|
#include "storage/storage_encrypted_file.h"
|
2019-07-24 08:46:23 +00:00
|
|
|
#include "main/main_account.h"
|
2019-04-10 11:26:15 +00:00
|
|
|
#include "media/player/media_player_instance.h" // instance()->play()
|
2018-06-28 17:44:07 +00:00
|
|
|
#include "boxes/abstract_box.h"
|
2018-07-10 16:41:11 +00:00
|
|
|
#include "passport/passport_form_controller.h"
|
2019-01-03 12:36:01 +00:00
|
|
|
#include "window/themes/window_theme.h"
|
2019-06-19 15:09:03 +00:00
|
|
|
#include "lang/lang_keys.h" // tr::lng_deleted(tr::now) in user name
|
2018-01-17 16:21:01 +00:00
|
|
|
#include "data/data_media_types.h"
|
2019-04-15 11:54:03 +00:00
|
|
|
#include "data/data_folder.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_channel.h"
|
|
|
|
#include "data/data_chat.h"
|
|
|
|
#include "data/data_user.h"
|
|
|
|
#include "data/data_file_origin.h"
|
2018-01-17 16:21:01 +00:00
|
|
|
#include "data/data_photo.h"
|
|
|
|
#include "data/data_document.h"
|
|
|
|
#include "data/data_web_page.h"
|
|
|
|
#include "data/data_game.h"
|
2018-12-18 05:43:11 +00:00
|
|
|
#include "data/data_poll.h"
|
2020-02-07 16:07:21 +00:00
|
|
|
#include "data/data_chat_filters.h"
|
2019-08-08 17:07:55 +00:00
|
|
|
#include "data/data_scheduled_messages.h"
|
2019-09-03 15:24:51 +00:00
|
|
|
#include "data/data_cloud_themes.h"
|
2019-12-28 14:56:06 +00:00
|
|
|
#include "data/data_streaming.h"
|
2020-02-05 15:27:53 +00:00
|
|
|
#include "data/data_media_rotation.h"
|
2020-02-18 11:39:24 +00:00
|
|
|
#include "data/data_histories.h"
|
2019-09-17 16:13:12 +00:00
|
|
|
#include "base/platform/base_platform_info.h"
|
2019-07-10 17:28:33 +00:00
|
|
|
#include "base/unixtime.h"
|
2019-09-26 10:55:35 +00:00
|
|
|
#include "base/call_delayed.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "facades.h"
|
|
|
|
#include "app.h"
|
2019-04-10 11:26:15 +00:00
|
|
|
#include "styles/style_boxes.h" // st::backgroundSize
|
2018-01-04 10:22:53 +00:00
|
|
|
|
|
|
|
namespace Data {
|
2018-01-17 16:21:01 +00:00
|
|
|
namespace {
|
2018-01-04 10:22:53 +00:00
|
|
|
|
2019-02-19 06:57:53 +00:00
|
|
|
constexpr auto kMaxNotifyCheckDelay = 24 * 3600 * crl::time(1000);
|
2019-01-16 12:25:29 +00:00
|
|
|
constexpr auto kMaxWallpaperSize = 10 * 1024 * 1024;
|
2018-04-09 17:48:29 +00:00
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
using ViewElement = HistoryView::Element;
|
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
// s: box 100x100
|
|
|
|
// m: box 320x320
|
|
|
|
// x: box 800x800
|
|
|
|
// y: box 1280x1280
|
|
|
|
// w: box 2560x2560 // if loading this fix HistoryPhoto::updateFrom
|
|
|
|
// a: crop 160x160
|
|
|
|
// b: crop 320x320
|
|
|
|
// c: crop 640x640
|
|
|
|
// d: crop 1280x1280
|
2020-05-25 14:16:04 +00:00
|
|
|
const auto InlineLevels = "i"_q;
|
2020-05-26 10:13:32 +00:00
|
|
|
const auto SmallLevels = "sa"_q;
|
|
|
|
const auto ThumbnailLevels = "mbsa"_q;
|
|
|
|
const auto LargeLevels = "ydxcwmbsa"_q;
|
2018-01-17 16:21:01 +00:00
|
|
|
|
2019-01-03 12:36:01 +00:00
|
|
|
void CheckForSwitchInlineButton(not_null<HistoryItem*> item) {
|
|
|
|
if (item->out() || !item->hasSwitchInlineButton()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (const auto user = item->history()->peer->asUser()) {
|
2019-07-18 08:51:11 +00:00
|
|
|
if (!user->isBot() || !user->botInfo->inlineReturnPeerId) {
|
2019-01-03 12:36:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (const auto markup = item->Get<HistoryMessageReplyMarkup>()) {
|
|
|
|
for (const auto &row : markup->rows) {
|
|
|
|
for (const auto &button : row) {
|
|
|
|
using ButtonType = HistoryMessageMarkupButton::Type;
|
|
|
|
if (button.type == ButtonType::SwitchInline) {
|
|
|
|
Notify::switchInlineBotButtonReceived(
|
|
|
|
QString::fromUtf8(button.data));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We should get a full restriction in "{full}: {reason}" format and we
|
|
|
|
// need to find an "-all" tag in {full}, otherwise ignore this restriction.
|
2019-12-09 13:57:33 +00:00
|
|
|
std::vector<UnavailableReason> ExtractUnavailableReasons(
|
2019-08-27 18:24:48 +00:00
|
|
|
const QVector<MTPRestrictionReason> &restrictions) {
|
2019-12-09 13:57:33 +00:00
|
|
|
return ranges::view::all(
|
2019-08-27 18:24:48 +00:00
|
|
|
restrictions
|
2019-12-09 13:57:33 +00:00
|
|
|
) | ranges::view::filter([](const MTPRestrictionReason &restriction) {
|
2019-08-27 18:24:48 +00:00
|
|
|
return restriction.match([&](const MTPDrestrictionReason &data) {
|
|
|
|
const auto platform = qs(data.vplatform());
|
2019-12-09 13:57:33 +00:00
|
|
|
return false
|
2019-08-27 18:24:48 +00:00
|
|
|
#ifdef OS_MAC_STORE
|
|
|
|
|| (platform == qstr("ios"))
|
|
|
|
#elif defined OS_WIN_STORE // OS_MAC_STORE
|
|
|
|
|| (platform == qstr("ms"))
|
|
|
|
#endif // OS_MAC_STORE || OS_WIN_STORE
|
2019-12-09 13:57:33 +00:00
|
|
|
|| (platform == qstr("all"));
|
2019-08-27 18:24:48 +00:00
|
|
|
});
|
2019-12-09 13:57:33 +00:00
|
|
|
}) | ranges::view::transform([](const MTPRestrictionReason &restriction) {
|
|
|
|
return restriction.match([&](const MTPDrestrictionReason &data) {
|
|
|
|
return UnavailableReason{ qs(data.vreason()), qs(data.vtext()) };
|
|
|
|
});
|
|
|
|
}) | ranges::to_vector;
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
|
|
|
|
2020-05-25 14:16:04 +00:00
|
|
|
[[nodiscard]] QByteArray FindInlineThumbnail(
|
|
|
|
const QVector<MTPPhotoSize> &sizes) {
|
2019-01-25 14:37:28 +00:00
|
|
|
const auto i = ranges::find(
|
2020-05-25 14:16:04 +00:00
|
|
|
sizes,
|
2019-01-25 14:37:28 +00:00
|
|
|
mtpc_photoStrippedSize,
|
|
|
|
&MTPPhotoSize::type);
|
2020-05-25 14:16:04 +00:00
|
|
|
return (i != sizes.end())
|
|
|
|
? i->c_photoStrippedSize().vbytes().v
|
|
|
|
: QByteArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] QByteArray FindDocumentInlineThumbnail(const MTPDdocument &data) {
|
|
|
|
return FindInlineThumbnail(data.vthumbs().value_or_empty());
|
2019-01-25 14:37:28 +00:00
|
|
|
}
|
|
|
|
|
2020-05-25 14:16:04 +00:00
|
|
|
[[nodiscard]] MTPPhotoSize FindDocumentThumbnail(const MTPDdocument &data) {
|
2019-01-03 14:39:19 +00:00
|
|
|
const auto area = [](const MTPPhotoSize &size) {
|
2019-01-25 14:37:28 +00:00
|
|
|
static constexpr auto kInvalid = 0;
|
2019-01-03 14:39:19 +00:00
|
|
|
return size.match([](const MTPDphotoSizeEmpty &) {
|
|
|
|
return kInvalid;
|
|
|
|
}, [](const MTPDphotoStrippedSize &) {
|
|
|
|
return kInvalid;
|
|
|
|
}, [](const auto &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
return (data.vw().v * data.vh().v);
|
2019-01-03 14:39:19 +00:00
|
|
|
});
|
|
|
|
};
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto thumbs = data.vthumbs();
|
|
|
|
if (!thumbs) {
|
|
|
|
return MTP_photoSizeEmpty(MTP_string());
|
|
|
|
}
|
|
|
|
const auto &list = thumbs->v;
|
|
|
|
const auto i = ranges::max_element(list, std::less<>(), area);
|
|
|
|
return (i != list.end() && area(*i) > 0)
|
2019-01-03 14:39:19 +00:00
|
|
|
? (*i)
|
2019-07-05 13:38:38 +00:00
|
|
|
: MTPPhotoSize(MTP_photoSizeEmpty(MTP_string()));
|
2019-01-03 14:39:19 +00:00
|
|
|
}
|
|
|
|
|
2020-05-25 14:16:04 +00:00
|
|
|
[[nodiscard]] std::optional<MTPVideoSize> FindDocumentVideoThumbnail(
|
2020-05-22 11:15:09 +00:00
|
|
|
const MTPDdocument &data) {
|
|
|
|
const auto area = [](const MTPVideoSize &size) {
|
|
|
|
static constexpr auto kInvalid = 0;
|
|
|
|
return size.match([](const MTPDvideoSize &data) {
|
|
|
|
return (data.vw().v * data.vh().v);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
const auto thumbs = data.vvideo_thumbs();
|
|
|
|
if (!thumbs) {
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
const auto &list = thumbs->v;
|
|
|
|
const auto i = ranges::max_element(list, std::less<>(), area);
|
|
|
|
return (i != list.end() && area(*i) > 0)
|
|
|
|
? std::make_optional(*i)
|
|
|
|
: std::nullopt;
|
|
|
|
}
|
|
|
|
|
2020-05-25 14:16:04 +00:00
|
|
|
[[nodiscard]] QByteArray FindPhotoInlineThumbnail(const MTPDphoto &data) {
|
|
|
|
return FindInlineThumbnail(data.vsizes().v);
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] rpl::producer<int> PinnedDialogsCountMaxValue(
|
2019-07-24 11:45:24 +00:00
|
|
|
not_null<Main::Session*> session) {
|
2019-04-22 14:22:39 +00:00
|
|
|
return rpl::single(
|
|
|
|
rpl::empty_value()
|
|
|
|
) | rpl::then(
|
2019-07-24 08:46:23 +00:00
|
|
|
session->account().configUpdates()
|
2019-04-22 14:22:39 +00:00
|
|
|
) | rpl::map([=] {
|
|
|
|
return Global::PinnedDialogsCountMax();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
} // namespace
|
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
Session::Session(not_null<Main::Session*> session)
|
2018-01-17 16:21:01 +00:00
|
|
|
: _session(session)
|
2019-01-21 13:42:21 +00:00
|
|
|
, _cache(Core::App().databases().get(
|
2018-08-29 13:23:16 +00:00
|
|
|
Local::cachePath(),
|
|
|
|
Local::cacheSettings()))
|
2019-02-25 17:26:08 +00:00
|
|
|
, _bigFileCache(Core::App().databases().get(
|
|
|
|
Local::cacheBigFilePath(),
|
|
|
|
Local::cacheBigFileSettings()))
|
2020-03-09 11:17:56 +00:00
|
|
|
, _chatsList(FilterId(), PinnedDialogsCountMaxValue(session))
|
2019-04-16 14:05:56 +00:00
|
|
|
, _contactsList(Dialogs::SortMode::Name)
|
|
|
|
, _contactsNoChatsList(Dialogs::SortMode::Name)
|
2019-01-03 12:36:01 +00:00
|
|
|
, _selfDestructTimer([=] { checkSelfDestructItems(); })
|
2019-04-01 14:53:18 +00:00
|
|
|
, _sendActionsAnimation([=](crl::time now) {
|
|
|
|
return sendActionsAnimationCallback(now);
|
|
|
|
})
|
2020-04-07 12:10:34 +00:00
|
|
|
, _pollsClosingTimer([=] { checkPollsClosings(); })
|
2019-08-08 14:13:26 +00:00
|
|
|
, _unmuteByFinishedTimer([=] { unmuteByFinished(); })
|
2018-04-09 17:48:29 +00:00
|
|
|
, _groups(this)
|
2020-02-07 16:07:21 +00:00
|
|
|
, _chatsFilters(std::make_unique<ChatFilters>(this))
|
2019-09-03 15:24:51 +00:00
|
|
|
, _scheduledMessages(std::make_unique<ScheduledMessages>(this))
|
2019-12-28 14:56:06 +00:00
|
|
|
, _cloudThemes(std::make_unique<CloudThemes>(session))
|
2020-02-05 15:27:53 +00:00
|
|
|
, _streaming(std::make_unique<Streaming>(this))
|
2020-02-18 11:39:24 +00:00
|
|
|
, _mediaRotation(std::make_unique<MediaRotation>())
|
|
|
|
, _histories(std::make_unique<Histories>(this)) {
|
2018-08-29 13:23:16 +00:00
|
|
|
_cache->open(Local::cacheKey());
|
2019-02-25 17:26:08 +00:00
|
|
|
_bigFileCache->open(Local::cacheBigFileKey());
|
2018-08-27 11:35:58 +00:00
|
|
|
|
2019-07-15 12:17:22 +00:00
|
|
|
if constexpr (Platform::IsLinux()) {
|
|
|
|
const auto wasVersion = Local::oldMapVersion();
|
|
|
|
if (wasVersion >= 1007011 && wasVersion < 1007015) {
|
|
|
|
_bigFileCache->clear();
|
|
|
|
_cache->clearByTag(Data::kImageCacheTag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-08 09:20:14 +00:00
|
|
|
setupContactViewsViewer();
|
|
|
|
setupChannelLeavingViewer();
|
2019-04-16 14:05:56 +00:00
|
|
|
setupPeerNameViewer();
|
|
|
|
setupUserIsContactViewer();
|
2020-03-16 10:20:18 +00:00
|
|
|
|
|
|
|
_chatsList.unreadStateChanges(
|
|
|
|
) | rpl::start_with_next([] {
|
|
|
|
Notify::unreadCounterUpdated();
|
|
|
|
}, _lifetime);
|
2018-02-08 09:20:14 +00:00
|
|
|
}
|
|
|
|
|
2019-01-03 12:36:01 +00:00
|
|
|
void Session::clear() {
|
|
|
|
_sendActions.clear();
|
|
|
|
|
2020-02-18 11:39:24 +00:00
|
|
|
_histories->unloadAll();
|
2019-08-08 17:07:55 +00:00
|
|
|
_scheduledMessages = nullptr;
|
2019-04-25 12:45:15 +00:00
|
|
|
_dependentMessages.clear();
|
|
|
|
base::take(_messages);
|
|
|
|
base::take(_channelMessages);
|
|
|
|
_messageByRandomId.clear();
|
|
|
|
_sentMessagesData.clear();
|
|
|
|
cSetRecentInlineBots(RecentInlineBots());
|
|
|
|
cSetRecentStickers(RecentStickerPack());
|
|
|
|
App::clearMousedItems();
|
2020-02-18 11:39:24 +00:00
|
|
|
_histories->clearAll();
|
2020-03-26 12:03:31 +00:00
|
|
|
_webpages.clear();
|
|
|
|
_locations.clear();
|
|
|
|
_polls.clear();
|
|
|
|
_games.clear();
|
|
|
|
_documents.clear();
|
|
|
|
_photos.clear();
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
not_null<PeerData*> Session::peer(PeerId id) {
|
|
|
|
const auto i = _peers.find(id);
|
|
|
|
if (i != _peers.cend()) {
|
|
|
|
return i->second.get();
|
|
|
|
}
|
|
|
|
auto result = [&]() -> std::unique_ptr<PeerData> {
|
|
|
|
if (peerIsUser(id)) {
|
|
|
|
return std::make_unique<UserData>(this, id);
|
|
|
|
} else if (peerIsChat(id)) {
|
|
|
|
return std::make_unique<ChatData>(this, id);
|
|
|
|
} else if (peerIsChannel(id)) {
|
|
|
|
return std::make_unique<ChannelData>(this, id);
|
|
|
|
}
|
|
|
|
Unexpected("Peer id type.");
|
|
|
|
}();
|
|
|
|
|
|
|
|
result->input = MTPinputPeer(MTP_inputPeerEmpty());
|
|
|
|
return _peers.emplace(id, std::move(result)).first->second.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
not_null<UserData*> Session::user(UserId id) {
|
|
|
|
return peer(peerFromUser(id))->asUser();
|
|
|
|
}
|
|
|
|
|
|
|
|
not_null<ChatData*> Session::chat(ChatId id) {
|
|
|
|
return peer(peerFromChat(id))->asChat();
|
|
|
|
}
|
|
|
|
|
|
|
|
not_null<ChannelData*> Session::channel(ChannelId id) {
|
|
|
|
return peer(peerFromChannel(id))->asChannel();
|
|
|
|
}
|
|
|
|
|
|
|
|
PeerData *Session::peerLoaded(PeerId id) const {
|
|
|
|
const auto i = _peers.find(id);
|
|
|
|
if (i == end(_peers)) {
|
|
|
|
return nullptr;
|
|
|
|
} else if (i->second->loadedStatus != PeerData::FullLoaded) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return i->second.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
UserData *Session::userLoaded(UserId id) const {
|
|
|
|
if (const auto peer = peerLoaded(peerFromUser(id))) {
|
|
|
|
return peer->asUser();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
ChatData *Session::chatLoaded(ChatId id) const {
|
|
|
|
if (const auto peer = peerLoaded(peerFromChat(id))) {
|
|
|
|
return peer->asChat();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
ChannelData *Session::channelLoaded(ChannelId id) const {
|
|
|
|
if (const auto peer = peerLoaded(peerFromChannel(id))) {
|
|
|
|
return peer->asChannel();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-01-18 12:27:37 +00:00
|
|
|
not_null<UserData*> Session::processUser(const MTPUser &data) {
|
2019-01-03 12:36:01 +00:00
|
|
|
const auto result = user(data.match([](const auto &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
return data.vid().v;
|
2019-01-03 12:36:01 +00:00
|
|
|
}));
|
|
|
|
auto minimal = false;
|
2019-04-01 14:53:18 +00:00
|
|
|
const MTPUserStatus *status = nullptr;
|
|
|
|
const MTPUserStatus emptyStatus = MTP_userStatusEmpty();
|
2019-01-03 12:36:01 +00:00
|
|
|
|
|
|
|
Notify::PeerUpdate update;
|
|
|
|
using UpdateFlag = Notify::PeerUpdate::Flag;
|
|
|
|
data.match([&](const MTPDuserEmpty &data) {
|
|
|
|
const auto canShareThisContact = result->canShareThisContactFast();
|
|
|
|
|
2019-07-05 13:38:38 +00:00
|
|
|
result->input = MTP_inputPeerUser(data.vid(), MTP_long(0));
|
|
|
|
result->inputUser = MTP_inputUser(data.vid(), MTP_long(0));
|
2019-06-19 15:09:03 +00:00
|
|
|
result->setName(tr::lng_deleted(tr::now), QString(), QString(), QString());
|
2019-01-03 12:36:01 +00:00
|
|
|
result->setPhoto(MTP_userProfilePhotoEmpty());
|
|
|
|
//result->setFlags(MTPDuser_ClientFlag::f_inaccessible | 0);
|
|
|
|
result->setFlags(MTPDuser::Flag::f_deleted);
|
|
|
|
if (!result->phone().isEmpty()) {
|
|
|
|
result->setPhone(QString());
|
|
|
|
update.flags |= UpdateFlag::UserPhoneChanged;
|
|
|
|
}
|
|
|
|
result->setBotInfoVersion(-1);
|
|
|
|
status = &emptyStatus;
|
2019-06-06 16:48:42 +00:00
|
|
|
result->setIsContact(false);
|
2019-01-03 12:36:01 +00:00
|
|
|
if (canShareThisContact != result->canShareThisContactFast()) {
|
|
|
|
update.flags |= UpdateFlag::UserCanShareContact;
|
|
|
|
}
|
|
|
|
}, [&](const MTPDuser &data) {
|
|
|
|
minimal = data.is_min();
|
|
|
|
|
|
|
|
const auto canShareThisContact = result->canShareThisContactFast();
|
|
|
|
if (minimal) {
|
|
|
|
const auto mask = 0
|
|
|
|
//| MTPDuser_ClientFlag::f_inaccessible
|
|
|
|
| MTPDuser::Flag::f_deleted;
|
2019-07-05 13:38:38 +00:00
|
|
|
result->setFlags((result->flags() & ~mask) | (data.vflags().v & mask));
|
2019-01-03 12:36:01 +00:00
|
|
|
} else {
|
2019-07-05 13:38:38 +00:00
|
|
|
result->setFlags(data.vflags().v);
|
2019-01-03 12:36:01 +00:00
|
|
|
if (data.is_self()) {
|
|
|
|
result->input = MTP_inputPeerSelf();
|
|
|
|
result->inputUser = MTP_inputUserSelf();
|
2019-07-05 13:38:38 +00:00
|
|
|
} else if (const auto accessHash = data.vaccess_hash()) {
|
|
|
|
result->input = MTP_inputPeerUser(data.vid(), *accessHash);
|
|
|
|
result->inputUser = MTP_inputUser(data.vid(), *accessHash);
|
|
|
|
} else {
|
|
|
|
result->input = MTP_inputPeerUser(data.vid(), MTP_long(result->accessHash()));
|
|
|
|
result->inputUser = MTP_inputUser(data.vid(), MTP_long(result->accessHash()));
|
|
|
|
}
|
|
|
|
if (const auto restriction = data.vrestriction_reason()) {
|
2019-12-09 13:57:33 +00:00
|
|
|
result->setUnavailableReasons(
|
|
|
|
ExtractUnavailableReasons(restriction->v));
|
2019-01-03 12:36:01 +00:00
|
|
|
} else {
|
2019-12-09 13:57:33 +00:00
|
|
|
result->setUnavailableReasons({});
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (data.is_deleted()) {
|
|
|
|
if (!result->phone().isEmpty()) {
|
|
|
|
result->setPhone(QString());
|
|
|
|
update.flags |= UpdateFlag::UserPhoneChanged;
|
|
|
|
}
|
2019-06-19 15:09:03 +00:00
|
|
|
result->setName(tr::lng_deleted(tr::now), QString(), QString(), QString());
|
2019-01-03 12:36:01 +00:00
|
|
|
result->setPhoto(MTP_userProfilePhotoEmpty());
|
|
|
|
status = &emptyStatus;
|
|
|
|
} else {
|
|
|
|
// apply first_name and last_name from minimal user only if we don't have
|
|
|
|
// local values for first name and last name already, otherwise skip
|
|
|
|
bool noLocalName = result->firstName.isEmpty() && result->lastName.isEmpty();
|
2019-07-05 13:38:38 +00:00
|
|
|
QString fname = (!minimal || noLocalName) ? TextUtilities::SingleLine(qs(data.vfirst_name().value_or_empty())) : result->firstName;
|
|
|
|
QString lname = (!minimal || noLocalName) ? TextUtilities::SingleLine(qs(data.vlast_name().value_or_empty())) : result->lastName;
|
2019-01-03 12:36:01 +00:00
|
|
|
|
2019-07-05 13:38:38 +00:00
|
|
|
QString phone = minimal ? result->phone() : qs(data.vphone().value_or_empty());
|
|
|
|
QString uname = minimal ? result->username : TextUtilities::SingleLine(qs(data.vusername().value_or_empty()));
|
2019-01-03 12:36:01 +00:00
|
|
|
|
|
|
|
const auto phoneChanged = (result->phone() != phone);
|
|
|
|
if (phoneChanged) {
|
|
|
|
result->setPhone(phone);
|
|
|
|
update.flags |= UpdateFlag::UserPhoneChanged;
|
|
|
|
}
|
|
|
|
const auto nameChanged = (result->firstName != fname)
|
|
|
|
|| (result->lastName != lname);
|
|
|
|
|
2019-03-12 10:36:33 +00:00
|
|
|
auto showPhone = !result->isServiceUser()
|
|
|
|
&& !data.is_support()
|
2019-01-03 12:36:01 +00:00
|
|
|
&& !data.is_self()
|
|
|
|
&& !data.is_contact()
|
|
|
|
&& !data.is_mutual_contact();
|
2019-03-12 10:36:33 +00:00
|
|
|
auto showPhoneChanged = !result->isServiceUser()
|
2019-01-03 12:36:01 +00:00
|
|
|
&& !data.is_self()
|
2019-06-06 16:48:42 +00:00
|
|
|
&& ((showPhone && result->isContact())
|
2019-01-03 12:36:01 +00:00
|
|
|
|| (!showPhone
|
2019-06-06 16:48:42 +00:00
|
|
|
&& !result->isContact()
|
|
|
|
&& !result->phone().isEmpty()));
|
2019-01-03 12:36:01 +00:00
|
|
|
if (minimal) {
|
|
|
|
showPhoneChanged = false;
|
2019-03-12 10:36:33 +00:00
|
|
|
showPhone = !result->isServiceUser()
|
2019-06-06 16:48:42 +00:00
|
|
|
&& !result->isContact()
|
|
|
|
&& !result->phone().isEmpty()
|
|
|
|
&& (result->id != _session->userPeerId());
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// see also Local::readPeer
|
|
|
|
|
|
|
|
const auto pname = (showPhoneChanged || phoneChanged || nameChanged)
|
|
|
|
? ((showPhone && !phone.isEmpty())
|
|
|
|
? App::formatPhone(phone)
|
|
|
|
: QString())
|
|
|
|
: result->nameOrPhone;
|
|
|
|
|
|
|
|
if (!minimal && data.is_self() && uname != result->username) {
|
|
|
|
CrashReports::SetAnnotation("Username", uname);
|
|
|
|
}
|
|
|
|
result->setName(fname, lname, pname, uname);
|
2019-07-05 13:38:38 +00:00
|
|
|
if (const auto photo = data.vphoto()) {
|
|
|
|
result->setPhoto(*photo);
|
2019-01-03 12:36:01 +00:00
|
|
|
} else {
|
|
|
|
result->setPhoto(MTP_userProfilePhotoEmpty());
|
|
|
|
}
|
2019-07-05 13:38:38 +00:00
|
|
|
if (const auto accessHash = data.vaccess_hash()) {
|
|
|
|
result->setAccessHash(accessHash->v);
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
2019-07-05 13:38:38 +00:00
|
|
|
status = data.vstatus();
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
|
|
|
if (!minimal) {
|
2019-07-05 13:38:38 +00:00
|
|
|
if (const auto botInfoVersion = data.vbot_info_version()) {
|
|
|
|
result->setBotInfoVersion(botInfoVersion->v);
|
2019-01-03 12:36:01 +00:00
|
|
|
result->botInfo->readsAllHistory = data.is_bot_chat_history();
|
|
|
|
if (result->botInfo->cantJoinGroups != data.is_bot_nochats()) {
|
|
|
|
result->botInfo->cantJoinGroups = data.is_bot_nochats();
|
|
|
|
update.flags |= UpdateFlag::BotCanAddToGroups;
|
|
|
|
}
|
2019-07-05 13:38:38 +00:00
|
|
|
if (const auto placeholder = data.vbot_inline_placeholder()) {
|
|
|
|
result->botInfo->inlinePlaceholder = '_' + qs(*placeholder);
|
|
|
|
} else {
|
|
|
|
result->botInfo->inlinePlaceholder = QString();
|
|
|
|
}
|
2019-01-03 12:36:01 +00:00
|
|
|
} else {
|
|
|
|
result->setBotInfoVersion(-1);
|
|
|
|
}
|
2019-06-06 16:48:42 +00:00
|
|
|
result->setIsContact(data.is_contact()
|
|
|
|
|| data.is_mutual_contact());
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (canShareThisContact != result->canShareThisContactFast()) {
|
|
|
|
update.flags |= UpdateFlag::UserCanShareContact;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (minimal) {
|
|
|
|
if (result->loadedStatus == PeerData::NotLoaded) {
|
|
|
|
result->loadedStatus = PeerData::MinimalLoaded;
|
|
|
|
}
|
|
|
|
} else if (result->loadedStatus != PeerData::FullLoaded
|
|
|
|
&& (!result->isSelf() || !result->phone().isEmpty())) {
|
|
|
|
result->loadedStatus = PeerData::FullLoaded;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status && !minimal) {
|
|
|
|
const auto oldOnlineTill = result->onlineTill;
|
|
|
|
const auto newOnlineTill = ApiWrap::OnlineTillFromStatus(
|
|
|
|
*status,
|
|
|
|
oldOnlineTill);
|
|
|
|
if (oldOnlineTill != newOnlineTill) {
|
|
|
|
result->onlineTill = newOnlineTill;
|
|
|
|
update.flags |= UpdateFlag::UserOnlineChanged;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (App::main()) {
|
|
|
|
if (update.flags) {
|
|
|
|
update.peer = result;
|
|
|
|
Notify::peerUpdatedDelayed(update);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-01-18 12:27:37 +00:00
|
|
|
not_null<PeerData*> Session::processChat(const MTPChat &data) {
|
2019-01-03 12:36:01 +00:00
|
|
|
const auto result = data.match([&](const MTPDchat &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
return peer(peerFromChat(data.vid().v));
|
2019-01-03 12:36:01 +00:00
|
|
|
}, [&](const MTPDchatForbidden &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
return peer(peerFromChat(data.vid().v));
|
2019-01-03 12:36:01 +00:00
|
|
|
}, [&](const MTPDchatEmpty &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
return peer(peerFromChat(data.vid().v));
|
2019-01-03 12:36:01 +00:00
|
|
|
}, [&](const MTPDchannel &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
return peer(peerFromChannel(data.vid().v));
|
2019-01-03 12:36:01 +00:00
|
|
|
}, [&](const MTPDchannelForbidden &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
return peer(peerFromChannel(data.vid().v));
|
2019-01-03 12:36:01 +00:00
|
|
|
});
|
|
|
|
auto minimal = false;
|
|
|
|
|
|
|
|
Notify::PeerUpdate update;
|
|
|
|
using UpdateFlag = Notify::PeerUpdate::Flag;
|
|
|
|
|
|
|
|
data.match([&](const MTPDchat &data) {
|
|
|
|
const auto chat = result->asChat();
|
2019-01-05 10:50:04 +00:00
|
|
|
|
|
|
|
const auto canAddMembers = chat->canAddMembers();
|
2019-07-05 13:38:38 +00:00
|
|
|
if (chat->version() < data.vversion().v) {
|
|
|
|
chat->setVersion(data.vversion().v);
|
2019-01-03 12:36:01 +00:00
|
|
|
chat->invalidateParticipants();
|
|
|
|
}
|
|
|
|
|
2019-07-05 13:38:38 +00:00
|
|
|
chat->input = MTP_inputPeerChat(data.vid());
|
|
|
|
chat->setName(qs(data.vtitle()));
|
|
|
|
chat->setPhoto(data.vphoto());
|
|
|
|
chat->date = data.vdate().v;
|
2019-01-03 12:36:01 +00:00
|
|
|
|
2019-07-05 13:38:38 +00:00
|
|
|
if (const auto rights = data.vadmin_rights()) {
|
|
|
|
chat->setAdminRights(*rights);
|
|
|
|
} else {
|
|
|
|
chat->setAdminRights(MTP_chatAdminRights(MTP_flags(0)));
|
|
|
|
}
|
|
|
|
if (const auto rights = data.vdefault_banned_rights()) {
|
|
|
|
chat->setDefaultRestrictions(*rights);
|
|
|
|
} else {
|
|
|
|
chat->setDefaultRestrictions(
|
|
|
|
MTP_chatBannedRights(MTP_flags(0), MTP_int(0)));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (const auto migratedTo = data.vmigrated_to()) {
|
|
|
|
migratedTo->match([&](const MTPDinputChannel &input) {
|
|
|
|
const auto channel = this->channel(input.vchannel_id().v);
|
|
|
|
channel->addFlags(MTPDchannel::Flag::f_megagroup);
|
|
|
|
if (!channel->access) {
|
2020-02-07 16:07:21 +00:00
|
|
|
channel->setAccessHash(input.vaccess_hash().v);
|
2019-07-05 13:38:38 +00:00
|
|
|
}
|
|
|
|
ApplyMigration(chat, channel);
|
|
|
|
}, [](const MTPDinputChannelFromMessage &) {
|
|
|
|
LOG(("API Error: "
|
|
|
|
"migrated_to contains channel from message."));
|
|
|
|
}, [](const MTPDinputChannelEmpty &) {
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
chat->setFlags(data.vflags().v);
|
|
|
|
chat->count = data.vparticipants_count().v;
|
2019-01-05 10:50:04 +00:00
|
|
|
|
|
|
|
if (canAddMembers != chat->canAddMembers()) {
|
|
|
|
update.flags |= UpdateFlag::RightsChanged;
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
|
|
|
}, [&](const MTPDchatForbidden &data) {
|
|
|
|
const auto chat = result->asChat();
|
2019-01-05 10:50:04 +00:00
|
|
|
|
|
|
|
const auto canAddMembers = chat->canAddMembers();
|
2019-01-03 12:36:01 +00:00
|
|
|
|
2019-07-05 13:38:38 +00:00
|
|
|
chat->input = MTP_inputPeerChat(data.vid());
|
|
|
|
chat->setName(qs(data.vtitle()));
|
2019-01-03 12:36:01 +00:00
|
|
|
chat->setPhoto(MTP_chatPhotoEmpty());
|
|
|
|
chat->date = 0;
|
|
|
|
chat->count = -1;
|
|
|
|
chat->invalidateParticipants();
|
|
|
|
chat->setFlags(MTPDchat_ClientFlag::f_forbidden | 0);
|
2019-01-05 10:50:04 +00:00
|
|
|
chat->setAdminRights(MTP_chatAdminRights(MTP_flags(0)));
|
|
|
|
chat->setDefaultRestrictions(
|
|
|
|
MTP_chatBannedRights(MTP_flags(0), MTP_int(0)));
|
|
|
|
|
|
|
|
if (canAddMembers != chat->canAddMembers()) {
|
|
|
|
update.flags |= UpdateFlag::RightsChanged;
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
|
|
|
}, [&](const MTPDchannel &data) {
|
|
|
|
const auto channel = result->asChannel();
|
|
|
|
|
|
|
|
minimal = data.is_min();
|
|
|
|
if (minimal) {
|
|
|
|
if (result->loadedStatus != PeerData::FullLoaded) {
|
|
|
|
LOG(("API Warning: not loaded minimal channel applied."));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto wasInChannel = channel->amIn();
|
|
|
|
const auto canViewAdmins = channel->canViewAdmins();
|
|
|
|
const auto canViewMembers = channel->canViewMembers();
|
|
|
|
const auto canAddMembers = channel->canAddMembers();
|
|
|
|
|
2019-07-05 13:38:38 +00:00
|
|
|
if (const auto count = data.vparticipants_count()) {
|
|
|
|
channel->setMembersCount(count->v);
|
|
|
|
}
|
|
|
|
if (const auto rights = data.vdefault_banned_rights()) {
|
|
|
|
channel->setDefaultRestrictions(*rights);
|
|
|
|
} else {
|
|
|
|
channel->setDefaultRestrictions(
|
|
|
|
MTP_chatBannedRights(MTP_flags(0), MTP_int(0)));
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
|
|
|
if (minimal) {
|
|
|
|
auto mask = 0
|
|
|
|
| MTPDchannel::Flag::f_broadcast
|
|
|
|
| MTPDchannel::Flag::f_verified
|
|
|
|
| MTPDchannel::Flag::f_megagroup
|
|
|
|
| MTPDchannel_ClientFlag::f_forbidden;
|
2019-07-05 13:38:38 +00:00
|
|
|
channel->setFlags((channel->flags() & ~mask) | (data.vflags().v & mask));
|
2019-01-03 12:36:01 +00:00
|
|
|
} else {
|
2019-07-05 13:38:38 +00:00
|
|
|
if (const auto rights = data.vadmin_rights()) {
|
|
|
|
channel->setAdminRights(*rights);
|
2019-01-03 12:36:01 +00:00
|
|
|
} else if (channel->hasAdminRights()) {
|
2019-01-03 14:39:19 +00:00
|
|
|
channel->setAdminRights(MTP_chatAdminRights(MTP_flags(0)));
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
2019-07-05 13:38:38 +00:00
|
|
|
if (const auto rights = data.vbanned_rights()) {
|
|
|
|
channel->setRestrictions(*rights);
|
2019-01-03 12:36:01 +00:00
|
|
|
} else if (channel->hasRestrictions()) {
|
2019-07-05 13:38:38 +00:00
|
|
|
channel->setRestrictions(
|
|
|
|
MTP_chatBannedRights(MTP_flags(0), MTP_int(0)));
|
|
|
|
}
|
2020-02-07 16:07:21 +00:00
|
|
|
channel->setAccessHash(
|
|
|
|
data.vaccess_hash().value_or(channel->access));
|
2019-07-05 13:38:38 +00:00
|
|
|
channel->date = data.vdate().v;
|
|
|
|
if (channel->version() < data.vversion().v) {
|
|
|
|
channel->setVersion(data.vversion().v);
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
2019-07-05 13:38:38 +00:00
|
|
|
if (const auto restriction = data.vrestriction_reason()) {
|
2019-12-09 13:57:33 +00:00
|
|
|
channel->setUnavailableReasons(
|
|
|
|
ExtractUnavailableReasons(restriction->v));
|
2019-07-05 13:38:38 +00:00
|
|
|
} else {
|
2019-12-09 13:57:33 +00:00
|
|
|
channel->setUnavailableReasons({});
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
2019-07-05 13:38:38 +00:00
|
|
|
channel->setFlags(data.vflags().v);
|
|
|
|
//if (const auto feedId = data.vfeed_id()) { // #feed
|
|
|
|
// channel->setFeed(feed(feedId->v));
|
2019-01-03 12:36:01 +00:00
|
|
|
//} else {
|
|
|
|
// channel->clearFeed();
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
|
2019-07-05 13:38:38 +00:00
|
|
|
channel->setName(
|
|
|
|
qs(data.vtitle()),
|
|
|
|
TextUtilities::SingleLine(qs(data.vusername().value_or_empty())));
|
2019-01-03 12:36:01 +00:00
|
|
|
|
2019-07-05 13:38:38 +00:00
|
|
|
channel->setPhoto(data.vphoto());
|
2019-01-03 12:36:01 +00:00
|
|
|
|
|
|
|
if (wasInChannel != channel->amIn()) {
|
|
|
|
update.flags |= UpdateFlag::ChannelAmIn;
|
|
|
|
}
|
|
|
|
if (canViewAdmins != channel->canViewAdmins()
|
|
|
|
|| canViewMembers != channel->canViewMembers()
|
|
|
|
|| canAddMembers != channel->canAddMembers()) {
|
2019-01-05 10:50:04 +00:00
|
|
|
update.flags |= UpdateFlag::RightsChanged;
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
|
|
|
}, [&](const MTPDchannelForbidden &data) {
|
|
|
|
const auto channel = result->asChannel();
|
|
|
|
|
|
|
|
auto wasInChannel = channel->amIn();
|
|
|
|
auto canViewAdmins = channel->canViewAdmins();
|
|
|
|
auto canViewMembers = channel->canViewMembers();
|
|
|
|
auto canAddMembers = channel->canAddMembers();
|
|
|
|
|
|
|
|
auto mask = mtpCastFlags(MTPDchannelForbidden::Flag::f_broadcast | MTPDchannelForbidden::Flag::f_megagroup);
|
2019-07-05 13:38:38 +00:00
|
|
|
channel->setFlags((channel->flags() & ~mask) | (mtpCastFlags(data.vflags()) & mask) | MTPDchannel_ClientFlag::f_forbidden);
|
2019-01-03 12:36:01 +00:00
|
|
|
|
|
|
|
if (channel->hasAdminRights()) {
|
2019-01-03 14:39:19 +00:00
|
|
|
channel->setAdminRights(MTP_chatAdminRights(MTP_flags(0)));
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
|
|
|
if (channel->hasRestrictions()) {
|
2019-01-05 10:50:04 +00:00
|
|
|
channel->setRestrictions(MTP_chatBannedRights(MTP_flags(0), MTP_int(0)));
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
|
|
|
|
2019-07-05 13:38:38 +00:00
|
|
|
channel->setName(qs(data.vtitle()), QString());
|
2019-01-03 12:36:01 +00:00
|
|
|
|
2020-02-07 16:07:21 +00:00
|
|
|
channel->setAccessHash(data.vaccess_hash().v);
|
2019-01-03 12:36:01 +00:00
|
|
|
channel->setPhoto(MTP_chatPhotoEmpty());
|
|
|
|
channel->date = 0;
|
|
|
|
channel->setMembersCount(0);
|
|
|
|
|
|
|
|
if (wasInChannel != channel->amIn()) {
|
|
|
|
update.flags |= UpdateFlag::ChannelAmIn;
|
|
|
|
}
|
|
|
|
if (canViewAdmins != channel->canViewAdmins()
|
|
|
|
|| canViewMembers != channel->canViewMembers()
|
|
|
|
|| canAddMembers != channel->canAddMembers()) {
|
2019-01-05 10:50:04 +00:00
|
|
|
update.flags |= UpdateFlag::RightsChanged;
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
|
|
|
}, [](const MTPDchatEmpty &) {
|
|
|
|
});
|
|
|
|
|
|
|
|
if (minimal) {
|
|
|
|
if (result->loadedStatus == PeerData::NotLoaded) {
|
|
|
|
result->loadedStatus = PeerData::MinimalLoaded;
|
|
|
|
}
|
|
|
|
} else if (result->loadedStatus != PeerData::FullLoaded) {
|
|
|
|
result->loadedStatus = PeerData::FullLoaded;
|
|
|
|
}
|
|
|
|
if (update.flags) {
|
|
|
|
update.peer = result;
|
|
|
|
Notify::peerUpdatedDelayed(update);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
UserData *Session::processUsers(const MTPVector<MTPUser> &data) {
|
|
|
|
auto result = (UserData*)nullptr;
|
|
|
|
for (const auto &user : data.v) {
|
2019-01-18 12:27:37 +00:00
|
|
|
result = processUser(user);
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
PeerData *Session::processChats(const MTPVector<MTPChat> &data) {
|
|
|
|
auto result = (PeerData*)nullptr;
|
|
|
|
for (const auto &chat : data.v) {
|
2019-01-18 12:27:37 +00:00
|
|
|
result = processChat(chat);
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-01-13 08:03:34 +00:00
|
|
|
void Session::applyMaximumChatVersions(const MTPVector<MTPChat> &data) {
|
|
|
|
for (const auto &chat : data.v) {
|
|
|
|
chat.match([&](const MTPDchat &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
if (const auto chat = chatLoaded(data.vid().v)) {
|
|
|
|
if (data.vversion().v < chat->version()) {
|
|
|
|
chat->setVersion(data.vversion().v);
|
2019-01-13 08:03:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [&](const MTPDchannel &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
if (const auto channel = channelLoaded(data.vid().v)) {
|
|
|
|
if (data.vversion().v < channel->version()) {
|
|
|
|
channel->setVersion(data.vversion().v);
|
2019-01-13 08:03:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [](const auto &) {
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-03 12:36:01 +00:00
|
|
|
PeerData *Session::peerByUsername(const QString &username) const {
|
|
|
|
const auto uname = username.trimmed();
|
|
|
|
for (const auto &[peerId, peer] : _peers) {
|
|
|
|
if (!peer->userName().compare(uname, Qt::CaseInsensitive)) {
|
|
|
|
return peer.get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::enumerateUsers(Fn<void(not_null<UserData*>)> action) const {
|
|
|
|
for (const auto &[peerId, peer] : _peers) {
|
|
|
|
if (const auto user = peer->asUser()) {
|
|
|
|
action(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::enumerateGroups(Fn<void(not_null<PeerData*>)> action) const {
|
|
|
|
for (const auto &[peerId, peer] : _peers) {
|
|
|
|
if (peer->isChat() || peer->isMegagroup()) {
|
|
|
|
action(peer.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::enumerateChannels(
|
|
|
|
Fn<void(not_null<ChannelData*>)> action) const {
|
|
|
|
for (const auto &[peerId, peer] : _peers) {
|
|
|
|
if (const auto channel = peer->asChannel()) {
|
|
|
|
if (!channel->isMegagroup()) {
|
|
|
|
action(channel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
not_null<History*> Session::history(PeerId peerId) {
|
2020-02-18 11:39:24 +00:00
|
|
|
return _histories->findOrCreate(peerId);
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
History *Session::historyLoaded(PeerId peerId) const {
|
2020-02-18 11:39:24 +00:00
|
|
|
return _histories->find(peerId);
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
not_null<History*> Session::history(not_null<const PeerData*> peer) {
|
|
|
|
return history(peer->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
History *Session::historyLoaded(const PeerData *peer) {
|
|
|
|
return peer ? historyLoaded(peer->id) : nullptr;
|
|
|
|
}
|
|
|
|
|
2019-03-25 11:49:57 +00:00
|
|
|
void Session::deleteConversationLocally(not_null<PeerData*> peer) {
|
|
|
|
const auto history = historyLoaded(peer);
|
|
|
|
if (history) {
|
2019-04-19 08:47:49 +00:00
|
|
|
if (history->folderKnown()) {
|
2020-03-17 13:04:30 +00:00
|
|
|
setChatPinned(history, FilterId(), false);
|
2019-04-19 08:47:49 +00:00
|
|
|
}
|
2019-03-25 11:49:57 +00:00
|
|
|
App::main()->removeDialog(history);
|
2019-04-08 09:16:45 +00:00
|
|
|
history->clear(peer->isChannel()
|
|
|
|
? History::ClearType::Unload
|
|
|
|
: History::ClearType::DeleteChat);
|
2019-03-25 11:49:57 +00:00
|
|
|
}
|
|
|
|
if (const auto channel = peer->asMegagroup()) {
|
|
|
|
channel->addFlags(MTPDchannel::Flag::f_left);
|
|
|
|
if (const auto from = channel->getMigrateFromChat()) {
|
|
|
|
if (const auto migrated = historyLoaded(from)) {
|
|
|
|
migrated->updateChatListExistence();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-03 12:36:01 +00:00
|
|
|
void Session::registerSendAction(
|
|
|
|
not_null<History*> history,
|
|
|
|
not_null<UserData*> user,
|
|
|
|
const MTPSendMessageAction &action,
|
|
|
|
TimeId when) {
|
|
|
|
if (history->updateSendActionNeedsAnimating(user, action)) {
|
|
|
|
user->madeAction(when);
|
|
|
|
|
|
|
|
const auto i = _sendActions.find(history);
|
|
|
|
if (!_sendActions.contains(history)) {
|
2019-02-19 06:57:53 +00:00
|
|
|
_sendActions.emplace(history, crl::now());
|
2019-04-01 14:53:18 +00:00
|
|
|
_sendActionsAnimation.start();
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-01 14:53:18 +00:00
|
|
|
bool Session::sendActionsAnimationCallback(crl::time now) {
|
2019-01-03 12:36:01 +00:00
|
|
|
for (auto i = begin(_sendActions); i != end(_sendActions);) {
|
2019-04-01 14:53:18 +00:00
|
|
|
if (i->first->updateSendActionNeedsAnimating(now)) {
|
2019-01-03 12:36:01 +00:00
|
|
|
++i;
|
|
|
|
} else {
|
|
|
|
i = _sendActions.erase(i);
|
|
|
|
}
|
|
|
|
}
|
2019-04-01 14:53:18 +00:00
|
|
|
return !_sendActions.empty();
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
|
|
|
|
2019-04-18 08:28:43 +00:00
|
|
|
bool Session::chatsListLoaded(Data::Folder *folder) {
|
2019-04-22 14:22:39 +00:00
|
|
|
return chatsList(folder)->loaded();
|
2019-04-18 08:28:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Session::chatsListChanged(FolderId folderId) {
|
|
|
|
chatsListChanged(folderId ? folder(folderId).get() : nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::chatsListChanged(Data::Folder *folder) {
|
|
|
|
_chatsListChanged.fire_copy(folder);
|
|
|
|
}
|
|
|
|
|
2019-04-22 14:22:39 +00:00
|
|
|
void Session::chatsListDone(Data::Folder *folder) {
|
2019-04-18 08:28:43 +00:00
|
|
|
if (folder) {
|
2020-03-16 10:20:18 +00:00
|
|
|
folder->chatsList()->setLoaded();
|
2019-04-18 08:28:43 +00:00
|
|
|
} else {
|
2019-04-22 14:22:39 +00:00
|
|
|
_chatsList.setLoaded();
|
2019-04-18 08:28:43 +00:00
|
|
|
}
|
|
|
|
_chatsListLoadedEvents.fire_copy(folder);
|
|
|
|
}
|
|
|
|
|
2018-08-27 11:35:58 +00:00
|
|
|
Storage::Cache::Database &Session::cache() {
|
2018-08-29 13:23:16 +00:00
|
|
|
return *_cache;
|
2018-08-27 11:35:58 +00:00
|
|
|
}
|
|
|
|
|
2019-02-25 17:26:08 +00:00
|
|
|
Storage::Cache::Database &Session::cacheBigFile() {
|
|
|
|
return *_bigFileCache;
|
|
|
|
}
|
|
|
|
|
2018-07-23 13:11:56 +00:00
|
|
|
void Session::startExport(PeerData *peer) {
|
|
|
|
startExport(peer ? peer->input : MTP_inputPeerEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::startExport(const MTPInputPeer &singlePeer) {
|
2018-06-24 00:33:47 +00:00
|
|
|
if (_exportPanel) {
|
|
|
|
_exportPanel->activatePanel();
|
|
|
|
return;
|
|
|
|
}
|
2019-02-17 11:06:37 +00:00
|
|
|
_export = std::make_unique<Export::Controller>(singlePeer);
|
2018-06-20 00:02:36 +00:00
|
|
|
_exportPanel = std::make_unique<Export::View::PanelController>(
|
|
|
|
_export.get());
|
|
|
|
|
|
|
|
_exportViewChanges.fire(_exportPanel.get());
|
|
|
|
|
2018-06-21 00:54:59 +00:00
|
|
|
_exportPanel->stopRequests(
|
2018-06-20 00:02:36 +00:00
|
|
|
) | rpl::start_with_next([=] {
|
2018-06-24 02:15:12 +00:00
|
|
|
LOG(("Export Info: Stop requested."));
|
2018-06-20 17:30:57 +00:00
|
|
|
stopExport();
|
2018-06-20 00:02:36 +00:00
|
|
|
}, _export->lifetime());
|
|
|
|
}
|
|
|
|
|
2018-06-22 23:18:43 +00:00
|
|
|
void Session::suggestStartExport(TimeId availableAt) {
|
|
|
|
_exportAvailableAt = availableAt;
|
|
|
|
suggestStartExport();
|
|
|
|
}
|
|
|
|
|
2018-06-28 17:44:07 +00:00
|
|
|
void Session::clearExportSuggestion() {
|
|
|
|
_exportAvailableAt = 0;
|
|
|
|
if (_exportSuggestion) {
|
|
|
|
_exportSuggestion->closeBox();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-22 23:18:43 +00:00
|
|
|
void Session::suggestStartExport() {
|
|
|
|
if (_exportAvailableAt <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
2018-06-23 21:21:32 +00:00
|
|
|
|
2019-07-10 17:28:33 +00:00
|
|
|
const auto now = base::unixtime::now();
|
2018-06-22 23:18:43 +00:00
|
|
|
const auto left = (_exportAvailableAt <= now)
|
|
|
|
? 0
|
|
|
|
: (_exportAvailableAt - now);
|
2018-06-23 21:21:32 +00:00
|
|
|
if (left) {
|
2019-09-26 10:55:35 +00:00
|
|
|
base::call_delayed(
|
2019-02-19 06:57:53 +00:00
|
|
|
std::min(left + 5, 3600) * crl::time(1000),
|
2018-06-22 23:18:43 +00:00
|
|
|
_session,
|
|
|
|
[=] { suggestStartExport(); });
|
2018-06-23 21:21:32 +00:00
|
|
|
} else if (_export) {
|
|
|
|
Export::View::ClearSuggestStart();
|
|
|
|
} else {
|
2018-06-28 17:44:07 +00:00
|
|
|
_exportSuggestion = Export::View::SuggestStart();
|
2018-06-22 23:18:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-20 00:02:36 +00:00
|
|
|
rpl::producer<Export::View::PanelController*> Session::currentExportView(
|
|
|
|
) const {
|
|
|
|
return _exportViewChanges.events_starting_with(_exportPanel.get());
|
|
|
|
}
|
|
|
|
|
2018-06-20 17:30:57 +00:00
|
|
|
bool Session::exportInProgress() const {
|
|
|
|
return _export != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::stopExportWithConfirmation(FnMut<void()> callback) {
|
|
|
|
if (!_exportPanel) {
|
|
|
|
callback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto closeAndCall = [=, callback = std::move(callback)]() mutable {
|
|
|
|
auto saved = std::move(callback);
|
2018-06-24 02:15:12 +00:00
|
|
|
LOG(("Export Info: Stop With Confirmation."));
|
2018-06-20 17:30:57 +00:00
|
|
|
stopExport();
|
|
|
|
if (saved) {
|
|
|
|
saved();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
_exportPanel->stopWithConfirmation(std::move(closeAndCall));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::stopExport() {
|
2018-06-20 00:02:36 +00:00
|
|
|
if (_exportPanel) {
|
2018-06-24 02:15:12 +00:00
|
|
|
LOG(("Export Info: Destroying."));
|
2018-06-20 00:02:36 +00:00
|
|
|
_exportPanel = nullptr;
|
|
|
|
_exportViewChanges.fire(nullptr);
|
|
|
|
}
|
|
|
|
_export = nullptr;
|
|
|
|
}
|
|
|
|
|
2018-07-10 16:41:11 +00:00
|
|
|
const Passport::SavedCredentials *Session::passportCredentials() const {
|
|
|
|
return _passportCredentials ? &_passportCredentials->first : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::rememberPassportCredentials(
|
|
|
|
Passport::SavedCredentials data,
|
2019-02-19 06:57:53 +00:00
|
|
|
crl::time rememberFor) {
|
2018-07-10 16:41:11 +00:00
|
|
|
Expects(rememberFor > 0);
|
|
|
|
|
|
|
|
static auto generation = 0;
|
|
|
|
_passportCredentials = std::make_unique<CredentialsWithGeneration>(
|
|
|
|
std::move(data),
|
|
|
|
++generation);
|
2019-09-26 10:55:35 +00:00
|
|
|
base::call_delayed(rememberFor, _session, [=, check = generation] {
|
2018-07-10 16:41:11 +00:00
|
|
|
if (_passportCredentials && _passportCredentials->second == check) {
|
|
|
|
forgetPassportCredentials();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::forgetPassportCredentials() {
|
|
|
|
_passportCredentials = nullptr;
|
|
|
|
}
|
|
|
|
|
2018-02-08 09:20:14 +00:00
|
|
|
void Session::setupContactViewsViewer() {
|
2018-01-04 10:22:53 +00:00
|
|
|
Notify::PeerUpdateViewer(
|
|
|
|
Notify::PeerUpdate::Flag::UserIsContact
|
|
|
|
) | rpl::map([](const Notify::PeerUpdate &update) {
|
|
|
|
return update.peer->asUser();
|
|
|
|
}) | rpl::filter([](UserData *user) {
|
|
|
|
return user != nullptr;
|
|
|
|
}) | rpl::start_with_next([=](not_null<UserData*> user) {
|
|
|
|
userIsContactUpdated(user);
|
|
|
|
}, _lifetime);
|
|
|
|
}
|
|
|
|
|
2018-02-08 09:20:14 +00:00
|
|
|
void Session::setupChannelLeavingViewer() {
|
|
|
|
Notify::PeerUpdateViewer(
|
|
|
|
Notify::PeerUpdate::Flag::ChannelAmIn
|
|
|
|
) | rpl::map([](const Notify::PeerUpdate &update) {
|
|
|
|
return update.peer->asChannel();
|
|
|
|
}) | rpl::filter([](ChannelData *channel) {
|
|
|
|
return (channel != nullptr)
|
2018-05-11 14:03:53 +00:00
|
|
|
&& !(channel->amIn());
|
2018-02-08 09:20:14 +00:00
|
|
|
}) | rpl::start_with_next([=](not_null<ChannelData*> channel) {
|
2019-04-15 11:54:03 +00:00
|
|
|
// channel->clearFeed(); // #feed
|
2019-01-03 12:36:01 +00:00
|
|
|
if (const auto history = historyLoaded(channel->id)) {
|
2018-05-11 14:03:53 +00:00
|
|
|
history->removeJoinedMessage();
|
|
|
|
history->updateChatListExistence();
|
|
|
|
history->updateChatListSortPosition();
|
|
|
|
}
|
2018-02-08 09:20:14 +00:00
|
|
|
}, _lifetime);
|
|
|
|
}
|
|
|
|
|
2019-04-16 14:05:56 +00:00
|
|
|
void Session::setupPeerNameViewer() {
|
|
|
|
Notify::PeerUpdateViewer(
|
|
|
|
Notify::PeerUpdate::Flag::NameChanged
|
|
|
|
) | rpl::start_with_next([=](const Notify::PeerUpdate &update) {
|
|
|
|
const auto peer = update.peer;
|
|
|
|
const auto &oldLetters = update.oldNameFirstLetters;
|
|
|
|
_contactsNoChatsList.peerNameChanged(peer, oldLetters);
|
|
|
|
_contactsList.peerNameChanged(peer, oldLetters);
|
|
|
|
}, _lifetime);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::setupUserIsContactViewer() {
|
|
|
|
Notify::PeerUpdateViewer(
|
|
|
|
Notify::PeerUpdate::Flag::UserIsContact
|
|
|
|
) | rpl::filter([=](const Notify::PeerUpdate &update) {
|
|
|
|
return update.peer->isUser();
|
|
|
|
}) | rpl::start_with_next([=](const Notify::PeerUpdate &update) {
|
|
|
|
const auto user = update.peer->asUser();
|
|
|
|
if (user->loadedStatus != PeerData::FullLoaded) {
|
|
|
|
LOG(("API Error: "
|
|
|
|
"userIsContactChanged() called for a not loaded user!"));
|
|
|
|
return;
|
|
|
|
}
|
2019-06-06 16:48:42 +00:00
|
|
|
if (user->isContact()) {
|
2019-04-16 14:05:56 +00:00
|
|
|
const auto history = user->owner().history(user->id);
|
|
|
|
_contactsList.addByName(history);
|
2019-04-22 18:18:57 +00:00
|
|
|
if (!history->inChatList()) {
|
2019-04-16 14:05:56 +00:00
|
|
|
_contactsNoChatsList.addByName(history);
|
|
|
|
}
|
|
|
|
} else if (const auto history = user->owner().historyLoaded(user)) {
|
|
|
|
_contactsNoChatsList.del(history);
|
|
|
|
_contactsList.del(history);
|
|
|
|
}
|
|
|
|
}, _lifetime);
|
|
|
|
}
|
|
|
|
|
2019-01-03 12:36:01 +00:00
|
|
|
Session::~Session() {
|
|
|
|
// Optimization: clear notifications before destroying items.
|
|
|
|
_session->notifications().clearAllFast();
|
|
|
|
|
|
|
|
clear();
|
|
|
|
Images::ClearRemote();
|
|
|
|
}
|
2018-01-04 10:22:53 +00:00
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
template <typename Method>
|
|
|
|
void Session::enumerateItemViews(
|
2018-01-18 11:46:45 +00:00
|
|
|
not_null<const HistoryItem*> item,
|
2018-01-17 16:21:01 +00:00
|
|
|
Method method) {
|
|
|
|
if (const auto i = _views.find(item); i != _views.end()) {
|
|
|
|
for (const auto view : i->second) {
|
|
|
|
method(view);
|
|
|
|
}
|
|
|
|
}
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
void Session::photoLoadSettingsChanged() {
|
|
|
|
for (const auto &[id, photo] : _photos) {
|
|
|
|
photo->automaticLoadSettingsChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 15:47:28 +00:00
|
|
|
void Session::documentLoadSettingsChanged() {
|
2018-01-17 16:21:01 +00:00
|
|
|
for (const auto &[id, document] : _documents) {
|
2018-12-06 15:47:28 +00:00
|
|
|
document->automaticLoadSettingsChanged();
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
2018-01-17 16:21:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Session::notifyPhotoLayoutChanged(not_null<const PhotoData*> photo) {
|
2018-01-21 19:52:44 +00:00
|
|
|
if (const auto i = _photoItems.find(photo); i != end(_photoItems)) {
|
|
|
|
for (const auto item : i->second) {
|
|
|
|
notifyItemLayoutChange(item);
|
2018-01-17 16:21:01 +00:00
|
|
|
}
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
2018-01-17 16:21:01 +00:00
|
|
|
}
|
|
|
|
|
2020-05-25 14:16:04 +00:00
|
|
|
void Session::requestPhotoViewRepaint(not_null<const PhotoData*> photo) {
|
|
|
|
const auto i = _photoItems.find(photo);
|
|
|
|
if (i != end(_photoItems)) {
|
|
|
|
for (const auto item : i->second) {
|
|
|
|
requestItemRepaint(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
void Session::notifyDocumentLayoutChanged(
|
|
|
|
not_null<const DocumentData*> document) {
|
2018-01-21 19:52:44 +00:00
|
|
|
const auto i = _documentItems.find(document);
|
|
|
|
if (i != end(_documentItems)) {
|
|
|
|
for (const auto item : i->second) {
|
|
|
|
notifyItemLayoutChange(item);
|
2018-01-17 16:21:01 +00:00
|
|
|
}
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
2018-01-17 16:21:01 +00:00
|
|
|
if (const auto items = InlineBots::Layout::documentItems()) {
|
|
|
|
if (const auto i = items->find(document); i != items->end()) {
|
|
|
|
for (const auto item : i->second) {
|
|
|
|
item->layoutChanged();
|
|
|
|
}
|
|
|
|
}
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
2018-01-17 16:21:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Session::requestDocumentViewRepaint(
|
|
|
|
not_null<const DocumentData*> document) {
|
2018-01-21 19:52:44 +00:00
|
|
|
const auto i = _documentItems.find(document);
|
|
|
|
if (i != end(_documentItems)) {
|
|
|
|
for (const auto item : i->second) {
|
|
|
|
requestItemRepaint(item);
|
2018-01-17 16:21:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-18 05:43:11 +00:00
|
|
|
void Session::requestPollViewRepaint(not_null<const PollData*> poll) {
|
|
|
|
if (const auto i = _pollViews.find(poll); i != _pollViews.end()) {
|
|
|
|
for (const auto view : i->second) {
|
|
|
|
requestViewResize(view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-10 11:17:10 +00:00
|
|
|
void Session::documentLoadProgress(not_null<DocumentData*> document) {
|
|
|
|
requestDocumentViewRepaint(document);
|
|
|
|
session().documentUpdated.notify(document, true);
|
|
|
|
|
|
|
|
if (document->isAudioFile()) {
|
|
|
|
::Media::Player::instance()->documentLoadProgress(document);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::documentLoadDone(not_null<DocumentData*> document) {
|
|
|
|
notifyDocumentLayoutChanged(document);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::documentLoadFail(
|
|
|
|
not_null<DocumentData*> document,
|
|
|
|
bool started) {
|
|
|
|
notifyDocumentLayoutChanged(document);
|
|
|
|
}
|
|
|
|
|
2020-05-25 14:16:04 +00:00
|
|
|
void Session::photoLoadProgress(not_null<PhotoData*> photo) {
|
|
|
|
requestPhotoViewRepaint(photo);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::photoLoadDone(not_null<PhotoData*> photo) {
|
|
|
|
notifyPhotoLayoutChanged(photo);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::photoLoadFail(
|
|
|
|
not_null<PhotoData*> photo,
|
|
|
|
bool started) {
|
|
|
|
notifyPhotoLayoutChanged(photo);
|
|
|
|
}
|
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
void Session::markMediaRead(not_null<const DocumentData*> document) {
|
|
|
|
const auto i = _documentItems.find(document);
|
|
|
|
if (i != end(_documentItems)) {
|
|
|
|
_session->api().markMediaRead({ begin(i->second), end(i->second) });
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-21 19:52:44 +00:00
|
|
|
void Session::notifyItemLayoutChange(not_null<const HistoryItem*> item) {
|
|
|
|
_itemLayoutChanges.fire_copy(item);
|
|
|
|
enumerateItemViews(item, [&](not_null<ViewElement*> view) {
|
|
|
|
notifyViewLayoutChange(view);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<not_null<const HistoryItem*>> Session::itemLayoutChanged() const {
|
|
|
|
return _itemLayoutChanges.events();
|
|
|
|
}
|
|
|
|
|
2018-01-17 18:20:55 +00:00
|
|
|
void Session::notifyViewLayoutChange(not_null<const ViewElement*> view) {
|
2018-01-14 16:02:25 +00:00
|
|
|
_viewLayoutChanges.fire_copy(view);
|
|
|
|
}
|
|
|
|
|
2018-01-17 18:20:55 +00:00
|
|
|
rpl::producer<not_null<const ViewElement*>> Session::viewLayoutChanged() const {
|
2018-01-14 16:02:25 +00:00
|
|
|
return _viewLayoutChanges.events();
|
|
|
|
}
|
|
|
|
|
2019-08-28 14:24:12 +00:00
|
|
|
void Session::notifyUnreadItemAdded(not_null<HistoryItem*> item) {
|
|
|
|
_unreadItemAdded.fire_copy(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<not_null<HistoryItem*>> Session::unreadItemAdded() const {
|
|
|
|
return _unreadItemAdded.events();
|
|
|
|
}
|
|
|
|
|
2019-04-25 12:45:15 +00:00
|
|
|
void Session::changeMessageId(ChannelId channel, MsgId wasId, MsgId nowId) {
|
|
|
|
const auto list = messagesListForInsert(channel);
|
|
|
|
auto i = list->find(wasId);
|
|
|
|
Assert(i != list->end());
|
|
|
|
auto owned = std::move(i->second);
|
|
|
|
list->erase(i);
|
2019-08-28 18:20:49 +00:00
|
|
|
const auto [j, ok] = list->emplace(nowId, std::move(owned));
|
|
|
|
|
|
|
|
Ensures(ok);
|
2019-04-25 12:45:15 +00:00
|
|
|
}
|
|
|
|
|
2018-01-17 18:20:55 +00:00
|
|
|
void Session::notifyItemIdChange(IdChange event) {
|
2019-04-25 12:45:15 +00:00
|
|
|
const auto item = event.item;
|
|
|
|
changeMessageId(item->history()->channelId(), event.oldId, item->id);
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
_itemIdChanges.fire_copy(event);
|
2018-01-19 17:10:58 +00:00
|
|
|
|
|
|
|
const auto refreshViewDataId = [](not_null<ViewElement*> view) {
|
|
|
|
view->refreshDataId();
|
|
|
|
};
|
2019-04-25 12:45:15 +00:00
|
|
|
enumerateItemViews(item, refreshViewDataId);
|
|
|
|
if (const auto group = groups().find(item)) {
|
2018-01-19 17:10:58 +00:00
|
|
|
const auto leader = group->items.back();
|
2019-04-25 12:45:15 +00:00
|
|
|
if (leader != item) {
|
2018-01-19 17:10:58 +00:00
|
|
|
enumerateItemViews(leader, refreshViewDataId);
|
|
|
|
}
|
|
|
|
}
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<Session::IdChange> Session::itemIdChanged() const {
|
|
|
|
return _itemIdChanges.events();
|
2018-01-04 10:22:53 +00:00
|
|
|
}
|
|
|
|
|
2018-01-18 11:46:45 +00:00
|
|
|
void Session::requestItemRepaint(not_null<const HistoryItem*> item) {
|
|
|
|
_itemRepaintRequest.fire_copy(item);
|
|
|
|
enumerateItemViews(item, [&](not_null<const ViewElement*> view) {
|
|
|
|
requestViewRepaint(view);
|
|
|
|
});
|
2018-01-04 10:22:53 +00:00
|
|
|
}
|
|
|
|
|
2018-01-18 11:46:45 +00:00
|
|
|
rpl::producer<not_null<const HistoryItem*>> Session::itemRepaintRequest() const {
|
|
|
|
return _itemRepaintRequest.events();
|
2018-01-04 10:22:53 +00:00
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
void Session::requestViewRepaint(not_null<const ViewElement*> view) {
|
|
|
|
_viewRepaintRequest.fire_copy(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<not_null<const ViewElement*>> Session::viewRepaintRequest() const {
|
|
|
|
return _viewRepaintRequest.events();
|
|
|
|
}
|
|
|
|
|
2018-01-18 11:46:45 +00:00
|
|
|
void Session::requestItemResize(not_null<const HistoryItem*> item) {
|
|
|
|
_itemResizeRequest.fire_copy(item);
|
|
|
|
enumerateItemViews(item, [&](not_null<ViewElement*> view) {
|
|
|
|
requestViewResize(view);
|
|
|
|
});
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
|
2018-01-18 11:46:45 +00:00
|
|
|
rpl::producer<not_null<const HistoryItem*>> Session::itemResizeRequest() const {
|
|
|
|
return _itemResizeRequest.events();
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
|
2018-01-18 11:46:45 +00:00
|
|
|
void Session::requestViewResize(not_null<ViewElement*> view) {
|
2018-01-19 17:10:58 +00:00
|
|
|
view->setPendingResize();
|
2018-01-14 16:02:25 +00:00
|
|
|
_viewResizeRequest.fire_copy(view);
|
2018-01-21 14:49:42 +00:00
|
|
|
notifyViewLayoutChange(view);
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
2018-01-18 11:46:45 +00:00
|
|
|
rpl::producer<not_null<ViewElement*>> Session::viewResizeRequest() const {
|
2018-01-14 16:02:25 +00:00
|
|
|
return _viewResizeRequest.events();
|
|
|
|
}
|
|
|
|
|
2018-01-18 13:59:22 +00:00
|
|
|
void Session::requestItemViewRefresh(not_null<HistoryItem*> item) {
|
2018-01-18 11:46:45 +00:00
|
|
|
if (const auto view = item->mainView()) {
|
|
|
|
view->setPendingResize();
|
|
|
|
}
|
2018-01-13 12:45:11 +00:00
|
|
|
_itemViewRefreshRequest.fire_copy(item);
|
|
|
|
}
|
|
|
|
|
2018-01-18 13:59:22 +00:00
|
|
|
rpl::producer<not_null<HistoryItem*>> Session::itemViewRefreshRequest() const {
|
2018-01-13 12:45:11 +00:00
|
|
|
return _itemViewRefreshRequest.events();
|
|
|
|
}
|
|
|
|
|
2018-03-13 10:19:06 +00:00
|
|
|
void Session::requestItemTextRefresh(not_null<HistoryItem*> item) {
|
|
|
|
if (const auto i = _views.find(item); i != _views.end()) {
|
|
|
|
for (const auto view : i->second) {
|
|
|
|
if (const auto media = view->media()) {
|
|
|
|
media->parentTextUpdated();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-21 14:49:42 +00:00
|
|
|
void Session::requestAnimationPlayInline(not_null<HistoryItem*> item) {
|
|
|
|
_animationPlayInlineRequest.fire_copy(item);
|
2019-03-26 08:54:51 +00:00
|
|
|
|
|
|
|
if (const auto media = item->media()) {
|
|
|
|
if (const auto data = media->document()) {
|
|
|
|
if (data && data->isVideoMessage()) {
|
|
|
|
const auto msgId = item->fullId();
|
|
|
|
::Media::Player::instance()->playPause({ data, msgId });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
2018-01-21 14:49:42 +00:00
|
|
|
rpl::producer<not_null<HistoryItem*>> Session::animationPlayInlineRequest() const {
|
|
|
|
return _animationPlayInlineRequest.events();
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
2018-01-04 10:22:53 +00:00
|
|
|
rpl::producer<not_null<const HistoryItem*>> Session::itemRemoved() const {
|
|
|
|
return _itemRemoved.events();
|
|
|
|
}
|
|
|
|
|
2018-03-09 11:44:42 +00:00
|
|
|
void Session::notifyViewRemoved(not_null<const ViewElement*> view) {
|
|
|
|
_viewRemoved.fire_copy(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<not_null<const ViewElement*>> Session::viewRemoved() const {
|
|
|
|
return _viewRemoved.events();
|
|
|
|
}
|
|
|
|
|
2018-01-17 18:20:55 +00:00
|
|
|
void Session::notifyHistoryUnloaded(not_null<const History*> history) {
|
2018-01-04 10:22:53 +00:00
|
|
|
_historyUnloaded.fire_copy(history);
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<not_null<const History*>> Session::historyUnloaded() const {
|
|
|
|
return _historyUnloaded.events();
|
|
|
|
}
|
|
|
|
|
2018-01-17 18:20:55 +00:00
|
|
|
void Session::notifyHistoryCleared(not_null<const History*> history) {
|
2018-01-04 10:22:53 +00:00
|
|
|
_historyCleared.fire_copy(history);
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<not_null<const History*>> Session::historyCleared() const {
|
|
|
|
return _historyCleared.events();
|
|
|
|
}
|
|
|
|
|
2018-01-18 11:46:45 +00:00
|
|
|
void Session::notifyHistoryChangeDelayed(not_null<History*> history) {
|
2018-01-19 17:10:58 +00:00
|
|
|
history->setHasPendingResizedItems();
|
2018-01-18 09:53:49 +00:00
|
|
|
_historiesChanged.insert(history);
|
|
|
|
}
|
|
|
|
|
2018-01-18 11:46:45 +00:00
|
|
|
rpl::producer<not_null<History*>> Session::historyChanged() const {
|
2018-01-18 09:53:49 +00:00
|
|
|
return _historyChanged.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::sendHistoryChangeNotifications() {
|
|
|
|
for (const auto history : base::take(_historiesChanged)) {
|
|
|
|
_historyChanged.fire_copy(history);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-14 09:50:44 +00:00
|
|
|
void Session::registerHeavyViewPart(not_null<ViewElement*> view) {
|
|
|
|
_heavyViewParts.emplace(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::unregisterHeavyViewPart(not_null<ViewElement*> view) {
|
|
|
|
_heavyViewParts.remove(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::unloadHeavyViewParts(
|
|
|
|
not_null<HistoryView::ElementDelegate*> delegate) {
|
|
|
|
if (_heavyViewParts.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
2019-12-11 14:15:29 +00:00
|
|
|
const auto remove = ranges::count(
|
|
|
|
_heavyViewParts,
|
|
|
|
delegate,
|
|
|
|
[](not_null<ViewElement*> element) { return element->delegate(); });
|
2019-05-14 09:50:44 +00:00
|
|
|
if (remove == _heavyViewParts.size()) {
|
|
|
|
for (const auto view : base::take(_heavyViewParts)) {
|
|
|
|
view->unloadHeavyPart();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
auto remove = std::vector<not_null<ViewElement*>>();
|
|
|
|
for (const auto view : _heavyViewParts) {
|
|
|
|
if (view->delegate() == delegate) {
|
|
|
|
remove.push_back(view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const auto view : remove) {
|
|
|
|
view->unloadHeavyPart();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::unloadHeavyViewParts(
|
|
|
|
not_null<HistoryView::ElementDelegate*> delegate,
|
|
|
|
int from,
|
|
|
|
int till) {
|
|
|
|
if (_heavyViewParts.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto remove = std::vector<not_null<ViewElement*>>();
|
|
|
|
for (const auto view : _heavyViewParts) {
|
|
|
|
if (view->delegate() == delegate
|
|
|
|
&& !delegate->elementIntersectsRange(view, from, till)) {
|
|
|
|
remove.push_back(view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const auto view : remove) {
|
|
|
|
view->unloadHeavyPart();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-04 10:22:53 +00:00
|
|
|
void Session::removeMegagroupParticipant(
|
|
|
|
not_null<ChannelData*> channel,
|
|
|
|
not_null<UserData*> user) {
|
|
|
|
_megagroupParticipantRemoved.fire({ channel, user });
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Session::megagroupParticipantRemoved() const
|
|
|
|
-> rpl::producer<MegagroupParticipant> {
|
|
|
|
return _megagroupParticipantRemoved.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<not_null<UserData*>> Session::megagroupParticipantRemoved(
|
|
|
|
not_null<ChannelData*> channel) const {
|
|
|
|
return megagroupParticipantRemoved(
|
|
|
|
) | rpl::filter([channel](auto updateChannel, auto user) {
|
|
|
|
return (updateChannel == channel);
|
|
|
|
}) | rpl::map([](auto updateChannel, auto user) {
|
|
|
|
return user;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::addNewMegagroupParticipant(
|
|
|
|
not_null<ChannelData*> channel,
|
|
|
|
not_null<UserData*> user) {
|
|
|
|
_megagroupParticipantAdded.fire({ channel, user });
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Session::megagroupParticipantAdded() const
|
|
|
|
-> rpl::producer<MegagroupParticipant> {
|
|
|
|
return _megagroupParticipantAdded.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<not_null<UserData*>> Session::megagroupParticipantAdded(
|
|
|
|
not_null<ChannelData*> channel) const {
|
|
|
|
return megagroupParticipantAdded(
|
|
|
|
) | rpl::filter([channel](auto updateChannel, auto user) {
|
|
|
|
return (updateChannel == channel);
|
|
|
|
}) | rpl::map([](auto updateChannel, auto user) {
|
|
|
|
return user;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-01-17 18:20:55 +00:00
|
|
|
void Session::notifyStickersUpdated() {
|
2018-01-04 10:22:53 +00:00
|
|
|
_stickersUpdated.fire({});
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<> Session::stickersUpdated() const {
|
|
|
|
return _stickersUpdated.events();
|
|
|
|
}
|
|
|
|
|
2019-06-12 19:49:28 +00:00
|
|
|
void Session::notifyRecentStickersUpdated() {
|
|
|
|
_recentStickersUpdated.fire({});
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<> Session::recentStickersUpdated() const {
|
|
|
|
return _recentStickersUpdated.events();
|
|
|
|
}
|
|
|
|
|
2018-01-17 18:20:55 +00:00
|
|
|
void Session::notifySavedGifsUpdated() {
|
2018-01-04 10:22:53 +00:00
|
|
|
_savedGifsUpdated.fire({});
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<> Session::savedGifsUpdated() const {
|
|
|
|
return _savedGifsUpdated.events();
|
|
|
|
}
|
|
|
|
|
2019-05-01 13:18:31 +00:00
|
|
|
void Session::notifyPinnedDialogsOrderUpdated() {
|
|
|
|
_pinnedDialogsOrderUpdated.fire({});
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<> Session::pinnedDialogsOrderUpdated() const {
|
|
|
|
return _pinnedDialogsOrderUpdated.events();
|
|
|
|
}
|
|
|
|
|
2018-01-04 10:22:53 +00:00
|
|
|
void Session::userIsContactUpdated(not_null<UserData*> user) {
|
2018-01-17 16:21:01 +00:00
|
|
|
const auto i = _contactViews.find(peerToUser(user->id));
|
|
|
|
if (i != _contactViews.end()) {
|
|
|
|
for (const auto view : i->second) {
|
|
|
|
requestViewResize(view);
|
2018-01-04 10:22:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HistoryItemsList Session::idsToItems(
|
|
|
|
const MessageIdsList &ids) const {
|
|
|
|
return ranges::view::all(
|
|
|
|
ids
|
2019-04-25 12:45:15 +00:00
|
|
|
) | ranges::view::transform([&](const FullMsgId &fullId) {
|
|
|
|
return message(fullId);
|
2018-01-04 10:22:53 +00:00
|
|
|
}) | ranges::view::filter([](HistoryItem *item) {
|
|
|
|
return item != nullptr;
|
|
|
|
}) | ranges::view::transform([](HistoryItem *item) {
|
|
|
|
return not_null<HistoryItem*>(item);
|
|
|
|
}) | ranges::to_vector;
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageIdsList Session::itemsToIds(
|
|
|
|
const HistoryItemsList &items) const {
|
|
|
|
return ranges::view::all(
|
|
|
|
items
|
|
|
|
) | ranges::view::transform([](not_null<HistoryItem*> item) {
|
|
|
|
return item->fullId();
|
|
|
|
}) | ranges::to_vector;
|
|
|
|
}
|
|
|
|
|
2018-01-11 15:51:59 +00:00
|
|
|
MessageIdsList Session::itemOrItsGroup(not_null<HistoryItem*> item) const {
|
2018-01-14 16:02:25 +00:00
|
|
|
if (const auto group = groups().find(item)) {
|
|
|
|
return itemsToIds(group->items);
|
2018-01-11 15:51:59 +00:00
|
|
|
}
|
|
|
|
return { 1, item->fullId() };
|
|
|
|
}
|
|
|
|
|
2020-03-17 13:04:30 +00:00
|
|
|
void Session::setChatPinned(
|
|
|
|
const Dialogs::Key &key,
|
|
|
|
FilterId filterId,
|
|
|
|
bool pinned) {
|
2019-04-19 08:47:49 +00:00
|
|
|
Expects(key.entry()->folderKnown());
|
|
|
|
|
2020-03-17 13:04:30 +00:00
|
|
|
const auto list = filterId
|
|
|
|
? chatsFilters().chatsList(filterId)
|
|
|
|
: chatsList(key.entry()->folder());
|
|
|
|
list->pinned()->setPinned(key, pinned);
|
2019-05-02 13:26:47 +00:00
|
|
|
notifyPinnedDialogsOrderUpdated();
|
2018-01-04 19:54:35 +00:00
|
|
|
}
|
|
|
|
|
2019-04-19 08:47:49 +00:00
|
|
|
void Session::setPinnedFromDialog(const Dialogs::Key &key, bool pinned) {
|
|
|
|
Expects(key.entry()->folderKnown());
|
|
|
|
|
2019-04-22 14:22:39 +00:00
|
|
|
const auto list = chatsList(key.entry()->folder())->pinned();
|
|
|
|
if (pinned) {
|
|
|
|
list->addPinned(key);
|
2019-04-19 08:47:49 +00:00
|
|
|
} else {
|
2019-04-22 14:22:39 +00:00
|
|
|
list->setPinned(key, false);
|
2019-04-19 08:47:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::applyPinnedChats(
|
2019-04-22 14:22:39 +00:00
|
|
|
Data::Folder *folder,
|
2019-04-19 08:47:49 +00:00
|
|
|
const QVector<MTPDialogPeer> &list) {
|
|
|
|
for (const auto &peer : list) {
|
|
|
|
peer.match([&](const MTPDdialogPeer &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto history = this->history(peerFromMTP(data.vpeer()));
|
2019-04-19 08:47:49 +00:00
|
|
|
if (folder) {
|
|
|
|
history->setFolder(folder);
|
|
|
|
} else {
|
|
|
|
history->clearFolder();
|
2018-01-04 19:54:35 +00:00
|
|
|
}
|
2019-04-16 08:50:59 +00:00
|
|
|
}, [&](const MTPDdialogPeerFolder &data) {
|
2019-04-19 08:47:49 +00:00
|
|
|
if (folder) {
|
|
|
|
LOG(("API Error: Nested folders detected."));
|
|
|
|
}
|
2019-04-15 11:54:03 +00:00
|
|
|
});
|
2018-01-04 19:54:35 +00:00
|
|
|
}
|
2019-04-22 14:22:39 +00:00
|
|
|
chatsList(folder)->pinned()->applyList(this, list);
|
2019-05-02 13:26:47 +00:00
|
|
|
notifyPinnedDialogsOrderUpdated();
|
2018-01-04 19:54:35 +00:00
|
|
|
}
|
|
|
|
|
2019-04-16 16:28:41 +00:00
|
|
|
void Session::applyDialogs(
|
2019-04-22 14:22:39 +00:00
|
|
|
Data::Folder *requestFolder,
|
2019-04-16 16:28:41 +00:00
|
|
|
const QVector<MTPMessage> &messages,
|
2019-04-23 12:29:23 +00:00
|
|
|
const QVector<MTPDialog> &dialogs,
|
|
|
|
std::optional<int> count) {
|
2019-04-25 12:45:15 +00:00
|
|
|
processMessages(messages, NewMessageType::Last);
|
2019-04-16 16:28:41 +00:00
|
|
|
for (const auto &dialog : dialogs) {
|
|
|
|
dialog.match([&](const auto &data) {
|
2019-04-22 14:22:39 +00:00
|
|
|
applyDialog(requestFolder, data);
|
2019-04-16 16:28:41 +00:00
|
|
|
});
|
|
|
|
}
|
2019-04-23 12:29:23 +00:00
|
|
|
if (requestFolder && count) {
|
2020-03-16 10:20:18 +00:00
|
|
|
requestFolder->chatsList()->setCloudListSize(*count);
|
2019-04-23 12:29:23 +00:00
|
|
|
}
|
2019-04-16 16:28:41 +00:00
|
|
|
}
|
|
|
|
|
2019-04-22 14:22:39 +00:00
|
|
|
void Session::applyDialog(
|
|
|
|
Data::Folder *requestFolder,
|
|
|
|
const MTPDdialog &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto peerId = peerFromMTP(data.vpeer());
|
2019-04-16 16:28:41 +00:00
|
|
|
if (!peerId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-21 07:58:50 +00:00
|
|
|
const auto history = this->history(peerId);
|
2019-04-22 14:22:39 +00:00
|
|
|
history->applyDialog(requestFolder, data);
|
2019-04-19 08:47:49 +00:00
|
|
|
setPinnedFromDialog(history, data.is_pinned());
|
2019-04-16 16:28:41 +00:00
|
|
|
|
|
|
|
if (const auto from = history->peer->migrateFrom()) {
|
|
|
|
if (const auto historyFrom = from->owner().historyLoaded(from)) {
|
|
|
|
App::main()->removeDialog(historyFrom);
|
|
|
|
}
|
|
|
|
} else if (const auto to = history->peer->migrateTo()) {
|
|
|
|
if (to->amIn()) {
|
|
|
|
App::main()->removeDialog(history);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-17 12:08:02 +00:00
|
|
|
void Session::applyDialog(
|
2019-04-22 14:22:39 +00:00
|
|
|
Data::Folder *requestFolder,
|
2019-04-19 08:47:49 +00:00
|
|
|
const MTPDdialogFolder &data) {
|
2019-04-22 14:22:39 +00:00
|
|
|
if (requestFolder) {
|
|
|
|
LOG(("API Error: requestFolder != nullptr for dialogFolder."));
|
2019-04-17 12:08:02 +00:00
|
|
|
}
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto folder = processFolder(data.vfolder());
|
2019-04-19 08:47:49 +00:00
|
|
|
folder->applyDialog(data);
|
|
|
|
setPinnedFromDialog(folder, data.is_pinned());
|
2019-04-16 16:28:41 +00:00
|
|
|
}
|
|
|
|
|
2020-03-17 13:04:30 +00:00
|
|
|
int Session::pinnedChatsCount(
|
|
|
|
Data::Folder *folder,
|
|
|
|
FilterId filterId) const {
|
|
|
|
if (!filterId) {
|
|
|
|
return pinnedChatsOrder(folder, filterId).size();
|
|
|
|
}
|
|
|
|
const auto &list = chatsFilters().list();
|
|
|
|
const auto i = ranges::find(list, filterId, &Data::ChatFilter::id);
|
|
|
|
return (i != end(list)) ? i->pinned().size() : 0;
|
2019-04-19 08:47:49 +00:00
|
|
|
}
|
|
|
|
|
2020-03-17 13:04:30 +00:00
|
|
|
int Session::pinnedChatsLimit(
|
|
|
|
Data::Folder *folder,
|
|
|
|
FilterId filterId) const {
|
2020-03-17 14:52:01 +00:00
|
|
|
if (!filterId) {
|
|
|
|
return folder
|
|
|
|
? Global::PinnedDialogsInFolderMax()
|
|
|
|
: Global::PinnedDialogsCountMax();
|
|
|
|
}
|
|
|
|
const auto &list = chatsFilters().list();
|
|
|
|
const auto i = ranges::find(list, filterId, &Data::ChatFilter::id);
|
|
|
|
const auto pinned = (i != end(list)) ? i->pinned().size() : 0;
|
|
|
|
const auto already = (i != end(list)) ? i->always().size() : 0;
|
|
|
|
return Data::ChatFilter::kPinnedLimit + pinned - already;
|
2018-01-04 19:54:35 +00:00
|
|
|
}
|
|
|
|
|
2019-04-19 08:47:49 +00:00
|
|
|
const std::vector<Dialogs::Key> &Session::pinnedChatsOrder(
|
2020-03-17 13:04:30 +00:00
|
|
|
Data::Folder *folder,
|
|
|
|
FilterId filterId) const {
|
|
|
|
const auto list = filterId
|
|
|
|
? chatsFilters().chatsList(filterId)
|
|
|
|
: chatsList(folder);
|
|
|
|
return list->pinned()->order();
|
2018-01-04 19:54:35 +00:00
|
|
|
}
|
|
|
|
|
2020-03-23 11:10:09 +00:00
|
|
|
void Session::clearPinnedChats(Data::Folder *folder) {
|
2019-04-22 14:22:39 +00:00
|
|
|
chatsList(folder)->pinned()->clear();
|
2018-01-04 19:54:35 +00:00
|
|
|
}
|
|
|
|
|
2019-04-19 08:47:49 +00:00
|
|
|
void Session::reorderTwoPinnedChats(
|
2020-03-17 13:04:30 +00:00
|
|
|
FilterId filterId,
|
2018-01-04 19:54:35 +00:00
|
|
|
const Dialogs::Key &key1,
|
|
|
|
const Dialogs::Key &key2) {
|
2019-04-19 08:47:49 +00:00
|
|
|
Expects(key1.entry()->folderKnown() && key2.entry()->folderKnown());
|
2020-03-17 13:04:30 +00:00
|
|
|
Expects(filterId || (key1.entry()->folder() == key2.entry()->folder()));
|
2019-04-19 08:47:49 +00:00
|
|
|
|
2020-03-17 13:04:30 +00:00
|
|
|
const auto list = filterId
|
|
|
|
? chatsFilters().chatsList(filterId)
|
|
|
|
: chatsList(key1.entry()->folder());
|
|
|
|
list->pinned()->reorder(key1, key2);
|
2019-05-02 13:26:47 +00:00
|
|
|
notifyPinnedDialogsOrderUpdated();
|
2018-01-04 19:54:35 +00:00
|
|
|
}
|
|
|
|
|
2019-04-25 12:45:15 +00:00
|
|
|
bool Session::checkEntitiesAndViewsUpdate(const MTPDmessage &data) {
|
|
|
|
const auto peer = [&] {
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto result = peerFromMTP(data.vto_id());
|
|
|
|
if (const auto fromId = data.vfrom_id()) {
|
|
|
|
if (result == session().userPeerId()) {
|
|
|
|
return peerFromUser(*fromId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
2019-04-25 12:45:15 +00:00
|
|
|
}();
|
2019-07-05 13:38:38 +00:00
|
|
|
if (const auto existing = message(peerToChannel(peer), data.vid().v)) {
|
2019-08-07 14:38:26 +00:00
|
|
|
existing->updateSentContent({
|
2019-07-05 13:38:38 +00:00
|
|
|
qs(data.vmessage()),
|
2019-09-16 11:14:06 +00:00
|
|
|
Api::EntitiesFromMTP(data.ventities().value_or_empty())
|
2019-08-07 14:38:26 +00:00
|
|
|
}, data.vmedia());
|
2019-07-05 13:38:38 +00:00
|
|
|
existing->updateReplyMarkup(data.vreply_markup());
|
|
|
|
existing->updateForwardedInfo(data.vfwd_from());
|
|
|
|
existing->setViewsCount(data.vviews().value_or(-1));
|
2019-04-25 12:45:15 +00:00
|
|
|
existing->indexAsNewItem();
|
2019-08-20 09:42:13 +00:00
|
|
|
existing->contributeToSlowmode(data.vdate().v);
|
2019-04-25 12:45:15 +00:00
|
|
|
requestItemTextRefresh(existing);
|
2019-12-27 12:15:16 +00:00
|
|
|
updateDependentMessages(existing);
|
2019-04-25 12:45:15 +00:00
|
|
|
if (existing->mainView()) {
|
2019-07-24 11:13:51 +00:00
|
|
|
checkSavedGif(existing);
|
2019-04-25 12:45:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-24 11:13:51 +00:00
|
|
|
void Session::addSavedGif(not_null<DocumentData*> 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<HistoryItem*> item) {
|
|
|
|
if (item->Has<HistoryMessageForwarded>()
|
|
|
|
|| (!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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-25 12:45:15 +00:00
|
|
|
void Session::updateEditedMessage(const MTPMessage &data) {
|
|
|
|
const auto existing = data.match([](const MTPDmessageEmpty &)
|
|
|
|
-> HistoryItem* {
|
|
|
|
return nullptr;
|
|
|
|
}, [&](const auto &data) {
|
|
|
|
const auto peer = [&] {
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto result = peerFromMTP(data.vto_id());
|
|
|
|
if (const auto fromId = data.vfrom_id()) {
|
|
|
|
if (result == session().userPeerId()) {
|
|
|
|
return peerFromUser(*fromId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
2019-04-25 12:45:15 +00:00
|
|
|
}();
|
2019-07-05 13:38:38 +00:00
|
|
|
return message(peerToChannel(peer), data.vid().v);
|
2019-04-25 12:45:15 +00:00
|
|
|
});
|
|
|
|
if (!existing) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (existing->isLocalUpdateMedia() && data.type() == mtpc_message) {
|
|
|
|
checkEntitiesAndViewsUpdate(data.c_message());
|
|
|
|
}
|
|
|
|
data.match([](const MTPDmessageEmpty &) {
|
|
|
|
}, [&](const auto &data) {
|
|
|
|
existing->applyEdition(data);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::processMessages(
|
|
|
|
const QVector<MTPMessage> &data,
|
|
|
|
NewMessageType type) {
|
|
|
|
auto indices = base::flat_map<uint64, int>();
|
|
|
|
for (int i = 0, l = data.size(); i != l; ++i) {
|
|
|
|
const auto &message = data[i];
|
|
|
|
if (message.type() == mtpc_message) {
|
|
|
|
const auto &data = message.c_message();
|
|
|
|
// new message, index my forwarded messages to links overview
|
|
|
|
if ((type == NewMessageType::Unread)
|
|
|
|
&& checkEntitiesAndViewsUpdate(data)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const auto id = IdFromMessage(message);
|
|
|
|
indices.emplace((uint64(uint32(id)) << 32) | uint64(i), i);
|
|
|
|
}
|
|
|
|
for (const auto [position, index] : indices) {
|
2019-08-09 19:19:23 +00:00
|
|
|
addNewMessage(
|
|
|
|
data[index],
|
|
|
|
MTPDmessage_ClientFlags(),
|
|
|
|
type);
|
2019-04-25 12:45:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::processMessages(
|
|
|
|
const MTPVector<MTPMessage> &data,
|
|
|
|
NewMessageType type) {
|
|
|
|
processMessages(data.v, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Session::Messages *Session::messagesList(ChannelId channelId) const {
|
|
|
|
if (channelId == NoChannel) {
|
|
|
|
return &_messages;
|
|
|
|
}
|
|
|
|
const auto i = _channelMessages.find(channelId);
|
|
|
|
return (i != end(_channelMessages)) ? &i->second : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Session::messagesListForInsert(ChannelId channelId)
|
|
|
|
-> not_null<Messages*> {
|
|
|
|
return (channelId == NoChannel)
|
|
|
|
? &_messages
|
|
|
|
: &_channelMessages[channelId];
|
|
|
|
}
|
|
|
|
|
2020-02-20 08:45:25 +00:00
|
|
|
void Session::registerMessage(not_null<HistoryItem*> item) {
|
|
|
|
const auto list = messagesListForInsert(item->channelId());
|
|
|
|
const auto itemId = item->id;
|
|
|
|
const auto i = list->find(itemId);
|
2019-04-25 12:45:15 +00:00
|
|
|
if (i != list->end()) {
|
|
|
|
LOG(("App Error: Trying to re-registerMessage()."));
|
|
|
|
i->second->destroy();
|
|
|
|
}
|
2020-02-20 08:45:25 +00:00
|
|
|
list->emplace(itemId, item);
|
2019-04-25 12:45:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Session::processMessagesDeleted(
|
|
|
|
ChannelId channelId,
|
|
|
|
const QVector<MTPint> &data) {
|
|
|
|
const auto list = messagesList(channelId);
|
|
|
|
const auto affected = (channelId != NoChannel)
|
|
|
|
? historyLoaded(peerFromChannel(channelId))
|
|
|
|
: nullptr;
|
|
|
|
if (!list && !affected) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto historiesToCheck = base::flat_set<not_null<History*>>();
|
|
|
|
for (const auto messageId : data) {
|
|
|
|
const auto i = list ? list->find(messageId.v) : Messages::iterator();
|
|
|
|
if (list && i != list->end()) {
|
|
|
|
const auto history = i->second->history();
|
2020-02-20 08:45:25 +00:00
|
|
|
i->second->destroy();
|
2019-04-25 12:45:15 +00:00
|
|
|
if (!history->chatListMessageKnown()) {
|
|
|
|
historiesToCheck.emplace(history);
|
|
|
|
}
|
|
|
|
} else if (affected) {
|
|
|
|
affected->unknownMessageDeleted(messageId.v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const auto history : historiesToCheck) {
|
|
|
|
history->requestChatListMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-30 08:04:42 +00:00
|
|
|
void Session::removeDependencyMessage(not_null<HistoryItem*> item) {
|
|
|
|
const auto i = _dependentMessages.find(item);
|
|
|
|
if (i == end(_dependentMessages)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto items = std::move(i->second);
|
|
|
|
_dependentMessages.erase(i);
|
|
|
|
|
|
|
|
for (const auto dependent : items) {
|
|
|
|
dependent->dependencyItemRemoved(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-20 08:45:25 +00:00
|
|
|
void Session::unregisterMessage(not_null<HistoryItem*> item) {
|
2019-04-30 08:04:42 +00:00
|
|
|
const auto peerId = item->history()->peer->id;
|
|
|
|
_itemRemoved.fire_copy(item);
|
|
|
|
groups().unregisterMessage(item);
|
|
|
|
removeDependencyMessage(item);
|
2020-02-20 08:45:25 +00:00
|
|
|
messagesListForInsert(peerToChannel(peerId))->erase(item->id);
|
2019-04-25 12:45:15 +00:00
|
|
|
}
|
|
|
|
|
2019-08-12 16:33:36 +00:00
|
|
|
MsgId Session::nextLocalMessageId() {
|
|
|
|
Expects(_localMessageIdCounter < EndClientMsgId);
|
|
|
|
|
|
|
|
return _localMessageIdCounter++;
|
|
|
|
}
|
|
|
|
|
2019-04-25 12:45:15 +00:00
|
|
|
HistoryItem *Session::message(ChannelId channelId, MsgId itemId) const {
|
|
|
|
if (!itemId) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto data = messagesList(channelId);
|
|
|
|
if (!data) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto i = data->find(itemId);
|
|
|
|
return (i != data->end()) ? i->second.get() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
HistoryItem *Session::message(
|
|
|
|
const ChannelData *channel,
|
|
|
|
MsgId itemId) const {
|
|
|
|
return message(channel ? peerToChannel(channel->id) : 0, itemId);
|
|
|
|
}
|
|
|
|
|
|
|
|
HistoryItem *Session::message(FullMsgId itemId) const {
|
|
|
|
return message(itemId.channel, itemId.msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::updateDependentMessages(not_null<HistoryItem*> item) {
|
|
|
|
const auto i = _dependentMessages.find(item);
|
|
|
|
if (i != end(_dependentMessages)) {
|
|
|
|
for (const auto dependent : i->second) {
|
|
|
|
dependent->updateDependencyItem();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (App::main()) {
|
|
|
|
App::main()->itemEdited(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::registerDependentMessage(
|
|
|
|
not_null<HistoryItem*> dependent,
|
|
|
|
not_null<HistoryItem*> dependency) {
|
|
|
|
_dependentMessages[dependency].emplace(dependent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::unregisterDependentMessage(
|
|
|
|
not_null<HistoryItem*> dependent,
|
|
|
|
not_null<HistoryItem*> dependency) {
|
|
|
|
const auto i = _dependentMessages.find(dependency);
|
|
|
|
if (i != end(_dependentMessages)) {
|
|
|
|
if (i->second.remove(dependent) && i->second.empty()) {
|
|
|
|
_dependentMessages.erase(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::registerMessageRandomId(uint64 randomId, FullMsgId itemId) {
|
|
|
|
_messageByRandomId.emplace(randomId, itemId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::unregisterMessageRandomId(uint64 randomId) {
|
|
|
|
_messageByRandomId.remove(randomId);
|
|
|
|
}
|
|
|
|
|
|
|
|
FullMsgId Session::messageIdByRandomId(uint64 randomId) const {
|
|
|
|
const auto i = _messageByRandomId.find(randomId);
|
|
|
|
return (i != end(_messageByRandomId)) ? i->second : FullMsgId();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::registerMessageSentData(
|
|
|
|
uint64 randomId,
|
|
|
|
PeerId peerId,
|
|
|
|
const QString &text) {
|
|
|
|
_sentMessagesData.emplace(randomId, SentData{ peerId, text });
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::unregisterMessageSentData(uint64 randomId) {
|
|
|
|
_sentMessagesData.remove(randomId);
|
|
|
|
}
|
|
|
|
|
|
|
|
Session::SentData Session::messageSentData(uint64 randomId) const {
|
|
|
|
const auto i = _sentMessagesData.find(randomId);
|
|
|
|
return (i != end(_sentMessagesData)) ? i->second : SentData();
|
|
|
|
}
|
|
|
|
|
2018-04-09 17:48:29 +00:00
|
|
|
NotifySettings &Session::defaultNotifySettings(
|
|
|
|
not_null<const PeerData*> peer) {
|
|
|
|
return peer->isUser()
|
|
|
|
? _defaultUserNotifySettings
|
2019-06-04 13:40:24 +00:00
|
|
|
: (peer->isChat() || peer->isMegagroup())
|
|
|
|
? _defaultChatNotifySettings
|
|
|
|
: _defaultBroadcastNotifySettings;
|
2018-04-09 17:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const NotifySettings &Session::defaultNotifySettings(
|
|
|
|
not_null<const PeerData*> peer) const {
|
|
|
|
return peer->isUser()
|
|
|
|
? _defaultUserNotifySettings
|
2019-06-04 13:40:24 +00:00
|
|
|
: (peer->isChat() || peer->isMegagroup())
|
|
|
|
? _defaultChatNotifySettings
|
|
|
|
: _defaultBroadcastNotifySettings;
|
2018-04-09 17:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Session::updateNotifySettingsLocal(not_null<PeerData*> peer) {
|
2019-01-03 12:36:01 +00:00
|
|
|
const auto history = historyLoaded(peer->id);
|
2019-02-19 06:57:53 +00:00
|
|
|
auto changesIn = crl::time(0);
|
2018-04-09 17:48:29 +00:00
|
|
|
const auto muted = notifyIsMuted(peer, &changesIn);
|
|
|
|
if (history && history->changeMute(muted)) {
|
|
|
|
// Notification already sent.
|
|
|
|
} else {
|
|
|
|
Notify::peerUpdatedDelayed(
|
|
|
|
peer,
|
|
|
|
Notify::PeerUpdate::Flag::NotificationsEnabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (muted) {
|
|
|
|
_mutedPeers.emplace(peer);
|
|
|
|
unmuteByFinishedDelayed(changesIn);
|
|
|
|
if (history) {
|
2019-08-30 14:06:21 +00:00
|
|
|
_session->notifications().clearIncomingFromHistory(history);
|
2018-04-09 17:48:29 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_mutedPeers.erase(peer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-19 06:57:53 +00:00
|
|
|
void Session::unmuteByFinishedDelayed(crl::time delay) {
|
2018-08-01 16:58:50 +00:00
|
|
|
accumulate_min(delay, kMaxNotifyCheckDelay);
|
2018-04-09 17:48:29 +00:00
|
|
|
if (!_unmuteByFinishedTimer.isActive()
|
|
|
|
|| _unmuteByFinishedTimer.remainingTime() > delay) {
|
|
|
|
_unmuteByFinishedTimer.callOnce(delay);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::unmuteByFinished() {
|
2019-02-19 06:57:53 +00:00
|
|
|
auto changesInMin = crl::time(0);
|
2018-04-09 17:48:29 +00:00
|
|
|
for (auto i = begin(_mutedPeers); i != end(_mutedPeers);) {
|
2019-01-03 12:36:01 +00:00
|
|
|
const auto history = historyLoaded((*i)->id);
|
2019-02-19 06:57:53 +00:00
|
|
|
auto changesIn = crl::time(0);
|
2018-04-09 17:48:29 +00:00
|
|
|
const auto muted = notifyIsMuted(*i, &changesIn);
|
|
|
|
if (muted) {
|
|
|
|
if (history) {
|
|
|
|
history->changeMute(true);
|
|
|
|
}
|
|
|
|
if (!changesInMin || changesInMin > changesIn) {
|
|
|
|
changesInMin = changesIn;
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
} else {
|
|
|
|
if (history) {
|
|
|
|
history->changeMute(false);
|
|
|
|
}
|
|
|
|
i = _mutedPeers.erase(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (changesInMin) {
|
|
|
|
unmuteByFinishedDelayed(changesInMin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-03 12:36:01 +00:00
|
|
|
HistoryItem *Session::addNewMessage(
|
|
|
|
const MTPMessage &data,
|
2019-08-09 19:19:23 +00:00
|
|
|
MTPDmessage_ClientFlags clientFlags,
|
2019-01-03 12:36:01 +00:00
|
|
|
NewMessageType type) {
|
|
|
|
const auto peerId = PeerFromMessage(data);
|
|
|
|
if (!peerId) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:19:23 +00:00
|
|
|
const auto result = history(peerId)->addNewMessage(
|
|
|
|
data,
|
|
|
|
clientFlags,
|
|
|
|
type);
|
2019-04-25 12:45:15 +00:00
|
|
|
if (result && type == NewMessageType::Unread) {
|
2019-01-03 12:36:01 +00:00
|
|
|
CheckForSwitchInlineButton(result);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Session::sendActionAnimationUpdated() const
|
|
|
|
-> rpl::producer<SendActionAnimationUpdate> {
|
|
|
|
return _sendActionAnimationUpdate.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::updateSendActionAnimation(
|
|
|
|
SendActionAnimationUpdate &&update) {
|
|
|
|
_sendActionAnimationUpdate.fire(std::move(update));
|
|
|
|
}
|
|
|
|
|
|
|
|
int Session::unreadBadge() const {
|
2019-04-24 15:28:01 +00:00
|
|
|
return computeUnreadBadge(_chatsList.unreadState());
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Session::unreadBadgeMuted() const {
|
2019-04-24 15:28:01 +00:00
|
|
|
return computeUnreadBadgeMuted(_chatsList.unreadState());
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 14:12:35 +00:00
|
|
|
int Session::unreadBadgeIgnoreOne(const Dialogs::Key &key) const {
|
|
|
|
const auto remove = (key && key.entry()->inChatList())
|
|
|
|
? key.entry()->chatListUnreadState()
|
|
|
|
: Dialogs::UnreadState();
|
2019-04-24 15:28:01 +00:00
|
|
|
return computeUnreadBadge(_chatsList.unreadState() - remove);
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 14:12:35 +00:00
|
|
|
bool Session::unreadBadgeMutedIgnoreOne(const Dialogs::Key &key) const {
|
|
|
|
if (!_session->settings().includeMutedCounter()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const auto remove = (key && key.entry()->inChatList())
|
|
|
|
? key.entry()->chatListUnreadState()
|
|
|
|
: Dialogs::UnreadState();
|
2019-04-24 15:28:01 +00:00
|
|
|
return computeUnreadBadgeMuted(_chatsList.unreadState() - remove);
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int Session::unreadOnlyMutedBadge() const {
|
2019-04-22 14:22:39 +00:00
|
|
|
const auto state = _chatsList.unreadState();
|
2019-01-03 12:36:01 +00:00
|
|
|
return _session->settings().countUnreadMessages()
|
2019-04-24 15:28:01 +00:00
|
|
|
? state.messagesMuted
|
|
|
|
: state.chatsMuted;
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 15:28:01 +00:00
|
|
|
int Session::computeUnreadBadge(const Dialogs::UnreadState &state) const {
|
|
|
|
const auto all = _session->settings().includeMutedCounter();
|
|
|
|
return std::max(state.marks - (all ? 0 : state.marksMuted), 0)
|
|
|
|
+ (_session->settings().countUnreadMessages()
|
|
|
|
? std::max(state.messages - (all ? 0 : state.messagesMuted), 0)
|
|
|
|
: std::max(state.chats - (all ? 0 : state.chatsMuted), 0));
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Session::computeUnreadBadgeMuted(
|
2019-04-24 15:28:01 +00:00
|
|
|
const Dialogs::UnreadState &state) const {
|
2019-01-03 12:36:01 +00:00
|
|
|
if (!_session->settings().includeMutedCounter()) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-04-24 15:28:01 +00:00
|
|
|
return (state.marksMuted >= state.marks)
|
|
|
|
&& (_session->settings().countUnreadMessages()
|
|
|
|
? (state.messagesMuted >= state.messages)
|
|
|
|
: (state.chatsMuted >= state.chats));
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
|
|
|
|
2019-02-19 06:57:53 +00:00
|
|
|
void Session::selfDestructIn(not_null<HistoryItem*> item, crl::time delay) {
|
2019-01-03 12:36:01 +00:00
|
|
|
_selfDestructItems.push_back(item->fullId());
|
|
|
|
if (!_selfDestructTimer.isActive()
|
|
|
|
|| _selfDestructTimer.remainingTime() > delay) {
|
|
|
|
_selfDestructTimer.callOnce(delay);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::checkSelfDestructItems() {
|
2019-04-25 12:45:15 +00:00
|
|
|
const auto now = crl::now();
|
2019-02-19 06:57:53 +00:00
|
|
|
auto nextDestructIn = crl::time(0);
|
2019-01-03 12:36:01 +00:00
|
|
|
for (auto i = _selfDestructItems.begin(); i != _selfDestructItems.cend();) {
|
2019-04-25 12:45:15 +00:00
|
|
|
if (const auto item = message(*i)) {
|
2019-01-03 12:36:01 +00:00
|
|
|
if (auto destructIn = item->getSelfDestructIn(now)) {
|
|
|
|
if (nextDestructIn > 0) {
|
|
|
|
accumulate_min(nextDestructIn, destructIn);
|
|
|
|
} else {
|
|
|
|
nextDestructIn = destructIn;
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
} else {
|
|
|
|
i = _selfDestructItems.erase(i);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
i = _selfDestructItems.erase(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (nextDestructIn > 0) {
|
|
|
|
_selfDestructTimer.callOnce(nextDestructIn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
not_null<PhotoData*> Session::photo(PhotoId id) {
|
|
|
|
auto i = _photos.find(id);
|
|
|
|
if (i == _photos.end()) {
|
2019-01-25 14:37:28 +00:00
|
|
|
i = _photos.emplace(
|
|
|
|
id,
|
|
|
|
std::make_unique<PhotoData>(this, id)).first;
|
2018-01-17 16:21:01 +00:00
|
|
|
}
|
|
|
|
return i->second.get();
|
|
|
|
}
|
|
|
|
|
2019-01-18 12:27:37 +00:00
|
|
|
not_null<PhotoData*> Session::processPhoto(const MTPPhoto &data) {
|
2019-01-25 14:37:28 +00:00
|
|
|
return data.match([&](const MTPDphoto &data) {
|
|
|
|
return processPhoto(data);
|
|
|
|
}, [&](const MTPDphotoEmpty &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
return photo(data.vid().v);
|
2019-01-25 14:37:28 +00:00
|
|
|
});
|
2018-01-17 16:21:01 +00:00
|
|
|
}
|
|
|
|
|
2019-01-18 12:27:37 +00:00
|
|
|
not_null<PhotoData*> Session::processPhoto(const MTPDphoto &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto result = photo(data.vid().v);
|
2018-01-17 16:21:01 +00:00
|
|
|
photoApplyFields(result, data);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-01-18 12:27:37 +00:00
|
|
|
not_null<PhotoData*> Session::processPhoto(
|
2018-01-17 16:21:01 +00:00
|
|
|
const MTPPhoto &data,
|
|
|
|
const PreparedPhotoThumbs &thumbs) {
|
2019-01-25 14:37:28 +00:00
|
|
|
Expects(!thumbs.empty());
|
|
|
|
|
|
|
|
const auto find = [&](const QByteArray &levels) {
|
|
|
|
const auto kInvalidIndex = int(levels.size());
|
|
|
|
const auto level = [&](const auto &pair) {
|
|
|
|
const auto letter = pair.first;
|
|
|
|
const auto index = levels.indexOf(letter);
|
|
|
|
return (index >= 0) ? index : kInvalidIndex;
|
|
|
|
};
|
|
|
|
const auto result = ranges::max_element(
|
|
|
|
thumbs,
|
|
|
|
std::greater<>(),
|
|
|
|
level);
|
|
|
|
return (level(*result) == kInvalidIndex) ? thumbs.end() : result;
|
|
|
|
};
|
|
|
|
const auto image = [&](const QByteArray &levels) {
|
|
|
|
const auto i = find(levels);
|
|
|
|
return (i == thumbs.end())
|
2020-05-25 14:16:04 +00:00
|
|
|
? ImageWithLocation()
|
|
|
|
: Images::FromImageInMemory(i->second, "JPG");
|
2019-01-25 14:37:28 +00:00
|
|
|
};
|
2020-05-25 14:16:04 +00:00
|
|
|
const auto small = image(SmallLevels);
|
2019-01-25 14:37:28 +00:00
|
|
|
const auto thumbnail = image(ThumbnailLevels);
|
|
|
|
const auto large = image(LargeLevels);
|
|
|
|
return data.match([&](const MTPDphoto &data) {
|
2018-01-17 16:21:01 +00:00
|
|
|
return photo(
|
2019-07-05 13:38:38 +00:00
|
|
|
data.vid().v,
|
|
|
|
data.vaccess_hash().v,
|
|
|
|
data.vfile_reference().v,
|
|
|
|
data.vdate().v,
|
|
|
|
data.vdc_id().v,
|
2019-03-10 12:55:24 +00:00
|
|
|
data.is_has_stickers(),
|
2020-05-25 14:16:04 +00:00
|
|
|
QByteArray(),
|
|
|
|
small,
|
2019-01-25 14:37:28 +00:00
|
|
|
thumbnail,
|
|
|
|
large);
|
|
|
|
}, [&](const MTPDphotoEmpty &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
return photo(data.vid().v);
|
2019-01-25 14:37:28 +00:00
|
|
|
});
|
2018-01-17 16:21:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
not_null<PhotoData*> Session::photo(
|
|
|
|
PhotoId id,
|
|
|
|
const uint64 &access,
|
2018-07-13 16:49:46 +00:00
|
|
|
const QByteArray &fileReference,
|
2018-01-17 16:21:01 +00:00
|
|
|
TimeId date,
|
2019-03-22 14:19:43 +00:00
|
|
|
int32 dc,
|
2019-03-10 12:55:24 +00:00
|
|
|
bool hasSticker,
|
2020-05-25 14:16:04 +00:00
|
|
|
const QByteArray &inlineThumbnailBytes,
|
|
|
|
const ImageWithLocation &small,
|
|
|
|
const ImageWithLocation &thumbnail,
|
|
|
|
const ImageWithLocation &large) {
|
2018-01-17 16:21:01 +00:00
|
|
|
const auto result = photo(id);
|
|
|
|
photoApplyFields(
|
|
|
|
result,
|
|
|
|
access,
|
2018-07-13 16:49:46 +00:00
|
|
|
fileReference,
|
2018-01-17 16:21:01 +00:00
|
|
|
date,
|
2019-03-22 14:19:43 +00:00
|
|
|
dc,
|
2019-03-10 12:55:24 +00:00
|
|
|
hasSticker,
|
2020-05-25 14:16:04 +00:00
|
|
|
inlineThumbnailBytes,
|
|
|
|
small,
|
2019-01-25 14:37:28 +00:00
|
|
|
thumbnail,
|
|
|
|
large);
|
2018-01-17 16:21:01 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::photoConvert(
|
|
|
|
not_null<PhotoData*> original,
|
|
|
|
const MTPPhoto &data) {
|
2019-01-25 14:37:28 +00:00
|
|
|
const auto id = data.match([](const auto &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
return data.vid().v;
|
2019-01-25 14:37:28 +00:00
|
|
|
});
|
2018-01-17 16:21:01 +00:00
|
|
|
if (original->id != id) {
|
|
|
|
auto i = _photos.find(id);
|
|
|
|
if (i == _photos.end()) {
|
|
|
|
const auto j = _photos.find(original->id);
|
|
|
|
Assert(j != _photos.end());
|
|
|
|
auto owned = std::move(j->second);
|
|
|
|
_photos.erase(j);
|
|
|
|
i = _photos.emplace(id, std::move(owned)).first;
|
|
|
|
}
|
|
|
|
|
|
|
|
original->id = id;
|
|
|
|
original->uploadingData = nullptr;
|
|
|
|
|
|
|
|
if (i->second.get() != original) {
|
|
|
|
photoApplyFields(i->second.get(), data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
photoApplyFields(original, data);
|
|
|
|
}
|
|
|
|
|
2018-03-04 20:04:13 +00:00
|
|
|
PhotoData *Session::photoFromWeb(
|
|
|
|
const MTPWebDocument &data,
|
2020-05-26 10:13:32 +00:00
|
|
|
const ImageLocation &thumbnailLocation) {
|
2020-05-25 14:16:04 +00:00
|
|
|
const auto large = Images::FromWebDocument(data);
|
|
|
|
if (!large.valid()) {
|
2018-03-04 20:04:13 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return photo(
|
|
|
|
rand_value<PhotoId>(),
|
|
|
|
uint64(0),
|
2018-07-13 16:49:46 +00:00
|
|
|
QByteArray(),
|
2019-07-10 17:28:33 +00:00
|
|
|
base::unixtime::now(),
|
2019-03-22 14:19:43 +00:00
|
|
|
0,
|
2019-03-10 12:55:24 +00:00
|
|
|
false,
|
2020-05-25 14:16:04 +00:00
|
|
|
QByteArray(),
|
2020-05-26 10:13:32 +00:00
|
|
|
ImageWithLocation{},
|
|
|
|
ImageWithLocation{ .location = thumbnailLocation },
|
2020-05-25 14:16:04 +00:00
|
|
|
ImageWithLocation{ .location = large });
|
2018-03-04 20:04:13 +00:00
|
|
|
}
|
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
void Session::photoApplyFields(
|
|
|
|
not_null<PhotoData*> photo,
|
|
|
|
const MTPPhoto &data) {
|
|
|
|
if (data.type() == mtpc_photo) {
|
|
|
|
photoApplyFields(photo, data.c_photo());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::photoApplyFields(
|
|
|
|
not_null<PhotoData*> photo,
|
|
|
|
const MTPDphoto &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto &sizes = data.vsizes().v;
|
2019-01-25 14:37:28 +00:00
|
|
|
const auto find = [&](const QByteArray &levels) {
|
|
|
|
const auto kInvalidIndex = int(levels.size());
|
|
|
|
const auto level = [&](const MTPPhotoSize &size) {
|
|
|
|
const auto letter = size.match([](const MTPDphotoSizeEmpty &) {
|
|
|
|
return char(0);
|
|
|
|
}, [](const auto &size) {
|
2019-07-05 13:38:38 +00:00
|
|
|
return size.vtype().v.isEmpty() ? char(0) : size.vtype().v[0];
|
2019-01-25 14:37:28 +00:00
|
|
|
});
|
|
|
|
const auto index = levels.indexOf(letter);
|
|
|
|
return (index >= 0) ? index : kInvalidIndex;
|
|
|
|
};
|
|
|
|
const auto result = ranges::max_element(
|
|
|
|
sizes,
|
|
|
|
std::greater<>(),
|
|
|
|
level);
|
|
|
|
return (level(*result) == kInvalidIndex) ? sizes.end() : result;
|
|
|
|
};
|
|
|
|
const auto image = [&](const QByteArray &levels) {
|
|
|
|
const auto i = find(levels);
|
2020-05-25 14:16:04 +00:00
|
|
|
return (i == sizes.end())
|
|
|
|
? ImageWithLocation()
|
|
|
|
: Images::FromPhotoSize(_session, data, *i);
|
2019-01-25 14:37:28 +00:00
|
|
|
};
|
|
|
|
const auto large = image(LargeLevels);
|
2020-05-25 14:16:04 +00:00
|
|
|
if (large.location.valid()) {
|
2018-01-17 16:21:01 +00:00
|
|
|
photoApplyFields(
|
|
|
|
photo,
|
2019-07-05 13:38:38 +00:00
|
|
|
data.vaccess_hash().v,
|
|
|
|
data.vfile_reference().v,
|
|
|
|
data.vdate().v,
|
|
|
|
data.vdc_id().v,
|
2019-03-10 12:55:24 +00:00
|
|
|
data.is_has_stickers(),
|
2020-05-25 14:16:04 +00:00
|
|
|
FindPhotoInlineThumbnail(data),
|
|
|
|
image(SmallLevels),
|
|
|
|
image(ThumbnailLevels),
|
2019-01-25 14:37:28 +00:00
|
|
|
large);
|
2018-01-17 16:21:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::photoApplyFields(
|
|
|
|
not_null<PhotoData*> photo,
|
|
|
|
const uint64 &access,
|
2018-07-13 16:49:46 +00:00
|
|
|
const QByteArray &fileReference,
|
2018-01-17 16:21:01 +00:00
|
|
|
TimeId date,
|
2019-03-22 14:19:43 +00:00
|
|
|
int32 dc,
|
2019-03-10 12:55:24 +00:00
|
|
|
bool hasSticker,
|
2020-05-25 14:16:04 +00:00
|
|
|
const QByteArray &inlineThumbnailBytes,
|
|
|
|
const ImageWithLocation &small,
|
|
|
|
const ImageWithLocation &thumbnail,
|
|
|
|
const ImageWithLocation &large) {
|
2018-01-17 16:21:01 +00:00
|
|
|
if (!date) {
|
|
|
|
return;
|
|
|
|
}
|
2019-03-22 14:19:43 +00:00
|
|
|
photo->setRemoteLocation(dc, access, fileReference);
|
2018-01-17 16:21:01 +00:00
|
|
|
photo->date = date;
|
2019-03-10 12:55:24 +00:00
|
|
|
photo->hasSticker = hasSticker;
|
2019-01-25 14:37:28 +00:00
|
|
|
photo->updateImages(
|
2020-05-25 14:16:04 +00:00
|
|
|
inlineThumbnailBytes,
|
|
|
|
small,
|
2019-01-25 14:37:28 +00:00
|
|
|
thumbnail,
|
|
|
|
large);
|
2018-01-17 16:21:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
not_null<DocumentData*> Session::document(DocumentId id) {
|
|
|
|
auto i = _documents.find(id);
|
|
|
|
if (i == _documents.cend()) {
|
2018-01-27 09:21:57 +00:00
|
|
|
i = _documents.emplace(
|
|
|
|
id,
|
2019-01-25 14:37:28 +00:00
|
|
|
std::make_unique<DocumentData>(this, id)).first;
|
2018-01-17 16:21:01 +00:00
|
|
|
}
|
|
|
|
return i->second.get();
|
|
|
|
}
|
|
|
|
|
2019-01-18 12:27:37 +00:00
|
|
|
not_null<DocumentData*> Session::processDocument(const MTPDocument &data) {
|
2020-04-16 12:37:26 +00:00
|
|
|
return data.match([&](const MTPDdocument &data) {
|
|
|
|
return processDocument(data);
|
|
|
|
}, [&](const MTPDdocumentEmpty &data) {
|
|
|
|
return document(data.vid().v);
|
|
|
|
});
|
2018-01-17 16:21:01 +00:00
|
|
|
}
|
|
|
|
|
2019-01-18 12:27:37 +00:00
|
|
|
not_null<DocumentData*> Session::processDocument(const MTPDdocument &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto result = document(data.vid().v);
|
2018-01-17 16:21:01 +00:00
|
|
|
documentApplyFields(result, data);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-01-18 12:27:37 +00:00
|
|
|
not_null<DocumentData*> Session::processDocument(
|
2018-01-17 16:21:01 +00:00
|
|
|
const MTPdocument &data,
|
2020-04-16 12:37:26 +00:00
|
|
|
const ImageWithLocation &thumbnail) {
|
|
|
|
return data.match([&](const MTPDdocument &data) {
|
2018-01-17 16:21:01 +00:00
|
|
|
return document(
|
2020-04-16 12:37:26 +00:00
|
|
|
data.vid().v,
|
|
|
|
data.vaccess_hash().v,
|
|
|
|
data.vfile_reference().v,
|
|
|
|
data.vdate().v,
|
|
|
|
data.vattributes().v,
|
|
|
|
qs(data.vmime_type()),
|
2020-04-08 15:09:29 +00:00
|
|
|
QByteArray(),
|
2020-04-16 12:37:26 +00:00
|
|
|
thumbnail,
|
2020-05-22 11:15:09 +00:00
|
|
|
ImageWithLocation(),
|
2020-04-16 12:37:26 +00:00
|
|
|
data.vdc_id().v,
|
|
|
|
data.vsize().v);
|
|
|
|
}, [&](const MTPDdocumentEmpty &data) {
|
|
|
|
return document(data.vid().v);
|
|
|
|
});
|
2018-01-17 16:21:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
not_null<DocumentData*> Session::document(
|
|
|
|
DocumentId id,
|
|
|
|
const uint64 &access,
|
2018-07-13 16:49:46 +00:00
|
|
|
const QByteArray &fileReference,
|
2018-01-17 16:21:01 +00:00
|
|
|
TimeId date,
|
|
|
|
const QVector<MTPDocumentAttribute> &attributes,
|
|
|
|
const QString &mime,
|
2020-04-08 15:09:29 +00:00
|
|
|
const QByteArray &inlineThumbnailBytes,
|
2020-04-16 12:37:26 +00:00
|
|
|
const ImageWithLocation &thumbnail,
|
2020-05-22 11:15:09 +00:00
|
|
|
const ImageWithLocation &videoThumbnail,
|
2018-01-17 16:21:01 +00:00
|
|
|
int32 dc,
|
2020-04-15 14:06:34 +00:00
|
|
|
int32 size) {
|
2018-01-17 16:21:01 +00:00
|
|
|
const auto result = document(id);
|
|
|
|
documentApplyFields(
|
|
|
|
result,
|
|
|
|
access,
|
2018-07-13 16:49:46 +00:00
|
|
|
fileReference,
|
2018-01-17 16:21:01 +00:00
|
|
|
date,
|
|
|
|
attributes,
|
|
|
|
mime,
|
2020-04-08 15:09:29 +00:00
|
|
|
inlineThumbnailBytes,
|
2020-04-16 12:37:26 +00:00
|
|
|
thumbnail,
|
2020-05-22 11:15:09 +00:00
|
|
|
videoThumbnail,
|
2018-01-17 16:21:01 +00:00
|
|
|
dc,
|
2020-04-15 14:06:34 +00:00
|
|
|
size);
|
2018-01-17 16:21:01 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::documentConvert(
|
|
|
|
not_null<DocumentData*> original,
|
|
|
|
const MTPDocument &data) {
|
|
|
|
const auto id = [&] {
|
|
|
|
switch (data.type()) {
|
2019-07-05 13:38:38 +00:00
|
|
|
case mtpc_document: return data.c_document().vid().v;
|
|
|
|
case mtpc_documentEmpty: return data.c_documentEmpty().vid().v;
|
2018-01-17 16:21:01 +00:00
|
|
|
}
|
|
|
|
Unexpected("Type in Session::documentConvert().");
|
|
|
|
}();
|
|
|
|
const auto oldKey = original->mediaKey();
|
2018-08-27 11:35:58 +00:00
|
|
|
const auto oldCacheKey = original->cacheKey();
|
2020-03-27 11:40:50 +00:00
|
|
|
const auto oldGoodKey = original->goodThumbnailCacheKey();
|
2018-01-17 16:21:01 +00:00
|
|
|
const auto idChanged = (original->id != id);
|
|
|
|
const auto sentSticker = idChanged && (original->sticker() != nullptr);
|
|
|
|
if (idChanged) {
|
|
|
|
auto i = _documents.find(id);
|
|
|
|
if (i == _documents.end()) {
|
|
|
|
const auto j = _documents.find(original->id);
|
|
|
|
Assert(j != _documents.end());
|
|
|
|
auto owned = std::move(j->second);
|
|
|
|
_documents.erase(j);
|
|
|
|
i = _documents.emplace(id, std::move(owned)).first;
|
|
|
|
}
|
|
|
|
|
|
|
|
original->id = id;
|
|
|
|
original->status = FileReady;
|
|
|
|
original->uploadingData = nullptr;
|
|
|
|
|
|
|
|
if (i->second.get() != original) {
|
|
|
|
documentApplyFields(i->second.get(), data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
documentApplyFields(original, data);
|
|
|
|
if (idChanged) {
|
2018-08-27 11:35:58 +00:00
|
|
|
cache().moveIfEmpty(oldCacheKey, original->cacheKey());
|
2020-03-27 11:40:50 +00:00
|
|
|
cache().moveIfEmpty(oldGoodKey, original->goodThumbnailCacheKey());
|
2018-01-17 16:21:01 +00:00
|
|
|
if (savedGifs().indexOf(original) >= 0) {
|
|
|
|
Local::writeSavedGifs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-04 20:04:13 +00:00
|
|
|
DocumentData *Session::documentFromWeb(
|
|
|
|
const MTPWebDocument &data,
|
2020-05-22 15:23:19 +00:00
|
|
|
const ImageLocation &thumbnailLocation,
|
|
|
|
const ImageLocation &videoThumbnailLocation) {
|
2020-04-16 12:37:26 +00:00
|
|
|
return data.match([&](const auto &data) {
|
2020-05-22 15:23:19 +00:00
|
|
|
return documentFromWeb(
|
|
|
|
data,
|
|
|
|
thumbnailLocation,
|
|
|
|
videoThumbnailLocation);
|
2020-04-16 12:37:26 +00:00
|
|
|
});
|
2018-03-04 20:04:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DocumentData *Session::documentFromWeb(
|
|
|
|
const MTPDwebDocument &data,
|
2020-05-22 15:23:19 +00:00
|
|
|
const ImageLocation &thumbnailLocation,
|
|
|
|
const ImageLocation &videoThumbnailLocation) {
|
2018-03-04 20:04:13 +00:00
|
|
|
const auto result = document(
|
|
|
|
rand_value<DocumentId>(),
|
|
|
|
uint64(0),
|
2018-07-13 16:49:46 +00:00
|
|
|
QByteArray(),
|
2019-07-10 17:28:33 +00:00
|
|
|
base::unixtime::now(),
|
2019-07-05 13:38:38 +00:00
|
|
|
data.vattributes().v,
|
|
|
|
data.vmime_type().v,
|
2020-04-08 15:09:29 +00:00
|
|
|
QByteArray(),
|
2020-04-16 12:37:26 +00:00
|
|
|
ImageWithLocation{ .location = thumbnailLocation },
|
2020-05-22 15:23:19 +00:00
|
|
|
ImageWithLocation{ .location = videoThumbnailLocation },
|
2018-03-04 20:04:13 +00:00
|
|
|
MTP::maindc(),
|
2020-04-15 14:06:34 +00:00
|
|
|
int32(0)); // data.vsize().v
|
2018-03-04 20:04:13 +00:00
|
|
|
result->setWebLocation(WebFileLocation(
|
2019-07-05 13:38:38 +00:00
|
|
|
data.vurl().v,
|
|
|
|
data.vaccess_hash().v));
|
2018-03-04 20:04:13 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
DocumentData *Session::documentFromWeb(
|
|
|
|
const MTPDwebDocumentNoProxy &data,
|
2020-05-22 15:23:19 +00:00
|
|
|
const ImageLocation &thumbnailLocation,
|
|
|
|
const ImageLocation &videoThumbnailLocation) {
|
2018-03-04 20:04:13 +00:00
|
|
|
const auto result = document(
|
|
|
|
rand_value<DocumentId>(),
|
|
|
|
uint64(0),
|
2018-07-13 16:49:46 +00:00
|
|
|
QByteArray(),
|
2019-07-10 17:28:33 +00:00
|
|
|
base::unixtime::now(),
|
2019-07-05 13:38:38 +00:00
|
|
|
data.vattributes().v,
|
|
|
|
data.vmime_type().v,
|
2020-04-08 15:09:29 +00:00
|
|
|
QByteArray(),
|
2020-04-16 12:37:26 +00:00
|
|
|
ImageWithLocation{ .location = thumbnailLocation },
|
2020-05-22 15:23:19 +00:00
|
|
|
ImageWithLocation{ .location = videoThumbnailLocation },
|
2018-03-04 20:04:13 +00:00
|
|
|
MTP::maindc(),
|
2020-04-15 14:06:34 +00:00
|
|
|
int32(0)); // data.vsize().v
|
2019-07-05 13:38:38 +00:00
|
|
|
result->setContentUrl(qs(data.vurl()));
|
2018-03-04 20:04:13 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
void Session::documentApplyFields(
|
|
|
|
not_null<DocumentData*> document,
|
|
|
|
const MTPDocument &data) {
|
|
|
|
if (data.type() == mtpc_document) {
|
|
|
|
documentApplyFields(document, data.c_document());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::documentApplyFields(
|
|
|
|
not_null<DocumentData*> document,
|
|
|
|
const MTPDdocument &data) {
|
2020-04-08 15:09:29 +00:00
|
|
|
const auto inlineThumbnailBytes = FindDocumentInlineThumbnail(data);
|
2019-03-22 14:19:43 +00:00
|
|
|
const auto thumbnailSize = FindDocumentThumbnail(data);
|
2020-05-22 11:15:09 +00:00
|
|
|
const auto videoThumbnailSize = FindDocumentVideoThumbnail(data);
|
2020-04-16 12:37:26 +00:00
|
|
|
const auto prepared = Images::FromPhotoSize(
|
|
|
|
_session,
|
|
|
|
data,
|
|
|
|
thumbnailSize);
|
2020-05-22 11:15:09 +00:00
|
|
|
const auto videoThumbnail = videoThumbnailSize
|
|
|
|
? Images::FromVideoSize(_session, data, *videoThumbnailSize)
|
|
|
|
: ImageWithLocation();
|
2018-01-17 16:21:01 +00:00
|
|
|
documentApplyFields(
|
|
|
|
document,
|
2019-07-05 13:38:38 +00:00
|
|
|
data.vaccess_hash().v,
|
|
|
|
data.vfile_reference().v,
|
|
|
|
data.vdate().v,
|
|
|
|
data.vattributes().v,
|
|
|
|
qs(data.vmime_type()),
|
2020-04-08 15:09:29 +00:00
|
|
|
inlineThumbnailBytes,
|
2020-04-16 12:37:26 +00:00
|
|
|
prepared,
|
2020-05-22 11:15:09 +00:00
|
|
|
videoThumbnail,
|
2019-07-05 13:38:38 +00:00
|
|
|
data.vdc_id().v,
|
2020-04-15 14:06:34 +00:00
|
|
|
data.vsize().v);
|
2018-01-17 16:21:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Session::documentApplyFields(
|
|
|
|
not_null<DocumentData*> document,
|
|
|
|
const uint64 &access,
|
2018-07-13 16:49:46 +00:00
|
|
|
const QByteArray &fileReference,
|
2018-01-17 16:21:01 +00:00
|
|
|
TimeId date,
|
|
|
|
const QVector<MTPDocumentAttribute> &attributes,
|
|
|
|
const QString &mime,
|
2020-04-08 15:09:29 +00:00
|
|
|
const QByteArray &inlineThumbnailBytes,
|
2020-04-16 12:37:26 +00:00
|
|
|
const ImageWithLocation &thumbnail,
|
2020-05-22 11:15:09 +00:00
|
|
|
const ImageWithLocation &videoThumbnail,
|
2018-01-17 16:21:01 +00:00
|
|
|
int32 dc,
|
2020-04-15 14:06:34 +00:00
|
|
|
int32 size) {
|
2018-01-17 16:21:01 +00:00
|
|
|
if (!date) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
document->date = date;
|
|
|
|
document->setMimeString(mime);
|
2020-05-22 11:15:09 +00:00
|
|
|
document->updateThumbnails(
|
|
|
|
inlineThumbnailBytes,
|
|
|
|
thumbnail,
|
|
|
|
videoThumbnail);
|
2018-01-17 16:21:01 +00:00
|
|
|
document->size = size;
|
2019-05-27 12:57:26 +00:00
|
|
|
document->setattributes(attributes);
|
2019-05-31 16:45:03 +00:00
|
|
|
|
|
|
|
// Uses 'type' that is computed from attributes.
|
|
|
|
document->recountIsImage();
|
|
|
|
if (dc != 0 && access != 0) {
|
|
|
|
document->setRemoteLocation(dc, access, fileReference);
|
|
|
|
}
|
2018-01-17 16:21:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
not_null<WebPageData*> Session::webpage(WebPageId id) {
|
|
|
|
auto i = _webpages.find(id);
|
|
|
|
if (i == _webpages.cend()) {
|
|
|
|
i = _webpages.emplace(id, std::make_unique<WebPageData>(id)).first;
|
|
|
|
}
|
|
|
|
return i->second.get();
|
|
|
|
}
|
|
|
|
|
2019-01-18 12:27:37 +00:00
|
|
|
not_null<WebPageData*> Session::processWebpage(const MTPWebPage &data) {
|
2018-01-17 16:21:01 +00:00
|
|
|
switch (data.type()) {
|
|
|
|
case mtpc_webPage:
|
2019-01-18 12:27:37 +00:00
|
|
|
return processWebpage(data.c_webPage());
|
2018-01-17 16:21:01 +00:00
|
|
|
case mtpc_webPageEmpty: {
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto result = webpage(data.c_webPageEmpty().vid().v);
|
2018-01-17 16:21:01 +00:00
|
|
|
if (result->pendingTill > 0) {
|
|
|
|
result->pendingTill = -1; // failed
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
} break;
|
|
|
|
case mtpc_webPagePending:
|
2019-01-18 12:27:37 +00:00
|
|
|
return processWebpage(data.c_webPagePending());
|
2018-01-17 16:21:01 +00:00
|
|
|
case mtpc_webPageNotModified:
|
|
|
|
LOG(("API Error: "
|
|
|
|
"webPageNotModified is unexpected in Session::webpage()."));
|
|
|
|
return webpage(0);
|
|
|
|
}
|
|
|
|
Unexpected("Type in Session::webpage().");
|
|
|
|
}
|
|
|
|
|
2019-01-18 12:27:37 +00:00
|
|
|
not_null<WebPageData*> Session::processWebpage(const MTPDwebPage &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto result = webpage(data.vid().v);
|
2018-01-17 16:21:01 +00:00
|
|
|
webpageApplyFields(result, data);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-01-18 12:27:37 +00:00
|
|
|
not_null<WebPageData*> Session::processWebpage(const MTPDwebPagePending &data) {
|
2018-01-17 16:21:01 +00:00
|
|
|
constexpr auto kDefaultPendingTimeout = 60;
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto result = webpage(data.vid().v);
|
2018-01-17 16:21:01 +00:00
|
|
|
webpageApplyFields(
|
|
|
|
result,
|
2018-10-31 10:11:01 +00:00
|
|
|
WebPageType::Article,
|
2018-01-17 16:21:01 +00:00
|
|
|
QString(),
|
|
|
|
QString(),
|
|
|
|
QString(),
|
|
|
|
QString(),
|
|
|
|
TextWithEntities(),
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2018-10-24 11:52:31 +00:00
|
|
|
WebPageCollage(),
|
2018-01-17 16:21:01 +00:00
|
|
|
0,
|
|
|
|
QString(),
|
2019-07-05 13:38:38 +00:00
|
|
|
data.vdate().v
|
|
|
|
? data.vdate().v
|
2019-07-10 17:28:33 +00:00
|
|
|
: (base::unixtime::now() + kDefaultPendingTimeout));
|
2018-01-17 16:21:01 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
not_null<WebPageData*> Session::webpage(
|
|
|
|
WebPageId id,
|
|
|
|
const QString &siteName,
|
|
|
|
const TextWithEntities &content) {
|
|
|
|
return webpage(
|
|
|
|
id,
|
2018-10-31 10:11:01 +00:00
|
|
|
WebPageType::Article,
|
2018-01-17 16:21:01 +00:00
|
|
|
QString(),
|
|
|
|
QString(),
|
|
|
|
siteName,
|
|
|
|
QString(),
|
|
|
|
content,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2018-10-24 11:52:31 +00:00
|
|
|
WebPageCollage(),
|
2018-01-17 16:21:01 +00:00
|
|
|
0,
|
|
|
|
QString(),
|
|
|
|
TimeId(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
not_null<WebPageData*> Session::webpage(
|
|
|
|
WebPageId id,
|
2018-10-31 10:11:01 +00:00
|
|
|
WebPageType type,
|
2018-01-17 16:21:01 +00:00
|
|
|
const QString &url,
|
|
|
|
const QString &displayUrl,
|
|
|
|
const QString &siteName,
|
|
|
|
const QString &title,
|
|
|
|
const TextWithEntities &description,
|
|
|
|
PhotoData *photo,
|
|
|
|
DocumentData *document,
|
2018-10-24 11:52:31 +00:00
|
|
|
WebPageCollage &&collage,
|
2018-01-17 16:21:01 +00:00
|
|
|
int duration,
|
|
|
|
const QString &author,
|
|
|
|
TimeId pendingTill) {
|
|
|
|
const auto result = webpage(id);
|
|
|
|
webpageApplyFields(
|
|
|
|
result,
|
|
|
|
type,
|
|
|
|
url,
|
|
|
|
displayUrl,
|
|
|
|
siteName,
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
photo,
|
|
|
|
document,
|
2018-10-24 11:52:31 +00:00
|
|
|
std::move(collage),
|
2018-01-17 16:21:01 +00:00
|
|
|
duration,
|
|
|
|
author,
|
|
|
|
pendingTill);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::webpageApplyFields(
|
|
|
|
not_null<WebPageData*> page,
|
|
|
|
const MTPDwebPage &data) {
|
|
|
|
auto description = TextWithEntities {
|
2019-07-05 13:38:38 +00:00
|
|
|
TextUtilities::Clean(qs(data.vdescription().value_or_empty()))
|
2018-01-17 16:21:01 +00:00
|
|
|
};
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto siteName = qs(data.vsite_name().value_or_empty());
|
2018-01-17 16:21:01 +00:00
|
|
|
auto parseFlags = TextParseLinks | TextParseMultiline | TextParseRichText;
|
|
|
|
if (siteName == qstr("Twitter") || siteName == qstr("Instagram")) {
|
|
|
|
parseFlags |= TextParseHashtags | TextParseMentions;
|
|
|
|
}
|
|
|
|
TextUtilities::ParseEntities(description, parseFlags);
|
|
|
|
const auto pendingTill = TimeId(0);
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto photo = data.vphoto();
|
|
|
|
const auto document = data.vdocument();
|
2019-12-29 12:28:27 +00:00
|
|
|
const auto lookupInAttribute = [&](
|
|
|
|
const MTPDwebPageAttributeTheme &data) -> DocumentData* {
|
2019-09-09 11:56:05 +00:00
|
|
|
if (const auto documents = data.vdocuments()) {
|
|
|
|
for (const auto &document : documents->v) {
|
|
|
|
const auto processed = processDocument(document);
|
|
|
|
if (processed->isTheme()) {
|
|
|
|
return processed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
};
|
2019-12-29 12:28:27 +00:00
|
|
|
const auto lookupThemeDocument = [&]() -> DocumentData* {
|
|
|
|
if (const auto attributes = data.vattributes()) {
|
|
|
|
for (const auto &attribute : attributes->v) {
|
|
|
|
const auto result = attribute.match([&](
|
|
|
|
const MTPDwebPageAttributeTheme &data) {
|
|
|
|
return lookupInAttribute(data);
|
|
|
|
});
|
|
|
|
if (result) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
};
|
2018-01-17 16:21:01 +00:00
|
|
|
webpageApplyFields(
|
|
|
|
page,
|
2018-10-31 10:11:01 +00:00
|
|
|
ParseWebPageType(data),
|
2019-07-05 13:38:38 +00:00
|
|
|
qs(data.vurl()),
|
|
|
|
qs(data.vdisplay_url()),
|
2018-01-17 16:21:01 +00:00
|
|
|
siteName,
|
2019-07-05 13:38:38 +00:00
|
|
|
qs(data.vtitle().value_or_empty()),
|
2018-01-17 16:21:01 +00:00
|
|
|
description,
|
2019-07-05 13:38:38 +00:00
|
|
|
photo ? processPhoto(*photo).get() : nullptr,
|
2019-09-09 11:56:05 +00:00
|
|
|
document ? processDocument(*document).get() : lookupThemeDocument(),
|
2018-10-24 11:52:31 +00:00
|
|
|
WebPageCollage(data),
|
2019-07-05 13:38:38 +00:00
|
|
|
data.vduration().value_or_empty(),
|
|
|
|
qs(data.vauthor().value_or_empty()),
|
2018-01-17 16:21:01 +00:00
|
|
|
pendingTill);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::webpageApplyFields(
|
|
|
|
not_null<WebPageData*> page,
|
2018-10-31 10:11:01 +00:00
|
|
|
WebPageType type,
|
2018-01-17 16:21:01 +00:00
|
|
|
const QString &url,
|
|
|
|
const QString &displayUrl,
|
|
|
|
const QString &siteName,
|
|
|
|
const QString &title,
|
|
|
|
const TextWithEntities &description,
|
|
|
|
PhotoData *photo,
|
|
|
|
DocumentData *document,
|
2018-10-24 11:52:31 +00:00
|
|
|
WebPageCollage &&collage,
|
2018-01-17 16:21:01 +00:00
|
|
|
int duration,
|
|
|
|
const QString &author,
|
|
|
|
TimeId pendingTill) {
|
2018-07-25 16:01:09 +00:00
|
|
|
const auto requestPending = (!page->pendingTill && pendingTill > 0);
|
2018-01-17 16:21:01 +00:00
|
|
|
const auto changed = page->applyChanges(
|
|
|
|
type,
|
|
|
|
url,
|
|
|
|
displayUrl,
|
|
|
|
siteName,
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
photo,
|
|
|
|
document,
|
2018-10-24 11:52:31 +00:00
|
|
|
std::move(collage),
|
2018-01-17 16:21:01 +00:00
|
|
|
duration,
|
|
|
|
author,
|
|
|
|
pendingTill);
|
2018-07-25 16:01:09 +00:00
|
|
|
if (requestPending) {
|
|
|
|
_session->api().requestWebPageDelayed(page);
|
|
|
|
}
|
2018-01-17 16:21:01 +00:00
|
|
|
if (changed) {
|
|
|
|
notifyWebPageUpdateDelayed(page);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
not_null<GameData*> Session::game(GameId id) {
|
|
|
|
auto i = _games.find(id);
|
|
|
|
if (i == _games.cend()) {
|
|
|
|
i = _games.emplace(id, std::make_unique<GameData>(id)).first;
|
|
|
|
}
|
|
|
|
return i->second.get();
|
|
|
|
}
|
|
|
|
|
2019-01-18 12:27:37 +00:00
|
|
|
not_null<GameData*> Session::processGame(const MTPDgame &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto result = game(data.vid().v);
|
2018-01-17 16:21:01 +00:00
|
|
|
gameApplyFields(result, data);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
not_null<GameData*> Session::game(
|
|
|
|
GameId id,
|
|
|
|
const uint64 &accessHash,
|
|
|
|
const QString &shortName,
|
|
|
|
const QString &title,
|
|
|
|
const QString &description,
|
|
|
|
PhotoData *photo,
|
|
|
|
DocumentData *document) {
|
|
|
|
const auto result = game(id);
|
|
|
|
gameApplyFields(
|
|
|
|
result,
|
|
|
|
accessHash,
|
|
|
|
shortName,
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
photo,
|
|
|
|
document);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::gameConvert(
|
|
|
|
not_null<GameData*> original,
|
|
|
|
const MTPGame &data) {
|
|
|
|
Expects(data.type() == mtpc_game);
|
|
|
|
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto id = data.c_game().vid().v;
|
2018-01-17 16:21:01 +00:00
|
|
|
if (original->id != id) {
|
|
|
|
auto i = _games.find(id);
|
|
|
|
if (i == _games.end()) {
|
|
|
|
const auto j = _games.find(original->id);
|
|
|
|
Assert(j != _games.end());
|
|
|
|
auto owned = std::move(j->second);
|
|
|
|
_games.erase(j);
|
|
|
|
i = _games.emplace(id, std::move(owned)).first;
|
|
|
|
}
|
|
|
|
|
|
|
|
original->id = id;
|
|
|
|
original->accessHash = 0;
|
|
|
|
|
|
|
|
if (i->second.get() != original) {
|
|
|
|
gameApplyFields(i->second.get(), data.c_game());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gameApplyFields(original, data.c_game());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::gameApplyFields(
|
|
|
|
not_null<GameData*> game,
|
|
|
|
const MTPDgame &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto document = data.vdocument();
|
2018-01-17 16:21:01 +00:00
|
|
|
gameApplyFields(
|
|
|
|
game,
|
2019-07-05 13:38:38 +00:00
|
|
|
data.vaccess_hash().v,
|
|
|
|
qs(data.vshort_name()),
|
|
|
|
qs(data.vtitle()),
|
|
|
|
qs(data.vdescription()),
|
|
|
|
processPhoto(data.vphoto()),
|
|
|
|
document ? processDocument(*document).get() : nullptr);
|
2018-01-17 16:21:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Session::gameApplyFields(
|
|
|
|
not_null<GameData*> game,
|
|
|
|
const uint64 &accessHash,
|
|
|
|
const QString &shortName,
|
|
|
|
const QString &title,
|
|
|
|
const QString &description,
|
|
|
|
PhotoData *photo,
|
|
|
|
DocumentData *document) {
|
2018-04-07 07:41:48 +00:00
|
|
|
if (game->accessHash) {
|
2018-01-17 16:21:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
game->accessHash = accessHash;
|
|
|
|
game->shortName = TextUtilities::Clean(shortName);
|
|
|
|
game->title = TextUtilities::SingleLine(title);
|
|
|
|
game->description = TextUtilities::Clean(description);
|
|
|
|
game->photo = photo;
|
|
|
|
game->document = document;
|
|
|
|
notifyGameUpdateDelayed(game);
|
|
|
|
}
|
|
|
|
|
2018-12-18 05:43:11 +00:00
|
|
|
not_null<PollData*> Session::poll(PollId id) {
|
|
|
|
auto i = _polls.find(id);
|
|
|
|
if (i == _polls.cend()) {
|
2020-01-09 17:24:54 +00:00
|
|
|
i = _polls.emplace(id, std::make_unique<PollData>(this, id)).first;
|
2018-12-18 05:43:11 +00:00
|
|
|
}
|
|
|
|
return i->second.get();
|
|
|
|
}
|
|
|
|
|
2019-01-18 12:27:37 +00:00
|
|
|
not_null<PollData*> Session::processPoll(const MTPPoll &data) {
|
2018-12-18 05:43:11 +00:00
|
|
|
return data.match([&](const MTPDpoll &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto id = data.vid().v;
|
2018-12-18 05:43:11 +00:00
|
|
|
const auto result = poll(id);
|
|
|
|
const auto changed = result->applyChanges(data);
|
|
|
|
if (changed) {
|
|
|
|
notifyPollUpdateDelayed(result);
|
|
|
|
}
|
2020-04-07 12:10:34 +00:00
|
|
|
if (result->closeDate > 0 && !result->closed()) {
|
|
|
|
_pollsClosings.emplace(result->closeDate, result);
|
|
|
|
checkPollsClosings();
|
|
|
|
}
|
2018-12-18 05:43:11 +00:00
|
|
|
return result;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-01-18 12:27:37 +00:00
|
|
|
not_null<PollData*> Session::processPoll(const MTPDmessageMediaPoll &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto result = processPoll(data.vpoll());
|
|
|
|
const auto changed = result->applyResults(data.vresults());
|
2018-12-18 05:43:11 +00:00
|
|
|
if (changed) {
|
2018-12-25 14:17:02 +00:00
|
|
|
notifyPollUpdateDelayed(result);
|
2018-12-18 05:43:11 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-04-07 12:10:34 +00:00
|
|
|
void Session::checkPollsClosings() {
|
|
|
|
const auto now = base::unixtime::now();
|
|
|
|
auto closest = 0;
|
|
|
|
for (auto i = _pollsClosings.begin(); i != _pollsClosings.end();) {
|
|
|
|
if (i->first <= now) {
|
|
|
|
if (i->second->closeByTimer()) {
|
|
|
|
notifyPollUpdateDelayed(i->second);
|
|
|
|
}
|
|
|
|
i = _pollsClosings.erase(i);
|
|
|
|
} else {
|
|
|
|
if (!closest) {
|
|
|
|
closest = i->first;
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (closest) {
|
|
|
|
_pollsClosingTimer.callOnce((closest - now) * crl::time(1000));
|
|
|
|
} else {
|
|
|
|
_pollsClosingTimer.cancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-13 08:03:34 +00:00
|
|
|
void Session::applyUpdate(const MTPDupdateMessagePoll &update) {
|
2018-12-18 13:56:38 +00:00
|
|
|
const auto updated = [&] {
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto poll = update.vpoll();
|
|
|
|
const auto i = _polls.find(update.vpoll_id().v);
|
2018-12-18 13:56:38 +00:00
|
|
|
return (i == end(_polls))
|
|
|
|
? nullptr
|
2019-07-05 13:38:38 +00:00
|
|
|
: poll
|
|
|
|
? processPoll(*poll).get()
|
2018-12-18 13:56:38 +00:00
|
|
|
: i->second.get();
|
2018-12-18 05:43:11 +00:00
|
|
|
}();
|
2019-07-05 13:38:38 +00:00
|
|
|
if (updated && updated->applyResults(update.vresults())) {
|
2018-12-25 14:17:02 +00:00
|
|
|
notifyPollUpdateDelayed(updated);
|
2018-12-18 05:43:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-13 08:03:34 +00:00
|
|
|
void Session::applyUpdate(const MTPDupdateChatParticipants &update) {
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto chatId = update.vparticipants().match([](const auto &update) {
|
|
|
|
return update.vchat_id().v;
|
2019-01-13 08:03:34 +00:00
|
|
|
});
|
|
|
|
if (const auto chat = chatLoaded(chatId)) {
|
|
|
|
ApplyChatUpdate(chat, update);
|
|
|
|
for (const auto user : chat->participants) {
|
2019-07-18 08:51:11 +00:00
|
|
|
if (user->isBot() && !user->botInfo->inited) {
|
2019-01-13 08:03:34 +00:00
|
|
|
_session->api().requestFullPeer(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::applyUpdate(const MTPDupdateChatParticipantAdd &update) {
|
2019-07-05 13:38:38 +00:00
|
|
|
if (const auto chat = chatLoaded(update.vchat_id().v)) {
|
2019-01-13 08:03:34 +00:00
|
|
|
ApplyChatUpdate(chat, update);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::applyUpdate(const MTPDupdateChatParticipantDelete &update) {
|
2019-07-05 13:38:38 +00:00
|
|
|
if (const auto chat = chatLoaded(update.vchat_id().v)) {
|
2019-01-13 08:03:34 +00:00
|
|
|
ApplyChatUpdate(chat, update);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::applyUpdate(const MTPDupdateChatParticipantAdmin &update) {
|
2019-07-05 13:38:38 +00:00
|
|
|
if (const auto chat = chatLoaded(update.vchat_id().v)) {
|
2019-01-13 08:03:34 +00:00
|
|
|
ApplyChatUpdate(chat, update);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::applyUpdate(const MTPDupdateChatDefaultBannedRights &update) {
|
2019-07-05 13:38:38 +00:00
|
|
|
if (const auto peer = peerLoaded(peerFromMTP(update.vpeer()))) {
|
2019-01-13 08:03:34 +00:00
|
|
|
if (const auto chat = peer->asChat()) {
|
|
|
|
ApplyChatUpdate(chat, update);
|
|
|
|
} else if (const auto channel = peer->asChannel()) {
|
|
|
|
ApplyChannelUpdate(channel, update);
|
|
|
|
} else {
|
|
|
|
LOG(("API Error: "
|
|
|
|
"User received in updateChatDefaultBannedRights."));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-21 12:27:46 +00:00
|
|
|
not_null<LocationThumbnail*> Session::location(const LocationPoint &point) {
|
|
|
|
const auto i = _locations.find(point);
|
|
|
|
return (i != _locations.cend())
|
|
|
|
? i->second.get()
|
|
|
|
: _locations.emplace(
|
|
|
|
point,
|
|
|
|
std::make_unique<LocationThumbnail>(point)).first->second.get();
|
2018-10-11 15:54:57 +00:00
|
|
|
}
|
|
|
|
|
2018-01-21 19:52:44 +00:00
|
|
|
void Session::registerPhotoItem(
|
2018-01-17 16:21:01 +00:00
|
|
|
not_null<const PhotoData*> photo,
|
2018-01-21 19:52:44 +00:00
|
|
|
not_null<HistoryItem*> item) {
|
|
|
|
_photoItems[photo].insert(item);
|
2018-01-17 16:21:01 +00:00
|
|
|
}
|
|
|
|
|
2018-01-21 19:52:44 +00:00
|
|
|
void Session::unregisterPhotoItem(
|
2018-01-17 16:21:01 +00:00
|
|
|
not_null<const PhotoData*> photo,
|
2018-01-21 19:52:44 +00:00
|
|
|
not_null<HistoryItem*> item) {
|
|
|
|
const auto i = _photoItems.find(photo);
|
|
|
|
if (i != _photoItems.end()) {
|
2018-01-17 16:21:01 +00:00
|
|
|
auto &items = i->second;
|
2018-01-21 19:52:44 +00:00
|
|
|
if (items.remove(item) && items.empty()) {
|
|
|
|
_photoItems.erase(i);
|
2018-01-17 16:21:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::registerDocumentItem(
|
|
|
|
not_null<const DocumentData*> document,
|
|
|
|
not_null<HistoryItem*> item) {
|
|
|
|
_documentItems[document].insert(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::unregisterDocumentItem(
|
|
|
|
not_null<const DocumentData*> document,
|
|
|
|
not_null<HistoryItem*> item) {
|
|
|
|
const auto i = _documentItems.find(document);
|
|
|
|
if (i != _documentItems.end()) {
|
|
|
|
auto &items = i->second;
|
|
|
|
if (items.remove(item) && items.empty()) {
|
|
|
|
_documentItems.erase(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::registerWebPageView(
|
|
|
|
not_null<const WebPageData*> page,
|
2018-01-17 18:20:55 +00:00
|
|
|
not_null<ViewElement*> view) {
|
2018-01-17 16:21:01 +00:00
|
|
|
_webpageViews[page].insert(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::unregisterWebPageView(
|
|
|
|
not_null<const WebPageData*> page,
|
2018-01-17 18:20:55 +00:00
|
|
|
not_null<ViewElement*> view) {
|
2018-01-17 16:21:01 +00:00
|
|
|
const auto i = _webpageViews.find(page);
|
|
|
|
if (i != _webpageViews.end()) {
|
|
|
|
auto &items = i->second;
|
|
|
|
if (items.remove(view) && items.empty()) {
|
|
|
|
_webpageViews.erase(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::registerWebPageItem(
|
|
|
|
not_null<const WebPageData*> page,
|
|
|
|
not_null<HistoryItem*> item) {
|
|
|
|
_webpageItems[page].insert(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::unregisterWebPageItem(
|
|
|
|
not_null<const WebPageData*> page,
|
|
|
|
not_null<HistoryItem*> item) {
|
|
|
|
const auto i = _webpageItems.find(page);
|
|
|
|
if (i != _webpageItems.end()) {
|
|
|
|
auto &items = i->second;
|
|
|
|
if (items.remove(item) && items.empty()) {
|
|
|
|
_webpageItems.erase(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::registerGameView(
|
|
|
|
not_null<const GameData*> game,
|
2018-01-17 18:20:55 +00:00
|
|
|
not_null<ViewElement*> view) {
|
2018-01-17 16:21:01 +00:00
|
|
|
_gameViews[game].insert(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::unregisterGameView(
|
|
|
|
not_null<const GameData*> game,
|
2018-01-17 18:20:55 +00:00
|
|
|
not_null<ViewElement*> view) {
|
2018-01-17 16:21:01 +00:00
|
|
|
const auto i = _gameViews.find(game);
|
|
|
|
if (i != _gameViews.end()) {
|
|
|
|
auto &items = i->second;
|
|
|
|
if (items.remove(view) && items.empty()) {
|
|
|
|
_gameViews.erase(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-18 05:43:11 +00:00
|
|
|
void Session::registerPollView(
|
|
|
|
not_null<const PollData*> poll,
|
|
|
|
not_null<ViewElement*> view) {
|
|
|
|
_pollViews[poll].insert(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::unregisterPollView(
|
|
|
|
not_null<const PollData*> poll,
|
|
|
|
not_null<ViewElement*> view) {
|
|
|
|
const auto i = _pollViews.find(poll);
|
|
|
|
if (i != _pollViews.end()) {
|
|
|
|
auto &items = i->second;
|
|
|
|
if (items.remove(view) && items.empty()) {
|
|
|
|
_pollViews.erase(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
void Session::registerContactView(
|
|
|
|
UserId contactId,
|
2018-01-17 18:20:55 +00:00
|
|
|
not_null<ViewElement*> view) {
|
2018-01-17 16:21:01 +00:00
|
|
|
if (!contactId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_contactViews[contactId].insert(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::unregisterContactView(
|
|
|
|
UserId contactId,
|
2018-01-17 18:20:55 +00:00
|
|
|
not_null<ViewElement*> view) {
|
2018-01-17 16:21:01 +00:00
|
|
|
if (!contactId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto i = _contactViews.find(contactId);
|
|
|
|
if (i != _contactViews.end()) {
|
|
|
|
auto &items = i->second;
|
|
|
|
if (items.remove(view) && items.empty()) {
|
|
|
|
_contactViews.erase(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::registerContactItem(
|
|
|
|
UserId contactId,
|
|
|
|
not_null<HistoryItem*> item) {
|
|
|
|
if (!contactId) {
|
|
|
|
return;
|
|
|
|
}
|
2019-01-03 12:36:01 +00:00
|
|
|
const auto contact = userLoaded(contactId);
|
2018-01-17 16:21:01 +00:00
|
|
|
const auto canShare = contact ? contact->canShareThisContact() : false;
|
|
|
|
|
|
|
|
_contactItems[contactId].insert(item);
|
|
|
|
|
|
|
|
if (contact && canShare != contact->canShareThisContact()) {
|
|
|
|
Notify::peerUpdatedDelayed(
|
|
|
|
contact,
|
|
|
|
Notify::PeerUpdate::Flag::UserCanShareContact);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (const auto i = _views.find(item); i != _views.end()) {
|
|
|
|
for (const auto view : i->second) {
|
|
|
|
if (const auto media = view->media()) {
|
|
|
|
media->updateSharedContactUserId(contactId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::unregisterContactItem(
|
|
|
|
UserId contactId,
|
|
|
|
not_null<HistoryItem*> item) {
|
|
|
|
if (!contactId) {
|
|
|
|
return;
|
|
|
|
}
|
2019-01-03 12:36:01 +00:00
|
|
|
const auto contact = userLoaded(contactId);
|
2018-01-17 16:21:01 +00:00
|
|
|
const auto canShare = contact ? contact->canShareThisContact() : false;
|
|
|
|
|
|
|
|
const auto i = _contactItems.find(contactId);
|
|
|
|
if (i != _contactItems.end()) {
|
|
|
|
auto &items = i->second;
|
|
|
|
if (items.remove(item) && items.empty()) {
|
|
|
|
_contactItems.erase(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (contact && canShare != contact->canShareThisContact()) {
|
|
|
|
Notify::peerUpdatedDelayed(
|
|
|
|
contact,
|
|
|
|
Notify::PeerUpdate::Flag::UserCanShareContact);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-30 15:46:13 +00:00
|
|
|
void Session::registerPlayingVideoFile(not_null<ViewElement*> view) {
|
2019-12-25 09:01:49 +00:00
|
|
|
if (++_playingVideoFiles[view] == 1) {
|
|
|
|
registerHeavyViewPart(view);
|
|
|
|
}
|
2018-01-17 16:21:01 +00:00
|
|
|
}
|
|
|
|
|
2019-07-30 15:46:13 +00:00
|
|
|
void Session::unregisterPlayingVideoFile(not_null<ViewElement*> view) {
|
2019-12-25 09:01:49 +00:00
|
|
|
const auto i = _playingVideoFiles.find(view);
|
|
|
|
if (i != _playingVideoFiles.end()) {
|
|
|
|
if (!--i->second) {
|
|
|
|
_playingVideoFiles.erase(i);
|
2020-03-27 11:40:50 +00:00
|
|
|
view->checkHeavyPart();
|
2019-12-25 09:01:49 +00:00
|
|
|
}
|
|
|
|
} else {
|
2020-03-27 11:40:50 +00:00
|
|
|
view->checkHeavyPart();
|
2019-12-25 09:01:49 +00:00
|
|
|
}
|
2018-01-17 16:21:01 +00:00
|
|
|
}
|
|
|
|
|
2019-07-30 15:46:13 +00:00
|
|
|
void Session::stopPlayingVideoFiles() {
|
2019-12-25 09:01:49 +00:00
|
|
|
for (const auto &[view, count] : base::take(_playingVideoFiles)) {
|
2018-01-17 16:21:01 +00:00
|
|
|
if (const auto media = view->media()) {
|
2018-01-21 14:49:42 +00:00
|
|
|
media->stopAnimation();
|
2018-01-17 16:21:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-30 15:46:13 +00:00
|
|
|
void Session::checkPlayingVideoFiles() {
|
2019-12-25 09:01:49 +00:00
|
|
|
const auto old = base::take(_playingVideoFiles);
|
|
|
|
for (const auto &[view, count] : old) {
|
2019-07-30 15:46:13 +00:00
|
|
|
if (const auto media = view->media()) {
|
2019-12-25 09:01:49 +00:00
|
|
|
if (const auto left = media->checkAnimationCount()) {
|
|
|
|
_playingVideoFiles.emplace(view, left);
|
|
|
|
registerHeavyViewPart(view);
|
|
|
|
continue;
|
|
|
|
}
|
2019-07-30 15:46:13 +00:00
|
|
|
}
|
2020-03-27 11:40:50 +00:00
|
|
|
view->checkHeavyPart();
|
2019-07-30 15:46:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
HistoryItem *Session::findWebPageItem(not_null<WebPageData*> page) const {
|
|
|
|
const auto i = _webpageItems.find(page);
|
|
|
|
if (i != _webpageItems.end()) {
|
|
|
|
for (const auto item : i->second) {
|
|
|
|
if (IsServerMsgId(item->id)) {
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Session::findContactPhone(not_null<UserData*> contact) const {
|
|
|
|
const auto result = contact->phone();
|
|
|
|
return result.isEmpty()
|
|
|
|
? findContactPhone(contact->bareId())
|
|
|
|
: App::formatPhone(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Session::findContactPhone(UserId contactId) const {
|
|
|
|
const auto i = _contactItems.find(contactId);
|
|
|
|
if (i != _contactItems.end()) {
|
|
|
|
if (const auto media = (*begin(i->second))->media()) {
|
|
|
|
if (const auto contact = media->sharedContact()) {
|
|
|
|
return contact->phoneNumber;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2018-12-18 05:43:11 +00:00
|
|
|
bool Session::hasPendingWebPageGamePollNotification() const {
|
|
|
|
return !_webpagesUpdated.empty()
|
|
|
|
|| !_gamesUpdated.empty()
|
|
|
|
|| !_pollsUpdated.empty();
|
|
|
|
}
|
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
void Session::notifyWebPageUpdateDelayed(not_null<WebPageData*> page) {
|
2018-12-18 05:43:11 +00:00
|
|
|
const auto invoke = !hasPendingWebPageGamePollNotification();
|
2018-01-17 16:21:01 +00:00
|
|
|
_webpagesUpdated.insert(page);
|
|
|
|
if (invoke) {
|
2018-12-18 05:43:11 +00:00
|
|
|
crl::on_main(_session, [=] { sendWebPageGamePollNotifications(); });
|
2018-01-17 16:21:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::notifyGameUpdateDelayed(not_null<GameData*> game) {
|
2018-12-18 05:43:11 +00:00
|
|
|
const auto invoke = !hasPendingWebPageGamePollNotification();
|
2018-01-17 16:21:01 +00:00
|
|
|
_gamesUpdated.insert(game);
|
|
|
|
if (invoke) {
|
2018-12-18 05:43:11 +00:00
|
|
|
crl::on_main(_session, [=] { sendWebPageGamePollNotifications(); });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::notifyPollUpdateDelayed(not_null<PollData*> poll) {
|
|
|
|
const auto invoke = !hasPendingWebPageGamePollNotification();
|
|
|
|
_pollsUpdated.insert(poll);
|
|
|
|
if (invoke) {
|
|
|
|
crl::on_main(_session, [=] { sendWebPageGamePollNotifications(); });
|
2018-01-17 16:21:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-18 05:43:11 +00:00
|
|
|
void Session::sendWebPageGamePollNotifications() {
|
2018-01-17 16:21:01 +00:00
|
|
|
for (const auto page : base::take(_webpagesUpdated)) {
|
|
|
|
const auto i = _webpageViews.find(page);
|
|
|
|
if (i != _webpageViews.end()) {
|
|
|
|
for (const auto view : i->second) {
|
|
|
|
requestViewResize(view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const auto game : base::take(_gamesUpdated)) {
|
|
|
|
if (const auto i = _gameViews.find(game); i != _gameViews.end()) {
|
|
|
|
for (const auto view : i->second) {
|
2018-12-18 05:43:11 +00:00
|
|
|
requestViewResize(view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const auto poll : base::take(_pollsUpdated)) {
|
|
|
|
if (const auto i = _pollViews.find(poll); i != _pollViews.end()) {
|
|
|
|
for (const auto view : i->second) {
|
2018-01-17 16:21:01 +00:00
|
|
|
requestViewResize(view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::registerItemView(not_null<ViewElement*> view) {
|
|
|
|
_views[view->data()].push_back(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::unregisterItemView(not_null<ViewElement*> view) {
|
|
|
|
const auto i = _views.find(view->data());
|
|
|
|
if (i != end(_views)) {
|
|
|
|
auto &list = i->second;
|
|
|
|
list.erase(ranges::remove(list, view), end(list));
|
|
|
|
if (list.empty()) {
|
|
|
|
_views.erase(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (App::hoveredItem() == view) {
|
|
|
|
App::hoveredItem(nullptr);
|
|
|
|
}
|
|
|
|
if (App::pressedItem() == view) {
|
|
|
|
App::pressedItem(nullptr);
|
|
|
|
}
|
|
|
|
if (App::hoveredLinkItem() == view) {
|
|
|
|
App::hoveredLinkItem(nullptr);
|
|
|
|
}
|
|
|
|
if (App::pressedLinkItem() == view) {
|
|
|
|
App::pressedLinkItem(nullptr);
|
|
|
|
}
|
|
|
|
if (App::mousedItem() == view) {
|
|
|
|
App::mousedItem(nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-15 11:54:03 +00:00
|
|
|
not_null<Folder*> Session::folder(FolderId id) {
|
|
|
|
if (const auto result = folderLoaded(id)) {
|
2018-01-04 10:22:53 +00:00
|
|
|
return result;
|
|
|
|
}
|
2019-04-15 11:54:03 +00:00
|
|
|
const auto [it, ok] = _folders.emplace(
|
2018-01-04 10:22:53 +00:00
|
|
|
id,
|
2019-04-15 11:54:03 +00:00
|
|
|
std::make_unique<Folder>(this, id));
|
2018-01-04 10:22:53 +00:00
|
|
|
return it->second.get();
|
|
|
|
}
|
|
|
|
|
2019-04-19 08:47:49 +00:00
|
|
|
Folder *Session::folderLoaded(FolderId id) const {
|
2019-04-15 11:54:03 +00:00
|
|
|
const auto it = _folders.find(id);
|
|
|
|
return (it == end(_folders)) ? nullptr : it->second.get();
|
|
|
|
}
|
2019-04-16 08:50:59 +00:00
|
|
|
|
|
|
|
not_null<Folder*> Session::processFolder(const MTPFolder &data) {
|
|
|
|
return data.match([&](const MTPDfolder &data) {
|
|
|
|
return processFolder(data);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
not_null<Folder*> Session::processFolder(const MTPDfolder &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto result = folder(data.vid().v);
|
|
|
|
//data.vphoto();
|
|
|
|
//data.vtitle();
|
2019-04-16 08:50:59 +00:00
|
|
|
return result;
|
|
|
|
}
|
2019-04-15 11:54:03 +00:00
|
|
|
// // #feed
|
|
|
|
//void Session::setDefaultFeedId(FeedId id) {
|
|
|
|
// _defaultFeedId = id;
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//FeedId Session::defaultFeedId() const {
|
|
|
|
// return _defaultFeedId.current();
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//rpl::producer<FeedId> Session::defaultFeedIdValue() const {
|
|
|
|
// return _defaultFeedId.value();
|
|
|
|
//}
|
2018-02-08 09:20:14 +00:00
|
|
|
|
2019-04-22 14:22:39 +00:00
|
|
|
not_null<Dialogs::MainList*> Session::chatsList(Data::Folder *folder) {
|
|
|
|
return folder ? folder->chatsList().get() : &_chatsList;
|
|
|
|
}
|
|
|
|
|
|
|
|
not_null<const Dialogs::MainList*> Session::chatsList(
|
|
|
|
Data::Folder *folder) const {
|
|
|
|
return folder ? folder->chatsList() : &_chatsList;
|
2019-04-16 14:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
not_null<Dialogs::IndexedList*> Session::contactsList() {
|
|
|
|
return &_contactsList;
|
|
|
|
}
|
|
|
|
|
|
|
|
not_null<Dialogs::IndexedList*> Session::contactsNoChatsList() {
|
|
|
|
return &_contactsNoChatsList;
|
|
|
|
}
|
|
|
|
|
2020-02-07 11:34:05 +00:00
|
|
|
auto Session::refreshChatListEntry(
|
|
|
|
Dialogs::Key key,
|
|
|
|
FilterId filterIdForResult)
|
2019-04-16 14:05:56 +00:00
|
|
|
-> RefreshChatListEntryResult {
|
2020-03-16 10:20:18 +00:00
|
|
|
Expects(key.entry()->folderKnown());
|
|
|
|
|
2019-04-16 14:05:56 +00:00
|
|
|
using namespace Dialogs;
|
|
|
|
|
|
|
|
const auto entry = key.entry();
|
2020-02-07 11:34:05 +00:00
|
|
|
const auto history = key.history();
|
2020-03-16 10:20:18 +00:00
|
|
|
const auto mainList = chatsList(entry->folder());
|
2020-02-07 11:34:05 +00:00
|
|
|
auto mainListResult = RefreshChatListEntryResult();
|
|
|
|
mainListResult.changed = !entry->inChatList();
|
|
|
|
if (mainListResult.changed) {
|
2020-03-16 10:20:18 +00:00
|
|
|
const auto mainRow = entry->addToChatList(0, mainList);
|
2019-04-16 14:05:56 +00:00
|
|
|
_contactsNoChatsList.del(key, mainRow);
|
|
|
|
} else {
|
2020-03-16 10:20:18 +00:00
|
|
|
mainListResult.moved = entry->adjustByPosInChatList(0, mainList);
|
2020-02-07 11:34:05 +00:00
|
|
|
}
|
|
|
|
auto result = filterIdForResult
|
|
|
|
? RefreshChatListEntryResult()
|
|
|
|
: mainListResult;
|
2020-03-16 10:20:18 +00:00
|
|
|
if (!history) {
|
|
|
|
return result;
|
|
|
|
}
|
2020-02-07 16:07:21 +00:00
|
|
|
for (const auto &filter : _chatsFilters->list()) {
|
|
|
|
const auto id = filter.id();
|
2020-03-16 10:20:18 +00:00
|
|
|
const auto filterList = chatsFilters().chatsList(id);
|
2020-02-07 11:34:05 +00:00
|
|
|
auto filterResult = RefreshChatListEntryResult();
|
2020-03-16 10:20:18 +00:00
|
|
|
if (filter.contains(history)) {
|
2020-02-07 16:07:21 +00:00
|
|
|
filterResult.changed = !entry->inChatList(id);
|
2020-02-07 11:34:05 +00:00
|
|
|
if (filterResult.changed) {
|
2020-03-16 10:20:18 +00:00
|
|
|
entry->addToChatList(id, filterList);
|
2020-02-07 11:34:05 +00:00
|
|
|
} else {
|
2020-03-16 10:20:18 +00:00
|
|
|
filterResult.moved = entry->adjustByPosInChatList(
|
|
|
|
id,
|
|
|
|
filterList);
|
2020-02-07 11:34:05 +00:00
|
|
|
}
|
2020-02-07 16:07:21 +00:00
|
|
|
} else if (entry->inChatList(id)) {
|
2020-03-16 10:20:18 +00:00
|
|
|
entry->removeFromChatList(id, filterList);
|
2020-02-07 11:34:05 +00:00
|
|
|
filterResult.changed = true;
|
|
|
|
}
|
2020-02-07 16:07:21 +00:00
|
|
|
if (id == filterIdForResult) {
|
2020-02-07 11:34:05 +00:00
|
|
|
result = filterResult;
|
|
|
|
}
|
|
|
|
}
|
2019-04-16 14:05:56 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::removeChatListEntry(Dialogs::Key key) {
|
|
|
|
using namespace Dialogs;
|
|
|
|
|
|
|
|
const auto entry = key.entry();
|
2020-03-16 10:20:18 +00:00
|
|
|
if (!entry->inChatList()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Assert(entry->folderKnown());
|
|
|
|
const auto mainList = chatsList(entry->folder());
|
|
|
|
entry->removeFromChatList(0, mainList);
|
2020-02-07 16:07:21 +00:00
|
|
|
for (const auto &filter : _chatsFilters->list()) {
|
2020-03-16 10:20:18 +00:00
|
|
|
const auto id = filter.id();
|
|
|
|
if (entry->inChatList(id)) {
|
|
|
|
entry->removeFromChatList(id, chatsFilters().chatsList(id));
|
|
|
|
}
|
2020-02-07 11:34:05 +00:00
|
|
|
}
|
2019-04-16 14:05:56 +00:00
|
|
|
if (_contactsList.contains(key)) {
|
|
|
|
if (!_contactsNoChatsList.contains(key)) {
|
|
|
|
_contactsNoChatsList.addByName(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::dialogsRowReplaced(DialogsRowReplacement replacement) {
|
|
|
|
_dialogsRowReplacements.fire(std::move(replacement));
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Session::dialogsRowReplacements() const
|
|
|
|
-> rpl::producer<DialogsRowReplacement> {
|
|
|
|
return _dialogsRowReplacements.events();
|
|
|
|
}
|
|
|
|
|
2018-04-09 17:48:29 +00:00
|
|
|
void Session::requestNotifySettings(not_null<PeerData*> peer) {
|
|
|
|
if (peer->notifySettingsUnknown()) {
|
|
|
|
_session->api().requestNotifySettings(
|
|
|
|
MTP_inputNotifyPeer(peer->input));
|
|
|
|
}
|
|
|
|
if (defaultNotifySettings(peer).settingsUnknown()) {
|
|
|
|
_session->api().requestNotifySettings(peer->isUser()
|
|
|
|
? MTP_inputNotifyUsers()
|
2018-11-06 11:10:20 +00:00
|
|
|
: (peer->isChat() || peer->isMegagroup())
|
|
|
|
? MTP_inputNotifyChats()
|
|
|
|
: MTP_inputNotifyBroadcasts());
|
2018-04-09 17:48:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::applyNotifySetting(
|
|
|
|
const MTPNotifyPeer ¬ifyPeer,
|
|
|
|
const MTPPeerNotifySettings &settings) {
|
|
|
|
switch (notifyPeer.type()) {
|
|
|
|
case mtpc_notifyUsers: {
|
|
|
|
if (_defaultUserNotifySettings.change(settings)) {
|
|
|
|
_defaultUserNotifyUpdates.fire({});
|
|
|
|
|
2019-01-03 12:36:01 +00:00
|
|
|
enumerateUsers([&](not_null<UserData*> user) {
|
2018-04-09 17:48:29 +00:00
|
|
|
if (!user->notifySettingsUnknown()
|
|
|
|
&& ((!user->notifyMuteUntil()
|
|
|
|
&& _defaultUserNotifySettings.muteUntil())
|
|
|
|
|| (!user->notifySilentPosts()
|
|
|
|
&& _defaultUserNotifySettings.silentPosts()))) {
|
|
|
|
updateNotifySettingsLocal(user);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case mtpc_notifyChats: {
|
|
|
|
if (_defaultChatNotifySettings.change(settings)) {
|
|
|
|
_defaultChatNotifyUpdates.fire({});
|
|
|
|
|
2019-01-03 12:36:01 +00:00
|
|
|
enumerateGroups([&](not_null<PeerData*> peer) {
|
2018-04-09 17:48:29 +00:00
|
|
|
if (!peer->notifySettingsUnknown()
|
|
|
|
&& ((!peer->notifyMuteUntil()
|
2018-06-06 19:56:35 +00:00
|
|
|
&& _defaultChatNotifySettings.muteUntil())
|
2018-04-09 17:48:29 +00:00
|
|
|
|| (!peer->notifySilentPosts()
|
2018-06-06 19:56:35 +00:00
|
|
|
&& _defaultChatNotifySettings.silentPosts()))) {
|
2018-04-09 17:48:29 +00:00
|
|
|
updateNotifySettingsLocal(peer);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} break;
|
2018-11-06 11:10:20 +00:00
|
|
|
case mtpc_notifyBroadcasts: {
|
|
|
|
if (_defaultBroadcastNotifySettings.change(settings)) {
|
|
|
|
_defaultBroadcastNotifyUpdates.fire({});
|
|
|
|
|
2019-01-03 12:36:01 +00:00
|
|
|
enumerateChannels([&](not_null<ChannelData*> channel) {
|
2018-11-06 11:10:20 +00:00
|
|
|
if (!channel->notifySettingsUnknown()
|
|
|
|
&& ((!channel->notifyMuteUntil()
|
|
|
|
&& _defaultBroadcastNotifySettings.muteUntil())
|
|
|
|
|| (!channel->notifySilentPosts()
|
|
|
|
&& _defaultBroadcastNotifySettings.silentPosts()))) {
|
|
|
|
updateNotifySettingsLocal(channel);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} break;
|
2018-04-09 17:48:29 +00:00
|
|
|
case mtpc_notifyPeer: {
|
|
|
|
const auto &data = notifyPeer.c_notifyPeer();
|
2019-07-05 13:38:38 +00:00
|
|
|
if (const auto peer = peerLoaded(peerFromMTP(data.vpeer()))) {
|
2018-04-09 17:48:29 +00:00
|
|
|
if (peer->notifyChange(settings)) {
|
|
|
|
updateNotifySettingsLocal(peer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::updateNotifySettings(
|
|
|
|
not_null<PeerData*> peer,
|
2018-09-21 16:28:46 +00:00
|
|
|
std::optional<int> muteForSeconds,
|
|
|
|
std::optional<bool> silentPosts) {
|
2018-04-09 17:48:29 +00:00
|
|
|
if (peer->notifyChange(muteForSeconds, silentPosts)) {
|
|
|
|
updateNotifySettingsLocal(peer);
|
|
|
|
_session->api().updateNotifySettingsDelayed(peer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Session::notifyIsMuted(
|
|
|
|
not_null<const PeerData*> peer,
|
2019-02-19 06:57:53 +00:00
|
|
|
crl::time *changesIn) const {
|
2018-04-09 17:48:29 +00:00
|
|
|
const auto resultFromUntil = [&](TimeId until) {
|
2019-07-10 17:28:33 +00:00
|
|
|
const auto now = base::unixtime::now();
|
2018-04-09 17:48:29 +00:00
|
|
|
const auto result = (until > now) ? (until - now) : 0;
|
|
|
|
if (changesIn) {
|
|
|
|
*changesIn = (result > 0)
|
2019-02-19 06:57:53 +00:00
|
|
|
? std::min(result * crl::time(1000), kMaxNotifyCheckDelay)
|
2018-04-09 17:48:29 +00:00
|
|
|
: kMaxNotifyCheckDelay;
|
|
|
|
}
|
|
|
|
return (result > 0);
|
|
|
|
};
|
|
|
|
if (const auto until = peer->notifyMuteUntil()) {
|
|
|
|
return resultFromUntil(*until);
|
|
|
|
}
|
|
|
|
const auto &settings = defaultNotifySettings(peer);
|
|
|
|
if (const auto until = settings.muteUntil()) {
|
|
|
|
return resultFromUntil(*until);
|
|
|
|
}
|
2018-06-07 19:28:09 +00:00
|
|
|
return true;
|
2018-04-09 17:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Session::notifySilentPosts(not_null<const PeerData*> peer) const {
|
|
|
|
if (const auto silent = peer->notifySilentPosts()) {
|
|
|
|
return *silent;
|
|
|
|
}
|
|
|
|
const auto &settings = defaultNotifySettings(peer);
|
|
|
|
if (const auto silent = settings.silentPosts()) {
|
|
|
|
return *silent;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Session::notifyMuteUnknown(not_null<const PeerData*> peer) const {
|
|
|
|
if (peer->notifySettingsUnknown()) {
|
|
|
|
return true;
|
|
|
|
} else if (const auto nonDefault = peer->notifyMuteUntil()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return defaultNotifySettings(peer).settingsUnknown();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Session::notifySilentPostsUnknown(
|
|
|
|
not_null<const PeerData*> peer) const {
|
|
|
|
if (peer->notifySettingsUnknown()) {
|
|
|
|
return true;
|
|
|
|
} else if (const auto nonDefault = peer->notifySilentPosts()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return defaultNotifySettings(peer).settingsUnknown();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Session::notifySettingsUnknown(not_null<const PeerData*> peer) const {
|
|
|
|
return notifyMuteUnknown(peer) || notifySilentPostsUnknown(peer);
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<> Session::defaultUserNotifyUpdates() const {
|
|
|
|
return _defaultUserNotifyUpdates.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<> Session::defaultChatNotifyUpdates() const {
|
|
|
|
return _defaultChatNotifyUpdates.events();
|
|
|
|
}
|
|
|
|
|
2018-11-06 11:10:20 +00:00
|
|
|
rpl::producer<> Session::defaultBroadcastNotifyUpdates() const {
|
|
|
|
return _defaultBroadcastNotifyUpdates.events();
|
|
|
|
}
|
|
|
|
|
2018-04-09 17:48:29 +00:00
|
|
|
rpl::producer<> Session::defaultNotifyUpdates(
|
|
|
|
not_null<const PeerData*> peer) const {
|
|
|
|
return peer->isUser()
|
|
|
|
? defaultUserNotifyUpdates()
|
2018-11-06 11:10:20 +00:00
|
|
|
: (peer->isChat() || peer->isMegagroup())
|
|
|
|
? defaultChatNotifyUpdates()
|
|
|
|
: defaultBroadcastNotifyUpdates();
|
2018-04-09 17:48:29 +00:00
|
|
|
}
|
|
|
|
|
2018-09-27 20:31:48 +00:00
|
|
|
void Session::serviceNotification(
|
|
|
|
const TextWithEntities &message,
|
|
|
|
const MTPMessageMedia &media) {
|
2019-07-10 17:28:33 +00:00
|
|
|
const auto date = base::unixtime::now();
|
2019-03-12 10:36:33 +00:00
|
|
|
if (!peerLoaded(PeerData::kServiceNotificationsId)) {
|
2019-01-18 12:27:37 +00:00
|
|
|
processUser(MTP_user(
|
2018-09-27 20:31:48 +00:00
|
|
|
MTP_flags(
|
|
|
|
MTPDuser::Flag::f_first_name
|
|
|
|
| MTPDuser::Flag::f_phone
|
|
|
|
| MTPDuser::Flag::f_status
|
|
|
|
| MTPDuser::Flag::f_verified),
|
2019-03-12 10:36:33 +00:00
|
|
|
MTP_int(peerToUser(PeerData::kServiceNotificationsId)),
|
2019-08-08 10:15:59 +00:00
|
|
|
MTPlong(), // access_hash
|
2018-09-27 20:31:48 +00:00
|
|
|
MTP_string("Telegram"),
|
2019-08-08 10:15:59 +00:00
|
|
|
MTPstring(), // last_name
|
|
|
|
MTPstring(), // username
|
2018-09-27 20:31:48 +00:00
|
|
|
MTP_string("42777"),
|
|
|
|
MTP_userProfilePhotoEmpty(),
|
|
|
|
MTP_userStatusRecently(),
|
2019-08-08 10:15:59 +00:00
|
|
|
MTPint(), // bot_info_version
|
|
|
|
MTPVector<MTPRestrictionReason>(),
|
|
|
|
MTPstring(), // bot_inline_placeholder
|
|
|
|
MTPstring())); // lang_code
|
2018-09-27 20:31:48 +00:00
|
|
|
}
|
2019-03-12 10:36:33 +00:00
|
|
|
const auto history = this->history(PeerData::kServiceNotificationsId);
|
2019-04-22 14:22:39 +00:00
|
|
|
if (!history->folderKnown()) {
|
2020-02-21 07:58:50 +00:00
|
|
|
histories().requestDialogEntry(history, [=] {
|
2018-09-27 20:31:48 +00:00
|
|
|
insertCheckedServiceNotification(message, media, date);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
insertCheckedServiceNotification(message, media, date);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-20 10:03:44 +00:00
|
|
|
void Session::checkNewAuthorization() {
|
|
|
|
_newAuthorizationChecks.fire({});
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<> Session::newAuthorizationChecks() const {
|
|
|
|
return _newAuthorizationChecks.events();
|
|
|
|
}
|
|
|
|
|
2018-09-27 20:31:48 +00:00
|
|
|
void Session::insertCheckedServiceNotification(
|
|
|
|
const TextWithEntities &message,
|
|
|
|
const MTPMessageMedia &media,
|
|
|
|
TimeId date) {
|
2019-03-12 10:36:33 +00:00
|
|
|
const auto history = this->history(PeerData::kServiceNotificationsId);
|
2018-09-27 20:31:48 +00:00
|
|
|
const auto flags = MTPDmessage::Flag::f_entities
|
|
|
|
| MTPDmessage::Flag::f_from_id
|
2019-02-11 12:50:35 +00:00
|
|
|
| MTPDmessage::Flag::f_media;
|
2019-08-12 16:33:36 +00:00
|
|
|
const auto clientFlags = MTPDmessage_ClientFlag::f_clientside_unread
|
|
|
|
| MTPDmessage_ClientFlag::f_local_history_entry;
|
2018-09-27 20:31:48 +00:00
|
|
|
auto sending = TextWithEntities(), left = message;
|
|
|
|
while (TextUtilities::CutPart(sending, left, MaxMessageSize)) {
|
2019-01-03 12:36:01 +00:00
|
|
|
addNewMessage(
|
2018-09-27 20:31:48 +00:00
|
|
|
MTP_message(
|
|
|
|
MTP_flags(flags),
|
2019-08-12 16:33:36 +00:00
|
|
|
MTP_int(nextLocalMessageId()),
|
2019-03-12 10:36:33 +00:00
|
|
|
MTP_int(peerToUser(PeerData::kServiceNotificationsId)),
|
2018-09-27 20:31:48 +00:00
|
|
|
MTP_peerUser(MTP_int(_session->userId())),
|
2019-03-15 15:15:56 +00:00
|
|
|
MTPMessageFwdHeader(),
|
2018-09-27 20:31:48 +00:00
|
|
|
MTPint(),
|
|
|
|
MTPint(),
|
|
|
|
MTP_int(date),
|
|
|
|
MTP_string(sending.text),
|
|
|
|
media,
|
2019-03-15 15:15:56 +00:00
|
|
|
MTPReplyMarkup(),
|
2019-09-16 11:14:06 +00:00
|
|
|
Api::EntitiesToMTP(sending.entities),
|
2018-09-27 20:31:48 +00:00
|
|
|
MTPint(),
|
|
|
|
MTPint(),
|
|
|
|
MTPstring(),
|
2019-08-08 10:15:59 +00:00
|
|
|
MTPlong(),
|
|
|
|
//MTPMessageReactions(),
|
|
|
|
MTPVector<MTPRestrictionReason>()),
|
2019-08-09 19:19:23 +00:00
|
|
|
clientFlags,
|
2019-04-25 12:45:15 +00:00
|
|
|
NewMessageType::Unread);
|
2018-09-27 20:31:48 +00:00
|
|
|
}
|
|
|
|
sendHistoryChangeNotifications();
|
|
|
|
}
|
|
|
|
|
2018-01-11 15:51:59 +00:00
|
|
|
void Session::setMimeForwardIds(MessageIdsList &&list) {
|
|
|
|
_mimeForwardIds = std::move(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageIdsList Session::takeMimeForwardIds() {
|
|
|
|
return std::move(_mimeForwardIds);
|
|
|
|
}
|
|
|
|
|
2020-04-24 12:40:20 +00:00
|
|
|
void Session::setTopPromoted(
|
|
|
|
PeerData *promoted,
|
|
|
|
const QString &type,
|
|
|
|
const QString &message) {
|
|
|
|
const auto changed = (_topPromoted != promoted);
|
|
|
|
const auto history = promoted ? this->history(promoted).get() : nullptr;
|
|
|
|
if (changed
|
|
|
|
|| (history && history->topPromotionMessage() != message)) {
|
|
|
|
if (changed) {
|
|
|
|
if (const auto history = historyLoaded(_topPromoted)) {
|
2020-04-29 08:46:02 +00:00
|
|
|
history->cacheTopPromotion(false, QString(), QString());
|
2020-04-24 12:40:20 +00:00
|
|
|
}
|
2020-04-24 10:31:28 +00:00
|
|
|
}
|
|
|
|
const auto old = std::exchange(_topPromoted, promoted);
|
2020-04-24 12:40:20 +00:00
|
|
|
if (history) {
|
2020-04-29 08:46:02 +00:00
|
|
|
history->cacheTopPromotion(true, type, message);
|
2019-01-15 11:57:45 +00:00
|
|
|
history->requestChatListMessage();
|
2018-05-15 16:38:27 +00:00
|
|
|
Notify::peerUpdatedDelayed(
|
2020-04-24 10:31:28 +00:00
|
|
|
_topPromoted,
|
2020-04-29 09:27:54 +00:00
|
|
|
Notify::PeerUpdate::Flag::TopPromotedChanged);
|
2018-05-15 16:38:27 +00:00
|
|
|
}
|
2020-04-24 12:40:20 +00:00
|
|
|
if (changed && old) {
|
2018-05-15 16:38:27 +00:00
|
|
|
Notify::peerUpdatedDelayed(
|
|
|
|
old,
|
2020-04-29 09:27:54 +00:00
|
|
|
Notify::PeerUpdate::Flag::TopPromotedChanged);
|
2018-05-11 14:03:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-24 10:31:28 +00:00
|
|
|
PeerData *Session::topPromoted() const {
|
|
|
|
return _topPromoted;
|
2018-05-11 14:03:53 +00:00
|
|
|
}
|
|
|
|
|
2019-01-16 12:25:29 +00:00
|
|
|
bool Session::updateWallpapers(const MTPaccount_WallPapers &data) {
|
|
|
|
return data.match([&](const MTPDaccount_wallPapers &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
setWallpapers(data.vwallpapers().v, data.vhash().v);
|
2019-01-16 12:25:29 +00:00
|
|
|
return true;
|
|
|
|
}, [&](const MTPDaccount_wallPapersNotModified &) {
|
|
|
|
return false;
|
|
|
|
});
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
|
|
|
|
2019-01-16 12:25:29 +00:00
|
|
|
void Session::setWallpapers(const QVector<MTPWallPaper> &data, int32 hash) {
|
|
|
|
_wallpapersHash = hash;
|
2019-01-03 12:36:01 +00:00
|
|
|
|
|
|
|
_wallpapers.clear();
|
2019-02-04 18:37:40 +00:00
|
|
|
_wallpapers.reserve(data.size() + 2);
|
2019-01-03 12:36:01 +00:00
|
|
|
|
2019-02-04 18:37:40 +00:00
|
|
|
_wallpapers.push_back(Data::Legacy1DefaultWallPaper());
|
2019-02-08 13:43:31 +00:00
|
|
|
_wallpapers.back().setLocalImageAsThumbnail(std::make_shared<Image>(
|
|
|
|
std::make_unique<Images::LocalFileSource>(
|
|
|
|
qsl(":/gui/art/bg_initial.jpg"),
|
|
|
|
QByteArray(),
|
|
|
|
"JPG")));
|
2019-01-03 12:36:01 +00:00
|
|
|
for (const auto &paper : data) {
|
2019-12-29 11:41:10 +00:00
|
|
|
if (const auto parsed = Data::WallPaper::Create(paper)) {
|
|
|
|
_wallpapers.push_back(*parsed);
|
|
|
|
}
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
2019-02-04 18:37:40 +00:00
|
|
|
const auto defaultFound = ranges::find_if(
|
|
|
|
_wallpapers,
|
|
|
|
Data::IsDefaultWallPaper);
|
|
|
|
if (defaultFound == end(_wallpapers)) {
|
|
|
|
_wallpapers.push_back(Data::DefaultWallPaper());
|
2019-02-08 13:43:31 +00:00
|
|
|
_wallpapers.back().setLocalImageAsThumbnail(std::make_shared<Image>(
|
|
|
|
std::make_unique<Images::LocalFileSource>(
|
|
|
|
qsl(":/gui/arg/bg.jpg"),
|
|
|
|
QByteArray(),
|
|
|
|
"JPG")));
|
2019-02-04 18:37:40 +00:00
|
|
|
}
|
2019-01-03 12:36:01 +00:00
|
|
|
}
|
|
|
|
|
2019-02-09 13:36:07 +00:00
|
|
|
void Session::removeWallpaper(const WallPaper &paper) {
|
|
|
|
const auto i = ranges::find(_wallpapers, paper.id(), &WallPaper::id);
|
|
|
|
if (i != end(_wallpapers)) {
|
|
|
|
_wallpapers.erase(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-16 12:25:29 +00:00
|
|
|
const std::vector<WallPaper> &Session::wallpapers() const {
|
|
|
|
return _wallpapers;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 Session::wallpapersHash() const {
|
|
|
|
return _wallpapersHash;
|
|
|
|
}
|
|
|
|
|
2019-01-03 12:36:01 +00:00
|
|
|
void Session::clearLocalStorage() {
|
|
|
|
clear();
|
|
|
|
|
|
|
|
_cache->close();
|
|
|
|
_cache->clear();
|
|
|
|
}
|
|
|
|
|
2018-01-04 10:22:53 +00:00
|
|
|
} // namespace Data
|