Fix user and chat flags handling.

This commit is contained in:
John Preston 2018-11-02 22:35:57 +04:00
parent 48548e9303
commit 75db59a8bb
2 changed files with 24 additions and 20 deletions

View File

@ -867,20 +867,23 @@ void ApiWrap::gotChatFull(PeerData *peer, const MTPmessages_ChatFull &result, mt
}
auto &f = d.vfull_chat.c_chatFull();
App::feedParticipants(f.vparticipants, false);
auto &v = f.vbot_info.v;
for_const (auto &item, v) {
switch (item.type()) {
case mtpc_botInfo: {
auto &b = item.c_botInfo();
if (auto user = App::userLoaded(b.vuser_id.v)) {
user->setBotInfo(item);
fullPeerUpdated().notify(user);
}
} break;
if (f.has_bot_info()) {
for (const auto &item : f.vbot_info.v) {
item.match([&](const MTPDbotInfo &data) {
if (const auto bot = App::userLoaded(data.vuser_id.v)) {
bot->setBotInfo(item);
fullPeerUpdated().notify(bot);
}
});
}
}
chat->setUserpicPhoto(f.vchat_photo);
chat->setInviteLink((f.vexported_invite.type() == mtpc_chatInviteExported) ? qs(f.vexported_invite.c_chatInviteExported().vlink) : QString());
chat->setUserpicPhoto(f.has_chat_photo()
? f.vchat_photo
: MTPPhoto(MTP_photoEmpty(MTP_long(0))));
chat->setInviteLink(
(f.vexported_invite.type() == mtpc_chatInviteExported
? qs(f.vexported_invite.c_chatInviteExported().vlink)
: QString()));
if (f.has_pinned_msg_id()) {
chat->setPinnedMessageId(f.vpinned_msg_id.v);
} else {
@ -1029,6 +1032,7 @@ void ApiWrap::gotUserFull(UserData *user, const MTPUserFull &result, mtpRequestI
} else {
user->clearPinnedMessage();
}
user->setFullFlags(d.vflags.v);
user->setBlockStatus(d.is_blocked() ? UserData::BlockStatus::Blocked : UserData::BlockStatus::NotBlocked);
user->setCallsStatus(d.is_phone_calls_private() ? UserData::CallsStatus::Private : d.is_phone_calls_available() ? UserData::CallsStatus::Enabled : UserData::CallsStatus::Disabled);
user->setAbout(d.has_about() ? qs(d.vabout) : QString());

View File

@ -172,13 +172,13 @@ void PeerData::setUserpic(
}
void PeerData::setUserpicPhoto(const MTPPhoto &data) {
auto photoId = [&]() -> PhotoId {
if (const auto photo = Auth().data().photo(data)) {
photo->peer = this;
return photo->id;
}
return 0;
}();
const auto photoId = data.match([&](const MTPDphoto &data) {
const auto photo = Auth().data().photo(data);
photo->peer = this;
return photo->id;
}, [](const MTPDphotoEmpty &data) {
return PhotoId(0);
});
if (_userpicPhotoId != photoId) {
_userpicPhotoId = photoId;
Notify::peerUpdatedDelayed(this, UpdateFlag::PhotoChanged);
@ -332,7 +332,7 @@ void PeerData::setUserpicChecked(
bool PeerData::canPinMessages() const {
if (const auto user = asUser()) {
return user->isSelf();
return user->fullFlags() & MTPDuserFull::Flag::f_can_pin_message;
} else if (const auto chat = asChat()) {
return chat->adminsEnabled() ? chat->amAdmin() : chat->amIn();
} else if (const auto channel = asChannel()) {