aboutsummaryrefslogtreecommitdiffhomepage
path: root/td/telegram/DraftMessageManager.h
blob: 0481347e1bc2bd555e25b2d3314594347262ce4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2025
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once

#include "td/telegram/DialogId.h"
#include "td/telegram/DraftMessage.h"
#include "td/telegram/files/FileSourceId.h"
#include "td/telegram/ForumTopicId.h"
#include "td/telegram/MessageTopic.h"
#include "td/telegram/SavedMessagesTopicId.h"

#include "td/actor/actor.h"

#include "td/utils/common.h"
#include "td/utils/FlatHashMap.h"
#include "td/utils/Promise.h"

namespace td {

class Td;

class DraftMessageManager final : public Actor {
 public:
  DraftMessageManager(Td *td, ActorShared<> parent);

  void save_draft_message(DialogId dialog_id, const MessageTopic &message_topic,
                          const unique_ptr<DraftMessage> &draft_message, Promise<Unit> &&promise);

  void reload_draft_message(DialogId dialog_id, const MessageTopic &message_topic, Promise<Unit> &&promise);

  void load_all_draft_messages();

  void clear_all_draft_messages(Promise<Unit> &&promise);

  FileSourceId get_draft_message_file_source_id(DialogId dialog_id, const MessageTopic &message_topic);

  void change_draft_message_files(DialogId dialog_id, const MessageTopic &message_topic,
                                  const vector<FileId> &old_file_ids, const vector<FileId> &new_file_ids,
                                  bool need_delete_files);

 private:
  void tear_down() final;

  Td *td_;
  ActorShared<> parent_;

  FileSourceId *get_file_source_id(DialogId dialog_id, const MessageTopic &message_topic);

  FlatHashMap<DialogId, FileSourceId, DialogIdHash> dialog_draft_message_file_source_ids_;
  FlatHashMap<DialogId, FlatHashMap<ForumTopicId, FileSourceId, ForumTopicIdHash>, DialogIdHash>
      forum_topic_draft_message_file_source_ids_;
  FlatHashMap<DialogId, FlatHashMap<SavedMessagesTopicId, FileSourceId, SavedMessagesTopicIdHash>, DialogIdHash>
      monoforum_topic_draft_message_file_source_ids_;
};

}  // namespace td