| /** |
| * Copyright (C) 2020 Savoir-faire Linux Inc. |
| * |
| * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> |
| * |
| * This program is free software; you can redistribute it and/or modify |
| * it under the terms of the GNU General Public License as published by |
| * the Free Software Foundation; either version 3 of the License, or |
| * (at your option) any later version. |
| * |
| * This program is distributed in the hope that it will be useful, |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| * GNU General Public License for more details. |
| * |
| * You should have received a copy of the GNU General Public License |
| * along with this program; if not, write to the Free Software |
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| */ |
| |
| #include "botchathandler.h" |
| |
| #include "pluglog.h" |
| |
| const char sep = separator(); |
| const std::string TAG = "bot"; |
| |
| #define NAME "bot" |
| |
| namespace jami { |
| |
| botChatHandler::botChatHandler(const JAMI_PluginAPI* api, |
| std::map<std::string, std::string>&& ppm, |
| std::string&& dataPath) |
| : api_ {api} |
| , datapath_ {dataPath} |
| { |
| ppm_ = ppm; |
| setId(datapath_); |
| peerChatSubscriber_ = std::make_shared<botPeerChatSubscriber>(api_, dataPath); |
| }; |
| |
| void |
| botChatHandler::notifyChatSubject(std::pair<std::string, std::string>& subjectConnection, |
| chatSubjectPtr subject) |
| { |
| if (subjects.find(subject) == subjects.end()) { |
| std::ostringstream oss; |
| oss << "NEW SUBJECT: account = " << subjectConnection.first |
| << " peer = " << subjectConnection.second << std::endl; |
| Plog::log(Plog::LogPriority::INFO, TAG, oss.str()); |
| subject->attach(peerChatSubscriber_.get()); |
| subjects.insert(subject); |
| } |
| } |
| |
| std::map<std::string, std::string> |
| botChatHandler::getChatHandlerDetails() |
| { |
| return {{"name", NAME}, {"iconPath", datapath_ + sep + "icon.png"}, {"pluginId", id()}}; |
| } |
| |
| void |
| botChatHandler::setPreferenceAttribute(const std::string& key, const std::string& value) |
| { |
| auto it = ppm_.find(key); |
| if (it != ppm_.end()) { |
| if (ppm_[key] != value) { |
| ppm_[key] = value; |
| } |
| } |
| } |
| |
| bool |
| botChatHandler::preferenceMapHasKey(const std::string& key) |
| { |
| return false; |
| } |
| |
| void |
| botChatHandler::detach(chatSubjectPtr subject) |
| { |
| if (subjects.find(subject) != subjects.end()) { |
| subject->detach(peerChatSubscriber_.get()); |
| subjects.erase(subject); |
| } |
| } |
| |
| botChatHandler::~botChatHandler() |
| { |
| auto& copy(subjects); |
| for (const auto& subject : copy) { |
| detach(subject); |
| } |
| copy.clear(); |
| } |
| } // namespace jami |