From faf24a3f6c5753409e4d61b58c703c02989bd2b4 Mon Sep 17 00:00:00 2001
From: Kamal Bramwell <kamal@elixxir.io>
Date: Mon, 8 Aug 2022 21:21:40 -0400
Subject: [PATCH] Created getContactsRequestsOnce() method for one-time call of

This method is for a single snapshot of the current requests, where a flow would not be appropriate
---
 .../main/java/io/xxlabs/messenger/data/room/dao/RequestsDao.kt | 3 +++
 .../xxlabs/messenger/requests/data/LocalRequestsDataSource.kt  | 1 +
 .../java/io/xxlabs/messenger/requests/data/RequestsDatabase.kt | 3 +++
 3 files changed, 7 insertions(+)

diff --git a/app/src/main/java/io/xxlabs/messenger/data/room/dao/RequestsDao.kt b/app/src/main/java/io/xxlabs/messenger/data/room/dao/RequestsDao.kt
index add64887..20b67752 100644
--- a/app/src/main/java/io/xxlabs/messenger/data/room/dao/RequestsDao.kt
+++ b/app/src/main/java/io/xxlabs/messenger/data/room/dao/RequestsDao.kt
@@ -21,6 +21,9 @@ interface RequestsDao {
     @Query("SELECT * FROM Requests WHERE requestId IN (SELECT userId FROM Contacts)")
     fun getContactRequests(): Flow<List<RequestData>>
 
+    @Query("SELECT * FROM Requests WHERE requestId IN (SELECT userId FROM Contacts)")
+    fun getContactRequestsOnce(): List<RequestData>
+
     @Query("SELECT * FROM Requests WHERE requestId IN (SELECT groupId FROM Groups)")
     fun getGroupInvitations(): Flow<List<RequestData>>
 
diff --git a/app/src/main/java/io/xxlabs/messenger/requests/data/LocalRequestsDataSource.kt b/app/src/main/java/io/xxlabs/messenger/requests/data/LocalRequestsDataSource.kt
index e30a49ec..b94bb691 100644
--- a/app/src/main/java/io/xxlabs/messenger/requests/data/LocalRequestsDataSource.kt
+++ b/app/src/main/java/io/xxlabs/messenger/requests/data/LocalRequestsDataSource.kt
@@ -8,6 +8,7 @@ import kotlinx.coroutines.flow.Flow
 interface LocalRequestsDataSource {
     val unreadCount: Flow<Int>
 
+    suspend fun getContactRequestsOnce(): List<RequestData>
     suspend fun getContactRequests(): Flow<List<RequestData>>
     suspend fun getGroupInvitations(): Flow<List<RequestData>>
     suspend fun getRequest(requestId: ByteArray): RequestData?
diff --git a/app/src/main/java/io/xxlabs/messenger/requests/data/RequestsDatabase.kt b/app/src/main/java/io/xxlabs/messenger/requests/data/RequestsDatabase.kt
index 71643dde..47a36b5f 100644
--- a/app/src/main/java/io/xxlabs/messenger/requests/data/RequestsDatabase.kt
+++ b/app/src/main/java/io/xxlabs/messenger/requests/data/RequestsDatabase.kt
@@ -52,6 +52,9 @@ class RequestsDatabase @Inject constructor(
         }
     }
 
+    override suspend fun getContactRequestsOnce(): List<RequestData> =
+        requestsDao.getContactRequestsOnce()
+
     override suspend fun getContactRequests(): Flow<List<RequestData>> =
         requestsDao.getContactRequests()
             .stateIn(scope, SharingStarted.Eagerly, listOf())
-- 
GitLab