Skip to content

Commit

Permalink
Add pseudo spaces for unread chats
Browse files Browse the repository at this point in the history
Change-Id: Iba2c7c44cada7c31e42636f198250639c2f8b5e3
  • Loading branch information
SpiritCroc committed Mar 29, 2024
1 parent 4935a09 commit 01eefc9
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
2 changes: 1 addition & 1 deletion FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Note that following list of changes compared to Element X is likely incomplete,
## Chat overview ("room list")

- Filter for spaces, including support for hierarchical spaces †‡
- Filter for favorites, DMs, and group chat via our spaces navigation
- Filter for favorites, unreads, DMs, and group chats via our spaces navigation
- Sort room list by unread first ‡
- Non-expanding compact app bar in the chat overview †
- Show unread counts ([MSC2654](https://github.com/matrix-org/matrix-spec-proposals/pull/2654)) ‡[^1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package chat.schildi.features.roomlist.spaces
import android.content.Context
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Groups
import androidx.compose.material.icons.filled.Notifications
import androidx.compose.material.icons.filled.Person
import androidx.compose.material.icons.filled.RemoveRedEye
import androidx.compose.material.icons.filled.Rocket
import androidx.compose.material.icons.filled.Star
import androidx.compose.material.icons.filled.Tag
Expand Down Expand Up @@ -137,6 +139,27 @@ class SpaceListDataSource @Inject constructor(
)
}
}
if (pseudoSpaceSettings.notifications) {
pseudoSpaces.add(
NotificationsPseudoSpaceItem(
context.getString(
if (pseudoSpaceSettings.unread)
chat.schildi.lib.R.string.sc_pseudo_space_notifications_short
else
chat.schildi.lib.R.string.sc_pseudo_space_unread
),
pseudoSpaceSettings.clientUnreadCounts
)
)
}
if (pseudoSpaceSettings.unread) {
pseudoSpaces.add(
UnreadPseudoSpaceItem(
context.getString(chat.schildi.lib.R.string.sc_pseudo_space_unread),
pseudoSpaceSettings.clientUnreadCounts
)
)
}
_allSpaces.emit(buildSpaceHierarchy(spaceListRoomSummaries, pseudoSpaces))
}

Expand Down Expand Up @@ -299,14 +322,43 @@ class SpaceListDataSource @Inject constructor(
rooms.filter { !excludedRooms.contains(it.roomId.value) }.toImmutableList()
}

@Immutable
data class NotificationsPseudoSpaceItem(override val name: String, val clientUnreadCounts: Boolean) : PseudoSpaceItem(
"notif",
Icons.Default.Notifications,
) {
override fun applyFilter(rooms: List<RoomListRoomSummary>): ImmutableList<RoomListRoomSummary> {
return if (clientUnreadCounts)
rooms.filter { it.numberOfUnreadNotifications > 0 || it.numberOfUnreadMentions > 0 || it.isMarkedUnread }.toImmutableList()
else
rooms.filter { it.notificationCount > 0 || it.highlightCount > 0 || it.numberOfUnreadMentions > 0 || it.isMarkedUnread }.toImmutableList()
}
}

@Immutable
data class UnreadPseudoSpaceItem(override val name: String, val clientUnreadCounts: Boolean) : PseudoSpaceItem(
"unread",
Icons.Default.RemoveRedEye,
) {
override fun applyFilter(rooms: List<RoomListRoomSummary>): ImmutableList<RoomListRoomSummary> {
return if (clientUnreadCounts)
rooms.filter { it.numberOfUnreadMessages > 0 || it.isMarkedUnread }.toImmutableList()
else
rooms.filter { it.unreadCount > 0 || it.isMarkedUnread }.toImmutableList()
}
}

data class PseudoSpaceSettings(
val favorites: Boolean,
val dms: Boolean,
val groups: Boolean,
val spacelessGroups: Boolean,
val spaceless: Boolean,
val notifications: Boolean,
val unread: Boolean,
val clientUnreadCounts: Boolean,
) {
fun hasSpaceIndependentPseudoSpace() = favorites || dms || groups
fun hasSpaceIndependentPseudoSpace() = favorites || dms || groups || notifications || unread
}
}

Expand All @@ -318,6 +370,9 @@ fun ScPreferencesStore.pseudoSpaceSettingsFlow(): Flow<SpaceListDataSource.Pseud
groups = ScPrefs.PSEUDO_SPACE_GROUPS.let { it.ensureType(lookup(it)) ?: it.defaultValue },
spacelessGroups = ScPrefs.PSEUDO_SPACE_SPACELESS_GROUPS.let { it.ensureType(lookup(it)) ?: it.defaultValue },
spaceless = ScPrefs.PSEUDO_SPACE_SPACELESS.let { it.ensureType(lookup(it)) ?: it.defaultValue },
notifications = ScPrefs.PSEUDO_SPACE_NOTIFICATIONS.let { it.ensureType(lookup(it)) ?: it.defaultValue },
unread = ScPrefs.PSEUDO_SPACE_UNREAD.let { it.ensureType(lookup(it)) ?: it.defaultValue },
clientUnreadCounts = ScPrefs.CLIENT_GENERATED_UNREAD_COUNTS.let { it.ensureType(lookup(it)) ?: it.defaultValue },
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ object ScPrefs {
val PSEUDO_SPACE_GROUPS = ScBoolPref("PSEUDO_SPACE_GROUPS", false, R.string.sc_pseudo_space_groups, null, dependencies = SPACE_NAV.asDependencies())
val PSEUDO_SPACE_SPACELESS_GROUPS = ScBoolPref("PSEUDO_SPACE_SPACELESS_GROUPS", false, R.string.sc_pseudo_space_spaceless_groups, null, dependencies = SPACE_NAV.asDependencies())
val PSEUDO_SPACE_SPACELESS = ScBoolPref("PSEUDO_SPACE_SPACELESS", false, R.string.sc_pseudo_space_spaceless, null, dependencies = SPACE_NAV.asDependencies())
val PSEUDO_SPACE_NOTIFICATIONS = ScBoolPref("PSEUDO_SPACE_NOTIFICATIONS", false, R.string.sc_pseudo_space_notifications, null, dependencies = SPACE_NAV.asDependencies())
val PSEUDO_SPACE_UNREAD = ScBoolPref("PSEUDO_SPACE_UNREAD", false, R.string.sc_pseudo_space_unread, null, dependencies = SPACE_NAV.asDependencies())

// Timeline
val SC_TIMELINE_LAYOUT = ScBoolPref("SC_TIMELINE_LAYOUT", true, R.string.sc_pref_sc_timeline_layout_title, upstreamChoice = false)
Expand Down Expand Up @@ -94,6 +96,8 @@ object ScPrefs {
PSEUDO_SPACE_GROUPS,
PSEUDO_SPACE_SPACELESS_GROUPS,
PSEUDO_SPACE_SPACELESS,
PSEUDO_SPACE_NOTIFICATIONS,
PSEUDO_SPACE_UNREAD,
), dependencies = SPACE_NAV.asDependencies())
)),
ScPrefCategory(R.string.sc_pref_category_timeline, null, listOf(
Expand Down Expand Up @@ -162,6 +166,8 @@ object ScPrefs {
PSEUDO_SPACE_GROUPS,
PSEUDO_SPACE_SPACELESS_GROUPS.copy(titleRes = R.string.sc_pseudo_space_spaceless_groups_short),
PSEUDO_SPACE_SPACELESS.copy(titleRes = R.string.sc_pseudo_space_spaceless_short),
PSEUDO_SPACE_NOTIFICATIONS.copy(titleRes = R.string.sc_pseudo_space_notifications_short),
PSEUDO_SPACE_UNREAD,
), dependencies = SPACE_NAV.asDependencies()),
SYNC_READ_RECEIPT_AND_MARKER,
)),
Expand Down
3 changes: 3 additions & 0 deletions schildi/lib/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
<string name="sc_pseudo_space_spaceless_short">Space orphans</string>
<string name="sc_pseudo_space_spaceless_groups">Group chats not added to spaces</string>
<string name="sc_pseudo_space_spaceless_groups_short">Groups</string>
<string name="sc_pseudo_space_notifications">Unread notifications and mentions</string>
<string name="sc_pseudo_space_notifications_short">Notifications</string>
<string name="sc_pseudo_space_unread">Unread</string>

<string name="sc_pref_dev_quick_options">Quick settings</string>
<string name="sc_pref_debug_read_marker">Debug read marker</string>
Expand Down

0 comments on commit 01eefc9

Please sign in to comment.