2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Support shared media / pins for sublists.

This commit is contained in:
John Preston
2025-06-02 15:00:36 +04:00
parent ffe6786ad1
commit dfc1ec3ccf
83 changed files with 1105 additions and 221 deletions

View File

@@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/notify/data_notify_settings.h"
#include "data/stickers/data_custom_emoji.h"
#include "data/data_document_media.h"
#include "data/data_saved_sublist.h"
#include "data/data_session.h"
#include "data/data_channel.h"
#include "data/data_forum_topic.h"
@@ -349,6 +350,15 @@ void System::registerThread(not_null<Data::Thread*> thread) {
clearFromTopic(topic);
}, i->second);
}
} else if (const auto sublist = thread->asSublist()) {
const auto &[i, ok] = _watchedSublists.emplace(
sublist,
rpl::lifetime());
if (ok) {
sublist->destroyed() | rpl::start_with_next([=] {
clearFromSublist(sublist);
}, i->second);
}
}
}
@@ -426,6 +436,7 @@ void System::clearAll() {
_waiters.clear();
_settingWaiters.clear();
_watchedTopics.clear();
_watchedSublists.clear();
}
void System::clearFromTopic(not_null<Data::ForumTopic*> topic) {
@@ -445,6 +456,23 @@ void System::clearFromTopic(not_null<Data::ForumTopic*> topic) {
showNext();
}
void System::clearFromSublist(not_null<Data::SavedSublist*> sublist) {
if (_manager) {
_manager->clearFromSublist(sublist);
}
sublist->clearNotifications();
_whenMaps.remove(sublist);
_whenAlerts.remove(sublist);
_waiters.remove(sublist);
_settingWaiters.remove(sublist);
_watchedSublists.remove(sublist);
_waitTimer.cancel();
showNext();
}
void System::clearForThreadIf(Fn<bool(not_null<Data::Thread*>)> predicate) {
for (auto i = _whenMaps.begin(); i != _whenMaps.end();) {
const auto thread = i->first;
@@ -460,6 +488,8 @@ void System::clearForThreadIf(Fn<bool(not_null<Data::Thread*>)> predicate) {
_settingWaiters.remove(thread);
if (const auto topic = thread->asTopic()) {
_watchedTopics.remove(topic);
} else if (const auto sublist = thread->asSublist()) {
_watchedSublists.remove(sublist);
}
}
const auto clearFrom = [&](auto &map) {
@@ -468,6 +498,8 @@ void System::clearForThreadIf(Fn<bool(not_null<Data::Thread*>)> predicate) {
if (predicate(thread)) {
if (const auto topic = thread->asTopic()) {
_watchedTopics.remove(topic);
} else if (const auto sublist = thread->asSublist()) {
_watchedSublists.remove(sublist);
}
i = map.erase(i);
} else {
@@ -517,6 +549,15 @@ void System::clearIncomingFromTopic(not_null<Data::ForumTopic*> topic) {
_whenAlerts.remove(topic);
}
void System::clearIncomingFromSublist(
not_null<Data::SavedSublist*> sublist) {
if (_manager) {
_manager->clearFromSublist(sublist);
}
sublist->clearIncomingNotifications();
_whenAlerts.remove(sublist);
}
void System::clearFromItem(not_null<HistoryItem*> item) {
if (_manager) {
_manager->clearFromItem(item);
@@ -533,6 +574,7 @@ void System::clearAllFast() {
_waiters.clear();
_settingWaiters.clear();
_watchedTopics.clear();
_watchedSublists.clear();
}
void System::checkDelayed() {
@@ -1114,10 +1156,14 @@ void Manager::notificationActivated(
history->peer,
id.msgId);
const auto topic = item ? item->topic() : nullptr;
const auto sublist = item ? item->savedSublist() : nullptr;
if (!options.draft.text.isEmpty()) {
const auto topicRootId = topic
? topic->rootId()
: id.contextId.topicRootId;
const auto monoforumPeerId = (sublist && sublist->parentChat())
? sublist->sublistPeer()->id
: id.contextId.monoforumPeerId;
const auto replyToId = (id.msgId > 0
&& !history->peer->isUser()
&& id.msgId != topicRootId)
@@ -1129,6 +1175,7 @@ void Manager::notificationActivated(
FullReplyTo{
.messageId = replyToId,
.topicRootId = topicRootId,
.monoforumPeerId = monoforumPeerId,
},
MessageCursor{
length,
@@ -1167,13 +1214,13 @@ Window::SessionController *Manager::openNotificationMessage(
&& item->isRegular()
&& (item->out() || (item->mentionsMe() && !history->peer->isUser()));
const auto topic = item ? item->topic() : nullptr;
const auto sublist = (item && item->history()->amMonoforumAdmin())
? item->savedSublist()
: nullptr;
const auto sublist = item ? item->savedSublist() : nullptr;
const auto guard = gsl::finally([&] {
if (topic) {
system()->clearFromTopic(topic);
} else if (sublist && sublist->parentChat()) {
system()->clearFromSublist(sublist);
} else {
system()->clearFromHistory(history);
}
@@ -1256,6 +1303,10 @@ void Manager::notificationReplied(
const auto topicRootId = topic
? topic->rootId()
: id.contextId.topicRootId;
const auto sublist = item ? item->savedSublist() : nullptr;
const auto monoforumPeerId = (sublist && sublist->parentChat())
? sublist->sublistPeer()->id
: id.contextId.monoforumPeerId;
auto message = Api::MessageToSend(Api::SendAction(history));
message.textWithTags = reply;
@@ -1268,6 +1319,7 @@ void Manager::notificationReplied(
message.action.replyTo = {
.messageId = { replyToId ? history->peer->id : 0, replyToId },
.topicRootId = topic ? topic->rootId() : 0,
.monoforumPeerId = monoforumPeerId,
};
message.action.clearDraft = false;
history->session().api().sendMessage(std::move(message));
@@ -1293,16 +1345,21 @@ void NativeManager::doShowNotification(NotificationFields &&fields) {
&& !reactionFrom
&& (item->out() || peer->isSelf())
&& item->isFromScheduled();
const auto topicWithChat = [&] {
const auto subWithChat = [&] {
const auto name = peer->name();
const auto topic = item->topic();
return topic ? (topic->title() + u" ("_q + name + ')') : name;
const auto sublist = item->savedSublist();
return topic
? (topic->title() + u" ("_q + name + ')')
: (sublist && sublist->parentChat())
? (sublist->sublistPeer()->shortName() + u" ("_q + name + ')')
: name;
};
const auto title = options.hideNameAndPhoto
? AppName.utf16()
: (scheduled && peer->isSelf())
? tr::lng_notification_reminder(tr::now)
: topicWithChat();
: subWithChat();
const auto fullTitle = addTargetAccountName(title, &peer->session());
const auto subtitle = reactionFrom
? (reactionFrom != peer ? reactionFrom->name() : QString())
@@ -1341,6 +1398,9 @@ void NativeManager::doShowNotification(NotificationFields &&fields) {
doShowNativeNotification({
.peer = item->history()->peer,
.topicRootId = item->topicRootId(),
.monoforumPeerId = (item->history()->amMonoforumAdmin()
? item->sublistPeerId()
: PeerId()),
.itemId = item->id,
.title = scheduled ? WrapFromScheduled(fullTitle) : fullTitle,
.subtitle = subtitle,