Show chat theme changing service messages.

This commit is contained in:
John Preston 2021-08-25 19:16:30 +03:00
parent 0821c21285
commit 70808dfa7d
7 changed files with 74 additions and 4 deletions

View File

@ -1209,6 +1209,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_action_proximity_reached" = "{from} is now within {distance} from {user}";
"lng_action_proximity_reached_you" = "{from} is now within {distance} from you";
"lng_action_you_proximity_reached" = "You are now within {distance} from {user}";
"lng_action_you_theme_changed" = "You changed chat theme to {emoji}";
"lng_action_theme_changed" = "{from} changed chat theme to {emoji}";
"lng_action_theme_changed_channel" = "Channel theme changed to {emoji}";
"lng_action_you_theme_disabled" = "You disabled chat theme";
"lng_action_theme_disabled" = "{from} disabled chat theme";
"lng_action_theme_disabled_channel" = "Channel theme disabled";
"lng_action_proximity_distance_m#one" = "{count} meter";
"lng_action_proximity_distance_m#other" = "{count} metres";
"lng_action_proximity_distance_km#one" = "{count} km";

View File

@ -0,0 +1,17 @@
import os, sys, requests, re
os.chdir()
keys = []
with open('lang.strings') as f:
for line in f:
m = re.match(r'\"(lng_[a-z_]+)(\#[a-z]+)?\"', line)
if m:
keys.append(m.group(1))
elif not re.match(r'^\s*$', line):
print('Bad line: ' + line)
sys.exit(1)
print('Keys: ' + str(len(keys)))
sys.exit()

View File

@ -1124,7 +1124,9 @@ ServiceAction ParseServiceAction(
.date = data.vschedule_date().v,
};
}, [&](const MTPDmessageActionSetChatTheme &data) {
// #TODO themes
result.content = ActionSetChatTheme{
.emoji = qs(data.vemoticon()),
};
}, [](const MTPDmessageActionEmpty &data) {});
return result;
}

View File

@ -475,6 +475,10 @@ struct ActionGroupCallScheduled {
TimeId date = 0;
};
struct ActionSetChatTheme {
QString emoji;
};
struct ServiceAction {
std::variant<
v::null_t,
@ -503,7 +507,8 @@ struct ServiceAction {
ActionGroupCall,
ActionInviteToGroupCall,
ActionSetMessagesTTL,
ActionGroupCallScheduled> content;
ActionGroupCallScheduled,
ActionSetChatTheme> content;
};
ServiceAction ParseServiceAction(

View File

@ -1095,8 +1095,17 @@ auto HtmlWriter::Wrap::pushMessage(
}, [&](const ActionGroupCallScheduled &data) {
const auto dateText = FormatDateTime(data.date);
return isChannel
? "Voice chat scheduled for " + dateText
? ("Voice chat scheduled for " + dateText)
: (serviceFrom + " scheduled a voice chat for " + dateText);
}, [&](const ActionSetChatTheme &data) {
if (data.emoji.isEmpty()) {
return isChannel
? "Channel theme was disabled"
: (serviceFrom + " disabled chat theme");
}
return isChannel
? ("Channel theme was changed to " + data.emoji).toUtf8()
: (serviceFrom + " changed chat theme to " + data.emoji).toUtf8();
}, [](v::null_t) { return QByteArray(); });
if (!serviceText.isEmpty()) {

View File

@ -517,6 +517,12 @@ QByteArray SerializeMessage(
pushActor();
pushAction("group_call_scheduled");
push("schedule_date", data.date);
}, [&](const ActionSetChatTheme &data) {
pushActor();
pushAction("edit_chat_theme");
if (!data.emoji.isEmpty()) {
push("emoticon", data.emoji.toUtf8());
}
}, [](v::null_t) {});
if (v::is_null(message.action.content)) {

View File

@ -427,6 +427,31 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) {
return result;
};
auto prepareSetChatTheme = [this](const MTPDmessageActionSetChatTheme &action) {
auto result = PreparedText{};
const auto text = qs(action.vemoticon());
if (!text.isEmpty()) {
if (isPost()) {
result.text = tr::lng_action_theme_changed_channel(tr::now, lt_emoji, text);
} else if (_from->isSelf()) {
result.text = tr::lng_action_you_theme_changed(tr::now, lt_emoji, text);
} else {
result.links.push_back(fromLink());
result.text = tr::lng_action_theme_changed(tr::now, lt_from, fromLinkText(), lt_emoji, text);
}
} else {
if (isPost()) {
result.text = tr::lng_action_theme_disabled_channel(tr::now);
} else if (_from->isSelf()) {
result.text = tr::lng_action_you_theme_disabled(tr::now);
} else {
result.links.push_back(fromLink());
result.text = tr::lng_action_theme_disabled(tr::now, lt_from, fromLinkText());
}
}
return result;
};
const auto messageText = action.match([&](
const MTPDmessageActionChatAddUser &data) {
return prepareChatAddUserText(data);
@ -485,7 +510,7 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) {
}, [&](const MTPDmessageActionGroupCallScheduled &data) {
return prepareCallScheduledText(data.vschedule_date().v);
}, [&](const MTPDmessageActionSetChatTheme &data) {
return PreparedText{ tr::lng_message_empty(tr::now) }; // #TODO themes
return prepareSetChatTheme(data);
}, [](const MTPDmessageActionEmpty &) {
return PreparedText{ tr::lng_message_empty(tr::now) };
});