Line data Source code
1 : /*
2 : * Copyright (C) 2004-2026 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 "observer.h"
20 : #include "streamdata.h"
21 : #include "jami/conversation_interface.h"
22 : #include <string>
23 : #include <map>
24 : #include <vector>
25 :
26 : namespace jami {
27 :
28 : using pluginMessagePtr = std::shared_ptr<JamiMessage>;
29 : using chatSubjectPtr = std::shared_ptr<PublishObservable<pluginMessagePtr>>;
30 :
31 : /**
32 : * @brief This abstract class is an API we need to implement from plugin side.
33 : * In other words, a plugin functionality that plays with messages, must start
34 : * from the implementation of this class.
35 : */
36 : class ChatHandler
37 : {
38 : public:
39 : virtual ~ChatHandler() {}
40 :
41 : /**
42 : * @brief Should attach a chat subject (Observable) and the plugin data process (Observer).
43 : * @param subjectConnection accountId, peerId pair
44 : * @param subject chat Subject pointer
45 : */
46 : virtual void notifyChatSubject(std::pair<std::string, std::string>& subjectConnection, chatSubjectPtr subject) = 0;
47 :
48 : /**
49 : * @brief Returns a map with handler's name, iconPath, and pluginId.
50 : */
51 : virtual std::map<std::string, std::string> getChatHandlerDetails() = 0;
52 :
53 : /**
54 : * @brief Should detach a chat subject (Observable) and the plugin data process (Observer).
55 : * @param subject chat subject pointer
56 : */
57 : virtual void detach(chatSubjectPtr subject) = 0;
58 :
59 : /**
60 : * @brief If a preference can be changed without the need to reload the plugin, it
61 : * should be done through this function.
62 : * @param key
63 : * @param value
64 : */
65 : virtual void setPreferenceAttribute(const std::string& key, const std::string& value) = 0;
66 :
67 : /**
68 : * @brief If a preference can be changed without the need to reload the plugin, this function
69 : * should return True.
70 : * @param key
71 : * @return True if preference can be changed through setPreferenceAttribute method.
72 : */
73 : virtual bool preferenceMapHasKey(const std::string& key) = 0;
74 :
75 : /**
76 : * @brief Called by ChatServicesManager to let plugins set pluginData["bodyOverwrite"] on
77 : * messages (e.g., to translate them). Only that field is read back by the daemon; any
78 : * other in-place modification is silently ignored.
79 : * The default implementation is a no-op.
80 : * @param messages Messages to transform; set pluginData["bodyOverwrite"] to override
81 : * the displayed body. Other modifications have no effect.
82 : * @param accountId Account that owns the conversation.
83 : * @param conversationId Conversation the messages belong to.
84 : */
85 : virtual void transformSwarmMessages(std::vector<libjami::SwarmMessage>& /* messages */,
86 : const std::string& /* accountId */,
87 : const std::string& /* conversationId */)
88 : {}
89 :
90 : /**
91 : * @brief Returns the dataPath of the plugin that created this ChatHandler.
92 : */
93 22 : std::string id() const { return id_; }
94 :
95 : /**
96 : * @brief Should be called by the ChatHandler creator to set the plugins id_ variable.
97 : */
98 : virtual void setId(const std::string& id) final { id_ = id; }
99 :
100 : private:
101 : // Is the dataPath of the plugin that created this ChatHandler.
102 : std::string id_;
103 : };
104 : } // namespace jami
|