From 7f5fa09354fa0e256121f484446ceedd88c57759 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Thu, 29 Feb 2024 11:18:09 -0500
Subject: [PATCH] typers: do not emit message for remote device

Change-Id: I6c783563a0a58327012a3e2889ea78ea6c595d89
---
 src/jamidht/typers.cpp | 19 +++++++++++--------
 src/jamidht/typers.h   |  9 +++++++--
 2 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/src/jamidht/typers.cpp b/src/jamidht/typers.cpp
index 1250e97a54..71c9538770 100644
--- a/src/jamidht/typers.cpp
+++ b/src/jamidht/typers.cpp
@@ -55,7 +55,7 @@ getIsComposing(const std::string& conversationId, bool isWriting)
 }
 
 void
-Typers::addTyper(const std::string &typer)
+Typers::addTyper(const std::string &typer, bool sendMessage)
 {
     auto acc = acc_.lock();
     if (!acc || !acc->isComposingEnabled())
@@ -73,27 +73,30 @@ Typers::addTyper(const std::string &typer)
 
         if (typer != selfUri_)
             emitSignal<libjami::ConfigurationSignal::ComposingStatusChanged>(accountId_,
-                                                                            convId_,
-                                                                            typer,
-                                                                            1);
+                                                                                convId_,
+                                                                                typer,
+                                                                                1);
+        return;
     }
-    if (typer == selfUri_) {
+    if (sendMessage) {
+        // In this case we should emit for remote to update the timer
         acc->sendInstantMessage(convId_,
                                {{MIME_TYPE_IM_COMPOSING, getIsComposing(convId_, true)}});
     }
 }
 
 void
-Typers::removeTyper(const std::string &typer)
+Typers::removeTyper(const std::string &typer, bool sendMessage)
 {
     auto acc = acc_.lock();
     if (!acc || !acc->isComposingEnabled())
         return;
     if (watcher_.erase(typer)) {
-        if (typer == selfUri_) {
+        if (sendMessage) {
             acc->sendInstantMessage(convId_,
                                 {{MIME_TYPE_IM_COMPOSING, getIsComposing(convId_, false)}});
-        } else {
+        }
+        if (typer != selfUri_) {
             emitSignal<libjami::ConfigurationSignal::ComposingStatusChanged>(accountId_,
                                                                                 convId_,
                                                                                 typer,
diff --git a/src/jamidht/typers.h b/src/jamidht/typers.h
index 5d177e30bd..eb0badc5eb 100644
--- a/src/jamidht/typers.h
+++ b/src/jamidht/typers.h
@@ -34,8 +34,13 @@ public:
     Typers(const std::shared_ptr<JamiAccount>& acc, const std::string &convId);
     ~Typers();
 
-    void addTyper(const std::string &typer);
-    void removeTyper(const std::string &typer);
+    /**
+     * Add typer to the list of typers
+     * @param typer
+     * @param sendMessage (should be true for local typer, false for remote typer)
+     */
+    void addTyper(const std::string &typer, bool sendMessage = false);
+    void removeTyper(const std::string &typer, bool sendMessage = false);
 
 private:
     void onTyperTimeout(const asio::error_code& ec, const std::string &typer);
-- 
GitLab