mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 14:45:14 +00:00
Added possible info about sponsors to menu from sponsored messages.
This commit is contained in:
@@ -17,8 +17,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "history/history.h"
|
||||
#include "history/history_item.h"
|
||||
#include "history/view/history_view_element.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "main/main_session.h"
|
||||
#include "ui/image/image_location_factory.h"
|
||||
#include "ui/text/text_utilities.h" // Ui::Text::RichLangValue.
|
||||
|
||||
namespace Data {
|
||||
namespace {
|
||||
@@ -313,6 +315,15 @@ void SponsoredMessages::append(
|
||||
return makeFrom(chat);
|
||||
});
|
||||
}();
|
||||
auto sponsorInfo = data.vsponsor_info()
|
||||
? tr::lng_sponsored_info_submenu(
|
||||
tr::now,
|
||||
lt_text,
|
||||
{ .text = qs(*data.vsponsor_info()) },
|
||||
Ui::Text::RichLangValue)
|
||||
: TextWithEntities();
|
||||
auto additionalInfo = TextWithEntities::Simple(
|
||||
data.vadditional_info() ? qs(*data.vadditional_info()) : QString());
|
||||
auto sharedMessage = SponsoredMessage{
|
||||
.randomId = randomId,
|
||||
.from = from,
|
||||
@@ -325,6 +336,8 @@ void SponsoredMessages::append(
|
||||
.history = history,
|
||||
.msgId = data.vchannel_post().value_or_empty(),
|
||||
.chatInviteHash = hash,
|
||||
.sponsorInfo = std::move(sponsorInfo),
|
||||
.additionalInfo = std::move(additionalInfo),
|
||||
};
|
||||
list.entries.push_back({ nullptr, std::move(sharedMessage) });
|
||||
}
|
||||
@@ -393,11 +406,23 @@ SponsoredMessages::Details SponsoredMessages::lookupDetails(
|
||||
if (!entryPtr) {
|
||||
return {};
|
||||
}
|
||||
const auto &hash = entryPtr->sponsored.chatInviteHash;
|
||||
const auto &data = entryPtr->sponsored;
|
||||
const auto &hash = data.chatInviteHash;
|
||||
|
||||
using InfoList = std::vector<TextWithEntities>;
|
||||
const auto info = (!data.sponsorInfo.text.isEmpty()
|
||||
&& !data.additionalInfo.text.isEmpty())
|
||||
? InfoList{ data.sponsorInfo, data.additionalInfo }
|
||||
: !data.sponsorInfo.text.isEmpty()
|
||||
? InfoList{ data.sponsorInfo }
|
||||
: !data.additionalInfo.text.isEmpty()
|
||||
? InfoList{ data.additionalInfo }
|
||||
: InfoList{};
|
||||
return {
|
||||
.hash = hash.isEmpty() ? std::nullopt : std::make_optional(hash),
|
||||
.peer = entryPtr->sponsored.from.peer,
|
||||
.msgId = entryPtr->sponsored.msgId,
|
||||
.peer = data.from.peer,
|
||||
.msgId = data.msgId,
|
||||
.info = std::move(info),
|
||||
};
|
||||
}
|
||||
|
||||
|
@@ -42,6 +42,8 @@ struct SponsoredMessage {
|
||||
History *history = nullptr;
|
||||
MsgId msgId;
|
||||
QString chatInviteHash;
|
||||
TextWithEntities sponsorInfo;
|
||||
TextWithEntities additionalInfo;
|
||||
};
|
||||
|
||||
class SponsoredMessages final {
|
||||
@@ -55,6 +57,7 @@ public:
|
||||
std::optional<QString> hash;
|
||||
PeerData *peer = nullptr;
|
||||
MsgId msgId;
|
||||
std::vector<TextWithEntities> info;
|
||||
};
|
||||
using RandomId = QByteArray;
|
||||
explicit SponsoredMessages(not_null<Session*> owner);
|
||||
|
@@ -28,6 +28,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "history/history_item_components.h"
|
||||
#include "history/history_item_text.h"
|
||||
#include "ui/chat/chat_style.h"
|
||||
#include "ui/widgets/menu/menu_add_action_callback_factory.h"
|
||||
#include "ui/widgets/menu/menu_multiline_action.h"
|
||||
#include "ui/widgets/popup_menu.h"
|
||||
#include "ui/image/image.h"
|
||||
#include "ui/toasts/common_toasts.h"
|
||||
@@ -130,6 +132,72 @@ int BinarySearchBlocksOrItems(const T &list, int edge) {
|
||||
return start;
|
||||
}
|
||||
|
||||
void FillSponsoredMessagesMenu(
|
||||
not_null<Window::SessionController*> controller,
|
||||
FullMsgId itemId,
|
||||
not_null<Ui::PopupMenu*> menu) {
|
||||
const auto &data = controller->session().data().sponsoredMessages();
|
||||
const auto info = data.lookupDetails(itemId).info;
|
||||
const auto toastParent = Window::Show(controller).toastParent();
|
||||
if (!info.empty()) {
|
||||
auto fillSubmenu = [&](not_null<Ui::PopupMenu*> menu) {
|
||||
const auto allText = ranges::accumulate(
|
||||
info,
|
||||
TextWithEntities(),
|
||||
[](TextWithEntities a, TextWithEntities b) {
|
||||
return a.text.isEmpty() ? b : a.append('\n').append(b);
|
||||
}).text;
|
||||
const auto callback = [=] {
|
||||
QGuiApplication::clipboard()->setText(allText);
|
||||
Ui::ShowMultilineToast({
|
||||
.parentOverride = toastParent,
|
||||
.text = { tr::lng_text_copied(tr::now) },
|
||||
});
|
||||
};
|
||||
for (const auto &i : info) {
|
||||
auto item = base::make_unique_q<Ui::Menu::MultilineAction>(
|
||||
menu,
|
||||
st::defaultMenu,
|
||||
st::historyHasCustomEmoji,
|
||||
st::historyHasCustomEmojiPosition,
|
||||
base::duplicate(i));
|
||||
item->clicks(
|
||||
) | rpl::start_with_next(callback, menu->lifetime());
|
||||
menu->addAction(std::move(item));
|
||||
if (i != info.back()) {
|
||||
menu->addSeparator();
|
||||
}
|
||||
}
|
||||
};
|
||||
using namespace Ui::Menu;
|
||||
CreateAddActionCallback(menu)(MenuCallback::Args{
|
||||
.text = tr::lng_sponsored_info_menu(tr::now),
|
||||
.handler = nullptr,
|
||||
.icon = nullptr,
|
||||
.fillSubmenu = std::move(fillSubmenu),
|
||||
});
|
||||
menu->addSeparator();
|
||||
}
|
||||
{
|
||||
auto item = base::make_unique_q<Ui::Menu::MultilineAction>(
|
||||
menu,
|
||||
st::menuWithIcons,
|
||||
st::historyHasCustomEmoji,
|
||||
st::historySponsoredAboutMenuLabelPosition,
|
||||
TextWithEntities{ tr::lng_sponsored_title(tr::now) },
|
||||
&st::menuIconInfo);
|
||||
item->clicks(
|
||||
) | rpl::start_with_next([=] {
|
||||
controller->show(Box(Ui::AboutSponsoredBox));
|
||||
}, item->lifetime());
|
||||
menu->addAction(std::move(item));
|
||||
}
|
||||
menu->addSeparator();
|
||||
menu->addAction(tr::lng_sponsored_hide_ads(tr::now), [=] {
|
||||
Settings::ShowPremium(controller, "no_ads");
|
||||
}, &st::menuIconBlock);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// flick scroll taken from http://qt-project.org/doc/qt-4.8/demos-embedded-anomaly-src-flickcharm-cpp.html
|
||||
@@ -2415,13 +2483,8 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
|
||||
}
|
||||
}
|
||||
if (item->isSponsored()) {
|
||||
_menu->addAction(tr::lng_sponsored_title({}), [=] {
|
||||
_controller->show(Box(Ui::AboutSponsoredBox));
|
||||
}, &st::menuIconInfo);
|
||||
_menu->addSeparator();
|
||||
_menu->addAction(tr::lng_sponsored_hide_ads({}), [=] {
|
||||
Settings::ShowPremium(_controller, "no_ads");
|
||||
}, &st::menuIconBlock);
|
||||
const auto itemId = item->fullId();
|
||||
FillSponsoredMessagesMenu(controller, itemId, _menu);
|
||||
}
|
||||
if (!item->isService() && view && actionText.isEmpty()) {
|
||||
if (!hasCopyRestriction(item)
|
||||
|
@@ -1251,6 +1251,8 @@ historyTranslateSettings: IconButton(defaultIconButton) {
|
||||
}
|
||||
historyTranslateMenuPosition: point(-6px, 30px);
|
||||
|
||||
historySponsoredAboutMenuLabelPosition: point(54px, 4px);
|
||||
|
||||
historySendDisabled: FlatLabel(defaultFlatLabel) {
|
||||
minWidth: 10px;
|
||||
maxHeight: 20px;
|
||||
|
Reference in New Issue
Block a user