mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Improved process of giveaway messages for export to HTML.
This commit is contained in:
parent
5b146217c0
commit
064bab60ff
4 changed files with 136 additions and 19 deletions
|
@ -361,7 +361,7 @@ void Premium::resolveGiveawayInfo(
|
||||||
? GiveawayState::Refunded
|
? GiveawayState::Refunded
|
||||||
: GiveawayState::Finished;
|
: GiveawayState::Finished;
|
||||||
info.giftCode = qs(data.vgift_code_slug().value_or_empty());
|
info.giftCode = qs(data.vgift_code_slug().value_or_empty());
|
||||||
info.activatedCount = data.vactivated_count().value_or_empty(); AssertIsDebug();
|
info.activatedCount = data.vactivated_count().value_or_empty();
|
||||||
info.finishDate = data.vfinish_date().v;
|
info.finishDate = data.vfinish_date().v;
|
||||||
info.startDate = data.vstart_date().v;
|
info.startDate = data.vstart_date().v;
|
||||||
});
|
});
|
||||||
|
|
|
@ -733,13 +733,23 @@ Poll ParsePoll(const MTPDmessageMediaPoll &data) {
|
||||||
GiveawayStart ParseGiveaway(const MTPDmessageMediaGiveaway &data) {
|
GiveawayStart ParseGiveaway(const MTPDmessageMediaGiveaway &data) {
|
||||||
auto result = GiveawayStart{
|
auto result = GiveawayStart{
|
||||||
.untilDate = data.vuntil_date().v,
|
.untilDate = data.vuntil_date().v,
|
||||||
|
.credits = data.vstars().value_or_empty(),
|
||||||
.quantity = data.vquantity().v,
|
.quantity = data.vquantity().v,
|
||||||
.months = data.vmonths().value_or_empty(), AssertIsDebug()
|
.months = data.vmonths().value_or_empty(),
|
||||||
//.stars = data.vstars().value_or_empty(),
|
.all = !data.is_only_new_subscribers(),
|
||||||
};
|
};
|
||||||
for (const auto &id : data.vchannels().v) {
|
for (const auto &id : data.vchannels().v) {
|
||||||
result.channels.push_back(ChannelId(id));
|
result.channels.push_back(ChannelId(id));
|
||||||
}
|
}
|
||||||
|
if (const auto countries = data.vcountries_iso2()) {
|
||||||
|
result.countries.reserve(countries->v.size());
|
||||||
|
for (const auto &country : countries->v) {
|
||||||
|
result.countries.push_back(qs(country));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (const auto additional = data.vprize_description()) {
|
||||||
|
result.additionalPrize = qs(*additional);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -210,10 +210,14 @@ struct Poll {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GiveawayStart {
|
struct GiveawayStart {
|
||||||
|
std::vector<QString> countries;
|
||||||
std::vector<ChannelId> channels;
|
std::vector<ChannelId> channels;
|
||||||
|
QString additionalPrize;
|
||||||
TimeId untilDate = 0;
|
TimeId untilDate = 0;
|
||||||
|
uint64 credits = 0;
|
||||||
int quantity = 0;
|
int quantity = 0;
|
||||||
int months = 0;
|
int months = 0;
|
||||||
|
bool all = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct UserpicsSlice {
|
struct UserpicsSlice {
|
||||||
|
|
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "export/output/export_output_html.h"
|
#include "export/output/export_output_html.h"
|
||||||
|
|
||||||
|
#include "countries/countries_instance.h"
|
||||||
#include "export/output/export_output_result.h"
|
#include "export/output/export_output_result.h"
|
||||||
#include "export/data/export_data_types.h"
|
#include "export/data/export_data_types.h"
|
||||||
#include "core/utils.h"
|
#include "core/utils.h"
|
||||||
|
@ -1307,9 +1308,11 @@ auto HtmlWriter::Wrap::pushMessage(
|
||||||
return serviceFrom + " just started a giveaway "
|
return serviceFrom + " just started a giveaway "
|
||||||
"of Telegram Premium subscriptions to its followers.";
|
"of Telegram Premium subscriptions to its followers.";
|
||||||
}, [&](const ActionGiveawayResults &data) {
|
}, [&](const ActionGiveawayResults &data) {
|
||||||
return QByteArray::number(data.winners)
|
return (data.winners > 0)
|
||||||
+ " of the giveaway were randomly selected by Telegram "
|
? NumberToString(data.winners)
|
||||||
"and received private messages with giftcodes.";
|
+ " of the giveaway were randomly selected by Telegram "
|
||||||
|
"and received private messages with giftcodes."
|
||||||
|
: "No winners of the giveaway could be selected.";
|
||||||
}, [&](const ActionBoostApply &data) {
|
}, [&](const ActionBoostApply &data) {
|
||||||
return serviceFrom
|
return serviceFrom
|
||||||
+ " boosted the group "
|
+ " boosted the group "
|
||||||
|
@ -1912,17 +1915,47 @@ QByteArray HtmlWriter::Wrap::pushGiveaway(
|
||||||
result.append(pushDiv("media_giveaway"));
|
result.append(pushDiv("media_giveaway"));
|
||||||
|
|
||||||
result.append(pushDiv("section_title bold"));
|
result.append(pushDiv("section_title bold"));
|
||||||
result.append(SerializeString("Giveaway Prizes"));
|
result.append((data.quantity > 1)
|
||||||
|
? SerializeString("Giveaway Prizes")
|
||||||
|
: SerializeString("Giveaway Prize"));
|
||||||
result.append(popTag());
|
result.append(popTag());
|
||||||
|
|
||||||
|
{
|
||||||
|
result.append(pushDiv("section_body"));
|
||||||
|
result.append("<b>"
|
||||||
|
+ Data::NumberToString(data.quantity)
|
||||||
|
+ "</b> "
|
||||||
|
+ SerializeString(data.additionalPrize.toUtf8()));
|
||||||
|
result.append(popTag());
|
||||||
|
result.append(pushDiv("section_title bold"));
|
||||||
|
result.append(SerializeString("with"));
|
||||||
|
result.append(popTag());
|
||||||
|
};
|
||||||
result.append(pushDiv("section_body"));
|
result.append(pushDiv("section_body"));
|
||||||
result.append("<b>"
|
if (data.credits > 0) {
|
||||||
+ Data::NumberToString(data.quantity)
|
result.append("<b>"
|
||||||
+ "</b> "
|
+ Data::NumberToString(data.credits)
|
||||||
+ SerializeString((data.quantity > 1)
|
+ (SerializeString(data.credits == 1 ? (" Star") : (" Stars")))
|
||||||
? "Telegram Premium Subscriptions"
|
+ "</b> " + SerializeString("will be distributed ")
|
||||||
: "Telegram Premium Subscription")
|
+ ((data.quantity == 1)
|
||||||
+ " for <b>" + Data::NumberToString(data.months) + "</b> "
|
? SerializeString("to ")
|
||||||
+ (data.months > 1 ? "months." : "month."));
|
+ "<b>"
|
||||||
|
+ Data::NumberToString(data.quantity)
|
||||||
|
+ "</b> " + SerializeString("winner.")
|
||||||
|
: SerializeString("among ")
|
||||||
|
+ "<b>"
|
||||||
|
+ Data::NumberToString(data.quantity)
|
||||||
|
+ "</b> " + SerializeString("winners.")));
|
||||||
|
} else {
|
||||||
|
result.append("<b>"
|
||||||
|
+ Data::NumberToString(data.quantity)
|
||||||
|
+ "</b> "
|
||||||
|
+ SerializeString((data.quantity > 1)
|
||||||
|
? "Telegram Premium Subscriptions"
|
||||||
|
: "Telegram Premium Subscription")
|
||||||
|
+ " for <b>" + Data::NumberToString(data.months) + "</b> "
|
||||||
|
+ (data.months > 1 ? "months." : "month."));
|
||||||
|
}
|
||||||
result.append(popTag());
|
result.append(popTag());
|
||||||
|
|
||||||
result.append(pushDiv("section_title bold"));
|
result.append(pushDiv("section_title bold"));
|
||||||
|
@ -1930,15 +1963,85 @@ QByteArray HtmlWriter::Wrap::pushGiveaway(
|
||||||
result.append(popTag());
|
result.append(popTag());
|
||||||
result.append(pushDiv("section_body"));
|
result.append(pushDiv("section_body"));
|
||||||
auto channels = QByteArrayList();
|
auto channels = QByteArrayList();
|
||||||
|
auto anyChannel = false;
|
||||||
|
auto anyGroup = false;
|
||||||
for (const auto &channel : data.channels) {
|
for (const auto &channel : data.channels) {
|
||||||
|
if (const auto chat = peers.peer(channel).chat()) {
|
||||||
|
if (chat->isBroadcast) {
|
||||||
|
anyChannel = true;
|
||||||
|
} else if (chat->isSupergroup) {
|
||||||
|
anyGroup = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
channels.append("<b>" + peers.wrapPeerName(channel) + "</b>");
|
channels.append("<b>" + peers.wrapPeerName(channel) + "</b>");
|
||||||
}
|
}
|
||||||
result.append(SerializeString((channels.size() > 1)
|
|
||||||
? "All subscribers of those channels: "
|
const auto participants = [&] {
|
||||||
: "All subscribers of the channel: ")
|
if (data.all && !anyGroup && anyChannel && channels.size() == 1) {
|
||||||
+ channels.join(", "));
|
return "All subscribers of the channel:";
|
||||||
|
}
|
||||||
|
if (data.all && !anyGroup && anyChannel && channels.size() > 1) {
|
||||||
|
return "All subscribers of the channels:";
|
||||||
|
}
|
||||||
|
if (data.all && anyGroup && !anyChannel && channels.size() == 1) {
|
||||||
|
return "All members of the group:";
|
||||||
|
}
|
||||||
|
if (data.all && anyGroup && !anyChannel && channels.size() > 1) {
|
||||||
|
return "All members of the groups:";
|
||||||
|
}
|
||||||
|
if (data.all && anyGroup && anyChannel && channels.size() == 1) {
|
||||||
|
return "All members of the group:";
|
||||||
|
}
|
||||||
|
if (data.all && anyGroup && anyChannel && channels.size() > 1) {
|
||||||
|
return "All members of the groups and channels:";
|
||||||
|
}
|
||||||
|
if (!data.all && !anyGroup && anyChannel && channels.size() == 1) {
|
||||||
|
return "All users who joined the channel below after this date:";
|
||||||
|
}
|
||||||
|
if (!data.all && !anyGroup && anyChannel && channels.size() > 1) {
|
||||||
|
return "All users who joined the channels below after this date:";
|
||||||
|
}
|
||||||
|
if (!data.all && anyGroup && !anyChannel && channels.size() == 1) {
|
||||||
|
return "All users who joined the group below after this date:";
|
||||||
|
}
|
||||||
|
if (!data.all && anyGroup && !anyChannel && channels.size() > 1) {
|
||||||
|
return "All users who joined the groups below after this date:";
|
||||||
|
}
|
||||||
|
if (!data.all && anyGroup && anyChannel && channels.size() == 1) {
|
||||||
|
return "All users who joined the group below after this date:";
|
||||||
|
}
|
||||||
|
if (!data.all && anyGroup && anyChannel && channels.size() > 1) {
|
||||||
|
return "All users who joined the groups and channels below "
|
||||||
|
"after this date:";
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}();
|
||||||
|
|
||||||
|
result.append(SerializeString(participants)) + channels.join(", ");
|
||||||
result.append(popTag());
|
result.append(popTag());
|
||||||
|
|
||||||
|
{
|
||||||
|
const auto &instance = Countries::Instance();
|
||||||
|
auto countries = QStringList();
|
||||||
|
for (const auto &country : data.countries) {
|
||||||
|
const auto name = instance.countryNameByISO2(country);
|
||||||
|
const auto flag = instance.flagEmojiByISO2(country);
|
||||||
|
countries.push_back(flag + QChar(0xA0) + name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (const auto count = countries.size()) {
|
||||||
|
auto united = countries.front();
|
||||||
|
for (auto i = 1; i != count; ++i) {
|
||||||
|
united = ((i + 1 == count)
|
||||||
|
? u"%1 and %2"_q
|
||||||
|
: u"%1, %2"_q).arg(united, countries[i]);
|
||||||
|
}
|
||||||
|
result.append(pushDiv("section_body"));
|
||||||
|
result.append(
|
||||||
|
SerializeString((u"from %1"_q).arg(united).toUtf8()));
|
||||||
|
result.append(popTag());
|
||||||
|
}
|
||||||
|
}
|
||||||
result.append(pushDiv("section_title bold"));
|
result.append(pushDiv("section_title bold"));
|
||||||
result.append(SerializeString("Winners Selection Date"));
|
result.append(SerializeString("Winners Selection Date"));
|
||||||
result.append(popTag());
|
result.append(popTag());
|
||||||
|
|
Loading…
Add table
Reference in a new issue