From 7f197733953d3d335bd7963afe698285d28392e8 Mon Sep 17 00:00:00 2001
From: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
Date: Sat, 26 Sep 2020 21:09:49 -0400
Subject: [PATCH] api: use id strings instead of Info refs in signals

If signals are to be consumed from a queue, then at least one copy
is required, and potentially beefy custom types shouldn't be
marshalled between threads without good reason. It is more sensible
to use conversation Id parameters, as consumers can likely make
good use only the Id, and may query for an Info structure at any
time if needed.

Change-Id: I5151c8ac006857c6510258332647e52ce16821af
---
 src/api/behaviorcontroller.h | 12 ++++--------
 src/conversationmodel.cpp    | 20 ++++++++++----------
 2 files changed, 14 insertions(+), 18 deletions(-)

diff --git a/src/api/behaviorcontroller.h b/src/api/behaviorcontroller.h
index 8d47dde4..62338c22 100644
--- a/src/api/behaviorcontroller.h
+++ b/src/api/behaviorcontroller.h
@@ -55,24 +55,20 @@ Q_SIGNALS:
     /**
      * Emitted when the client should open the chat view.
      */
-    void showChatView(const QString& accountId,
-                      const api::conversation::Info& conversationInfo) const;
+    void showChatView(const QString& accountId, const QString& convUid) const;
     /**
      * Emitted when the client should ask the user whether it wants to leave a message after a
      * failed call.
      */
-    void showLeaveMessageView(const QString& accountId,
-                              const api::conversation::Info& conversationInfo) const;
+    void showLeaveMessageView(const QString& accountId, const QString& convUid) const;
     /**
      * Emitted when the client should open the call view.
      */
-    void showCallView(const QString& accountId,
-                      const api::conversation::Info& conversationInfo) const;
+    void showCallView(const QString& accountId, const QString& convUid) const;
     /**
      * Emitted when the client should open the incoming call view.
      */
-    void showIncomingCallView(const QString& accountId,
-                              const api::conversation::Info& conversationInfo) const;
+    void showIncomingCallView(const QString& accountId, const QString& convUid) const;
     /**
      * Emitted when the client receives a new trust request
      */
diff --git a/src/conversationmodel.cpp b/src/conversationmodel.cpp
index 94657926..4ccc8656 100644
--- a/src/conversationmodel.cpp
+++ b/src/conversationmodel.cpp
@@ -652,9 +652,9 @@ ConversationModel::selectConversation(const QString& uid) const
         }
 
         if (not callEnded and not conversation.confId.isEmpty()) {
-            emit pimpl_->behaviorController.showCallView(owner.id, conversation);
+            emit pimpl_->behaviorController.showCallView(owner.id, conversation.uid);
         } else if (callEnded) {
-            emit pimpl_->behaviorController.showChatView(owner.id, conversation);
+            emit pimpl_->behaviorController.showChatView(owner.id, conversation.uid);
         } else {
             try {
                 auto call = owner.callModel->getCall(conversation.callId);
@@ -664,23 +664,23 @@ ConversationModel::selectConversation(const QString& uid) const
                 case call::Status::CONNECTING:
                 case call::Status::SEARCHING:
                     // We are currently in a call
-                    emit pimpl_->behaviorController.showIncomingCallView(owner.id, conversation);
+                    emit pimpl_->behaviorController.showIncomingCallView(owner.id, conversation.uid);
                     break;
                 case call::Status::PAUSED:
                 case call::Status::CONNECTED:
                 case call::Status::IN_PROGRESS:
                     // We are currently receiving a call
-                    emit pimpl_->behaviorController.showCallView(owner.id, conversation);
+                    emit pimpl_->behaviorController.showCallView(owner.id, conversation.uid);
                     break;
                 case call::Status::PEER_BUSY:
-                    emit pimpl_->behaviorController.showLeaveMessageView(owner.id, conversation);
+                    emit pimpl_->behaviorController.showLeaveMessageView(owner.id, conversation.uid);
                     break;
                 case call::Status::TIMEOUT:
                 case call::Status::TERMINATING:
                 case call::Status::INVALID:
                 case call::Status::INACTIVE:
                     // call just ended
-                    emit pimpl_->behaviorController.showChatView(owner.id, conversation);
+                    emit pimpl_->behaviorController.showChatView(owner.id, conversation.uid);
                     break;
                 case call::Status::ENDED:
                 default: // ENDED
@@ -689,7 +689,7 @@ ConversationModel::selectConversation(const QString& uid) const
                 }
             } catch (const std::out_of_range&) {
                 // Should not happen
-                emit pimpl_->behaviorController.showChatView(owner.id, conversation);
+                emit pimpl_->behaviorController.showChatView(owner.id, conversation.uid);
             }
         }
     } catch (const std::out_of_range& e) {
@@ -808,7 +808,7 @@ ConversationModelPimpl::placeCall(const QString& uid, bool isAudioOnly)
                 }
 
                 dirtyConversations = {true, true};
-                emit behaviorController.showIncomingCallView(linked.owner.id, newConv);
+                emit behaviorController.showIncomingCallView(linked.owner.id, newConv.uid);
             });
 
         if (isTemporary) {
@@ -1877,7 +1877,7 @@ ConversationModelPimpl::slotIncomingCall(const QString& fromId, const QString& c
     qDebug() << "Add call to conversation with " << fromId;
     conversation.callId = callId;
     dirtyConversations = {true, true};
-    emit behaviorController.showIncomingCallView(linked.owner.id, conversation);
+    emit behaviorController.showIncomingCallView(linked.owner.id, conversation.uid);
 }
 
 void
@@ -1906,7 +1906,7 @@ ConversationModelPimpl::slotCallStatusChanged(const QString& callId, int code)
                 }
             }
         } else if (call.status == call::Status::PEER_BUSY) {
-            emit behaviorController.showLeaveMessageView(linked.owner.id, *i);
+            emit behaviorController.showLeaveMessageView(linked.owner.id, i->uid);
         }
     } catch (std::out_of_range& e) {
         qDebug() << "ConversationModelPimpl::slotCallStatusChanged can't get inexistant call";
-- 
GitLab