blob: d83ed56244515c8b6e897afa24e72c2e0d8676e8 [file] [log] [blame]
agsantos82678f32020-12-09 15:03:24 -05001HEADER
2
3#include "GENERICChatSubscriber.h"
4#include "pluglog.h"
5
6const std::string TAG = "GENERIC";
7
8namespace jami {
9
10GENERICChatSubscriber::GENERICChatSubscriber(const JAMI_PluginAPI* api)
11 : api_ {api}
12{}
13
14GENERICChatSubscriber::~GENERICChatSubscriber()
15{
16 std::ostringstream oss;
17 oss << "~GENERICChatProcessor" << std::endl;
18 Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
19}
20
21void
22GENERICChatSubscriber::update(Observable<pluginMessagePtr>*, const pluginMessagePtr& message)
23{
24 if (isAttached) {
25 if (message->direction == "0") { // "0" for input message; "1" for output message
26 for (auto& pair : message->data) {
27 // READ THE MESSAGE
28 }
29 // DO SOMETHING WITH YOUR TEXT
30 }
31 }
32}
33
34void
35GENERICChatSubscriber::attached(Observable<pluginMessagePtr>* observable)
36{
37 if (observables_.find(observable) == observables_.end()) {
38 std::ostringstream oss;
39 oss << "::Attached ! " << std::endl;
40 Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
41 observables_.insert(observable);
42 isAttached = true;
43 }
44}
45
46void
47GENERICChatSubscriber::detached(Observable<pluginMessagePtr>* observable)
48{
49 if (observables_.find(observable) != observables_.end()) {
50 observables_.erase(observable);
51 std::ostringstream oss;
52 oss << "::Detached()" << std::endl;
53 Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
54 if (observables_.empty())
55 isAttached = false;
56 }
57}
58
59void
60GENERICChatSubscriber::sendText(std::string& accountId,
61 std::string& peerId,
62 std::map<std::string, std::string>& sendMsg)
63{
64 pluginMessagePtr GENERICAnswer = std::make_shared<JamiMessage>(accountId, peerId, "0", sendMsg, true);
65 api_->invokeService(api_, "sendTextMessage", GENERICAnswer.get());
66}
67} // namespace jami