Line data Source code
1 : /*
2 : * Copyright (C) 2004-2025 Savoir-faire Linux Inc.
3 : *
4 : * This program is free software: you can redistribute it and/or modify
5 : * it under the terms of the GNU General Public License as published by
6 : * the Free Software Foundation, either version 3 of the License, or
7 : * (at your option) any later version.
8 : *
9 : * This program is distributed in the hope that it will be useful,
10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 : * GNU General Public License for more details.
13 : *
14 : * You should have received a copy of the GNU General Public License
15 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 : */
17 :
18 : #ifndef LIBJAMI_CONVERSATIONI_H
19 : #define LIBJAMI_CONVERSATIONI_H
20 :
21 : #include "def.h"
22 :
23 : #include <vector>
24 : #include <map>
25 : #include <string>
26 : #include <list>
27 :
28 : #include "jami.h"
29 :
30 : namespace libjami {
31 :
32 : struct SwarmMessage
33 : {
34 : std::string id;
35 : std::string type;
36 : std::string linearizedParent;
37 : std::map<std::string, std::string> body;
38 : std::vector<std::map<std::string, std::string>> reactions;
39 : std::vector<std::map<std::string, std::string>> editions;
40 : std::map<std::string, int32_t> status;
41 :
42 8643 : void fromMapStringString(const std::map<std::string, std::string>& commit)
43 : {
44 8643 : id = commit.at("id");
45 8646 : type = commit.at("type");
46 8647 : body = commit; // TODO erase type/id?
47 8642 : }
48 : };
49 :
50 : // Conversation management
51 : LIBJAMI_PUBLIC std::string startConversation(const std::string& accountId);
52 : LIBJAMI_PUBLIC void acceptConversationRequest(const std::string& accountId, const std::string& conversationId);
53 : LIBJAMI_PUBLIC void declineConversationRequest(const std::string& accountId, const std::string& conversationId);
54 : LIBJAMI_PUBLIC bool removeConversation(const std::string& accountId, const std::string& conversationId);
55 : LIBJAMI_PUBLIC std::vector<std::string> getConversations(const std::string& accountId);
56 : LIBJAMI_PUBLIC std::vector<std::map<std::string, std::string>> getConversationRequests(const std::string& accountId);
57 :
58 : // Calls
59 : LIBJAMI_PUBLIC std::vector<std::map<std::string, std::string>> getActiveCalls(const std::string& accountId,
60 : const std::string& conversationId);
61 :
62 : // Conversation's infos management
63 : LIBJAMI_PUBLIC void updateConversationInfos(const std::string& accountId,
64 : const std::string& conversationId,
65 : const std::map<std::string, std::string>& infos);
66 : LIBJAMI_PUBLIC std::map<std::string, std::string> conversationInfos(const std::string& accountId,
67 : const std::string& conversationId);
68 : LIBJAMI_PUBLIC void setConversationPreferences(const std::string& accountId,
69 : const std::string& conversationId,
70 : const std::map<std::string, std::string>& prefs);
71 : LIBJAMI_PUBLIC std::map<std::string, std::string> getConversationPreferences(const std::string& accountId,
72 : const std::string& conversationId);
73 :
74 : // Member management
75 : LIBJAMI_PUBLIC void addConversationMember(const std::string& accountId,
76 : const std::string& conversationId,
77 : const std::string& contactUri);
78 : LIBJAMI_PUBLIC void removeConversationMember(const std::string& accountId,
79 : const std::string& conversationId,
80 : const std::string& contactUri);
81 : LIBJAMI_PUBLIC std::vector<std::map<std::string, std::string>> getConversationMembers(const std::string& accountId,
82 : const std::string& conversationId);
83 :
84 : // Message send/load
85 : LIBJAMI_PUBLIC void sendMessage(const std::string& accountId,
86 : const std::string& conversationId,
87 : const std::string& message,
88 : const std::string& replyTo,
89 : const int32_t& flag = 0);
90 : LIBJAMI_PUBLIC uint32_t loadConversation(const std::string& accountId,
91 : const std::string& conversationId,
92 : const std::string& fromMessage,
93 : size_t n);
94 : LIBJAMI_PUBLIC uint32_t loadSwarmUntil(const std::string& accountId,
95 : const std::string& conversationId,
96 : const std::string& fromMessage,
97 : const std::string& toMessage);
98 : LIBJAMI_PUBLIC uint32_t countInteractions(const std::string& accountId,
99 : const std::string& conversationId,
100 : const std::string& toId,
101 : const std::string& fromId,
102 : const std::string& authorUri);
103 : LIBJAMI_PUBLIC void clearCache(const std::string& accountId, const std::string& conversationId);
104 : LIBJAMI_PUBLIC uint32_t searchConversation(const std::string& accountId,
105 : const std::string& conversationId,
106 : const std::string& author,
107 : const std::string& lastId,
108 : const std::string& regexSearch,
109 : const std::string& type,
110 : const int64_t& after,
111 : const int64_t& before,
112 : const uint32_t& maxResult,
113 : const int32_t& flag);
114 : LIBJAMI_PUBLIC void reloadConversationsAndRequests(const std::string& accountId);
115 :
116 : struct LIBJAMI_PUBLIC ConversationSignal
117 : {
118 : struct LIBJAMI_PUBLIC SwarmLoaded
119 : {
120 : constexpr static const char* name = "SwarmLoaded";
121 : using cb_type = void(uint32_t /* id */,
122 : const std::string& /*accountId*/,
123 : const std::string& /* conversationId */,
124 : std::vector<SwarmMessage> /*messages*/);
125 : };
126 : struct LIBJAMI_PUBLIC MessagesFound
127 : {
128 : constexpr static const char* name = "MessagesFound";
129 : using cb_type = void(uint32_t /* id */,
130 : const std::string& /*accountId*/,
131 : const std::string& /* conversationId */,
132 : std::vector<std::map<std::string, std::string>> /*messages*/);
133 : };
134 : struct LIBJAMI_PUBLIC SwarmMessageReceived
135 : {
136 : constexpr static const char* name = "SwarmMessageReceived";
137 : using cb_type = void(const std::string& /*accountId*/,
138 : const std::string& /* conversationId */,
139 : const SwarmMessage& /*message*/);
140 : };
141 : struct LIBJAMI_PUBLIC SwarmMessageUpdated
142 : {
143 : constexpr static const char* name = "SwarmMessageUpdated";
144 : using cb_type = void(const std::string& /*accountId*/,
145 : const std::string& /* conversationId */,
146 : const SwarmMessage& /*message*/);
147 : };
148 : struct LIBJAMI_PUBLIC ReactionAdded
149 : {
150 : constexpr static const char* name = "ReactionAdded";
151 : using cb_type = void(const std::string& /*accountId*/,
152 : const std::string& /* conversationId */,
153 : const std::string& /* messageId */,
154 : std::map<std::string, std::string> /*reaction*/);
155 : };
156 : struct LIBJAMI_PUBLIC ReactionRemoved
157 : {
158 : constexpr static const char* name = "ReactionRemoved";
159 : using cb_type = void(const std::string& /*accountId*/,
160 : const std::string& /* conversationId */,
161 : const std::string& /* messageId */,
162 : const std::string& /* reactionId */);
163 : };
164 : struct LIBJAMI_PUBLIC ConversationProfileUpdated
165 : {
166 : constexpr static const char* name = "ConversationProfileUpdated";
167 : using cb_type = void(const std::string& /*accountId*/,
168 : const std::string& /* conversationId */,
169 : std::map<std::string, std::string> /*profile*/);
170 : };
171 : struct LIBJAMI_PUBLIC ConversationRequestReceived
172 : {
173 : constexpr static const char* name = "ConversationRequestReceived";
174 : using cb_type = void(const std::string& /*accountId*/,
175 : const std::string& /* conversationId */,
176 : std::map<std::string, std::string> /*metadatas*/);
177 : };
178 : struct LIBJAMI_PUBLIC ConversationRequestDeclined
179 : {
180 : constexpr static const char* name = "ConversationRequestDeclined";
181 : using cb_type = void(const std::string& /*accountId*/, const std::string& /* conversationId */);
182 : };
183 : struct LIBJAMI_PUBLIC ConversationReady
184 : {
185 : constexpr static const char* name = "ConversationReady";
186 : using cb_type = void(const std::string& /*accountId*/, const std::string& /* conversationId */);
187 : };
188 : struct LIBJAMI_PUBLIC ConversationRemoved
189 : {
190 : constexpr static const char* name = "ConversationRemoved";
191 : using cb_type = void(const std::string& /*accountId*/, const std::string& /* conversationId */);
192 : };
193 : struct LIBJAMI_PUBLIC ConversationMemberEvent
194 : {
195 : constexpr static const char* name = "ConversationMemberEvent";
196 : using cb_type = void(const std::string& /*accountId*/,
197 : const std::string& /* conversationId */,
198 : const std::string& /* memberUri */,
199 : int /* event 0 = add, 1 = joins, 2 = leave, 3 = banned */);
200 : };
201 :
202 : struct LIBJAMI_PUBLIC ConversationSyncFinished
203 : {
204 : constexpr static const char* name = "ConversationSyncFinished";
205 : using cb_type = void(const std::string& /*accountId*/);
206 : };
207 :
208 : struct LIBJAMI_PUBLIC ConversationCloned
209 : {
210 : constexpr static const char* name = "ConversationCloned";
211 : using cb_type = void(const std::string& /*accountId*/);
212 : };
213 :
214 : struct LIBJAMI_PUBLIC CallConnectionRequest
215 : {
216 : constexpr static const char* name = "CallConnectionRequest";
217 : using cb_type = void(const std::string& /*accountId*/, const std::string& /*peerId*/, bool hasVideo);
218 : };
219 :
220 : struct LIBJAMI_PUBLIC OnConversationError
221 : {
222 : constexpr static const char* name = "OnConversationError";
223 : using cb_type = void(const std::string& /*accountId*/,
224 : const std::string& /* conversationId */,
225 : int code,
226 : const std::string& what);
227 : };
228 :
229 : // Preferences
230 : struct LIBJAMI_PUBLIC ConversationPreferencesUpdated
231 : {
232 : constexpr static const char* name = "ConversationPreferencesUpdated";
233 : using cb_type = void(const std::string& /*accountId*/,
234 : const std::string& /*conversationId*/,
235 : std::map<std::string, std::string> /*preferences*/);
236 : };
237 : };
238 :
239 : } // namespace libjami
240 :
241 : #endif // LIBJAMI_CONVERSATIONI_H
|