Move all (item/view/media) maps to Data::Session.

This commit is contained in:
John Preston
2018-01-17 19:21:01 +03:00
parent 7425e80f05
commit 8a56ede187
78 changed files with 2900 additions and 2320 deletions
+2 -722
View File
@@ -55,25 +55,9 @@ namespace {
using MutedPeers = QMap<not_null<PeerData*>, bool>;
MutedPeers mutedPeers;
PhotosData photosData;
DocumentsData documentsData;
using LocationsData = QHash<LocationCoords, LocationData*>;
LocationsData locationsData;
using WebPagesData = QHash<WebPageId, WebPageData*>;
WebPagesData webPagesData;
using GamesData = QHash<GameId, GameData*>;
GamesData gamesData;
PhotoItems photoItems;
DocumentItems documentItems;
WebPageItems webPageItems;
GameItems gameItems;
SharedContactItems sharedContactItems;
GifItems gifItems;
using DependentItemsSet = OrderedSet<HistoryItem*>;
using DependentItems = QMap<HistoryItem*, DependentItemsSet>;
DependentItems dependentItems;
@@ -114,11 +98,6 @@ namespace {
int32 serviceImageCacheSize = 0;
using LastPhotosList = QLinkedList<PhotoData*>;
LastPhotosList lastPhotos;
using LastPhotosMap = QHash<PhotoData*, LastPhotosList::iterator>;
LastPhotosMap lastPhotosMap;
} // namespace
namespace App {
@@ -928,8 +907,9 @@ namespace {
auto entities = m.has_entities()
? TextUtilities::EntitiesFromMTP(m.ventities.v)
: EntitiesInText();
const auto media = m.has_media() ? &m.vmedia : nullptr;
existing->setText({ text, entities });
existing->updateMedia(m.has_media() ? (&m.vmedia) : nullptr);
existing->updateSentMedia(m.has_media() ? &m.vmedia : nullptr);
existing->updateReplyMarkup(m.has_reply_markup()
? (&m.vreply_markup)
: nullptr);
@@ -1146,207 +1126,6 @@ namespace {
}
}
PhotoData *feedPhoto(const MTPPhoto &photo, PhotoData *convert) {
switch (photo.type()) {
case mtpc_photo: {
return feedPhoto(photo.c_photo(), convert);
} break;
case mtpc_photoEmpty: {
return App::photoSet(photo.c_photoEmpty().vid.v, convert, 0, 0, ImagePtr(), ImagePtr(), ImagePtr());
} break;
}
return App::photo(0);
}
PhotoData *feedPhoto(const MTPPhoto &photo, const PreparedPhotoThumbs &thumbs) {
const QPixmap *thumb = 0, *medium = 0, *full = 0;
int32 thumbLevel = -1, mediumLevel = -1, fullLevel = -1;
for (PreparedPhotoThumbs::const_iterator i = thumbs.cbegin(), e = thumbs.cend(); i != e; ++i) {
int32 newThumbLevel = -1, newMediumLevel = -1, newFullLevel = -1;
switch (i.key()) {
case 's': newThumbLevel = 0; newMediumLevel = 5; newFullLevel = 4; break; // box 100x100
case 'm': newThumbLevel = 2; newMediumLevel = 0; newFullLevel = 3; break; // box 320x320
case 'x': newThumbLevel = 5; newMediumLevel = 3; newFullLevel = 1; break; // box 800x800
case 'y': newThumbLevel = 6; newMediumLevel = 6; newFullLevel = 0; break; // box 1280x1280
case 'w': newThumbLevel = 8; newMediumLevel = 8; newFullLevel = 2; break; // box 2560x2560 // if loading this fix HistoryPhoto::updateFrom
case 'a': newThumbLevel = 1; newMediumLevel = 4; newFullLevel = 8; break; // crop 160x160
case 'b': newThumbLevel = 3; newMediumLevel = 1; newFullLevel = 7; break; // crop 320x320
case 'c': newThumbLevel = 4; newMediumLevel = 2; newFullLevel = 6; break; // crop 640x640
case 'd': newThumbLevel = 7; newMediumLevel = 7; newFullLevel = 5; break; // crop 1280x1280
}
if (newThumbLevel < 0 || newMediumLevel < 0 || newFullLevel < 0) {
continue;
}
if (thumbLevel < 0 || newThumbLevel < thumbLevel) {
thumbLevel = newThumbLevel;
thumb = &i.value();
}
if (mediumLevel < 0 || newMediumLevel < mediumLevel) {
mediumLevel = newMediumLevel;
medium = &i.value();
}
if (fullLevel < 0 || newFullLevel < fullLevel) {
fullLevel = newFullLevel;
full = &i.value();
}
}
if (!thumb || !medium || !full) {
return App::photo(0);
}
switch (photo.type()) {
case mtpc_photo: {
const auto &ph(photo.c_photo());
return App::photoSet(ph.vid.v, 0, ph.vaccess_hash.v, ph.vdate.v, ImagePtr(*thumb, "JPG"), ImagePtr(*medium, "JPG"), ImagePtr(*full, "JPG"));
} break;
case mtpc_photoEmpty: return App::photo(photo.c_photoEmpty().vid.v);
}
return App::photo(0);
}
PhotoData *feedPhoto(const MTPDphoto &photo, PhotoData *convert) {
auto &sizes = photo.vsizes.v;
const MTPPhotoSize *thumb = 0, *medium = 0, *full = 0;
int32 thumbLevel = -1, mediumLevel = -1, fullLevel = -1;
for (QVector<MTPPhotoSize>::const_iterator i = sizes.cbegin(), e = sizes.cend(); i != e; ++i) {
char size = 0;
switch (i->type()) {
case mtpc_photoSize: {
auto &s = i->c_photoSize().vtype.v;
if (s.size()) size = s[0];
} break;
case mtpc_photoCachedSize: {
auto &s = i->c_photoCachedSize().vtype.v;
if (s.size()) size = s[0];
} break;
}
if (!size) continue;
int32 newThumbLevel = -1, newMediumLevel = -1, newFullLevel = -1;
switch (size) {
case 's': newThumbLevel = 0; newMediumLevel = 5; newFullLevel = 4; break; // box 100x100
case 'm': newThumbLevel = 2; newMediumLevel = 0; newFullLevel = 3; break; // box 320x320
case 'x': newThumbLevel = 5; newMediumLevel = 3; newFullLevel = 1; break; // box 800x800
case 'y': newThumbLevel = 6; newMediumLevel = 6; newFullLevel = 0; break; // box 1280x1280
case 'w': newThumbLevel = 8; newMediumLevel = 8; newFullLevel = 2; break; // box 2560x2560
case 'a': newThumbLevel = 1; newMediumLevel = 4; newFullLevel = 8; break; // crop 160x160
case 'b': newThumbLevel = 3; newMediumLevel = 1; newFullLevel = 7; break; // crop 320x320
case 'c': newThumbLevel = 4; newMediumLevel = 2; newFullLevel = 6; break; // crop 640x640
case 'd': newThumbLevel = 7; newMediumLevel = 7; newFullLevel = 5; break; // crop 1280x1280
}
if (newThumbLevel < 0 || newMediumLevel < 0 || newFullLevel < 0) {
continue;
}
if (thumbLevel < 0 || newThumbLevel < thumbLevel) {
thumbLevel = newThumbLevel;
thumb = &(*i);
}
if (mediumLevel < 0 || newMediumLevel < mediumLevel) {
mediumLevel = newMediumLevel;
medium = &(*i);
}
if (fullLevel < 0 || newFullLevel < fullLevel) {
fullLevel = newFullLevel;
full = &(*i);
}
}
if (thumb && medium && full) {
return App::photoSet(photo.vid.v, convert, photo.vaccess_hash.v, photo.vdate.v, App::image(*thumb), App::image(*medium), App::image(*full));
}
return App::photoSet(photo.vid.v, convert, 0, 0, ImagePtr(), ImagePtr(), ImagePtr());
}
DocumentData *feedDocument(const MTPdocument &document, const QPixmap &thumb) {
switch (document.type()) {
case mtpc_document: {
auto &d = document.c_document();
return App::documentSet(d.vid.v, 0, d.vaccess_hash.v, d.vversion.v, d.vdate.v, d.vattributes.v, qs(d.vmime_type), ImagePtr(thumb, "JPG"), d.vdc_id.v, d.vsize.v, StorageImageLocation());
} break;
case mtpc_documentEmpty: return App::document(document.c_documentEmpty().vid.v);
}
return App::document(0);
}
DocumentData *feedDocument(const MTPdocument &document, DocumentData *convert) {
switch (document.type()) {
case mtpc_document: {
return feedDocument(document.c_document(), convert);
} break;
case mtpc_documentEmpty: {
return App::documentSet(document.c_documentEmpty().vid.v, convert, 0, 0, 0, QVector<MTPDocumentAttribute>(), QString(), ImagePtr(), 0, 0, StorageImageLocation());
} break;
}
return App::document(0);
}
DocumentData *feedDocument(const MTPDdocument &document, DocumentData *convert) {
return App::documentSet(
document.vid.v,
convert,
document.vaccess_hash.v,
document.vversion.v,
document.vdate.v,
document.vattributes.v,
qs(document.vmime_type),
App::image(document.vthumb),
document.vdc_id.v,
document.vsize.v,
StorageImageLocation::FromMTP(document.vthumb));
}
WebPageData *feedWebPage(const MTPDwebPage &webpage, WebPageData *convert) {
auto description = TextWithEntities { webpage.has_description() ? TextUtilities::Clean(qs(webpage.vdescription)) : QString() };
auto siteName = webpage.has_site_name() ? qs(webpage.vsite_name) : QString();
auto parseFlags = TextParseLinks | TextParseMultiline | TextParseRichText;
if (siteName == qstr("Twitter") || siteName == qstr("Instagram")) {
parseFlags |= TextParseHashtags | TextParseMentions;
}
TextUtilities::ParseEntities(description, parseFlags);
return App::webPageSet(webpage.vid.v, convert, webpage.has_type() ? qs(webpage.vtype) : qsl("article"), qs(webpage.vurl), qs(webpage.vdisplay_url), siteName, webpage.has_title() ? qs(webpage.vtitle) : QString(), description, webpage.has_photo() ? App::feedPhoto(webpage.vphoto) : nullptr, webpage.has_document() ? App::feedDocument(webpage.vdocument) : nullptr, webpage.has_duration() ? webpage.vduration.v : 0, webpage.has_author() ? qs(webpage.vauthor) : QString(), 0);
}
WebPageData *feedWebPage(const MTPDwebPagePending &webpage, WebPageData *convert) {
constexpr auto kDefaultPendingTimeout = 60;
return App::webPageSet(
webpage.vid.v,
convert,
QString(),
QString(),
QString(),
QString(),
QString(),
TextWithEntities(),
nullptr,
nullptr,
0,
QString(),
webpage.vdate.v
? webpage.vdate.v
: (unixtime() + kDefaultPendingTimeout));
}
WebPageData *feedWebPage(const MTPWebPage &webpage) {
switch (webpage.type()) {
case mtpc_webPage: return App::feedWebPage(webpage.c_webPage());
case mtpc_webPageEmpty: {
WebPageData *page = App::webPage(webpage.c_webPageEmpty().vid.v);
if (page->pendingTill > 0) page->pendingTill = -1; // failed
return page;
} break;
case mtpc_webPagePending: return App::feedWebPage(webpage.c_webPagePending());
case mtpc_webPageNotModified: LOG(("API Error: webPageNotModified is unexpected in feedWebPage().")); break;
}
return nullptr;
}
WebPageData *feedWebPage(WebPageId webPageId, const QString &siteName, const TextWithEntities &content) {
return App::webPageSet(webPageId, nullptr, qsl("article"), QString(), QString(), siteName, QString(), content, nullptr, nullptr, 0, QString(), 0);
}
GameData *feedGame(const MTPDgame &game, GameData *convert) {
return App::gameSet(game.vid.v, convert, game.vaccess_hash.v, qs(game.vshort_name), qs(game.vtitle), qs(game.vdescription), App::feedPhoto(game.vphoto), game.has_document() ? App::feedDocument(game.vdocument) : nullptr);
}
PeerData *peer(const PeerId &id, PeerData::LoadedStatus restriction) {
if (!id) return nullptr;
@@ -1402,361 +1181,6 @@ namespace {
return nullptr;
}
void updateImage(ImagePtr &old, ImagePtr now) {
if (now->isNull()) return;
if (old->isNull()) {
old = now;
} else if (DelayedStorageImage *img = old->toDelayedStorageImage()) {
StorageImageLocation loc = now->location();
if (!loc.isNull()) {
img->setStorageLocation(loc);
}
}
}
PhotoData *photo(const PhotoId &photo) {
auto i = ::photosData.constFind(photo);
if (i == ::photosData.cend()) {
i = ::photosData.insert(photo, new PhotoData(photo));
}
return i.value();
}
PhotoData *photoSet(
const PhotoId &photo,
PhotoData *convert,
const uint64 &access,
int32 date,
const ImagePtr &thumb,
const ImagePtr &medium,
const ImagePtr &full) {
if (convert) {
if (convert->id != photo) {
const auto i = ::photosData.find(convert->id);
if (i != ::photosData.cend() && i.value() == convert) {
::photosData.erase(i);
}
convert->id = photo;
convert->uploadingData = nullptr;
}
if (date) {
convert->access = access;
convert->date = date;
updateImage(convert->thumb, thumb);
updateImage(convert->medium, medium);
updateImage(convert->full, full);
}
}
const auto i = ::photosData.constFind(photo);
PhotoData *result;
auto inLastIter = lastPhotosMap.end();
if (i == ::photosData.cend()) {
if (convert) {
result = convert;
} else {
result = new PhotoData(photo, access, date, thumb, medium, full);
}
::photosData.insert(photo, result);
} else {
result = i.value();
if (result != convert && date) {
result->access = access;
result->date = date;
updateImage(result->thumb, thumb);
updateImage(result->medium, medium);
updateImage(result->full, full);
}
inLastIter = lastPhotosMap.find(result);
}
if (inLastIter == lastPhotosMap.end()) { // insert new one
if (lastPhotos.size() == MaxPhotosInMemory) {
lastPhotos.front()->forget();
lastPhotosMap.remove(lastPhotos.front());
lastPhotos.pop_front();
}
lastPhotosMap.insert(result, lastPhotos.insert(lastPhotos.end(), result));
} else {
lastPhotos.erase(inLastIter.value()); // move to back
(*inLastIter) = lastPhotos.insert(lastPhotos.end(), result);
}
return result;
}
DocumentData *document(const DocumentId &document) {
auto i = ::documentsData.constFind(document);
if (i == ::documentsData.cend()) {
i = ::documentsData.insert(document, DocumentData::create(document));
}
return i.value();
}
DocumentData *documentSet(
const DocumentId &document,
DocumentData *convert,
const uint64 &access,
int32 version,
int32 date,
const QVector<MTPDocumentAttribute> &attributes,
const QString &mime,
const ImagePtr &thumb,
int32 dc,
int32 size,
const StorageImageLocation &thumbLocation) {
bool versionChanged = false;
bool sentSticker = false;
if (convert) {
const auto oldKey = convert->mediaKey();
const auto idChanged = (convert->id != document);
if (idChanged) {
const auto i = ::documentsData.find(convert->id);
if (i != ::documentsData.cend() && i.value() == convert) {
::documentsData.erase(i);
}
convert->id = document;
convert->status = FileReady;
convert->uploadingData = nullptr;
sentSticker = (convert->sticker() != 0);
}
if (date) {
convert->setattributes(attributes);
versionChanged = convert->setRemoteVersion(version);
convert->setRemoteLocation(dc, access);
convert->date = date;
convert->setMimeString(mime);
if (!thumb->isNull() && (convert->thumb->isNull() || convert->thumb->width() < thumb->width() || convert->thumb->height() < thumb->height() || versionChanged)) {
updateImage(convert->thumb, thumb);
}
convert->size = size;
convert->recountIsImage();
if (convert->sticker() && convert->sticker()->loc.isNull() && !thumbLocation.isNull()) {
convert->sticker()->loc = thumbLocation;
}
const auto newKey = convert->mediaKey();
if (idChanged) {
if (convert->isVoiceMessage()) {
Local::copyAudio(oldKey, newKey);
} else if (convert->sticker() || convert->isAnimation()) {
Local::copyStickerImage(oldKey, newKey);
}
}
}
if (Auth().data().savedGifs().indexOf(convert) >= 0) { // id changed
Local::writeSavedGifs();
}
}
const auto i = ::documentsData.constFind(document);
DocumentData *result;
if (i == ::documentsData.cend()) {
if (convert) {
result = convert;
} else {
result = DocumentData::create(document, dc, access, version, attributes);
result->date = date;
result->setMimeString(mime);
result->thumb = thumb;
result->size = size;
result->recountIsImage();
if (result->sticker()) {
result->sticker()->loc = thumbLocation;
}
}
::documentsData.insert(document, result);
} else {
result = i.value();
if (result != convert && date) {
result->setattributes(attributes);
versionChanged = result->setRemoteVersion(version);
if (!result->isValid()) {
result->setRemoteLocation(dc, access);
}
result->date = date;
result->setMimeString(mime);
if (!thumb->isNull() && (result->thumb->isNull() || result->thumb->width() < thumb->width() || result->thumb->height() < thumb->height() || versionChanged)) {
result->thumb = thumb;
}
result->size = size;
result->recountIsImage();
if (result->sticker() && result->sticker()->loc.isNull() && !thumbLocation.isNull()) {
result->sticker()->loc = thumbLocation;
}
}
}
if (sentSticker && App::main()) {
App::main()->incrementSticker(result);
}
if (versionChanged) {
if (result->sticker() && result->sticker()->set.type() == mtpc_inputStickerSetID) {
auto it = Auth().data().stickerSets().constFind(result->sticker()->set.c_inputStickerSetID().vid.v);
if (it != Auth().data().stickerSets().cend()) {
if (it->id == Stickers::CloudRecentSetId) {
Local::writeRecentStickers();
} else if (it->id == Stickers::FavedSetId) {
Local::writeFavedStickers();
} else if (it->flags & MTPDstickerSet::Flag::f_archived) {
Local::writeArchivedStickers();
} else if (it->flags & MTPDstickerSet::Flag::f_installed) {
Local::writeInstalledStickers();
}
if (it->flags & MTPDstickerSet_ClientFlag::f_featured) {
Local::writeFeaturedStickers();
}
}
}
auto &items = App::documentItems();
auto i = items.constFind(result);
if (i != items.cend()) {
for_const (auto item, i.value()) {
Auth().data().requestItemViewResize(item);
}
}
}
return result;
}
WebPageData *webPage(const WebPageId &webPage) {
auto i = webPagesData.constFind(webPage);
if (i == webPagesData.cend()) {
i = webPagesData.insert(webPage, new WebPageData(webPage));
}
return i.value();
}
WebPageData *webPageSet(
const WebPageId &webPage,
WebPageData *convert,
const QString &type,
const QString &url,
const QString &displayUrl,
const QString &siteName,
const QString &title,
const TextWithEntities &description,
PhotoData *photo,
DocumentData *document,
int duration,
const QString &author,
int pendingTill) {
if (convert) {
if (convert->id != webPage) {
const auto i = webPagesData.find(convert->id);
if (i != webPagesData.cend() && i.value() == convert) {
webPagesData.erase(i);
}
convert->id = webPage;
}
convert->applyChanges(
type,
url,
displayUrl,
siteName,
title,
description,
photo,
document,
duration,
author,
pendingTill);
}
const auto i = webPagesData.constFind(webPage);
WebPageData *result;
if (i == webPagesData.cend()) {
if (convert) {
result = convert;
} else {
result = new WebPageData(
webPage,
toWebPageType(type),
url,
displayUrl,
siteName,
title,
description,
document,
photo,
duration,
author,
(pendingTill >= -1) ? pendingTill : -1);
if (pendingTill > 0) {
Auth().api().requestWebPageDelayed(result);
}
}
webPagesData.insert(webPage, result);
} else {
result = i.value();
if (result != convert) {
result->applyChanges(
type,
url,
displayUrl,
siteName,
title,
description,
photo,
document,
duration,
author,
pendingTill);
}
}
return result;
}
GameData *game(const GameId &game) {
auto i = gamesData.constFind(game);
if (i == gamesData.cend()) {
i = gamesData.insert(game, new GameData(game));
}
return i.value();
}
GameData *gameSet(const GameId &game, GameData *convert, const uint64 &accessHash, const QString &shortName, const QString &title, const QString &description, PhotoData *photo, DocumentData *document) {
if (convert) {
if (convert->id != game) {
auto i = gamesData.find(convert->id);
if (i != gamesData.cend() && i.value() == convert) {
gamesData.erase(i);
}
convert->id = game;
convert->accessHash = 0;
}
if (!convert->accessHash && accessHash) {
convert->accessHash = accessHash;
convert->shortName = TextUtilities::Clean(shortName);
convert->title = TextUtilities::SingleLine(title);
convert->description = TextUtilities::Clean(description);
convert->photo = photo;
convert->document = document;
if (App::main()) App::main()->gameUpdated(convert);
}
}
auto i = gamesData.constFind(game);
GameData *result;
if (i == gamesData.cend()) {
if (convert) {
result = convert;
} else {
result = new GameData(game, accessHash, shortName, title, description, photo, document);
}
gamesData.insert(game, result);
} else {
result = i.value();
if (result != convert) {
if (!result->accessHash && accessHash) {
result->accessHash = accessHash;
result->shortName = TextUtilities::Clean(shortName);
result->title = TextUtilities::SingleLine(title);
result->description = TextUtilities::Clean(description);
result->photo = photo;
result->document = document;
if (App::main()) App::main()->gameUpdated(result);
}
}
}
return result;
}
LocationData *location(const LocationCoords &coords) {
auto i = locationsData.constFind(coords);
if (i == locationsData.cend()) {
@@ -1766,14 +1190,6 @@ namespace {
}
void forgetMedia() {
lastPhotos.clear();
lastPhotosMap.clear();
for_const (auto photo, ::photosData) {
photo->forget();
}
for_const (auto document, ::documentsData) {
document->forget();
}
for_const (auto location, ::locationsData) {
location->thumb->forget();
}
@@ -1914,22 +1330,6 @@ namespace {
delete peer;
}
::peersData.clear();
for_const (auto game, ::gamesData) {
delete game;
}
::gamesData.clear();
for_const (auto webpage, ::webPagesData) {
delete webpage;
}
::webPagesData.clear();
for_const (auto photo, ::photosData) {
delete photo;
}
::photosData.clear();
for_const (auto document, ::documentsData) {
delete document;
}
::documentsData.clear();
if (AuthSession::Exists()) {
Auth().api().clearWebPageRequests();
@@ -1939,14 +1339,6 @@ namespace {
cSetAutoDownloadPhoto(0);
cSetAutoDownloadAudio(0);
cSetAutoDownloadGif(0);
::photoItems.clear();
::documentItems.clear();
::webPageItems.clear();
::gameItems.clear();
::sharedContactItems.clear();
::gifItems.clear();
lastPhotos.clear();
lastPhotosMap.clear();
::self = nullptr;
Global::RefSelfChanged().notify(true);
}
@@ -2367,118 +1759,6 @@ namespace {
return QPixmap::fromImage(std::move(image), Qt::ColorOnly);
}
void regPhotoItem(PhotoData *data, HistoryItem *item) {
::photoItems[data].insert(item);
}
void unregPhotoItem(PhotoData *data, HistoryItem *item) {
::photoItems[data].remove(item);
}
const PhotoItems &photoItems() {
return ::photoItems;
}
const PhotosData &photosData() {
return ::photosData;
}
void regDocumentItem(DocumentData *data, HistoryItem *item) {
::documentItems[data].insert(item);
}
void unregDocumentItem(DocumentData *data, HistoryItem *item) {
::documentItems[data].remove(item);
}
const DocumentItems &documentItems() {
return ::documentItems;
}
const DocumentsData &documentsData() {
return ::documentsData;
}
void regWebPageItem(WebPageData *data, HistoryItem *item) {
::webPageItems[data].insert(item);
}
void unregWebPageItem(WebPageData *data, HistoryItem *item) {
::webPageItems[data].remove(item);
}
const WebPageItems &webPageItems() {
return ::webPageItems;
}
void regGameItem(GameData *data, HistoryItem *item) {
::gameItems[data].insert(item);
}
void unregGameItem(GameData *data, HistoryItem *item) {
::gameItems[data].remove(item);
}
const GameItems &gameItems() {
return ::gameItems;
}
void regSharedContactItem(int32 userId, HistoryItem *item) {
auto user = App::userLoaded(userId);
auto canShareThisContact = user ? user->canShareThisContact() : false;
::sharedContactItems[userId].insert(item);
if (canShareThisContact != (user ? user->canShareThisContact() : false)) {
Notify::peerUpdatedDelayed(user, Notify::PeerUpdate::Flag::UserCanShareContact);
}
}
void unregSharedContactItem(int32 userId, HistoryItem *item) {
auto user = App::userLoaded(userId);
auto canShareThisContact = user ? user->canShareThisContact() : false;
::sharedContactItems[userId].remove(item);
if (canShareThisContact != (user ? user->canShareThisContact() : false)) {
Notify::peerUpdatedDelayed(user, Notify::PeerUpdate::Flag::UserCanShareContact);
}
}
const SharedContactItems &sharedContactItems() {
return ::sharedContactItems;
}
void regGifItem(Media::Clip::Reader *reader, HistoryItem *item) {
::gifItems.insert(reader, item);
}
void unregGifItem(Media::Clip::Reader *reader) {
::gifItems.remove(reader);
}
void stopGifItems() {
if (!::gifItems.isEmpty()) {
auto gifs = ::gifItems;
for_const (auto item, gifs) {
// #TODO GIFs
//if (auto media = item->getMedia()) {
// if (!media->isRoundVideoPlaying()) {
// media->stopInline();
// }
//}
}
}
}
QString phoneFromSharedContact(int32 userId) {
auto i = ::sharedContactItems.constFind(userId);
if (i != ::sharedContactItems.cend() && !i->empty()) {
if (const auto media = (*i->cbegin())->media()) {
if (const auto contact = media->sharedContact()) {
return contact->phoneNumber;
}
}
}
return QString();
}
void regMuted(not_null<PeerData*> peer, TimeMs changeIn) {
::mutedPeers.insert(peer, true);
App::main()->updateMutedIn(changeIn);