PeerId PeerFromMessage(const MTPmessage &message) { return message.match([](const MTPDmessageEmpty &) { return PeerId(0); }, [](const auto &message) { auto from_id = message.has_from_id() ? peerFromUser(message.vfrom_id) : 0; auto to_id = peerFromMTP(message.vto_id); auto out = message.is_out(); return (out || !peerIsUser(to_id)) ? to_id : from_id; }); }
HistoryMessage::HistoryMessage( not_null<History*> history, const MTPDmessage &data) : HistoryItem( history, data.vid.v, data.vflags.v, data.vdate.v, data.has_from_id() ? data.vfrom_id.v : UserId(0)) { CreateConfig config; if (data.has_fwd_from() && data.vfwd_from.type() == mtpc_messageFwdHeader) { auto &f = data.vfwd_from.c_messageFwdHeader(); config.originalDate = f.vdate.v; if (f.has_from_id() || f.has_channel_id()) { config.senderOriginal = f.has_channel_id() ? peerFromChannel(f.vchannel_id) : peerFromUser(f.vfrom_id); if (f.has_channel_post()) config.originalId = f.vchannel_post.v; if (f.has_post_author()) config.authorOriginal = qs(f.vpost_author); if (f.has_saved_from_peer() && f.has_saved_from_msg_id()) { config.savedFromPeer = peerFromMTP(f.vsaved_from_peer); config.savedFromMsgId = f.vsaved_from_msg_id.v; } } } if (data.has_reply_to_msg_id()) config.replyTo = data.vreply_to_msg_id.v; if (data.has_via_bot_id()) config.viaBotId = data.vvia_bot_id.v; if (data.has_views()) config.viewsCount = data.vviews.v; if (data.has_reply_markup()) config.mtpMarkup = &data.vreply_markup; if (data.has_edit_date()) config.editDate = data.vedit_date.v; if (data.has_post_author()) config.author = qs(data.vpost_author); createComponents(config); if (data.has_media()) { setMedia(data.vmedia); } auto text = TextUtilities::Clean(qs(data.vmessage)); auto entities = data.has_entities() ? TextUtilities::EntitiesFromMTP(data.ventities.v) : EntitiesInText(); setText({ text, entities }); if (data.has_grouped_id()) { setGroupId(MessageGroupId::FromRaw(data.vgrouped_id.v)); } }
void UserData::setBotInfo(const MTPBotInfo &info) { switch (info.type()) { case mtpc_botInfo: { const auto &d(info.c_botInfo()); if (peerFromUser(d.vuser_id.v) != id || !botInfo) return; QString desc = qs(d.vdescription); if (botInfo->description != desc) { botInfo->description = desc; botInfo->text = Text(st::msgMinWidth); } auto &v = d.vcommands.v; botInfo->commands.reserve(v.size()); auto changedCommands = false; int32 j = 0; for (int32 i = 0, l = v.size(); i < l; ++i) { if (v.at(i).type() != mtpc_botCommand) continue; QString cmd = qs(v.at(i).c_botCommand().vcommand), desc = qs(v.at(i).c_botCommand().vdescription); if (botInfo->commands.size() <= j) { botInfo->commands.push_back(BotCommand(cmd, desc)); changedCommands = true; } else { if (botInfo->commands[j].command != cmd) { botInfo->commands[j].command = cmd; changedCommands = true; } if (botInfo->commands[j].setDescription(desc)) { changedCommands = true; } } ++j; } while (j < botInfo->commands.size()) { botInfo->commands.pop_back(); changedCommands = true; } botInfo->inited = true; if (changedCommands) { Notify::botCommandsChanged(this); } } break; } }
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(); }(); setUserpicChecked(photoId, loc, photo); }