Show "View Message" button in sponsored.

This commit is contained in:
John Preston 2021-12-31 16:05:20 +03:00
parent edf93b0031
commit bba7010e74
5 changed files with 14 additions and 5 deletions

View File

@ -151,7 +151,9 @@ void SponsoredMessages::append(
});
const auto randomId = data.vrandom_id().v;
const auto hash = qs(data.vchat_invite_hash().value_or_empty());
const auto makeFrom = [](not_null<PeerData*> peer) {
const auto makeFrom = [](
not_null<PeerData*> peer,
bool exactPost = false) {
const auto channel = peer->asChannel();
return SponsoredFrom{
.peer = peer,
@ -161,12 +163,14 @@ void SponsoredMessages::append(
.isChannel = (channel != nullptr),
.isPublic = (channel && channel->isPublic()),
.isBot = (peer->isUser() && peer->asUser()->isBot()),
.isExactPost = exactPost,
};
};
const auto from = [&]() -> SponsoredFrom {
if (data.vfrom_id()) {
return makeFrom(
_session->data().peer(peerFromMTP(*data.vfrom_id())));
_session->data().peer(peerFromMTP(*data.vfrom_id())),
(data.vchannel_post() != nullptr));
}
Assert(data.vchat_invite());
return data.vchat_invite()->match([](const MTPDchatInvite &data) {

View File

@ -28,6 +28,7 @@ struct SponsoredFrom {
bool isChannel = false;
bool isPublic = false;
bool isBot = false;
bool isExactPost = false;
};
struct SponsoredMessage {

View File

@ -107,6 +107,7 @@ struct HistoryMessageSponsored : public RuntimeComponent<HistoryMessageSponsored
User,
Group,
Broadcast,
Post,
Bot,
};
std::unique_ptr<HiddenSenderInfo> sender;

View File

@ -1947,7 +1947,9 @@ void HistoryMessage::setSponsoredFrom(const Data::SponsoredFrom &from) {
false);
using Type = HistoryMessageSponsored::Type;
sponsored->type = from.isBot
sponsored->type = from.isExactPost
? Type::Post
: from.isBot
? Type::Bot
: from.isBroadcast
? Type::Broadcast

View File

@ -36,10 +36,11 @@ using SponsoredType = HistoryMessageSponsored::Type;
inline auto SponsoredPhrase(SponsoredType type) {
const auto phrase = [&] {
switch (type) {
case SponsoredType::Bot: return tr::lng_view_button_bot;
case SponsoredType::User: return tr::lng_view_button_user;
case SponsoredType::Group: return tr::lng_view_button_group;
case SponsoredType::Broadcast: return tr::lng_view_button_channel;
case SponsoredType::User: return tr::lng_view_button_user;
case SponsoredType::Post: return tr::lng_view_button_message;
case SponsoredType::Bot: return tr::lng_view_button_bot;
}
Unexpected("SponsoredType in SponsoredPhrase.");
}();