From 17c0bc64a374d601012943a0a79ace65734dd922 Mon Sep 17 00:00:00 2001
From: agsantos <aline.gondimsantos@savoirfairelinux.com>
Date: Tue, 15 Dec 2020 16:42:56 -0500
Subject: [PATCH] swarm: add support

Change-Id: I12ec5fd0d79c9cdda63f25e7d042e6836828833c
---
 AutoAnswer/BotPeerChatSubscriber.cpp | 26 ++++++++++++++++++++------
 AutoAnswer/BotPeerChatSubscriber.h   |  3 ++-
 AutoAnswer/CMakeLists.txt            |  2 +-
 AutoAnswer/main.cpp                  |  4 ++--
 AutoAnswer/manifest.json             | 10 +++++-----
 AutoAnswer/package.json              |  2 +-
 6 files changed, 31 insertions(+), 16 deletions(-)

diff --git a/AutoAnswer/BotPeerChatSubscriber.cpp b/AutoAnswer/BotPeerChatSubscriber.cpp
index 26c6d30..c1e6761 100644
--- a/AutoAnswer/BotPeerChatSubscriber.cpp
+++ b/AutoAnswer/BotPeerChatSubscriber.cpp
@@ -59,13 +59,21 @@ BotPeerChatSubscriber::update(Observable<pluginMessagePtr>*, const pluginMessage
     if (isAttached) {
         if (message->direction) {
             std::map<std::string, std::string> sendMsg;
-            for (auto& pair : message->data) {
-                if (pair.first == "text/plain" && pair.second == inText_) {
-                    sendMsg[pair.first] = textAnswer_;
+            if (message->fromHistory)
+                return;
+            if (!message->isSwarm)
+                for (auto& pair : message->data) {
+                    if (pair.first == "text/plain" && pair.second == inText_) {
+                        sendMsg[pair.first] = textAnswer_;
+                    }
                 }
+            else if (message->data.at("type") == "text/plain"
+                     && message->data.at("body") == inText_) {
+                sendMsg["type"] = "text/plain";
+                sendMsg["body"] = textAnswer_;
             }
             if (!sendMsg.empty()) {
-                sendText(message->accountId, message->peerId, sendMsg);
+                sendText(message->accountId, message->peerId, sendMsg, message->isSwarm);
             }
         }
     }
@@ -100,9 +108,15 @@ BotPeerChatSubscriber::detached(Observable<pluginMessagePtr>* observable)
 void
 BotPeerChatSubscriber::sendText(std::string& accountId,
                                 std::string& peerId,
-                                std::map<std::string, std::string>& sendMsg)
+                                std::map<std::string, std::string>& sendMsg,
+                                bool swarm)
 {
-    pluginMessagePtr botAnswer = std::make_shared<JamiMessage>(accountId, peerId, false, sendMsg, true);
+    pluginMessagePtr botAnswer = std::make_shared<JamiMessage>(accountId,
+                                                               peerId,
+                                                               false,
+                                                               sendMsg,
+                                                               true);
+    botAnswer->isSwarm = swarm;
     api_->invokeService(api_, "sendTextMessage", botAnswer.get());
 }
 } // namespace jami
diff --git a/AutoAnswer/BotPeerChatSubscriber.h b/AutoAnswer/BotPeerChatSubscriber.h
index a2c66db..26b7a27 100644
--- a/AutoAnswer/BotPeerChatSubscriber.h
+++ b/AutoAnswer/BotPeerChatSubscriber.h
@@ -44,7 +44,8 @@ public:
 
     void sendText(std::string& accountId,
                   std::string& peerId,
-                  std::map<std::string, std::string>& sendMsg);
+                  std::map<std::string, std::string>& sendMsg,
+                  bool swarm);
     void setAnswer(const std::string& textAnswer);
     void setInText(const std::string& inText);
 
diff --git a/AutoAnswer/CMakeLists.txt b/AutoAnswer/CMakeLists.txt
index db5d00d..8e01446 100644
--- a/AutoAnswer/CMakeLists.txt
+++ b/AutoAnswer/CMakeLists.txt
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.10)
 
 # set the project name
 set (ProjectName AutoAnswer)
-set (Version 0.1.0)
+set (Version 1.0.0)
 
 project(${ProjectName} VERSION ${Version})
 
diff --git a/AutoAnswer/main.cpp b/AutoAnswer/main.cpp
index b35e176..7d90bba 100644
--- a/AutoAnswer/main.cpp
+++ b/AutoAnswer/main.cpp
@@ -32,8 +32,8 @@
 #define EXPORT_PLUGIN
 #endif
 
-#define AutoAnswer_VERSION_MAJOR 0
-#define AutoAnswer_VERSION_MINOR 1
+#define AutoAnswer_VERSION_MAJOR 1
+#define AutoAnswer_VERSION_MINOR 0
 #define AutoAnswer_VERSION_PATCH 0
 
 extern "C" {
diff --git a/AutoAnswer/manifest.json b/AutoAnswer/manifest.json
index 5855af7..2cb02f9 100644
--- a/AutoAnswer/manifest.json
+++ b/AutoAnswer/manifest.json
@@ -1,6 +1,6 @@
 {
-	"name": "AutoAnswer",
-	"description" : "A plugin that automatically answers with given text",
-	"version" : "0.1.0",
-    "iconPath" : "icon.svg"
-}
+    "name": "AutoAnswer",
+    "description": "A plugin that automatically answers with given text",
+    "version": "1.0.0",
+    "iconPath": "icon.svg"
+}
\ No newline at end of file
diff --git a/AutoAnswer/package.json b/AutoAnswer/package.json
index 5d42d67..25df316 100644
--- a/AutoAnswer/package.json
+++ b/AutoAnswer/package.json
@@ -1,6 +1,6 @@
 {
     "name": "AutoAnswer",
-    "version": "0.1.0",
+    "version": "1.0.0",
     "extractLibs": false,
     "deps": [],
     "defines": [],
-- 
GitLab