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

@@ -651,8 +651,38 @@ void History::destroyMessagesBySublist(not_null<PeerData*> sublistPeer) {
}
}
void History::unpinMessagesFor(MsgId topicRootId) {
if (!topicRootId) {
void History::unpinMessagesFor(MsgId topicRootId, PeerId monoforumPeerId) {
if (topicRootId) {
session().storage().remove(
Storage::SharedMediaRemoveAll(
peer->id,
topicRootId,
Storage::SharedMediaType::Pinned));
if (const auto topic = peer->forumTopicFor(topicRootId)) {
topic->setHasPinnedMessages(false);
}
for (const auto &item : _items) {
if (item->isPinned() && item->topicRootId() == topicRootId) {
item->setIsPinned(false);
}
}
} else if (monoforumPeerId) {
session().storage().remove(
Storage::SharedMediaRemoveAll(
peer->id,
monoforumPeerId,
Storage::SharedMediaType::Pinned));
if (const auto sublist = peer->monoforumSublistFor(
monoforumPeerId)) {
sublist->setHasPinnedMessages(false);
}
for (const auto &item : _items) {
if (item->isPinned()
&& item->sublistPeerId() == monoforumPeerId) {
item->setIsPinned(false);
}
}
} else {
session().storage().remove(
Storage::SharedMediaRemoveAll(
peer->id,
@@ -668,20 +698,6 @@ void History::unpinMessagesFor(MsgId topicRootId) {
item->setIsPinned(false);
}
}
} else {
session().storage().remove(
Storage::SharedMediaRemoveAll(
peer->id,
topicRootId,
Storage::SharedMediaType::Pinned));
if (const auto topic = peer->forumTopicFor(topicRootId)) {
topic->setHasPinnedMessages(false);
}
for (const auto &item : _items) {
if (item->isPinned() && item->topicRootId() == topicRootId) {
item->setIsPinned(false);
}
}
}
}
@@ -898,6 +914,7 @@ not_null<HistoryItem*> History::addNewToBack(
storage.add(Storage::SharedMediaAddExisting(
peer->id,
MsgId(0), // topicRootId
PeerId(0), // monoforumPeerId
types,
item->id,
{ from, till }));
@@ -909,6 +926,7 @@ not_null<HistoryItem*> History::addNewToBack(
storage.add(Storage::SharedMediaAddExisting(
peer->id,
topic->rootId(),
PeerId(), // monoforumPeerId
types,
item->id,
{ item->id, item->id}));
@@ -916,6 +934,18 @@ not_null<HistoryItem*> History::addNewToBack(
topic->setHasPinnedMessages(true);
}
}
if (const auto sublist = item->savedSublist()) {
storage.add(Storage::SharedMediaAddExisting(
peer->id,
MsgId(), // topicRootId
item->sublistPeerId(),
types,
item->id,
{ item->id, item->id }));
if (pinned) {
sublist->setHasPinnedMessages(true);
}
}
}
}
if (item->from()->id) {
@@ -1182,7 +1212,8 @@ void History::applyServiceChanges(
if (id && item) {
session().storage().add(Storage::SharedMediaAddSlice(
peer->id,
MsgId(0),
MsgId(0), // topicRootId
PeerId(0), // monoforumPeerId
Storage::SharedMediaType::Pinned,
{ id },
{ id, ServerMaxMsgId }));
@@ -1191,11 +1222,22 @@ void History::applyServiceChanges(
session().storage().add(Storage::SharedMediaAddSlice(
peer->id,
topic->rootId(),
PeerId(), // monoforumPeerId
Storage::SharedMediaType::Pinned,
{ id },
{ id, ServerMaxMsgId }));
topic->setHasPinnedMessages(true);
}
if (const auto sublist = item->savedSublist()) {
session().storage().add(Storage::SharedMediaAddSlice(
peer->id,
MsgId(), // topicRootId
item->sublistPeerId(),
Storage::SharedMediaType::Pinned,
{ id },
{ id, ServerMaxMsgId }));
sublist->setHasPinnedMessages(true);
}
}
}, [&](const MTPDmessageReplyStoryHeader &data) {
LOG(("API Error: story reply in messageActionPinMessage."));
@@ -1470,6 +1512,7 @@ void History::addEdgesToSharedMedia() {
session().storage().add(Storage::SharedMediaAddSlice(
peer->id,
MsgId(0), // topicRootId
PeerId(0), // monoforumPeerId
type,
{},
{ from, till }));
@@ -1683,6 +1726,7 @@ void History::addToSharedMedia(
session().storage().add(Storage::SharedMediaAddSlice(
peer->id,
MsgId(0), // topicRootId
PeerId(0), // monoforumPeerId
type,
std::move(medias[i]),
{ from, till }));
@@ -3162,11 +3206,9 @@ void History::forceFullResize() {
Data::Thread *History::threadFor(MsgId topicRootId, PeerId monoforumPeerId) {
return topicRootId
? peer->forumTopicFor(topicRootId)
: !monoforumPeerId
? static_cast<Data::Thread*>(this)
: peer->monoforum()
? peer->monoforum()->sublistLoaded(owner().peer(monoforumPeerId))
: nullptr;
: monoforumPeerId
? peer->monoforumSublistFor(monoforumPeerId)
: static_cast<Data::Thread*>(this);
}
const Data::Thread *History::threadFor(