Line data Source code
1 : /* 2 : * Copyright (C) 2004-2024 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 <string> 22 : #include <map> 23 : 24 : namespace jami { 25 : 26 : using pluginMessagePtr = std::shared_ptr<JamiMessage>; 27 : using chatSubjectPtr = std::shared_ptr<PublishObservable<pluginMessagePtr>>; 28 : 29 : /** 30 : * @brief This abstract class is an API we need to implement from plugin side. 31 : * In other words, a plugin functionality that plays with messages, must start 32 : * from the implementation of this class. 33 : */ 34 : class ChatHandler 35 : { 36 : public: 37 : virtual ~ChatHandler() {} 38 : 39 : /** 40 : * @brief Should attach a chat subject (Observable) and the plugin data process (Observer). 41 : * @param subjectConnection accountId, peerId pair 42 : * @param subject chat Subject pointer 43 : */ 44 : virtual void notifyChatSubject(std::pair<std::string, std::string>& subjectConnection, 45 : chatSubjectPtr subject) 46 : = 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 Returns the dataPath of the plugin that created this ChatHandler. 77 : */ 78 24 : std::string id() const { return id_; } 79 : 80 : /** 81 : * @brief Should be called by the ChatHandler creator to set the plugins id_ variable. 82 : */ 83 : virtual void setId(const std::string& id) final { id_ = id; } 84 : 85 : private: 86 : // Is the dataPath of the plugin that created this ChatHandler. 87 : std::string id_; 88 : }; 89 : } // namespace jami