Support topics in Recent Actions.

This commit is contained in:
John Preston 2022-10-18 17:47:43 +04:00
parent df5602d203
commit fe41fbd7e9
7 changed files with 145 additions and 14 deletions

View File

@ -2971,6 +2971,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_admin_log_filter_voice_chats_channel" = "Live stream";
"lng_admin_log_filter_invite_links" = "Invite links";
"lng_admin_log_filter_members_removed" = "Leaving members";
"lng_admin_log_filter_topics" = "Topics";
"lng_admin_log_filter_all_admins" = "All users and admins";
"lng_admin_log_about" = "What is this?";
"lng_admin_log_about_text" = "This is a list of all service actions taken by the group's members and admins in the last 48 hours.";
@ -3076,6 +3077,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_admin_log_invite_link_label" = "Name: {previous} -> {limit}";
"lng_admin_log_invite_link_request_needed" = "Now admin approval is required to join.";
"lng_admin_log_invite_link_request_not_needed" = "Now admin approval is not required to join.";
"lng_admin_log_topics_enabled" = "{from} enabled topics";
"lng_admin_log_topics_disabled" = "{from} disabled topics";
"lng_admin_log_topics_created" = "{from} created topic {topic}";
"lng_admin_log_topics_changed" = "{from} changed topic {topic} to {new_topic}";
"lng_admin_log_topics_closed" = "{from} closed topic {topic}";
"lng_admin_log_topics_reopened" = "{from} reopened topic {topic}";
"lng_admin_log_topics_deleted" = "{from} deleted topic {topic}";
"lng_admin_log_topics_pinned" = "{from} pinned topic {topic}";
"lng_admin_log_topics_unpinned" = "{from} unpinned topic {topic}";
"lng_admin_log_restricted_forever" = "indefinitely";
"lng_admin_log_restricted_until" = "until {date}";
"lng_admin_log_banned_view_messages" = "Read messages";

View File

@ -428,7 +428,7 @@ bool ResolvePrivatePost(
const auto topicId = topicParam.toInt();
const auto threadParam = params.value(qsl("thread"));
const auto threadId = topicId ? topicId : threadParam.toInt();
if (!channelId || !IsServerMsgId(msgId)) {
if (!channelId || (msgId && !IsServerMsgId(msgId))) {
return false;
}
const auto fromMessageId = context.value<ClickHandlerContext>().itemId;
@ -941,9 +941,13 @@ QString TryConvertUrlToLocal(QString url) {
? "gradient"
: "slug";
return qsl("tg://bg?") + type + '=' + bg + (params.isEmpty() ? QString() : '&' + params);
} else if (auto postMatch = regex_match(qsl("^c/(\\-?\\d+)/(\\d+)(/?\\?|/?$)"), query, matchOptions)) {
auto params = query.mid(postMatch->captured(0).size()).toString();
return qsl("tg://privatepost?channel=%1&post=%2").arg(postMatch->captured(1), postMatch->captured(2)) + (params.isEmpty() ? QString() : '&' + params);
} else if (auto postMatch = regex_match(qsl("^c/(\\-?\\d+)(/\\d+)?(/?\\?|/?$)"), query, matchOptions)) {
const auto params = query.mid(postMatch->captured(0).size()).toString();
const auto base = u"tg://privatepost?channel="_q + postMatch->captured(1);
const auto post = postMatch->captured(2).mid(1);
return base
+ (post.isEmpty() ? QString() : u"&post="_q + post)
+ (params.isEmpty() ? QString() : '&' + params);
} else if (auto usernameMatch = regex_match(qsl("^([a-zA-Z0-9\\.\\_]+)(/?\\?|/?$|/(\\d+)/?(?:\\?|$))"), query, matchOptions)) {
auto params = query.mid(usernameMatch->captured(0).size()).toString();
auto postParam = QString();

View File

@ -305,6 +305,9 @@ void FilterBox::Inner::createActionsCheckboxes(const FilterValue &filter) {
}
addFlag(Flag::Invites, tr::lng_admin_log_filter_invite_links(tr::now));
addFlag(Flag::Leave, tr::lng_admin_log_filter_members_removed(tr::now));
if (isGroup) {
addFlag(Flag::Topics, tr::lng_admin_log_filter_topics(tr::now));
}
}
void FilterBox::Inner::createAllUsersCheckbox(const FilterValue &filter) {

View File

@ -753,7 +753,8 @@ void InnerWidget::preloadMore(Direction direction) {
| ((f & LocalFlag::Edit) ? Flag::f_edit : empty)
| ((f & LocalFlag::Delete) ? Flag::f_delete : empty)
| ((f & LocalFlag::GroupCall) ? Flag::f_group_call : empty)
| ((f & LocalFlag::Invites) ? Flag::f_invites : empty);
| ((f & LocalFlag::Invites) ? Flag::f_invites : empty)
| ((f & LocalFlag::Topics) ? Flag::f_forums : empty);
}();
if (_filter.flags != 0) {
flags |= MTPchannels_GetAdminLog::Flag::f_events_filter;

View File

@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_user.h"
#include "data/data_session.h"
#include "data/data_message_reaction_id.h"
#include "data/stickers/data_custom_emoji.h"
#include "lang/lang_keys.h"
#include "ui/text/format_values.h"
#include "ui/text/text_utilities.h"
@ -609,6 +610,48 @@ TextWithEntities GenerateDefaultBannedRightsChangeText(
return result;
}
[[nodiscard]] bool IsTopicClosed(const MTPForumTopic &topic) {
return topic.match([](const MTPDforumTopic &data) {
return data.is_closed();
}, [](const MTPDforumTopicDeleted &) {
return false;
});
}
[[nodiscard]] TextWithEntities GenerateTopicLink(
not_null<ChannelData*> channel,
const MTPForumTopic &topic) {
return topic.match([&](const MTPDforumTopic &data) {
const auto wrapIcon = [](DocumentId id) {
return TextWithEntities{
"@",
{ EntityInText(
EntityType::CustomEmoji,
0,
1,
Data::SerializeCustomEmojiId({ .id = id }))
},
};
};
auto result = (data.vicon_emoji_id() && data.vicon_emoji_id()->v)
? wrapIcon(data.vicon_emoji_id()->v)
: TextWithEntities();
result.append(qs(data.vtitle()));
result.entities.insert(
result.entities.begin(),
EntityInText(
EntityType::CustomUrl,
0,
result.text.size(),
u"https://t.me/c/%1?topic=%2"_q.arg(
peerToChannel(channel->id).bare).arg(
data.vid().v)));
return result;
}, [](const MTPDforumTopicDeleted &) {
return TextWithEntities{ u"Deleted"_q };
});
}
} // namespace
OwnedItem::OwnedItem(std::nullptr_t) {
@ -1585,23 +1628,89 @@ void GenerateItems(
};
const auto createToggleForum = [&](const LogToggleForum &data) {
const auto enabled = (data.vnew_value().type() == mtpc_boolTrue);
const auto text = (enabled
? tr::lng_admin_log_topics_enabled
: tr::lng_admin_log_topics_disabled)(
tr::now,
lt_from,
fromLinkText,
Ui::Text::WithEntities);
addSimpleServiceMessage(text);
};
const auto createCreateTopic = [&](const LogCreateTopic &data) {
auto topicLink = GenerateTopicLink(channel, data.vtopic());
addSimpleServiceMessage(tr::lng_admin_log_topics_created(
tr::now,
lt_from,
fromLinkText,
lt_topic,
topicLink,
Ui::Text::WithEntities));
};
const auto createEditTopic = [&](const LogEditTopic &data) {
const auto prevLink = GenerateTopicLink(channel, data.vprev_topic());
const auto nowLink = GenerateTopicLink(channel, data.vnew_topic());
if (prevLink != nowLink) {
addSimpleServiceMessage(tr::lng_admin_log_topics_changed(
tr::now,
lt_from,
fromLinkText,
lt_topic,
prevLink,
lt_new_topic,
nowLink,
Ui::Text::WithEntities));
}
const auto wasClosed = IsTopicClosed(data.vprev_topic());
const auto nowClosed = IsTopicClosed(data.vnew_topic());
if (nowClosed != wasClosed) {
addSimpleServiceMessage((nowClosed
? tr::lng_admin_log_topics_closed
: tr::lng_admin_log_topics_reopened)(
tr::now,
lt_from,
fromLinkText,
lt_topic,
nowLink,
Ui::Text::WithEntities));
}
};
const auto createDeleteTopic = [&](const LogDeleteTopic &data) {
auto topicLink = GenerateTopicLink(channel, data.vtopic());
topicLink.entities.erase(topicLink.entities.begin());
addSimpleServiceMessage(tr::lng_admin_log_topics_deleted(
tr::now,
lt_from,
fromLinkText,
lt_topic,
topicLink,
Ui::Text::WithEntities));
};
const auto createPinTopic = [&](const LogPinTopic &data) {
if (const auto &topic = data.vnew_topic()) {
auto topicLink = GenerateTopicLink(channel, *topic);
addSimpleServiceMessage(tr::lng_admin_log_topics_pinned(
tr::now,
lt_from,
fromLinkText,
lt_topic,
topicLink,
Ui::Text::WithEntities));
} else if (const auto &previous = data.vprev_topic()) {
auto topicLink = GenerateTopicLink(channel, *previous);
addSimpleServiceMessage(tr::lng_admin_log_topics_unpinned(
tr::now,
lt_from,
fromLinkText,
lt_topic,
topicLink,
Ui::Text::WithEntities));
}
};
action.match(

View File

@ -46,8 +46,9 @@ struct FilterValue {
Delete = (1U << 13),
GroupCall = (1U << 14),
Invites = (1U << 15),
Topics = (1U << 16),
MAX_FIELD = (1U << 15),
MAX_FIELD = (1U << 16),
};
using Flags = base::flags<Flag>;
friend inline constexpr bool is_flag_type(Flag) { return true; };

View File

@ -104,10 +104,11 @@ namespace {
const QString &addToLink) {
return [=](QString link) {
if (!link.startsWith(u"https://"_q)) {
link = peer->session().createInternalLinkFull(peer->userName());
link = peer->session().createInternalLinkFull(peer->userName())
+ addToLink;
}
if (!link.isEmpty()) {
QGuiApplication::clipboard()->setText(link + addToLink);
QGuiApplication::clipboard()->setText(link);
Ui::Toast::Show(
show.toastParent(),
tr::lng_username_copied(tr::now));
@ -426,7 +427,9 @@ object_ptr<Ui::RpWidget> DetailsFiller::setupInfo() {
link + addToLink);
});
auto linkLine = addInfoOneLine(
UsernamesSubtext(_peer, tr::lng_info_link_label()),
(topicRootId
? tr::lng_info_link_label(Ui::Text::WithEntities)
: UsernamesSubtext(_peer, tr::lng_info_link_label())),
std::move(linkText),
QString());
const auto controller = _controller->parentController();