Skip to content

Commit

Permalink
notif [nfc]: Remove ByConversationMap.
Browse files Browse the repository at this point in the history
`ByConversationMap` was originally intended to store conversations
based on `Identity` as key, so that we would be able to group
conversations by realmId easily.

Here we are removing it, and introducing a new data class in the
following commit that will store realmId and messages along with
notificationId of that particular conversation.

A reason to do this is that structurally we are identifying unique
notification based on its title not by its `Identity`. So its easy
to create a direct mapping of UI notification with the
`ConversationMap` data structure this way. Extra information about
the conversation (eg: realmId) will be included in the value of
ConversationMap (see the next commit).

Skips: zulip#4633
  • Loading branch information
AkashDhiman committed Jul 1, 2021
1 parent 6fe02a3 commit 872dea6
Showing 1 changed file with 5 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,14 @@ import java.util.*
val TAG = "ZulipNotif"

/**
* The Zulip messages we're showing as a notification, grouped by conversation.
* All Zulip messages we're showing in notifications.
*
* Each key identifies a conversation; see [buildKeyString].
*
* Each value is the messages in the conversation, in the order we
* received them.
*
* When we start showing a separate notification for each [Identity],
* this type will represent the messages for just one [Identity].
* See also [ConversationMap].
*/
open class ByConversationMap : LinkedHashMap<String, MutableList<MessageFcmMessage>>()

/**
* All Zulip messages we're showing in notifications.
*
* Currently an alias of [ByConversationMap]. When we start showing
* a separate notification for each [Identity], this type will become
* a collection of one [ByConversationMap] per [Identity].
*/
class ConversationMap : ByConversationMap()
class ConversationMap : LinkedHashMap<String, MutableList<MessageFcmMessage>>()

fun fetchBitmap(url: URL): Bitmap? {
return try {
Expand All @@ -64,7 +51,7 @@ fun sizedURL(context: Context, url: URL, dpSize: Float): URL {
return URL(url, "?$query")
}

fun buildNotificationContent(conversations: ByConversationMap, inboxStyle: NotificationCompat.InboxStyle) {
fun buildNotificationContent(conversations: ConversationMap, inboxStyle: NotificationCompat.InboxStyle) {
for (conversation in conversations.values) {
// TODO ensure latest sender is shown last? E.g. Gmail-style A, B, ..., A.
val seenSenders = HashSet<String>()
Expand All @@ -86,7 +73,7 @@ fun buildNotificationContent(conversations: ByConversationMap, inboxStyle: Notif
}
}

fun extractTotalMessagesCount(conversations: ByConversationMap): Int {
fun extractTotalMessagesCount(conversations: ConversationMap): Int {
var totalNumber = 0
for ((_, value) in conversations) {
totalNumber += value.size
Expand All @@ -109,7 +96,7 @@ private fun buildKeyString(fcmMessage: MessageFcmMessage): String {
}
}

fun extractNames(conversations: ByConversationMap): ArrayList<String> {
fun extractNames(conversations: ConversationMap): ArrayList<String> {
val namesSet = LinkedHashSet<String>()
for (fcmMessages in conversations.values) {
for (fcmMessage in fcmMessages) {
Expand Down

0 comments on commit 872dea6

Please sign in to comment.