Edit Chat Theme / Auto Delete on service message click.

This commit is contained in:
John Preston 2022-06-22 18:48:57 +04:00
parent db15a58dde
commit 0e771312f4
3 changed files with 61 additions and 1 deletions

View File

@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mainwidget.h"
#include "main/main_session.h"
#include "main/main_domain.h" // Core::App().domain().activate().
#include "menu/menu_ttl_validator.h"
#include "apiwrap.h"
#include "history/history.h"
#include "history/view/media/history_view_invoice.h"
@ -1362,7 +1363,11 @@ void HistoryService::createFromMtp(const MTPDmessage &message) {
void HistoryService::createFromMtp(const MTPDmessageService &message) {
const auto type = message.vaction().type();
if (type == mtpc_messageActionGameScore) {
if (type == mtpc_messageActionSetChatTheme) {
setupChatThemeChange();
} else if (type == mtpc_messageActionSetMessagesTTL) {
setupTTLChange();
} else if (type == mtpc_messageActionGameScore) {
const auto &data = message.vaction().c_messageActionGameScore();
UpdateComponents(HistoryServiceGameScore::Bit());
Get<HistoryServiceGameScore>()->score = data.vscore().v;
@ -1525,6 +1530,42 @@ void HistoryService::clearDependency() {
}
}
void HistoryService::setupChatThemeChange() {
if (const auto user = history()->peer->asUser()) {
auto link = std::make_shared<LambdaClickHandler>([=](
ClickContext context) {
const auto my = context.other.value<ClickHandlerContext>();
if (const auto controller = my.sessionWindow.get()) {
controller->toggleChooseChatTheme(user);
}
});
UpdateComponents(HistoryServiceChatThemeChange::Bit());
Get<HistoryServiceChatThemeChange>()->link = std::move(link);
} else {
RemoveComponents(HistoryServiceChatThemeChange::Bit());
}
}
void HistoryService::setupTTLChange() {
const auto peer = history()->peer;
auto link = std::make_shared<LambdaClickHandler>([=](
ClickContext context) {
const auto my = context.other.value<ClickHandlerContext>();
if (const auto controller = my.sessionWindow.get()) {
const auto validator = TTLMenu::TTLValidator(
std::make_shared<Window::Show>(controller),
peer);
if (validator.can()) {
validator.showBox();
}
}
});
UpdateComponents(HistoryServiceTTLChange::Bit());
Get<HistoryServiceTTLChange>()->link = std::move(link);
}
void HistoryService::dependencyItemRemoved(HistoryItem *dependency) {
clearDependency();
updateDependentText();

View File

@ -59,6 +59,16 @@ struct HistoryServiceOngoingCall
rpl::lifetime lifetime;
};
struct HistoryServiceChatThemeChange
: public RuntimeComponent<HistoryServiceChatThemeChange, HistoryItem> {
ClickHandlerPtr link;
};
struct HistoryServiceTTLChange
: public RuntimeComponent<HistoryServiceTTLChange, HistoryItem> {
ClickHandlerPtr link;
};
namespace HistoryView {
class ServiceMessagePainter;
} // namespace HistoryView
@ -155,6 +165,8 @@ private:
void updateDependentText();
void updateText(PreparedText &&text);
void clearDependency();
void setupChatThemeChange();
void setupTTLChange();
void createFromMtp(const MTPDmessage &message);
void createFromMtp(const MTPDmessageService &message);

View File

@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/text/text_options.h"
#include "ui/ui_utility.h"
#include "mainwidget.h"
#include "menu/menu_ttl_validator.h"
#include "lang/lang_keys.h"
#include "styles/style_chat.h"
@ -613,6 +614,12 @@ TextState Service::textState(QPoint point, StateRequest request) const {
if (PeerHasThisCall(peer, call->id).value_or(false)) {
result.link = call->link;
}
} else if (const auto theme = item->Get<HistoryServiceChatThemeChange>()) {
result.link = theme->link;
} else if (const auto ttl = item->Get<HistoryServiceTTLChange>()) {
if (TTLMenu::TTLValidator(nullptr, history()->peer).can()) {
result.link = ttl->link;
}
}
}
} else if (media) {