Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix notif badge for space invite #4061

Merged
merged 2 commits into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/4059.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Space Invites are not lighting up the drawer menu
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.room.RoomSortOrder
import org.matrix.android.sdk.api.session.room.model.Membership
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
import org.matrix.android.sdk.api.session.room.spaceSummaryQueryParams
import org.matrix.android.sdk.api.session.room.summary.RoomAggregateNotificationCount
import org.matrix.android.sdk.rx.asObservable
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -143,6 +144,17 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia
roomSummaryQueryParams { this.memberships = listOf(Membership.INVITE) }
).size
}

val spaceInviteCount = if (autoAcceptInvites.hideInvites) {
0
} else {
session.getRoomSummaries(
spaceSummaryQueryParams {
this.memberships = listOf(Membership.INVITE)
}
).size
}

val totalCount = session.getNotificationCountForRooms(
roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN)
Expand All @@ -161,15 +173,16 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia
// filter out current selection
it.roomId != selectedSpace
}

CountInfo(
homeCount = counts,
otherCount = RoomAggregateNotificationCount(
rootCounts.fold(0, { acc, rs ->
acc + rs.notificationCount
}) + (counts.notificationCount.takeIf { selectedSpace != null } ?: 0),
rootCounts.fold(0, { acc, rs ->
acc + rs.highlightCount
}) + (counts.highlightCount.takeIf { selectedSpace != null } ?: 0)
notificationCount = rootCounts.fold(0, { acc, rs -> acc + rs.notificationCount })
+ (counts.notificationCount.takeIf { selectedSpace != null } ?: 0)
+ spaceInviteCount,
highlightCount = rootCounts.fold(0, { acc, rs -> acc + rs.highlightCount })
+ (counts.highlightCount.takeIf { selectedSpace != null } ?: 0)
+ spaceInviteCount
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this formatting it is really hard to read.
change to

                            CountInfo(
                                    homeCount = counts,
                                    otherCount = RoomAggregateNotificationCount(
                                            notificationCount = rootCounts.fold(0, { acc, rs -> acc + rs.notificationCount })
                                                    + (counts.notificationCount.takeIf { selectedSpace != null } ?: 0)
                                                    + spaceInviteCount,
                                            highlightCount = rootCounts.fold(0, { acc, rs -> acc + rs.highlightCount })
                                                    + (counts.highlightCount.takeIf { selectedSpace != null } ?: 0)
                                                    + spaceInviteCount
                                    )
                            )

)
)
}
Expand Down