mirror of https://github.com/procxx/kepka.git
Refactor userpic storage and access in PeerData.
This commit is contained in:
parent
62568daffe
commit
68009b6fba
|
@ -320,15 +320,7 @@ void ApiWrap::gotChatFull(PeerData *peer, const MTPmessages_ChatFull &result, mt
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto newPhotoId = PhotoId(0);
|
chat->setUserpicPhoto(f.vchat_photo);
|
||||||
if (auto photo = App::feedPhoto(f.vchat_photo)) {
|
|
||||||
newPhotoId = photo->id;
|
|
||||||
photo->peer = chat;
|
|
||||||
}
|
|
||||||
if (chat->photoId != newPhotoId) {
|
|
||||||
chat->photoId = newPhotoId;
|
|
||||||
Notify::peerUpdatedDelayed(chat, UpdateFlag::PhotoChanged);
|
|
||||||
}
|
|
||||||
chat->setInviteLink((f.vexported_invite.type() == mtpc_chatInviteExported) ? qs(f.vexported_invite.c_chatInviteExported().vlink) : QString());
|
chat->setInviteLink((f.vexported_invite.type() == mtpc_chatInviteExported) ? qs(f.vexported_invite.c_chatInviteExported().vlink) : QString());
|
||||||
chat->fullUpdated();
|
chat->fullUpdated();
|
||||||
|
|
||||||
|
@ -345,15 +337,7 @@ void ApiWrap::gotChatFull(PeerData *peer, const MTPmessages_ChatFull &result, mt
|
||||||
auto canEditStickers = channel->canEditStickers();
|
auto canEditStickers = channel->canEditStickers();
|
||||||
|
|
||||||
channel->setFullFlags(f.vflags.v);
|
channel->setFullFlags(f.vflags.v);
|
||||||
auto newPhotoId = PhotoId(0);
|
channel->setUserpicPhoto(f.vchat_photo);
|
||||||
if (auto photo = App::feedPhoto(f.vchat_photo)) {
|
|
||||||
newPhotoId = photo->id;
|
|
||||||
photo->peer = channel;
|
|
||||||
}
|
|
||||||
if (channel->photoId != newPhotoId) {
|
|
||||||
channel->photoId = newPhotoId;
|
|
||||||
Notify::peerUpdatedDelayed(channel, UpdateFlag::PhotoChanged);
|
|
||||||
}
|
|
||||||
if (f.has_migrated_from_chat_id()) {
|
if (f.has_migrated_from_chat_id()) {
|
||||||
channel->addFlags(MTPDchannel::Flag::f_megagroup);
|
channel->addFlags(MTPDchannel::Flag::f_megagroup);
|
||||||
auto cfrom = App::chat(peerFromChat(f.vmigrated_from_chat_id));
|
auto cfrom = App::chat(peerFromChat(f.vmigrated_from_chat_id));
|
||||||
|
|
|
@ -1159,28 +1159,6 @@ namespace {
|
||||||
return ImagePtr();
|
return ImagePtr();
|
||||||
}
|
}
|
||||||
|
|
||||||
StorageImageLocation imageLocation(int32 w, int32 h, const MTPFileLocation &loc) {
|
|
||||||
if (loc.type() == mtpc_fileLocation) {
|
|
||||||
const auto &l(loc.c_fileLocation());
|
|
||||||
return StorageImageLocation(w, h, l.vdc_id.v, l.vvolume_id.v, l.vlocal_id.v, l.vsecret.v);
|
|
||||||
}
|
|
||||||
return StorageImageLocation(w, h, 0, 0, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
StorageImageLocation imageLocation(const MTPPhotoSize &size) {
|
|
||||||
switch (size.type()) {
|
|
||||||
case mtpc_photoSize: {
|
|
||||||
const auto &d(size.c_photoSize());
|
|
||||||
return imageLocation(d.vw.v, d.vh.v, d.vlocation);
|
|
||||||
} break;
|
|
||||||
case mtpc_photoCachedSize: {
|
|
||||||
const auto &d(size.c_photoCachedSize());
|
|
||||||
return imageLocation(d.vw.v, d.vh.v, d.vlocation);
|
|
||||||
} break;
|
|
||||||
}
|
|
||||||
return StorageImageLocation();
|
|
||||||
}
|
|
||||||
|
|
||||||
void feedInboxRead(const PeerId &peer, MsgId upTo) {
|
void feedInboxRead(const PeerId &peer, MsgId upTo) {
|
||||||
if (auto history = App::historyLoaded(peer)) {
|
if (auto history = App::historyLoaded(peer)) {
|
||||||
history->inboxRead(upTo);
|
history->inboxRead(upTo);
|
||||||
|
@ -1418,7 +1396,18 @@ namespace {
|
||||||
}
|
}
|
||||||
|
|
||||||
DocumentData *feedDocument(const MTPDdocument &document, DocumentData *convert) {
|
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, App::imageLocation(document.vthumb));
|
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) {
|
WebPageData *feedWebPage(const MTPDwebPage &webpage, WebPageData *convert) {
|
||||||
|
|
|
@ -82,8 +82,6 @@ namespace App {
|
||||||
void feedUserLink(MTPint userId, const MTPContactLink &myLink, const MTPContactLink &foreignLink);
|
void feedUserLink(MTPint userId, const MTPContactLink &myLink, const MTPContactLink &foreignLink);
|
||||||
|
|
||||||
ImagePtr image(const MTPPhotoSize &size);
|
ImagePtr image(const MTPPhotoSize &size);
|
||||||
StorageImageLocation imageLocation(int32 w, int32 h, const MTPFileLocation &loc);
|
|
||||||
StorageImageLocation imageLocation(const MTPPhotoSize &size);
|
|
||||||
|
|
||||||
PhotoData *feedPhoto(const MTPPhoto &photo, const PreparedPhotoThumbs &thumbs);
|
PhotoData *feedPhoto(const MTPPhoto &photo, const PreparedPhotoThumbs &thumbs);
|
||||||
PhotoData *feedPhoto(const MTPPhoto &photo, PhotoData *convert = nullptr);
|
PhotoData *feedPhoto(const MTPPhoto &photo, PhotoData *convert = nullptr);
|
||||||
|
|
|
@ -628,8 +628,12 @@ ConfirmInviteBox::ConfirmInviteBox(QWidget*, const QString &title, bool isChanne
|
||||||
}
|
}
|
||||||
_status->setText(status);
|
_status->setText(status);
|
||||||
if (photo.type() == mtpc_chatPhoto) {
|
if (photo.type() == mtpc_chatPhoto) {
|
||||||
auto &d = photo.c_chatPhoto();
|
const auto &data = photo.c_chatPhoto();
|
||||||
auto location = App::imageLocation(160, 160, d.vphoto_small);
|
const auto size = 160;
|
||||||
|
const auto location = StorageImageLocation::FromMTP(
|
||||||
|
size,
|
||||||
|
size,
|
||||||
|
data.vphoto_small);
|
||||||
if (!location.isNull()) {
|
if (!location.isNull()) {
|
||||||
_photo = ImagePtr(location);
|
_photo = ImagePtr(location);
|
||||||
if (!_photo->loaded()) {
|
if (!_photo->loaded()) {
|
||||||
|
|
|
@ -436,20 +436,26 @@ void Panel::processUserPhoto() {
|
||||||
if (!_user->userpicLoaded()) {
|
if (!_user->userpicLoaded()) {
|
||||||
_user->loadUserpic(true);
|
_user->loadUserpic(true);
|
||||||
}
|
}
|
||||||
auto photo = (_user->photoId && _user->photoId != UnknownPeerPhotoId) ? App::photo(_user->photoId) : nullptr;
|
const auto photo = _user->userpicPhotoId()
|
||||||
|
? App::photo(_user->userpicPhotoId())
|
||||||
|
: nullptr;
|
||||||
if (isGoodUserPhoto(photo)) {
|
if (isGoodUserPhoto(photo)) {
|
||||||
photo->full->load(true);
|
photo->full->load(true);
|
||||||
} else {
|
} else if (_user->userpicPhotoUnknown() || (photo && !photo->date)) {
|
||||||
if ((_user->photoId == UnknownPeerPhotoId) || (_user->photoId && (!photo || !photo->date))) {
|
Auth().api().requestFullPeer(_user);
|
||||||
Auth().api().requestFullPeer(_user);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
refreshUserPhoto();
|
refreshUserPhoto();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Panel::refreshUserPhoto() {
|
void Panel::refreshUserPhoto() {
|
||||||
auto photo = (_user->photoId && _user->photoId != UnknownPeerPhotoId) ? App::photo(_user->photoId) : nullptr;
|
const auto photo = _user->userpicPhotoId()
|
||||||
if (isGoodUserPhoto(photo) && photo->full->loaded() && (photo->id != _userPhotoId || !_userPhotoFull)) {
|
? App::photo(_user->userpicPhotoId())
|
||||||
|
: nullptr;
|
||||||
|
const auto isNewPhoto = [&](not_null<PhotoData*> photo) {
|
||||||
|
return photo->full->loaded()
|
||||||
|
&& (photo->id != _userPhotoId || !_userPhotoFull);
|
||||||
|
};
|
||||||
|
if (isGoodUserPhoto(photo) && isNewPhoto(photo)) {
|
||||||
_userPhotoId = photo->id;
|
_userPhotoId = photo->id;
|
||||||
_userPhotoFull = true;
|
_userPhotoFull = true;
|
||||||
createUserpicCache(photo->full);
|
createUserpicCache(photo->full);
|
||||||
|
|
|
@ -24,6 +24,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||||
#include <rpl/map.h>
|
#include <rpl/map.h>
|
||||||
#include "data/data_peer_values.h"
|
#include "data/data_peer_values.h"
|
||||||
#include "data/data_channel_admins.h"
|
#include "data/data_channel_admins.h"
|
||||||
|
#include "data/data_photo.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "observer_peer.h"
|
#include "observer_peer.h"
|
||||||
#include "mainwidget.h"
|
#include "mainwidget.h"
|
||||||
|
@ -38,6 +39,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr auto kUpdateFullPeerTimeout = TimeMs(5000); // Not more than once in 5 seconds.
|
constexpr auto kUpdateFullPeerTimeout = TimeMs(5000); // Not more than once in 5 seconds.
|
||||||
|
constexpr auto kUserpicSize = 160;
|
||||||
|
|
||||||
int peerColorIndex(const PeerId &peer) {
|
int peerColorIndex(const PeerId &peer) {
|
||||||
auto myId = Auth().userId();
|
auto myId = Auth().userId();
|
||||||
|
@ -347,8 +349,10 @@ ClickHandlerPtr PeerData::createOpenLink() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerData::setUserpic(
|
void PeerData::setUserpic(
|
||||||
ImagePtr userpic,
|
PhotoId photoId,
|
||||||
StorageImageLocation location) {
|
const StorageImageLocation &location,
|
||||||
|
ImagePtr userpic) {
|
||||||
|
_userpicPhotoId = photoId;
|
||||||
_userpic = userpic;
|
_userpic = userpic;
|
||||||
_userpicLocation = location;
|
_userpicLocation = location;
|
||||||
if (useEmptyUserpic()) {
|
if (useEmptyUserpic()) {
|
||||||
|
@ -358,6 +362,20 @@ void PeerData::setUserpic(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PeerData::setUserpicPhoto(const MTPPhoto &data) {
|
||||||
|
auto photoId = [&]() -> PhotoId {
|
||||||
|
if (auto photo = App::feedPhoto(data)) {
|
||||||
|
photo->peer = this;
|
||||||
|
return photo->id;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}();
|
||||||
|
if (_userpicPhotoId != photoId) {
|
||||||
|
_userpicPhotoId = photoId;
|
||||||
|
Notify::peerUpdatedDelayed(this, UpdateFlag::PhotoChanged);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ImagePtr PeerData::currentUserpic() const {
|
ImagePtr PeerData::currentUserpic() const {
|
||||||
if (_userpic) {
|
if (_userpic) {
|
||||||
_userpic->load();
|
_userpic->load();
|
||||||
|
@ -449,38 +467,47 @@ bool UserData::canShareThisContact() const {
|
||||||
return canShareThisContactFast() || !App::phoneFromSharedContact(peerToUser(id)).isEmpty();
|
return canShareThisContactFast() || !App::phoneFromSharedContact(peerToUser(id)).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserData::setPhoto(const MTPUserProfilePhoto &p) { // see Local::readPeer as well
|
void PeerData::updateUserpic(
|
||||||
auto newPhotoId = photoId;
|
PhotoId photoId,
|
||||||
auto newPhoto = _userpic;
|
const MTPFileLocation &location) {
|
||||||
auto newPhotoLoc = _userpicLocation;
|
const auto size = kUserpicSize;
|
||||||
|
const auto loc = StorageImageLocation::FromMTP(size, size, location);
|
||||||
switch (p.type()) {
|
const auto photo = loc.isNull() ? ImagePtr() : ImagePtr(loc);
|
||||||
case mtpc_userProfilePhoto: {
|
if (_userpicPhotoId != photoId
|
||||||
const auto &d(p.c_userProfilePhoto());
|
|| _userpic.v() != photo.v()
|
||||||
newPhotoId = d.vphoto_id.v;
|
|| _userpicLocation != loc) {
|
||||||
newPhotoLoc = App::imageLocation(160, 160, d.vphoto_small);
|
setUserpic(photoId, loc, photo);
|
||||||
newPhoto = newPhotoLoc.isNull() ? ImagePtr() : ImagePtr(newPhotoLoc);
|
|
||||||
//App::feedPhoto(App::photoFromUserPhoto(peerToUser(id), MTP_int(unixtime()), p));
|
|
||||||
} break;
|
|
||||||
default: {
|
|
||||||
newPhotoId = 0;
|
|
||||||
if (id == ServiceUserId) {
|
|
||||||
if (!_userpic) {
|
|
||||||
newPhoto = ImagePtr(App::pixmapFromImageInPlace(Messenger::Instance().logoNoMargin().scaledToWidth(160, Qt::SmoothTransformation)), "PNG");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
newPhoto = ImagePtr();
|
|
||||||
}
|
|
||||||
newPhotoLoc = StorageImageLocation();
|
|
||||||
} break;
|
|
||||||
}
|
|
||||||
if (newPhotoId != photoId || newPhoto.v() != _userpic.v() || newPhotoLoc != _userpicLocation) {
|
|
||||||
photoId = newPhotoId;
|
|
||||||
setUserpic(newPhoto, newPhotoLoc);
|
|
||||||
Notify::peerUpdatedDelayed(this, UpdateFlag::PhotoChanged);
|
Notify::peerUpdatedDelayed(this, UpdateFlag::PhotoChanged);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PeerData::clearUserpic() {
|
||||||
|
const auto photoId = PhotoId(0);
|
||||||
|
const auto loc = StorageImageLocation();
|
||||||
|
const auto photo = [&] {
|
||||||
|
if (id == peerFromUser(ServiceUserId)) {
|
||||||
|
auto image = Messenger::Instance().logoNoMargin().scaledToWidth(
|
||||||
|
kUserpicSize,
|
||||||
|
Qt::SmoothTransformation);
|
||||||
|
auto pixmap = App::pixmapFromImageInPlace(std::move(image));
|
||||||
|
return _userpic
|
||||||
|
? _userpic
|
||||||
|
: ImagePtr(std::move(pixmap), "PNG");
|
||||||
|
}
|
||||||
|
return ImagePtr();
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
|
||||||
|
// see Local::readPeer as well
|
||||||
|
void UserData::setPhoto(const MTPUserProfilePhoto &photo) {
|
||||||
|
if (photo.type() == mtpc_userProfilePhoto) {
|
||||||
|
const auto &data = photo.c_userProfilePhoto();
|
||||||
|
updateUserpic(data.vphoto_id.v, data.vphoto_small);
|
||||||
|
} else {
|
||||||
|
clearUserpic();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PeerData::fillNames() {
|
void PeerData::fillNames() {
|
||||||
_nameWords.clear();
|
_nameWords.clear();
|
||||||
_nameFirstChars.clear();
|
_nameFirstChars.clear();
|
||||||
|
@ -668,32 +695,16 @@ bool UserData::hasCalls() const {
|
||||||
return (callsStatus() != CallsStatus::Disabled) && (callsStatus() != CallsStatus::Unknown);
|
return (callsStatus() != CallsStatus::Disabled) && (callsStatus() != CallsStatus::Unknown);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatData::setPhoto(const MTPChatPhoto &p, const PhotoId &phId) { // see Local::readPeer as well
|
void ChatData::setPhoto(const MTPChatPhoto &photo) {
|
||||||
auto newPhotoId = photoId;
|
setPhoto(userpicPhotoId(), photo);
|
||||||
auto newPhoto = _userpic;
|
}
|
||||||
auto newPhotoLoc = _userpicLocation;
|
|
||||||
|
|
||||||
switch (p.type()) {
|
void ChatData::setPhoto(PhotoId photoId, const MTPChatPhoto &photo) {
|
||||||
case mtpc_chatPhoto: {
|
if (photo.type() == mtpc_chatPhoto) {
|
||||||
auto &d = p.c_chatPhoto();
|
const auto &data = photo.c_chatPhoto();
|
||||||
if (phId != UnknownPeerPhotoId) {
|
updateUserpic(photoId, data.vphoto_small);
|
||||||
newPhotoId = phId;
|
} else {
|
||||||
}
|
clearUserpic();
|
||||||
newPhotoLoc = App::imageLocation(160, 160, d.vphoto_small);
|
|
||||||
newPhoto = newPhotoLoc.isNull() ? ImagePtr() : ImagePtr(newPhotoLoc);
|
|
||||||
// photoFull = newPhoto ? ImagePtr(640, 640, d.vphoto_big, ImagePtr()) : ImagePtr();
|
|
||||||
} break;
|
|
||||||
default: {
|
|
||||||
newPhotoId = 0;
|
|
||||||
newPhotoLoc = StorageImageLocation();
|
|
||||||
newPhoto = ImagePtr();
|
|
||||||
// photoFull = ImagePtr();
|
|
||||||
} break;
|
|
||||||
}
|
|
||||||
if (newPhotoId != photoId || newPhoto.v() != _userpic.v() || newPhotoLoc != _userpicLocation) {
|
|
||||||
photoId = newPhotoId;
|
|
||||||
setUserpic(newPhoto, newPhotoLoc);
|
|
||||||
Notify::peerUpdatedDelayed(this, UpdateFlag::PhotoChanged);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -736,32 +747,16 @@ ChannelData::ChannelData(const PeerId &id)
|
||||||
}, _lifetime);
|
}, _lifetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChannelData::setPhoto(const MTPChatPhoto &p, const PhotoId &phId) { // see Local::readPeer as well
|
void ChannelData::setPhoto(const MTPChatPhoto &photo) {
|
||||||
auto newPhotoId = photoId;
|
setPhoto(userpicPhotoId(), photo);
|
||||||
auto newPhoto = _userpic;
|
}
|
||||||
auto newPhotoLoc = _userpicLocation;
|
|
||||||
|
|
||||||
switch (p.type()) {
|
void ChannelData::setPhoto(PhotoId photoId, const MTPChatPhoto &photo) {
|
||||||
case mtpc_chatPhoto: {
|
if (photo.type() == mtpc_chatPhoto) {
|
||||||
auto &d = p.c_chatPhoto();
|
const auto &data = photo.c_chatPhoto();
|
||||||
if (phId != UnknownPeerPhotoId) {
|
updateUserpic(photoId, data.vphoto_small);
|
||||||
newPhotoId = phId;
|
} else {
|
||||||
}
|
clearUserpic();
|
||||||
newPhotoLoc = App::imageLocation(160, 160, d.vphoto_small);
|
|
||||||
newPhoto = newPhotoLoc.isNull() ? ImagePtr() : ImagePtr(newPhotoLoc);
|
|
||||||
// photoFull = newPhoto ? ImagePtr(640, 640, d.vphoto_big, newPhoto) : ImagePtr();
|
|
||||||
} break;
|
|
||||||
default: {
|
|
||||||
newPhotoId = 0;
|
|
||||||
newPhotoLoc = StorageImageLocation();
|
|
||||||
newPhoto = ImagePtr();
|
|
||||||
// photoFull = ImagePtr();
|
|
||||||
} break;
|
|
||||||
}
|
|
||||||
if (newPhotoId != photoId || newPhoto.v() != _userpic.v() || newPhotoLoc != _userpicLocation) {
|
|
||||||
photoId = newPhotoId;
|
|
||||||
setUserpic(newPhoto, newPhotoLoc);
|
|
||||||
Notify::peerUpdatedDelayed(this, UpdateFlag::PhotoChanged);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,8 +70,6 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const PhotoId UnknownPeerPhotoId = 0xFFFFFFFFFFFFFFFFULL;
|
|
||||||
|
|
||||||
class PeerData;
|
class PeerData;
|
||||||
|
|
||||||
class PeerClickHandler : public ClickHandler {
|
class PeerClickHandler : public ClickHandler {
|
||||||
|
@ -190,7 +188,11 @@ public:
|
||||||
LoadedStatus loadedStatus = NotLoaded;
|
LoadedStatus loadedStatus = NotLoaded;
|
||||||
MTPinputPeer input;
|
MTPinputPeer input;
|
||||||
|
|
||||||
void setUserpic(ImagePtr userpic, StorageImageLocation location);
|
void setUserpic(
|
||||||
|
PhotoId photoId,
|
||||||
|
const StorageImageLocation &location,
|
||||||
|
ImagePtr userpic);
|
||||||
|
void setUserpicPhoto(const MTPPhoto &data);
|
||||||
void paintUserpic(
|
void paintUserpic(
|
||||||
Painter &p,
|
Painter &p,
|
||||||
int x,
|
int x,
|
||||||
|
@ -233,8 +235,12 @@ public:
|
||||||
StorageImageLocation userpicLocation() const {
|
StorageImageLocation userpicLocation() const {
|
||||||
return _userpicLocation;
|
return _userpicLocation;
|
||||||
}
|
}
|
||||||
|
bool userpicPhotoUnknown() const {
|
||||||
PhotoId photoId = UnknownPeerPhotoId;
|
return (_userpicPhotoId == kUnknownPhotoId);
|
||||||
|
}
|
||||||
|
PhotoId userpicPhotoId() const {
|
||||||
|
return userpicPhotoUnknown() ? 0 : _userpicPhotoId;
|
||||||
|
}
|
||||||
|
|
||||||
int nameVersion = 1;
|
int nameVersion = 1;
|
||||||
|
|
||||||
|
@ -259,14 +265,19 @@ protected:
|
||||||
const QString &newName,
|
const QString &newName,
|
||||||
const QString &newNameOrPhone,
|
const QString &newNameOrPhone,
|
||||||
const QString &newUsername);
|
const QString &newUsername);
|
||||||
|
void updateUserpic(PhotoId photoId, const MTPFileLocation &location);
|
||||||
ImagePtr _userpic;
|
void clearUserpic();
|
||||||
mutable EmptyUserpic _userpicEmpty;
|
|
||||||
StorageImageLocation _userpicLocation;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void fillNames();
|
void fillNames();
|
||||||
|
|
||||||
|
static constexpr auto kUnknownPhotoId = PhotoId(0xFFFFFFFFFFFFFFFFULL);
|
||||||
|
|
||||||
|
ImagePtr _userpic;
|
||||||
|
PhotoId _userpicPhotoId = kUnknownPhotoId;
|
||||||
|
mutable EmptyUserpic _userpicEmpty;
|
||||||
|
StorageImageLocation _userpicLocation;
|
||||||
|
|
||||||
Data::NotifySettings _notify;
|
Data::NotifySettings _notify;
|
||||||
|
|
||||||
ClickHandlerPtr _openLink;
|
ClickHandlerPtr _openLink;
|
||||||
|
@ -519,9 +530,8 @@ public:
|
||||||
: PeerData(id)
|
: PeerData(id)
|
||||||
, inputChat(MTP_int(bareId())) {
|
, inputChat(MTP_int(bareId())) {
|
||||||
}
|
}
|
||||||
void setPhoto(
|
void setPhoto(const MTPChatPhoto &photo);
|
||||||
const MTPChatPhoto &photo,
|
void setPhoto(PhotoId photoId, const MTPChatPhoto &photo);
|
||||||
const PhotoId &phId = UnknownPeerPhotoId);
|
|
||||||
|
|
||||||
void setName(const QString &newName);
|
void setName(const QString &newName);
|
||||||
|
|
||||||
|
@ -768,9 +778,8 @@ public:
|
||||||
|
|
||||||
ChannelData(const PeerId &id);
|
ChannelData(const PeerId &id);
|
||||||
|
|
||||||
void setPhoto(
|
void setPhoto(const MTPChatPhoto &photo);
|
||||||
const MTPChatPhoto &photo,
|
void setPhoto(PhotoId photoId, const MTPChatPhoto &photo);
|
||||||
const PhotoId &phId = UnknownPeerPhotoId);
|
|
||||||
|
|
||||||
void setName(const QString &name, const QString &username);
|
void setName(const QString &name, const QString &username);
|
||||||
|
|
||||||
|
|
|
@ -231,7 +231,8 @@ base::optional<int> SharedMediaWithLastSlice::indexOfImpl(Value value) const {
|
||||||
return base::get_if<FullMsgId>(&value)
|
return base::get_if<FullMsgId>(&value)
|
||||||
? _slice.indexOf(*base::get_if<FullMsgId>(&value))
|
? _slice.indexOf(*base::get_if<FullMsgId>(&value))
|
||||||
: (isolatedInSlice()
|
: (isolatedInSlice()
|
||||||
|| (*base::get_if<not_null<PhotoData*>>(&value))->id != _lastPhotoId)
|
|| !_lastPhotoId
|
||||||
|
|| (*base::get_if<not_null<PhotoData*>>(&value))->id != *_lastPhotoId)
|
||||||
? base::none
|
? base::none
|
||||||
: Add(_slice.size() - 1, lastPhotoSkip());
|
: Add(_slice.size() - 1, lastPhotoSkip());
|
||||||
}
|
}
|
||||||
|
@ -256,7 +257,7 @@ SharedMediaWithLastSlice::Value SharedMediaWithLastSlice::operator[](int index)
|
||||||
}
|
}
|
||||||
return (index < _slice.size())
|
return (index < _slice.size())
|
||||||
? Value(_slice[index])
|
? Value(_slice[index])
|
||||||
: Value(App::photo(_lastPhotoId));
|
: Value(App::photo(*_lastPhotoId));
|
||||||
}
|
}
|
||||||
|
|
||||||
base::optional<int> SharedMediaWithLastSlice::distance(
|
base::optional<int> SharedMediaWithLastSlice::distance(
|
||||||
|
@ -274,20 +275,23 @@ void SharedMediaWithLastSlice::reverse() {
|
||||||
_reversed = !_reversed;
|
_reversed = !_reversed;
|
||||||
}
|
}
|
||||||
|
|
||||||
PhotoId SharedMediaWithLastSlice::LastPeerPhotoId(PeerId peerId) {
|
base::optional<PhotoId> SharedMediaWithLastSlice::LastPeerPhotoId(
|
||||||
|
PeerId peerId) {
|
||||||
if (auto peer = App::peerLoaded(peerId)) {
|
if (auto peer = App::peerLoaded(peerId)) {
|
||||||
return peer->photoId;
|
return peer->userpicPhotoUnknown()
|
||||||
|
? base::none
|
||||||
|
: base::make_optional(peer->userpicPhotoId());
|
||||||
}
|
}
|
||||||
return UnknownPeerPhotoId;
|
return base::none;
|
||||||
}
|
}
|
||||||
|
|
||||||
base::optional<bool> SharedMediaWithLastSlice::IsLastIsolated(
|
base::optional<bool> SharedMediaWithLastSlice::IsLastIsolated(
|
||||||
const SparseIdsMergedSlice &slice,
|
const SparseIdsMergedSlice &slice,
|
||||||
const base::optional<SparseIdsMergedSlice> &ending,
|
const base::optional<SparseIdsMergedSlice> &ending,
|
||||||
PhotoId lastPeerPhotoId) {
|
base::optional<PhotoId> lastPeerPhotoId) {
|
||||||
if (lastPeerPhotoId == UnknownPeerPhotoId) {
|
if (!lastPeerPhotoId) {
|
||||||
return base::none;
|
return base::none;
|
||||||
} else if (!lastPeerPhotoId) {
|
} else if (!*lastPeerPhotoId) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return LastFullMsgId(ending ? *ending : slice)
|
return LastFullMsgId(ending ? *ending : slice)
|
||||||
|
@ -299,7 +303,7 @@ base::optional<bool> SharedMediaWithLastSlice::IsLastIsolated(
|
||||||
: nullptr;
|
: nullptr;
|
||||||
}
|
}
|
||||||
| [](PhotoData *photo) { return photo ? photo->id : 0; }
|
| [](PhotoData *photo) { return photo ? photo->id : 0; }
|
||||||
| [&](PhotoId photoId) { return lastPeerPhotoId != photoId; };
|
| [&](PhotoId photoId) { return *lastPeerPhotoId != photoId; };
|
||||||
}
|
}
|
||||||
|
|
||||||
base::optional<FullMsgId> SharedMediaWithLastSlice::LastFullMsgId(
|
base::optional<FullMsgId> SharedMediaWithLastSlice::LastFullMsgId(
|
||||||
|
|
|
@ -142,11 +142,11 @@ private:
|
||||||
: base::none;
|
: base::none;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PhotoId LastPeerPhotoId(PeerId peerId);
|
static base::optional<PhotoId> LastPeerPhotoId(PeerId peerId);
|
||||||
static base::optional<bool> IsLastIsolated(
|
static base::optional<bool> IsLastIsolated(
|
||||||
const SparseIdsMergedSlice &slice,
|
const SparseIdsMergedSlice &slice,
|
||||||
const base::optional<SparseIdsMergedSlice> &ending,
|
const base::optional<SparseIdsMergedSlice> &ending,
|
||||||
PhotoId lastPeerPhotoId);
|
base::optional<PhotoId> lastPeerPhotoId);
|
||||||
static base::optional<FullMsgId> LastFullMsgId(
|
static base::optional<FullMsgId> LastFullMsgId(
|
||||||
const SparseIdsMergedSlice &slice);
|
const SparseIdsMergedSlice &slice);
|
||||||
static base::optional<int> Add(
|
static base::optional<int> Add(
|
||||||
|
@ -183,7 +183,7 @@ private:
|
||||||
Key _key;
|
Key _key;
|
||||||
SparseIdsMergedSlice _slice;
|
SparseIdsMergedSlice _slice;
|
||||||
base::optional<SparseIdsMergedSlice> _ending;
|
base::optional<SparseIdsMergedSlice> _ending;
|
||||||
PhotoId _lastPhotoId = 0;
|
base::optional<PhotoId> _lastPhotoId;
|
||||||
base::optional<bool> _isolatedLastPhoto;
|
base::optional<bool> _isolatedLastPhoto;
|
||||||
bool _reversed = false;
|
bool _reversed = false;
|
||||||
|
|
||||||
|
|
|
@ -984,8 +984,9 @@ HistoryItem *History::createItem(const MTPMessage &msg, bool applyServiceAction,
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case mtpc_messageActionChatDeletePhoto: {
|
case mtpc_messageActionChatDeletePhoto: {
|
||||||
auto chat = peer->asChat();
|
if (const auto chat = peer->asChat()) {
|
||||||
if (chat) chat->setPhoto(MTP_chatPhotoEmpty());
|
chat->setPhoto(MTP_chatPhotoEmpty());
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case mtpc_messageActionChatDeleteUser: {
|
case mtpc_messageActionChatDeleteUser: {
|
||||||
|
@ -1048,10 +1049,11 @@ HistoryItem *History::createItem(const MTPMessage &msg, bool applyServiceAction,
|
||||||
case mtpc_photoCachedSize: bigLoc = &bigSize.c_photoCachedSize().vlocation; break;
|
case mtpc_photoCachedSize: bigLoc = &bigSize.c_photoCachedSize().vlocation; break;
|
||||||
}
|
}
|
||||||
if (smallLoc && bigLoc) {
|
if (smallLoc && bigLoc) {
|
||||||
if (peer->isChat()) {
|
const auto newPhotoId = photo ? photo->id : 0;
|
||||||
peer->asChat()->setPhoto(MTP_chatPhoto(*smallLoc, *bigLoc), photo ? photo->id : 0);
|
if (const auto chat = peer->asChat()) {
|
||||||
} else if (peer->isChannel()) {
|
chat->setPhoto(newPhotoId, MTP_chatPhoto(*smallLoc, *bigLoc));
|
||||||
peer->asChannel()->setPhoto(MTP_chatPhoto(*smallLoc, *bigLoc), photo ? photo->id : 0);
|
} else if (const auto channel = peer->asChannel()) {
|
||||||
|
channel->setPhoto(newPhotoId, MTP_chatPhoto(*smallLoc, *bigLoc));
|
||||||
}
|
}
|
||||||
peer->loadUserpic();
|
peer->loadUserpic();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1048,9 +1048,9 @@ void MainWidget::deletePhotoLayer(PhotoData *photo) {
|
||||||
auto me = App::self();
|
auto me = App::self();
|
||||||
if (!me) return;
|
if (!me) return;
|
||||||
|
|
||||||
if (me->photoId == photo->id) {
|
if (me->userpicPhotoId() == photo->id) {
|
||||||
Messenger::Instance().peerClearPhoto(me->id);
|
Messenger::Instance().peerClearPhoto(me->id);
|
||||||
} else if (photo->peer && !photo->peer->isUser() && photo->peer->photoId == photo->id) {
|
} else if (photo->peer && !photo->peer->isUser() && photo->peer->userpicPhotoId() == photo->id) {
|
||||||
Messenger::Instance().peerClearPhoto(photo->peer->id);
|
Messenger::Instance().peerClearPhoto(photo->peer->id);
|
||||||
} else {
|
} else {
|
||||||
MTP::send(MTPphotos_DeletePhotos(MTP_vector<MTPInputPhoto>(1, MTP_inputPhoto(MTP_long(photo->id), MTP_long(photo->access)))));
|
MTP::send(MTPphotos_DeletePhotos(MTP_vector<MTPInputPhoto>(1, MTP_inputPhoto(MTP_long(photo->id), MTP_long(photo->access)))));
|
||||||
|
@ -5318,16 +5318,14 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
|
||||||
if (auto user = App::userLoaded(d.vuser_id.v)) {
|
if (auto user = App::userLoaded(d.vuser_id.v)) {
|
||||||
user->setPhoto(d.vphoto);
|
user->setPhoto(d.vphoto);
|
||||||
user->loadUserpic();
|
user->loadUserpic();
|
||||||
if (mtpIsTrue(d.vprevious)
|
if (mtpIsTrue(d.vprevious) || !user->userpicPhotoId()) {
|
||||||
|| !user->photoId
|
|
||||||
|| user->photoId == UnknownPeerPhotoId) {
|
|
||||||
Auth().storage().remove(Storage::UserPhotosRemoveAfter(
|
Auth().storage().remove(Storage::UserPhotosRemoveAfter(
|
||||||
user->bareId(),
|
user->bareId(),
|
||||||
user->photoId));
|
user->userpicPhotoId()));
|
||||||
} else {
|
} else {
|
||||||
Auth().storage().add(Storage::UserPhotosAddNew(
|
Auth().storage().add(Storage::UserPhotosAddNew(
|
||||||
user->bareId(),
|
user->bareId(),
|
||||||
user->photoId));
|
user->userpicPhotoId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
|
@ -398,7 +398,7 @@ void MediaView::updateActions() {
|
||||||
return true;
|
return true;
|
||||||
} else if (!_msgid && _photo && App::self() && _user == App::self()) {
|
} else if (!_msgid && _photo && App::self() && _user == App::self()) {
|
||||||
return _userPhotosData && _fullIndex && _fullCount;
|
return _userPhotosData && _fullIndex && _fullCount;
|
||||||
} else if (_photo && _photo->peer && _photo->peer->photoId == _photo->id) {
|
} else if (_photo && _photo->peer && _photo->peer->userpicPhotoId() == _photo->id) {
|
||||||
if (auto chat = _photo->peer->asChat()) {
|
if (auto chat = _photo->peer->asChat()) {
|
||||||
return chat->canEdit();
|
return chat->canEdit();
|
||||||
} else if (auto channel = _photo->peer->asChannel()) {
|
} else if (auto channel = _photo->peer->asChannel()) {
|
||||||
|
@ -948,7 +948,7 @@ void MediaView::onDelete() {
|
||||||
auto deletingPeerPhoto = [this]() {
|
auto deletingPeerPhoto = [this]() {
|
||||||
if (!_msgid) return true;
|
if (!_msgid) return true;
|
||||||
if (_photo && _history) {
|
if (_photo && _history) {
|
||||||
if (_history->peer->photoId == _photo->id) {
|
if (_history->peer->userpicPhotoId() == _photo->id) {
|
||||||
return _firstOpenedPeerPhoto;
|
return _firstOpenedPeerPhoto;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1010,12 +1010,12 @@ base::optional<MediaView::SharedMediaType> MediaView::sharedMediaType() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
base::optional<MediaView::SharedMediaKey> MediaView::sharedMediaKey() const {
|
base::optional<MediaView::SharedMediaKey> MediaView::sharedMediaKey() const {
|
||||||
if (!_msgid && _peer && !_user && _photo && _peer->photoId == _photo->id) {
|
if (!_msgid && _peer && !_user && _photo && _peer->userpicPhotoId() == _photo->id) {
|
||||||
return SharedMediaKey {
|
return SharedMediaKey {
|
||||||
_history->peer->id,
|
_history->peer->id,
|
||||||
_migrated ? _migrated->peer->id : 0,
|
_migrated ? _migrated->peer->id : 0,
|
||||||
SharedMediaType::ChatPhoto,
|
SharedMediaType::ChatPhoto,
|
||||||
_peer->photoId
|
_peer->userpicPhotoId()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (!IsServerMsgId(_msgid.msg)) {
|
if (!IsServerMsgId(_msgid.msg)) {
|
||||||
|
|
|
@ -94,9 +94,11 @@ CoverWidget::CoverWidget(QWidget *parent, UserData *self)
|
||||||
}
|
}
|
||||||
|
|
||||||
PhotoData *CoverWidget::validatePhoto() const {
|
PhotoData *CoverWidget::validatePhoto() const {
|
||||||
auto photo = (_self->photoId && _self->photoId != UnknownPeerPhotoId) ? App::photo(_self->photoId) : nullptr;
|
const auto photo = _self->userpicPhotoId()
|
||||||
|
? App::photo(_self->userpicPhotoId())
|
||||||
|
: nullptr;
|
||||||
_userpicButton->setPointerCursor(photo != nullptr && photo->date != 0);
|
_userpicButton->setPointerCursor(photo != nullptr && photo->date != 0);
|
||||||
if ((_self->photoId == UnknownPeerPhotoId) || (_self->photoId && (!photo || !photo->date))) {
|
if (_self->userpicPhotoUnknown() || (photo && !photo->date)) {
|
||||||
Auth().api().requestFullPeer(_self);
|
Auth().api().requestFullPeer(_self);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4010,11 +4010,9 @@ uint32 _peerSize(PeerData *peer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void _writePeer(QDataStream &stream, PeerData *peer) {
|
void _writePeer(QDataStream &stream, PeerData *peer) {
|
||||||
stream << quint64(peer->id) << quint64(peer->photoId);
|
stream << quint64(peer->id) << quint64(peer->userpicPhotoId());
|
||||||
Serialize::writeStorageImageLocation(stream, peer->userpicLocation());
|
Serialize::writeStorageImageLocation(stream, peer->userpicLocation());
|
||||||
if (peer->isUser()) {
|
if (const auto user = peer->asUser()) {
|
||||||
UserData *user = peer->asUser();
|
|
||||||
|
|
||||||
stream << user->firstName << user->lastName << user->phone() << user->username << quint64(user->accessHash());
|
stream << user->firstName << user->lastName << user->phone() << user->username << quint64(user->accessHash());
|
||||||
if (AppVersion >= 9012) {
|
if (AppVersion >= 9012) {
|
||||||
stream << qint32(user->flags());
|
stream << qint32(user->flags());
|
||||||
|
@ -4023,14 +4021,10 @@ void _writePeer(QDataStream &stream, PeerData *peer) {
|
||||||
stream << (user->botInfo ? user->botInfo->inlinePlaceholder : QString());
|
stream << (user->botInfo ? user->botInfo->inlinePlaceholder : QString());
|
||||||
}
|
}
|
||||||
stream << qint32(user->onlineTill) << qint32(user->contact) << qint32(user->botInfo ? user->botInfo->version : -1);
|
stream << qint32(user->onlineTill) << qint32(user->contact) << qint32(user->botInfo ? user->botInfo->version : -1);
|
||||||
} else if (peer->isChat()) {
|
} else if (const auto chat = peer->asChat()) {
|
||||||
auto chat = peer->asChat();
|
|
||||||
|
|
||||||
stream << chat->name << qint32(chat->count) << qint32(chat->date) << qint32(chat->version) << qint32(chat->creator);
|
stream << chat->name << qint32(chat->count) << qint32(chat->date) << qint32(chat->version) << qint32(chat->creator);
|
||||||
stream << qint32(0) << quint32(chat->flags()) << chat->inviteLink();
|
stream << qint32(0) << quint32(chat->flags()) << chat->inviteLink();
|
||||||
} else if (peer->isChannel()) {
|
} else if (auto channel = peer->asChannel()) {
|
||||||
auto channel = peer->asChannel();
|
|
||||||
|
|
||||||
stream << channel->name << quint64(channel->access) << qint32(channel->date) << qint32(channel->version);
|
stream << channel->name << quint64(channel->access) << qint32(channel->date) << qint32(channel->version);
|
||||||
stream << qint32(0) << quint32(channel->flags()) << channel->inviteLink();
|
stream << qint32(0) << quint32(channel->flags()) << channel->inviteLink();
|
||||||
}
|
}
|
||||||
|
@ -4048,9 +4042,7 @@ PeerData *_readPeer(FileReadDescriptor &from, int32 fileVersion = 0) {
|
||||||
result = App::peer(peerId);
|
result = App::peer(peerId);
|
||||||
result->loadedStatus = PeerData::FullLoaded;
|
result->loadedStatus = PeerData::FullLoaded;
|
||||||
}
|
}
|
||||||
if (result->isUser()) {
|
if (const auto user = result->asUser()) {
|
||||||
UserData *user = result->asUser();
|
|
||||||
|
|
||||||
QString first, last, phone, username, inlinePlaceholder;
|
QString first, last, phone, username, inlinePlaceholder;
|
||||||
quint64 access;
|
quint64 access;
|
||||||
qint32 flags = 0, onlineTill, contact, botInfoVersion;
|
qint32 flags = 0, onlineTill, contact, botInfoVersion;
|
||||||
|
@ -4086,14 +4078,8 @@ PeerData *_readPeer(FileReadDescriptor &from, int32 fileVersion = 0) {
|
||||||
user->input = MTP_inputPeerUser(MTP_int(peerToUser(user->id)), MTP_long(user->accessHash()));
|
user->input = MTP_inputPeerUser(MTP_int(peerToUser(user->id)), MTP_long(user->accessHash()));
|
||||||
user->inputUser = MTP_inputUser(MTP_int(peerToUser(user->id)), MTP_long(user->accessHash()));
|
user->inputUser = MTP_inputUser(MTP_int(peerToUser(user->id)), MTP_long(user->accessHash()));
|
||||||
}
|
}
|
||||||
|
|
||||||
user->setUserpic(
|
|
||||||
photoLoc.isNull() ? ImagePtr() : ImagePtr(photoLoc),
|
|
||||||
photoLoc);
|
|
||||||
}
|
}
|
||||||
} else if (result->isChat()) {
|
} else if (const auto chat = result->asChat()) {
|
||||||
ChatData *chat = result->asChat();
|
|
||||||
|
|
||||||
QString name, inviteLink;
|
QString name, inviteLink;
|
||||||
qint32 count, date, version, creator, oldForbidden;
|
qint32 count, date, version, creator, oldForbidden;
|
||||||
quint32 flagsData, flags;
|
quint32 flagsData, flags;
|
||||||
|
@ -4121,14 +4107,8 @@ PeerData *_readPeer(FileReadDescriptor &from, int32 fileVersion = 0) {
|
||||||
|
|
||||||
chat->input = MTP_inputPeerChat(MTP_int(peerToChat(chat->id)));
|
chat->input = MTP_inputPeerChat(MTP_int(peerToChat(chat->id)));
|
||||||
chat->inputChat = MTP_int(peerToChat(chat->id));
|
chat->inputChat = MTP_int(peerToChat(chat->id));
|
||||||
|
|
||||||
chat->setUserpic(
|
|
||||||
photoLoc.isNull() ? ImagePtr() : ImagePtr(photoLoc),
|
|
||||||
photoLoc);
|
|
||||||
}
|
}
|
||||||
} else if (result->isChannel()) {
|
} else if (const auto channel = result->asChannel()) {
|
||||||
ChannelData *channel = result->asChannel();
|
|
||||||
|
|
||||||
QString name, inviteLink;
|
QString name, inviteLink;
|
||||||
quint64 access;
|
quint64 access;
|
||||||
qint32 date, version, oldForbidden;
|
qint32 date, version, oldForbidden;
|
||||||
|
@ -4147,12 +4127,14 @@ PeerData *_readPeer(FileReadDescriptor &from, int32 fileVersion = 0) {
|
||||||
|
|
||||||
channel->input = MTP_inputPeerChannel(MTP_int(peerToChannel(channel->id)), MTP_long(access));
|
channel->input = MTP_inputPeerChannel(MTP_int(peerToChannel(channel->id)), MTP_long(access));
|
||||||
channel->inputChannel = MTP_inputChannel(MTP_int(peerToChannel(channel->id)), MTP_long(access));
|
channel->inputChannel = MTP_inputChannel(MTP_int(peerToChannel(channel->id)), MTP_long(access));
|
||||||
|
|
||||||
channel->setUserpic(
|
|
||||||
photoLoc.isNull() ? ImagePtr() : ImagePtr(photoLoc),
|
|
||||||
photoLoc);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!wasLoaded) {
|
||||||
|
result->setUserpic(
|
||||||
|
photoId,
|
||||||
|
photoLoc,
|
||||||
|
photoLoc.isNull() ? ImagePtr() : ImagePtr(photoLoc));
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,6 +115,30 @@ public:
|
||||||
return _secret;
|
return _secret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static StorageImageLocation FromMTP(
|
||||||
|
int32 width,
|
||||||
|
int32 height,
|
||||||
|
const MTPFileLocation &location) {
|
||||||
|
if (location.type() == mtpc_fileLocation) {
|
||||||
|
const auto &data = location.c_fileLocation();
|
||||||
|
return StorageImageLocation(width, height, data);
|
||||||
|
}
|
||||||
|
return StorageImageLocation(width, height, 0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
static StorageImageLocation FromMTP(const MTPPhotoSize &size) {
|
||||||
|
switch (size.type()) {
|
||||||
|
case mtpc_photoSize: {
|
||||||
|
const auto &data = size.c_photoSize();
|
||||||
|
return FromMTP(data.vw.v, data.vh.v, data.vlocation);
|
||||||
|
} break;
|
||||||
|
case mtpc_photoCachedSize: {
|
||||||
|
const auto &data = size.c_photoCachedSize();
|
||||||
|
return FromMTP(data.vw.v, data.vh.v, data.vlocation);
|
||||||
|
} break;
|
||||||
|
}
|
||||||
|
return StorageImageLocation();
|
||||||
|
}
|
||||||
|
|
||||||
static StorageImageLocation Null;
|
static StorageImageLocation Null;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -483,11 +483,11 @@ void UserpicButton::openPeerPhoto() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto id = _peer->photoId;
|
const auto id = _peer->userpicPhotoId();
|
||||||
if (!id || id == UnknownPeerPhotoId) {
|
if (!id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto photo = App::photo(id);
|
const auto photo = App::photo(id);
|
||||||
if (photo->date) {
|
if (photo->date) {
|
||||||
Messenger::Instance().showPhoto(photo, _peer);
|
Messenger::Instance().showPhoto(photo, _peer);
|
||||||
}
|
}
|
||||||
|
@ -632,18 +632,15 @@ QPoint UserpicButton::prepareRippleStartPosition() const {
|
||||||
void UserpicButton::processPeerPhoto() {
|
void UserpicButton::processPeerPhoto() {
|
||||||
Expects(_peer != nullptr);
|
Expects(_peer != nullptr);
|
||||||
|
|
||||||
auto hasPhoto = (_peer->photoId
|
|
||||||
&& _peer->photoId != UnknownPeerPhotoId);
|
|
||||||
_waiting = !_peer->userpicLoaded();
|
_waiting = !_peer->userpicLoaded();
|
||||||
if (_waiting) {
|
if (_waiting) {
|
||||||
_peer->loadUserpic(true);
|
_peer->loadUserpic(true);
|
||||||
}
|
}
|
||||||
if (_role == Role::OpenPhoto) {
|
if (_role == Role::OpenPhoto) {
|
||||||
auto id = _peer->photoId;
|
if (_peer->userpicPhotoUnknown()) {
|
||||||
if (id == UnknownPeerPhotoId) {
|
|
||||||
_peer->updateFullForced();
|
_peer->updateFullForced();
|
||||||
}
|
}
|
||||||
_canOpenPhoto = (id != 0 && id != UnknownPeerPhotoId);
|
_canOpenPhoto = (_peer->userpicPhotoId() != 0);
|
||||||
updateCursor();
|
updateCursor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue