agsantos | 82678f3 | 2020-12-09 15:03:24 -0500 | [diff] [blame] | 1 | HEADER |
| 2 | |
| 3 | #include "GENERICChatHandler.h" |
| 4 | |
| 5 | #include "pluglog.h" |
| 6 | |
| 7 | const char sep = separator(); |
| 8 | const std::string TAG = "GENERIC"; |
| 9 | |
| 10 | #define NAME "GENERIC" |
| 11 | |
| 12 | namespace jami { |
| 13 | |
| 14 | GENERICChatHandler::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 | |
| 25 | void |
| 26 | GENERICChatHandler::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 | |
| 39 | std::map<std::string, std::string> |
| 40 | GENERICChatHandler::getChatHandlerDetails() |
| 41 | { |
| 42 | return { {"name", NAME}, |
agsantos | d00bf41 | 2021-01-26 13:43:33 -0500 | [diff] [blame] | 43 | {"iconPath", datapath_ + sep + "icon.svg"}, |
agsantos | 82678f3 | 2020-12-09 15:03:24 -0500 | [diff] [blame] | 44 | {"pluginId", id()} }; |
| 45 | } |
| 46 | |
| 47 | void |
| 48 | GENERICChatHandler::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 | |
| 60 | bool |
| 61 | GENERICChatHandler::preferenceMapHasKey(const std::string& key) |
| 62 | {---------------- |
| 63 | if (key == "PREFERENCE2") { return true; }---------------- |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | void |
| 68 | GENERICChatHandler::detach(chatSubjectPtr subject) |
| 69 | { |
| 70 | if (subjects.find(subject) != subjects.end()) { |
| 71 | subject->detach(GENERICChatSubscriber_.get()); |
| 72 | subjects.erase(subject); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | GENERICChatHandler::~GENERICChatHandler() |
| 77 | { |
| 78 | auto& copy(subjects); |
| 79 | for (const auto& subject : copy) { |
| 80 | detach(subject); |
| 81 | } |
| 82 | copy.clear(); |
| 83 | } |
| 84 | } // namespace jami |