From aa72a928ab476d05f282379c8151d86ea3dcfdb0 Mon Sep 17 00:00:00 2001
From: Kateryna Kostiuk <katryna.kostiuk@savoirfairelinux.com>
Date: Tue, 14 Feb 2023 16:34:13 -0500
Subject: [PATCH] invitations:  reload invitations when registering account

On iOS, when the app is in the background, invitations are received
and saved by the notifications extension. When Jami becomes active in
the foreground, those invitations may not be visible. This
patch reload invitations from the file when registering an account.

https://git.jami.net/savoirfairelinux/jami-client-ios/-/issues/250
Change-Id: I9ae3d8ec285c94081c5a6d1ceeb31f9058673dcf
---
 src/jamidht/conversation_module.cpp | 6 ++++++
 src/jamidht/conversation_module.h   | 7 ++++++-
 src/jamidht/jamiaccount.cpp         | 9 +++++++++
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/jamidht/conversation_module.cpp b/src/jamidht/conversation_module.cpp
index 36d75db4de..a58442eeac 100644
--- a/src/jamidht/conversation_module.cpp
+++ b/src/jamidht/conversation_module.cpp
@@ -1108,6 +1108,12 @@ ConversationModule::clearPendingFetch()
     }
 }
 
+void
+ConversationModule::reloadRequests()
+{
+    pimpl_->conversationsRequests_ = convRequests(pimpl_->accountId_);
+}
+
 std::vector<std::string>
 ConversationModule::getConversations() const
 {
diff --git a/src/jamidht/conversation_module.h b/src/jamidht/conversation_module.h
index 4ddce27f0f..8b9d898627 100644
--- a/src/jamidht/conversation_module.h
+++ b/src/jamidht/conversation_module.h
@@ -73,6 +73,11 @@ public:
      */
     void clearPendingFetch();
 
+    /**
+     * Reload requests from file
+     */
+    void reloadRequests();
+
     /**
      * Return all conversation's id (including syncing ones)
      */
@@ -432,4 +437,4 @@ private:
     std::shared_ptr<Impl> pimpl_;
 };
 
-} // namespace jami
\ No newline at end of file
+} // namespace jami
diff --git a/src/jamidht/jamiaccount.cpp b/src/jamidht/jamiaccount.cpp
index 4a4025e1d5..7340f63914 100644
--- a/src/jamidht/jamiaccount.cpp
+++ b/src/jamidht/jamiaccount.cpp
@@ -1453,6 +1453,15 @@ void
 JamiAccount::registerAsyncOps()
 {
     auto onLoad = [this, loaded = std::make_shared<std::atomic_uint>()] {
+        if (auto cm = convModule()) {
+            /*
+             On iOS, when the app is in the background, invitations are received
+             and saved by the notifications extension.
+             When app becomes active requests need to be reloaded, to retrieve invitations
+             received when app was in background.
+             */
+            cm->reloadRequests();
+        }
         if (++(*loaded) == 2u) {
             runOnMainThread([w = weak()] {
                 if (auto s = w.lock()) {
-- 
GitLab