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, in favor of using
`NotificationManager#getActiveNotifications` in the following
commits.

Notifications will persist automatically if we are to do this, and
we don't have to be concerned with handling logic for storing
past notifications, Android SDK will abstract it away for us.

This will eventually be followed by removal of`ConversationMap`,
and other associated code.

Skips: zulip#4633
  • Loading branch information
AkashDhiman committed Aug 4, 2021
1 parent 3672723 commit 8fa79f2
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 8fa79f2

Please sign in to comment.