Skip to content

Commit

Permalink
Moved out ScheduledMessages module to components submodule.
Browse files Browse the repository at this point in the history
  • Loading branch information
23rd authored and john-preston committed Apr 15, 2024
1 parent 3d48111 commit a35f020
Show file tree
Hide file tree
Showing 20 changed files with 60 additions and 60 deletions.
4 changes: 2 additions & 2 deletions Telegram/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ PRIVATE
data/business/data_business_info.h
data/business/data_shortcut_messages.cpp
data/business/data_shortcut_messages.h
data/components/scheduled_messages.cpp
data/components/scheduled_messages.h
data/components/sponsored_messages.cpp
data/components/sponsored_messages.h
data/notify/data_notify_settings.cpp
Expand Down Expand Up @@ -579,8 +581,6 @@ PRIVATE
data/data_send_action.h
data/data_session.cpp
data/data_session.h
data/data_scheduled_messages.cpp
data/data_scheduled_messages.h
data/data_shared_media.cpp
data/data_shared_media.h
data/data_sparse_ids.cpp
Expand Down
5 changes: 2 additions & 3 deletions Telegram/SourceFiles/api/api_editing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ For license and copyright information please follow this link:
#include "api/api_text_entities.h"
#include "ui/boxes/confirm_box.h"
#include "data/business/data_shortcut_messages.h"
#include "data/components/scheduled_messages.h"
#include "data/data_histories.h"
#include "data/data_scheduled_messages.h"
#include "data/data_session.h"
#include "data/data_web_page.h"
#include "history/history.h"
#include "history/history_item.h"
#include "lang/lang_keys.h"
#include "main/main_session.h"
#include "mtproto/mtproto_response.h"
Expand Down Expand Up @@ -95,7 +94,7 @@ mtpRequestId EditMessage(
: emptyFlag);

const auto id = item->isScheduled()
? session->data().scheduledMessages().lookupId(item)
? session->scheduledMessages().lookupId(item)
: item->isBusinessShortcut()
? session->data().shortcutMessages().lookupId(item)
: item->id;
Expand Down
14 changes: 8 additions & 6 deletions Telegram/SourceFiles/api/api_updates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ For license and copyright information please follow this link:
#include "mtproto/mtproto_config.h"
#include "mtproto/mtproto_dc_options.h"
#include "data/business/data_shortcut_messages.h"
#include "data/components/scheduled_messages.h"
#include "data/notify/data_notify_settings.h"
#include "data/stickers/data_stickers.h"
#include "data/data_saved_messages.h"
Expand All @@ -37,7 +38,6 @@ For license and copyright information please follow this link:
#include "data/data_histories.h"
#include "data/data_folder.h"
#include "data/data_forum.h"
#include "data/data_scheduled_messages.h"
#include "data/data_send_action.h"
#include "data/data_stories.h"
#include "data/data_message_reactions.h"
Expand Down Expand Up @@ -94,7 +94,7 @@ void ProcessScheduledMessageWithElapsedTime(
// Note that when a message is scheduled until online
// while the recipient is already online, the server sends
// an ordinary new message with skipped "from_scheduled" flag.
session->data().scheduledMessages().checkEntitiesAndUpdate(data);
session->scheduledMessages().checkEntitiesAndUpdate(data);
}
}

Expand Down Expand Up @@ -1464,7 +1464,9 @@ void Updates::applyUpdates(
if (const auto id = owner.messageIdByRandomId(randomId)) {
const auto local = owner.message(id);
if (local && local->isScheduled()) {
owner.scheduledMessages().sendNowSimpleMessage(d, local);
session().scheduledMessages().sendNowSimpleMessage(
d,
local);
}
}
const auto wasAlready = (lookupMessage() != nullptr);
Expand Down Expand Up @@ -1561,7 +1563,7 @@ void Updates::feedUpdate(const MTPUpdate &update) {
auto &owner = session().data();
if (const auto local = owner.message(id)) {
if (local->isScheduled()) {
session().data().scheduledMessages().apply(d, local);
session().scheduledMessages().apply(d, local);
} else if (local->isBusinessShortcut()) {
session().data().shortcutMessages().apply(d, local);
} else {
Expand Down Expand Up @@ -1771,12 +1773,12 @@ void Updates::feedUpdate(const MTPUpdate &update) {

case mtpc_updateNewScheduledMessage: {
const auto &d = update.c_updateNewScheduledMessage();
session().data().scheduledMessages().apply(d);
session().scheduledMessages().apply(d);
} break;

case mtpc_updateDeleteScheduledMessages: {
const auto &d = update.c_updateDeleteScheduledMessages();
session().data().scheduledMessages().apply(d);
session().scheduledMessages().apply(d);
} break;

case mtpc_updateQuickReplies: {
Expand Down
8 changes: 4 additions & 4 deletions Telegram/SourceFiles/apiwrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ For license and copyright information please follow this link:
#include "api/api_user_names.h"
#include "api/api_websites.h"
#include "data/business/data_shortcut_messages.h"
#include "data/components/scheduled_messages.h"
#include "data/notify/data_notify_settings.h"
#include "data/data_changes.h"
#include "data/data_web_page.h"
Expand All @@ -43,7 +44,6 @@ For license and copyright information please follow this link:
#include "data/data_forum.h"
#include "data/data_saved_sublist.h"
#include "data/data_search_controller.h"
#include "data/data_scheduled_messages.h"
#include "data/data_session.h"
#include "data/data_channel.h"
#include "data/data_chat.h"
Expand Down Expand Up @@ -542,7 +542,7 @@ void ApiWrap::sendMessageFail(
}
}
} else if (error == u"SCHEDULE_STATUS_PRIVATE"_q) {
auto &scheduled = _session->data().scheduledMessages();
auto &scheduled = _session->scheduledMessages();
Assert(peer->isUser());
if (const auto item = scheduled.lookupItem(peer->id, itemId.msg)) {
scheduled.removeSending(item);
Expand Down Expand Up @@ -2447,8 +2447,8 @@ void ApiWrap::refreshFileReference(
_session->data().peer(storyId.peer)->input,
MTP_vector<MTPint>(1, MTP_int(storyId.story))));
} else if (item->isScheduled()) {
const auto &scheduled = _session->data().scheduledMessages();
const auto realId = scheduled.lookupId(item);
const auto realId = _session->scheduledMessages().lookupId(
item);
request(MTPmessages_GetScheduledMessages(
item->history()->peer->input,
MTP_vector<MTPint>(1, MTP_int(realId))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "data/data_scheduled_messages.h"
#include "data/components/scheduled_messages.h"

#include "base/unixtime.h"
#include "data/data_forum_topic.h"
Expand Down Expand Up @@ -101,10 +101,10 @@ bool IsScheduledMsgId(MsgId id) {
return (id > ServerMaxMsgId) && (id < ScheduledMaxMsgId);
}

ScheduledMessages::ScheduledMessages(not_null<Session*> owner)
: _session(&owner->session())
ScheduledMessages::ScheduledMessages(not_null<Main::Session*> session)
: _session(session)
, _clearTimer([=] { clearOldRequests(); }) {
owner->itemRemoved(
_session->data().itemRemoved(
) | rpl::filter([](not_null<const HistoryItem*> item) {
return item->isScheduled();
}) | rpl::start_with_next([=](not_null<const HistoryItem*> item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ class Session;

namespace Data {

class Session;
struct MessagesSlice;

[[nodiscard]] bool IsScheduledMsgId(MsgId id);

class ScheduledMessages final {
public:
explicit ScheduledMessages(not_null<Session*> owner);
explicit ScheduledMessages(not_null<Main::Session*> session);
ScheduledMessages(const ScheduledMessages &other) = delete;
ScheduledMessages &operator=(const ScheduledMessages &other) = delete;
~ScheduledMessages();
Expand Down
9 changes: 5 additions & 4 deletions Telegram/SourceFiles/data/data_histories.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ For license and copyright information please follow this link:

#include "api/api_text_entities.h"
#include "data/business/data_shortcut_messages.h"
#include "data/components/scheduled_messages.h"
#include "data/data_session.h"
#include "data/data_channel.h"
#include "data/data_chat.h"
#include "data/data_folder.h"
#include "data/data_forum.h"
#include "data/data_forum_topic.h"
#include "data/data_scheduled_messages.h"
#include "data/data_user.h"
#include "base/unixtime.h"
#include "base/random.h"
Expand Down Expand Up @@ -830,11 +830,12 @@ void Histories::deleteMessages(const MessageIdsList &ids, bool revoke) {
if (item->isScheduled()) {
const auto wasOnServer = !item->isSending()
&& !item->hasFailed();
auto &scheduled = _owner->session().scheduledMessages();
if (wasOnServer) {
scheduledIdsByPeer[history->peer].push_back(MTP_int(
_owner->scheduledMessages().lookupId(item)));
scheduledIdsByPeer[history->peer].push_back(
MTP_int(scheduled.lookupId(item)));
} else {
_owner->scheduledMessages().removeSending(item);
scheduled.removeSending(item);
}
continue;
} else if (item->isBusinessShortcut()) {
Expand Down
3 changes: 0 additions & 3 deletions Telegram/SourceFiles/data/data_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ For license and copyright information please follow this link:
#include "data/data_poll.h"
#include "data/data_replies_list.h"
#include "data/data_chat_filters.h"
#include "data/data_scheduled_messages.h"
#include "data/data_send_action.h"
#include "data/data_message_reactions.h"
#include "data/data_emoji_statuses.h"
Expand Down Expand Up @@ -271,7 +270,6 @@ Session::Session(not_null<Main::Session*> session)
, _savedMessages(std::make_unique<SavedMessages>(this))
, _chatbots(std::make_unique<Chatbots>(this))
, _businessInfo(std::make_unique<BusinessInfo>(this))
, _scheduledMessages(std::make_unique<ScheduledMessages>(this))
, _shortcutMessages(std::make_unique<ShortcutMessages>(this)) {
_cache->open(_session->local().cacheKey());
_bigFileCache->open(_session->local().cacheBigFileKey());
Expand Down Expand Up @@ -395,7 +393,6 @@ void Session::clear() {
_sendActionManager->clear();

_histories->unloadAll();
_scheduledMessages = nullptr;
_shortcutMessages = nullptr;
_dependentMessages.clear();
base::take(_messages);
Expand Down
5 changes: 0 additions & 5 deletions Telegram/SourceFiles/data/data_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ namespace Data {
class Folder;
class LocationPoint;
class WallPaper;
class ScheduledMessages;
class ShortcutMessages;
class SendActionManager;
class Reactions;
Expand Down Expand Up @@ -103,9 +102,6 @@ class Session final {
[[nodiscard]] ChatFilters &chatsFilters() const {
return *_chatsFilters;
}
[[nodiscard]] ScheduledMessages &scheduledMessages() const {
return *_scheduledMessages;
}
[[nodiscard]] ShortcutMessages &shortcutMessages() const {
return *_shortcutMessages;
}
Expand Down Expand Up @@ -1080,7 +1076,6 @@ class Session final {
const std::unique_ptr<SavedMessages> _savedMessages;
const std::unique_ptr<Chatbots> _chatbots;
const std::unique_ptr<BusinessInfo> _businessInfo;
std::unique_ptr<ScheduledMessages> _scheduledMessages;
std::unique_ptr<ShortcutMessages> _shortcutMessages;

MsgId _nonHistoryEntryId = ShortcutMaxMsgId;
Expand Down
6 changes: 3 additions & 3 deletions Telegram/SourceFiles/data/data_shared_media.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ For license and copyright information please follow this link:
#include "storage/storage_facade.h"
#include "history/history.h"
#include "history/history_item.h"
#include "data/components/scheduled_messages.h"
#include "data/data_document.h"
#include "data/data_media_types.h"
#include "data/data_photo.h"
#include "data/data_scheduled_messages.h"
#include "data/data_session.h"
#include "core/crash_reports.h"

Expand Down Expand Up @@ -193,9 +193,9 @@ rpl::producer<SparseIdsMergedSlice> SharedScheduledMediaViewer(
const auto history = session->data().history(key.mergedKey.peerId);

return rpl::single(rpl::empty) | rpl::then(
session->data().scheduledMessages().updates(history)
session->scheduledMessages().updates(history)
) | rpl::map([=] {
const auto list = session->data().scheduledMessages().list(history);
const auto list = session->scheduledMessages().list(history);

auto items = ranges::views::all(
list.ids
Expand Down
4 changes: 2 additions & 2 deletions Telegram/SourceFiles/history/history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ For license and copyright information please follow this link:
#include "history/history_unread_things.h"
#include "dialogs/ui/dialogs_layout.h"
#include "data/business/data_shortcut_messages.h"
#include "data/components/scheduled_messages.h"
#include "data/components/sponsored_messages.h"
#include "data/notify/data_notify_settings.h"
#include "data/stickers/data_stickers.h"
Expand All @@ -29,7 +30,6 @@ For license and copyright information please follow this link:
#include "data/data_channel_admins.h"
#include "data/data_changes.h"
#include "data/data_chat_filters.h"
#include "data/data_scheduled_messages.h"
#include "data/data_send_action.h"
#include "data/data_folder.h"
#include "data/data_forum.h"
Expand Down Expand Up @@ -590,7 +590,7 @@ not_null<HistoryItem*> History::addNewItem(
not_null<HistoryItem*> item,
bool unread) {
if (item->isScheduled()) {
owner().scheduledMessages().appendSending(item);
session().scheduledMessages().appendSending(item);
return item;
} else if (item->isBusinessShortcut()) {
owner().shortcutMessages().appendSending(item);
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/history/history_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ For license and copyright information please follow this link:
#include "base/timer_rpl.h"
#include "api/api_text_entities.h"
#include "api/api_updates.h"
#include "data/components/scheduled_messages.h"
#include "data/components/sponsored_messages.h"
#include "data/notify/data_notify_settings.h"
#include "data/data_bot_app.h"
#include "data/data_saved_messages.h"
#include "data/data_saved_sublist.h"
#include "data/data_scheduled_messages.h"
#include "data/data_changes.h"
#include "data/data_session.h"
#include "data/data_message_reactions.h"
Expand Down
4 changes: 2 additions & 2 deletions Telegram/SourceFiles/history/history_item_components.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ For license and copyright information please follow this link:
#include "media/audio/media_audio.h"
#include "media/player/media_player_instance.h"
#include "data/business/data_shortcut_messages.h"
#include "data/components/scheduled_messages.h"
#include "data/stickers/data_custom_emoji.h"
#include "data/data_channel.h"
#include "data/data_media_types.h"
Expand All @@ -42,7 +43,6 @@ For license and copyright information please follow this link:
#include "data/data_document.h"
#include "data/data_web_page.h"
#include "data/data_file_click_handler.h"
#include "data/data_scheduled_messages.h"
#include "data/data_session.h"
#include "data/data_stories.h"
#include "main/main_session.h"
Expand Down Expand Up @@ -301,7 +301,7 @@ ReplyFields ReplyFieldsFromMTP(
const auto owner = &item->history()->owner();
if (const auto id = data.vreply_to_msg_id().value_or_empty()) {
result.messageId = data.is_reply_to_scheduled()
? owner->scheduledMessages().localMessageId(id)
? owner->session().scheduledMessages().localMessageId(id)
: item->shortcutId()
? owner->shortcutMessages().localMessageId(id)
: id;
Expand Down
8 changes: 4 additions & 4 deletions Telegram/SourceFiles/history/history_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ For license and copyright information please follow this link:
#include "base/unixtime.h"
#include "base/call_delayed.h"
#include "data/business/data_shortcut_messages.h"
#include "data/components/scheduled_messages.h"
#include "data/components/sponsored_messages.h"
#include "data/notify/data_notify_settings.h"
#include "data/data_changes.h"
Expand All @@ -69,7 +70,6 @@ For license and copyright information please follow this link:
#include "data/data_forum_topic.h"
#include "data/data_user.h"
#include "data/data_chat_filters.h"
#include "data/data_scheduled_messages.h"
#include "data/data_file_origin.h"
#include "data/data_histories.h"
#include "data/data_group_call.h"
Expand Down Expand Up @@ -2772,9 +2772,9 @@ void HistoryWidget::setupScheduledToggle() {
controller()->activeChatValue(
) | rpl::map([=](Dialogs::Key key) -> rpl::producer<> {
if (const auto history = key.history()) {
return session().data().scheduledMessages().updates(history);
return session().scheduledMessages().updates(history);
} else if (const auto topic = key.topic()) {
return session().data().scheduledMessages().updates(
return session().scheduledMessages().updates(
topic->owningHistory());
}
return rpl::never<rpl::empty_value>();
Expand All @@ -2789,7 +2789,7 @@ void HistoryWidget::setupScheduledToggle() {
void HistoryWidget::refreshScheduledToggle() {
const auto has = _history
&& _canSendMessages
&& (session().data().scheduledMessages().count(_history) > 0);
&& (session().scheduledMessages().count(_history) > 0);
if (!_scheduled && has) {
_scheduled.create(this, st::historyScheduledToggle);
_scheduled->show();
Expand Down
Loading

0 comments on commit a35f020

Please sign in to comment.