agsantos | 82678f3 | 2020-12-09 15:03:24 -0500 | [diff] [blame] | 1 | HEADER |
| 2 | |
| 3 | #include "GENERICChatSubscriber.h" |
| 4 | #include "pluglog.h" |
| 5 | |
| 6 | const std::string TAG = "GENERIC"; |
| 7 | |
| 8 | namespace jami { |
| 9 | |
| 10 | GENERICChatSubscriber::GENERICChatSubscriber(const JAMI_PluginAPI* api) |
| 11 | : api_ {api} |
| 12 | {} |
| 13 | |
| 14 | GENERICChatSubscriber::~GENERICChatSubscriber() |
| 15 | { |
| 16 | std::ostringstream oss; |
| 17 | oss << "~GENERICChatProcessor" << std::endl; |
| 18 | Plog::log(Plog::LogPriority::INFO, TAG, oss.str()); |
| 19 | } |
| 20 | |
| 21 | void |
| 22 | GENERICChatSubscriber::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 | |
| 34 | void |
| 35 | GENERICChatSubscriber::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 | |
| 46 | void |
| 47 | GENERICChatSubscriber::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 | |
| 59 | void |
| 60 | GENERICChatSubscriber::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 |