Ring Daemon 16.0.0
Loading...
Searching...
No Matches
chatservicesmanager.h
Go to the documentation of this file.
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#pragma once
18
19#include "noncopyable.h"
20#include "chathandler.h"
22
23namespace jami {
24
25class PluginManager;
26
27using ChatHandlerPtr = std::unique_ptr<ChatHandler>;
28
38{
39public:
48
50
51 bool hasHandlers() const;
52
57 std::vector<std::string> getChatHandlers() const;
58
64 void publishMessage(pluginMessagePtr message);
65
72 void cleanChatSubjects(const std::string& accountId, const std::string& peerId = "");
73
81 void toggleChatHandler(const std::string& chatHandlerId,
82 const std::string& accountId,
83 const std::string& peerId,
84 const bool toggle);
85
92 std::vector<std::string> getChatHandlerStatus(const std::string& accountId,
93 const std::string& peerId);
94
100 std::map<std::string, std::string> getChatHandlerDetails(const std::string& chatHandlerIdStr);
101
109 bool setPreference(const std::string& key,
110 const std::string& value,
111 const std::string& rootPath);
112
113private:
118 void registerComponentsLifeCycleManagers(PluginManager& pluginManager);
119
125 void registerChatService(PluginManager& pluginManager);
126
128 const std::string& accountId,
129 const std::string& peerId,
130 const bool toggle);
131
132 // Components that a plugin can register through registerChatHandler service.
133 // These objects can then be activated with toggleChatHandler.
134 std::list<ChatHandlerPtr> chatHandlers_;
135
136 // Component that stores active ChatHandlers for each existing accountId, peerId pair.
137 std::map<std::pair<std::string, std::string>, std::set<uintptr_t>> chatHandlerToggled_;
138
139 // When there is a new message, chat subjects are created.
140 // Here we store a reference to them in order to make them interact with
141 // ChatHandlers.
142 // For easy access they are mapped accordingly to the accountId, peerId pair to
143 // which they belong.
144 std::map<std::pair<std::string, std::string>, chatSubjectPtr> chatSubjects_;
145
146 // Maps a ChatHandler name and the address of this ChatHandler.
147 std::map<std::string, uintptr_t> handlersNameMap_ {};
148
149 // Component that stores persistent ChatHandlers' status for each existing
150 // accountId, peerId pair.
151 // A map of accountId, peerId pairs and ChatHandler-status pairs.
152 ChatHandlerList allowDenyList_ {};
153};
154} // namespace jami
This class provides the interface between loaded ChatHandlers and conversation messages.
std::vector< std::string > getChatHandlerStatus(const std::string &accountId, const std::string &peerId)
Returns a list of active ChatHandlers for a given accountId, peerId pair.
bool setPreference(const std::string &key, const std::string &value, const std::string &rootPath)
Sets a preference that may be changed while ChatHandler is active.
NON_COPYABLE(ChatServicesManager)
void publishMessage(pluginMessagePtr message)
Publishes every message sent or received in a conversation that has (or should have) an active ChatHa...
std::vector< std::string > getChatHandlers() const
List all ChatHandlers available.
void cleanChatSubjects(const std::string &accountId, const std::string &peerId="")
If an account is unregistered or a contact is erased, we clear all chat subjects related to that acco...
std::map< std::string, std::string > getChatHandlerDetails(const std::string &chatHandlerIdStr)
Gets details from ChatHandler implementation.
void toggleChatHandler(const std::string &chatHandlerId, const std::string &accountId, const std::string &peerId, const bool toggle)
Activates or deactivate a given ChatHandler to a given accountId, peerId pair.
This class manages plugin (un)loading.
std::unique_ptr< ChatHandler > ChatHandlerPtr
void emitSignal(Args... args)
Definition ring_signal.h:64
std::map< std::pair< std::string, std::string >, std::map< std::string, bool > > ChatHandlerList
std::shared_ptr< JamiMessage > pluginMessagePtr
Definition chathandler.h:26
std::shared_ptr< PublishObservable< pluginMessagePtr > > chatSubjectPtr
Definition chathandler.h:27
Simple macro to hide class' copy constructor and assignment operator.