blob: 03185cc9243b0991658837d2f46f37942fa72d4b [file] [log] [blame]
agsantos82678f32020-12-09 15:03:24 -05001HEADER
2
3#include "GENERICChatHandler.h"
4
5#include "pluglog.h"
6
7const char sep = separator();
8const std::string TAG = "GENERIC";
9
10#define NAME "GENERIC"
11
12namespace jami {
13
14GENERICChatHandler::GENERICChatHandler(const JAMI_PluginAPI* api,
15 std::map<std::string, std::string>&& preferences,
16 std::string&& dataPath)
17 : api_ {api}
18 , datapath_ {dataPath}
19{
20 preferences_ = preferences;
21 setId(datapath_);
22 GENERICChatSubscriber_ = std::make_shared<GENERICChatSubscriber>(api_);
23};
24
25void
26GENERICChatHandler::notifyChatSubject(std::pair<std::string, std::string>& subjectConnection,
27 chatSubjectPtr subject)
28{
29 if (subjects.find(subject) == subjects.end()) {
30 std::ostringstream oss;
31 oss << "NEW SUBJECT: account = " << subjectConnection.first
32 << " peer = " << subjectConnection.second << std::endl;
33 Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
34 subject->attach(GENERICChatSubscriber_.get());
35 subjects.insert(subject);
36 }
37}
38
39std::map<std::string, std::string>
40GENERICChatHandler::getChatHandlerDetails()
41{
42 return { {"name", NAME},
agsantosd00bf412021-01-26 13:43:33 -050043 {"iconPath", datapath_ + sep + "icon.svg"},
agsantos82678f32020-12-09 15:03:24 -050044 {"pluginId", id()} };
45}
46
47void
48GENERICChatHandler::setPreferenceAttribute(const std::string& key, const std::string& value)
49{
50 auto it = preferences_.find(key);
51 if (it != preferences_.end() && it->second != value) {
52 it->second = value;----------------
53 if (key == "PREFERENCE1") {
54 // use preference
55 return;
56 }----------------
57 }
58}
59
60bool
61GENERICChatHandler::preferenceMapHasKey(const std::string& key)
62{----------------
63 if (key == "PREFERENCE2") { return true; }----------------
64 return false;
65}
66
67void
68GENERICChatHandler::detach(chatSubjectPtr subject)
69{
70 if (subjects.find(subject) != subjects.end()) {
71 subject->detach(GENERICChatSubscriber_.get());
72 subjects.erase(subject);
73 }
74}
75
76GENERICChatHandler::~GENERICChatHandler()
77{
78 auto& copy(subjects);
79 for (const auto& subject : copy) {
80 detach(subject);
81 }
82 copy.clear();
83}
84} // namespace jami