From 835a4bc496108a8941135780ab0587e6a048ce84 Mon Sep 17 00:00:00 2001
From: Taras Smakula <tarassmakula@gmail.com>
Date: Tue, 11 Jun 2024 17:10:57 +0300
Subject: [PATCH] Remove invite/knock from view from people tab

---
 .../feature/people/PeopleDataSource.kt        | 37 ++----------
 .../circles/feature/people/PeopleFragment.kt  |  1 -
 .../circles/feature/people/PeopleNavigator.kt |  4 --
 .../feature/people/list/PeopleAdapter.kt      |  9 +--
 .../feature/people/list/PeopleViewHolder.kt   | 23 --------
 .../org/futo/circles/model/PeopleListItem.kt  |  6 --
 .../main/res/navigation/people_nav_graph.xml  | 13 ----
 .../futo/circles/core/model/InviteListItem.kt | 59 -------------------
 8 files changed, 7 insertions(+), 145 deletions(-)
 delete mode 100644 core/src/main/java/org/futo/circles/core/model/InviteListItem.kt

diff --git a/app/src/main/java/org/futo/circles/feature/people/PeopleDataSource.kt b/app/src/main/java/org/futo/circles/feature/people/PeopleDataSource.kt
index 5681987e6..097a647d7 100644
--- a/app/src/main/java/org/futo/circles/feature/people/PeopleDataSource.kt
+++ b/app/src/main/java/org/futo/circles/feature/people/PeopleDataSource.kt
@@ -1,53 +1,34 @@
 package org.futo.circles.feature.people
 
-import androidx.lifecycle.asFlow
-import androidx.lifecycle.map
 import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.flow.Flow
 import kotlinx.coroutines.flow.combine
 import kotlinx.coroutines.flow.distinctUntilChanged
 import kotlinx.coroutines.withContext
-import org.futo.circles.core.feature.room.knoks.KnockRequestsDataSource
 import org.futo.circles.core.feature.select_users.SearchUserDataSource
-import org.futo.circles.core.utils.getSpacesLiveData
 import org.futo.circles.feature.people.category.PeopleCategoryDataSource
 import org.futo.circles.mapping.toPeopleUserListItem
 import org.futo.circles.model.PeopleCategoryListItem
 import org.futo.circles.model.PeopleListItem
-import org.futo.circles.model.PeopleRequestNotificationListItem
-import org.matrix.android.sdk.api.session.room.model.Membership
 import org.matrix.android.sdk.api.session.user.model.User
 import javax.inject.Inject
 
 class PeopleDataSource @Inject constructor(
     private val searchUserDataSource: SearchUserDataSource,
-    private val knockRequestsDataSource: KnockRequestsDataSource,
     private val peopleCategoryDataSource: PeopleCategoryDataSource
 ) {
 
-    private fun getKnockRequestCountFlow(): Flow<Int> =
-        knockRequestsDataSource.getKnockRequestsListItemsLiveData(peopleCategoryDataSource.getProfileRoomId())
-            .map { it.size }.asFlow()
-
-    private fun getProfileSpaceInvitesCountFlow() =
-        getSpacesLiveData(listOf(Membership.INVITE)).map { it.size }.asFlow()
-
 
     suspend fun getPeopleList(query: String) = combine(
         searchUserDataSource.searchKnownUsers(query),
         searchUserDataSource.searchSuggestions(query),
-        peopleCategoryDataSource.getIgnoredUserFlow(),
-        getKnockRequestCountFlow(),
-        getProfileSpaceInvitesCountFlow()
-    ) { knowUsers, suggestions, ignoredUsers, knocksCount, profileInvitesCount ->
+        peopleCategoryDataSource.getIgnoredUserFlow()
+    ) { knowUsers, suggestions, ignoredUsers ->
         withContext(Dispatchers.IO) {
             buildList(
                 query,
                 knowUsers,
                 suggestions,
-                ignoredUsers,
-                knocksCount,
-                profileInvitesCount
+                ignoredUsers
             )
         }
     }.distinctUntilChanged()
@@ -60,12 +41,10 @@ class PeopleDataSource @Inject constructor(
         query: String,
         knowUsers: List<User>,
         suggestions: List<User>,
-        ignoredUsers: List<User>,
-        knocksCount: Int,
-        profileInvitesCount: Int
+        ignoredUsers: List<User>
     ): List<PeopleListItem> =
         if (query.isNotEmpty()) buildSearchResultsList(knowUsers, suggestions, ignoredUsers)
-        else buildCategoriesList(knowUsers, ignoredUsers, knocksCount, profileInvitesCount)
+        else buildCategoriesList(knowUsers, ignoredUsers)
 
 
     private fun buildSearchResultsList(
@@ -84,12 +63,9 @@ class PeopleDataSource @Inject constructor(
 
     private fun buildCategoriesList(
         knowUsers: List<User>,
-        ignoredUsers: List<User>,
-        knocksCount: Int,
-        profileInvitesCount: Int
+        ignoredUsers: List<User>
     ): List<PeopleListItem> {
         val list = mutableListOf<PeopleListItem>()
-        val requestsCount = knocksCount + profileInvitesCount
         val followingUsers = peopleCategoryDataSource.getPeopleImFollowing()
         val followersUsers = peopleCategoryDataSource.getFollowers()
         val otherMembers = peopleCategoryDataSource.getOtherUsers(
@@ -99,7 +75,6 @@ class PeopleDataSource @Inject constructor(
         )
 
         list.apply {
-            if (requestsCount > 0) add(PeopleRequestNotificationListItem(requestsCount))
             add(PeopleCategoryListItem.followingUsers.copy(count = followingUsers.size))
             add(PeopleCategoryListItem.followersUsers.copy(count = followersUsers.size))
             add(PeopleCategoryListItem.others.copy(count = otherMembers.size))
diff --git a/app/src/main/java/org/futo/circles/feature/people/PeopleFragment.kt b/app/src/main/java/org/futo/circles/feature/people/PeopleFragment.kt
index cb70d40b1..c2300e8be 100644
--- a/app/src/main/java/org/futo/circles/feature/people/PeopleFragment.kt
+++ b/app/src/main/java/org/futo/circles/feature/people/PeopleFragment.kt
@@ -30,7 +30,6 @@ class PeopleFragment : BaseBindingFragment<FragmentPeopleBinding>(FragmentPeople
 
     private val peopleAdapter by lazy {
         PeopleAdapter(onUserClicked = { userId -> navigator.navigateToUserPage(userId) },
-            onOpenRequestsClicked = { navigator.navigateToInvites() },
             onCategoryClicked = { categoryType ->
                 navigator.navigateToPeopleCategoryPage(categoryType)
             })
diff --git a/app/src/main/java/org/futo/circles/feature/people/PeopleNavigator.kt b/app/src/main/java/org/futo/circles/feature/people/PeopleNavigator.kt
index f048416a0..07bfcce32 100644
--- a/app/src/main/java/org/futo/circles/feature/people/PeopleNavigator.kt
+++ b/app/src/main/java/org/futo/circles/feature/people/PeopleNavigator.kt
@@ -8,10 +8,6 @@ import org.futo.circles.model.PeopleCategoryTypeArg
 
 class PeopleNavigator(private val fragment: PeopleFragment) {
 
-    fun navigateToInvites() {
-        fragment.findNavController().navigateSafe(PeopleFragmentDirections.toInvites())
-    }
-
     fun navigateToUserPage(userId: String) {
         fragment.findNavController().navigateSafe(PeopleFragmentDirections.toUserFragment(userId))
     }
diff --git a/app/src/main/java/org/futo/circles/feature/people/list/PeopleAdapter.kt b/app/src/main/java/org/futo/circles/feature/people/list/PeopleAdapter.kt
index 9eb54d9cc..61a75086b 100644
--- a/app/src/main/java/org/futo/circles/feature/people/list/PeopleAdapter.kt
+++ b/app/src/main/java/org/futo/circles/feature/people/list/PeopleAdapter.kt
@@ -6,15 +6,13 @@ import org.futo.circles.model.PeopleCategoryListItem
 import org.futo.circles.model.PeopleCategoryTypeArg
 import org.futo.circles.model.PeopleIgnoredUserListItem
 import org.futo.circles.model.PeopleListItem
-import org.futo.circles.model.PeopleRequestNotificationListItem
 import org.futo.circles.model.PeopleUserListItem
 import org.futo.circles.model.PeopleUserListItemPayload
 
-enum class PeopleItemViewType { Category, Default, RequestNotification, Ignored }
+enum class PeopleItemViewType { Category, Default, Ignored }
 
 class PeopleAdapter(
     private val onUserClicked: (String) -> Unit,
-    private val onOpenRequestsClicked: () -> Unit = {},
     private val onCategoryClicked: (PeopleCategoryTypeArg) -> Unit = {},
     private val onUnIgnore: (String) -> Unit = {},
 ) : BaseRvAdapter<PeopleListItem, PeopleViewHolder>(PayloadIdEntityCallback { old, new ->
@@ -29,7 +27,6 @@ class PeopleAdapter(
     override fun getItemViewType(position: Int): Int = when (getItem(position)) {
         is PeopleCategoryListItem -> PeopleItemViewType.Category.ordinal
         is PeopleIgnoredUserListItem -> PeopleItemViewType.Ignored.ordinal
-        is PeopleRequestNotificationListItem -> PeopleItemViewType.RequestNotification.ordinal
         is PeopleUserListItem -> PeopleItemViewType.Default.ordinal
     }
 
@@ -43,10 +40,6 @@ class PeopleAdapter(
                 }
             )
 
-            PeopleItemViewType.RequestNotification -> FollowRequestNotificationViewHolder(
-                parent = parent, onClicked = { onOpenRequestsClicked() }
-            )
-
             PeopleItemViewType.Ignored -> IgnoredUsersViewHolder(
                 parent,
                 onUnIgnore = { position -> onUnIgnore(getItem(position).id) }
diff --git a/app/src/main/java/org/futo/circles/feature/people/list/PeopleViewHolder.kt b/app/src/main/java/org/futo/circles/feature/people/list/PeopleViewHolder.kt
index 343c2b549..f272dcf54 100644
--- a/app/src/main/java/org/futo/circles/feature/people/list/PeopleViewHolder.kt
+++ b/app/src/main/java/org/futo/circles/feature/people/list/PeopleViewHolder.kt
@@ -3,10 +3,8 @@ package org.futo.circles.feature.people.list
 import android.view.View
 import android.view.ViewGroup
 import androidx.recyclerview.widget.RecyclerView
-import org.futo.circles.R
 import org.futo.circles.core.base.list.ViewBindingHolder
 import org.futo.circles.core.base.list.context
-import org.futo.circles.core.databinding.ListItemInviteNotificationBinding
 import org.futo.circles.core.databinding.ListItemPeopleCategoryBinding
 import org.futo.circles.core.databinding.ListItemPeopleDefaultBinding
 import org.futo.circles.core.extensions.gone
@@ -17,7 +15,6 @@ import org.futo.circles.databinding.ListItemPeopleIgnoredBinding
 import org.futo.circles.model.PeopleCategoryListItem
 import org.futo.circles.model.PeopleIgnoredUserListItem
 import org.futo.circles.model.PeopleListItem
-import org.futo.circles.model.PeopleRequestNotificationListItem
 import org.futo.circles.model.PeopleUserListItem
 import org.futo.circles.model.PeopleUserListItemPayload
 
@@ -111,26 +108,6 @@ class IgnoredUsersViewHolder(
 
 }
 
-class FollowRequestNotificationViewHolder(
-    parent: ViewGroup,
-    onClicked: () -> Unit
-) : PeopleViewHolder(inflate(parent, ListItemInviteNotificationBinding::inflate)) {
-
-    private companion object : ViewBindingHolder
-
-    private val binding = baseBinding as ListItemInviteNotificationBinding
-
-    init {
-        onClick(binding.lInviteNotification) { _ -> onClicked() }
-    }
-
-    override fun bind(data: PeopleListItem) {
-        if (data !is PeopleRequestNotificationListItem) return
-        binding.tvInvitesMessage.text =
-            context.getString(R.string.show_connection_invites_format, data.requestsCount)
-    }
-}
-
 class PeopleCategoryViewHolder(
     parent: ViewGroup,
     onClicked: (Int) -> Unit
diff --git a/app/src/main/java/org/futo/circles/model/PeopleListItem.kt b/app/src/main/java/org/futo/circles/model/PeopleListItem.kt
index e76f8f400..7e3433dd0 100644
--- a/app/src/main/java/org/futo/circles/model/PeopleListItem.kt
+++ b/app/src/main/java/org/futo/circles/model/PeopleListItem.kt
@@ -52,9 +52,3 @@ class PeopleIgnoredUserListItem(
 ) : PeopleListItem() {
     override val id: String = user.id
 }
-
-class PeopleRequestNotificationListItem(
-    val requestsCount: Int
-) : PeopleListItem() {
-    override val id: String = "PeopleRequestNotificationListItem"
-}
diff --git a/app/src/main/res/navigation/people_nav_graph.xml b/app/src/main/res/navigation/people_nav_graph.xml
index 1aa73eeb0..8e1b3011f 100644
--- a/app/src/main/res/navigation/people_nav_graph.xml
+++ b/app/src/main/res/navigation/people_nav_graph.xml
@@ -19,17 +19,6 @@
                 app:argType="string"
                 app:nullable="false" />
 
-        </action>
-        <action
-            android:id="@+id/to_invites"
-            app:destination="@id/invites_nav_graph">
-
-            <argument
-                android:name="type"
-                android:defaultValue="People"
-                app:argType="org.futo.circles.core.model.InviteTypeArg"
-                app:nullable="false" />
-
         </action>
         <action
             android:id="@+id/to_editProfileDialogFragment"
@@ -46,8 +35,6 @@
         </action>
     </fragment>
 
-    <include app:graph="@navigation/invites_nav_graph" />
-
     <include app:graph="@navigation/user_nav_graph" />
 
     <dialog
diff --git a/core/src/main/java/org/futo/circles/core/model/InviteListItem.kt b/core/src/main/java/org/futo/circles/core/model/InviteListItem.kt
deleted file mode 100644
index be79cb77f..000000000
--- a/core/src/main/java/org/futo/circles/core/model/InviteListItem.kt
+++ /dev/null
@@ -1,59 +0,0 @@
-package org.futo.circles.core.model
-
-import org.futo.circles.core.R
-import org.futo.circles.core.base.list.IdEntity
-import org.futo.circles.core.extensions.notEmptyDisplayName
-import org.futo.circles.core.mapping.toRoomInfo
-import org.futo.circles.core.provider.MatrixSessionProvider
-import org.matrix.android.sdk.api.session.getUserOrDefault
-import org.matrix.android.sdk.api.session.room.model.RoomSummary
-
-sealed class InviteListItem(
-    override val id: String
-) : IdEntity<String>
-
-
-data class InviteHeader(
-    val titleRes: Int
-) : InviteListItem(titleRes.toString()) {
-    companion object {
-        val connectInvitesHeader = InviteHeader(R.string.invites)
-        val followRequestHeader = InviteHeader(R.string.requests)
-    }
-}
-
-data class RoomInviteListItem(
-    val roomId: String,
-    val roomType: CircleRoomTypeArg,
-    val info: RoomInfo,
-    val isEncrypted: Boolean,
-    val inviterName: String,
-    val shouldBlurIcon: Boolean,
-    val isLoading: Boolean = false
-) : InviteListItem(roomId)
-
-data class FollowRequestListItem(
-    val user: CirclesUserSummary,
-    val reasonMessage: String?,
-    val isLoading: Boolean = false
-) : InviteListItem(user.id)
-
-data class ConnectionInviteListItem(
-    val roomId: String,
-    val user: CirclesUserSummary,
-    val isLoading: Boolean = false
-) : InviteListItem(roomId)
-
-fun RoomSummary.toRoomInviteListItem(roomType: CircleRoomTypeArg, shouldBlurIcon: Boolean) =
-    RoomInviteListItem(
-        roomId = roomId,
-        info = toRoomInfo(),
-        inviterName = getInviterName(),
-        isEncrypted = isEncrypted,
-        shouldBlurIcon = shouldBlurIcon,
-        roomType = roomType
-    )
-
-fun RoomSummary.getInviterName() =
-    MatrixSessionProvider.currentSession?.getUserOrDefault(inviterId ?: "")?.notEmptyDisplayName()
-        ?: ""
\ No newline at end of file
-- 
GitLab