blob: f1b1907694f8a4233f9f4508e3f786b907580c6c [file] [log] [blame]
Aline Gondim Santosfd302912022-08-18 12:07:46 -03001/**
2 * Copyright (C) 2020-2021 Savoir-faire Linux Inc.
3 *
4 * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#include "ChatHandlerTester.h"
22
23#include "pluglog.h"
24
25const char sep = separator();
26const std::string TAG = "ChatHandlerTester";
27
28#define NAME "ChatHandlerTester"
29
30namespace jami {
31
32ChatHandlerTester::ChatHandlerTester(std::string&& dataPath)
33 : datapath_ {dataPath}
34{
35 setId(datapath_);
36 mCS_ = std::make_shared<ChatSubscriberTester>();
37}
38
39void
40ChatHandlerTester::notifyChatSubject(std::pair<std::string, std::string>& subjectConnection,
41 chatSubjectPtr subject)
42{
43 if (mCS_ && subjects.find(subject) == subjects.end()) {
44 std::ostringstream oss;
45 oss << "NEW SUBJECT: account = " << subjectConnection.first
46 << " peer = " << subjectConnection.second << std::endl;
47 Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
48 subject->attach(mCS_.get());
49 subjects.insert(subject);
50 }
51}
52
53std::map<std::string, std::string>
54ChatHandlerTester::getChatHandlerDetails()
55{
56 return {{"name", NAME}, {"iconPath", datapath_ + sep + "icon.svg"}, {"pluginId", id()}};
57}
58
59void
60ChatHandlerTester::detach(chatSubjectPtr subject)
61{
62 auto it = subjects.find(subject);
63 if (it != subjects.end()) {
64 subject->detach(mCS_.get());
65 subjects.erase(it);
66 }
67}
68
69ChatHandlerTester::~ChatHandlerTester()
70{
71 const auto copy = subjects;
72 for (const auto& subject : copy) {
73 detach(subject);
74 }
75}
76} // namespace jami