2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Added initial ability to send and receive scheduled messages in forums.

This commit is contained in:
23rd
2024-03-12 15:36:36 +03:00
parent cd59f1d576
commit 672ad64e53
9 changed files with 246 additions and 37 deletions

View File

@@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_scheduled_messages.h"
#include "base/unixtime.h"
#include "data/data_forum_topic.h"
#include "data/data_peer.h"
#include "data/data_session.h"
#include "api/api_hash.h"
@@ -173,6 +174,16 @@ int ScheduledMessages::count(not_null<History*> history) const {
return (i != end(_data)) ? i->second.items.size() : 0;
}
bool ScheduledMessages::hasFor(not_null<Data::ForumTopic*> topic) const {
const auto i = _data.find(topic->owningHistory());
if (i == end(_data)) {
return false;
}
return ranges::any_of(i->second.items, [&](const OwnedItem &item) {
return item->topic() == topic;
});
}
void ScheduledMessages::sendNowSimpleMessage(
const MTPDupdateShortSentMessage &update,
not_null<HistoryItem*> local) {
@@ -374,7 +385,8 @@ rpl::producer<> ScheduledMessages::updates(not_null<History*> history) {
}) | rpl::to_empty;
}
Data::MessagesSlice ScheduledMessages::list(not_null<History*> history) {
Data::MessagesSlice ScheduledMessages::list(
not_null<History*> history) const {
auto result = Data::MessagesSlice();
const auto i = _data.find(history);
if (i == end(_data)) {
@@ -396,6 +408,31 @@ Data::MessagesSlice ScheduledMessages::list(not_null<History*> history) {
return result;
}
Data::MessagesSlice ScheduledMessages::list(
not_null<const Data::ForumTopic*> topic) const {
auto result = Data::MessagesSlice();
const auto i = _data.find(topic->Data::Thread::owningHistory());
if (i == end(_data)) {
const auto i = _requests.find(topic->Data::Thread::owningHistory());
if (i == end(_requests)) {
return result;
}
result.fullCount = result.skippedAfter = result.skippedBefore = 0;
return result;
}
const auto &list = i->second.items;
result.skippedAfter = result.skippedBefore = 0;
result.fullCount = int(list.size());
result.ids = ranges::views::all(
list
) | ranges::views::filter([&](const OwnedItem &item) {
return item->topic() == topic;
}) | ranges::views::transform(
&HistoryItem::fullId
) | ranges::to_vector;
return result;
}
void ScheduledMessages::request(not_null<History*> history) {
const auto peer = history->peer;
if (peer->isBroadcast() && !Data::CanSendAnything(peer)) {

View File

@@ -34,6 +34,7 @@ public:
[[nodiscard]] HistoryItem *lookupItem(PeerId peer, MsgId msg) const;
[[nodiscard]] HistoryItem *lookupItem(FullMsgId itemId) const;
[[nodiscard]] int count(not_null<History*> history) const;
[[nodiscard]] bool hasFor(not_null<Data::ForumTopic*> topic) const;
[[nodiscard]] MsgId localMessageId(MsgId remoteId) const;
void checkEntitiesAndUpdate(const MTPDmessage &data);
@@ -51,7 +52,9 @@ public:
not_null<HistoryItem*> local);
[[nodiscard]] rpl::producer<> updates(not_null<History*> history);
[[nodiscard]] Data::MessagesSlice list(not_null<History*> history);
[[nodiscard]] Data::MessagesSlice list(not_null<History*> history) const;
[[nodiscard]] Data::MessagesSlice list(
not_null<const Data::ForumTopic*> topic) const;
private:
using OwnedItem = std::unique_ptr<HistoryItem, HistoryItem::Destroyer>;