Skip to content

Commit

Permalink
refactor: remove unused fields from notification model (#2922)
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamadJaara authored Apr 23, 2024
1 parent 0acad2f commit 2dca015
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@ import androidx.annotation.StringRes
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.app.Person
import androidx.core.graphics.drawable.IconCompat
import androidx.core.text.toSpannable
import com.wire.android.R
import com.wire.android.appLogger
import com.wire.android.notification.NotificationConstants.getConversationNotificationId
import com.wire.android.ui.home.appLock.LockCodeTimeManager
import com.wire.android.util.toBitmap
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.data.id.QualifiedID
import com.wire.kalium.logic.data.notification.LocalNotification
Expand Down Expand Up @@ -252,8 +250,6 @@ class MessageNotificationManager

setWhen(conversation.lastMessageTime)

setLargeIcon(conversation.image?.toBitmap())

setStyle(updatedMessageStyle)
}.build()
}
Expand Down Expand Up @@ -409,10 +405,6 @@ class MessageNotificationManager
author?.name.also {
setName(it)
}

author?.image?.toBitmap()?.let {
setIcon(IconCompat.createWithAdaptiveBitmap(it))
}
}
}
.build()
Expand Down
68 changes: 8 additions & 60 deletions app/src/main/kotlin/com/wire/android/notification/Models.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,11 @@ import com.wire.kalium.logic.data.notification.LocalNotificationMessage

data class NotificationConversation(
val id: String,
val name: String,
val image: ByteArray?,
val name: String?,
val messages: List<NotificationMessage>,
val isOneToOneConversation: Boolean,
val lastMessageTime: Long
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as NotificationConversation

if (id != other.id) return false
if (name != other.name) return false
if (image != null) {
if (other.image == null) return false
if (!image.contentEquals(other.image)) return false
} else if (other.image != null) return false
if (messages != other.messages) return false
if (isOneToOneConversation != other.isOneToOneConversation) return false
if (lastMessageTime != other.lastMessageTime) return false

return true
}

override fun hashCode(): Int {
var result = id.hashCode()
result = 31 * result + name.hashCode()
result = 31 * result + (image?.contentHashCode() ?: 0)
result = 31 * result + messages.hashCode()
result = 31 * result + isOneToOneConversation.hashCode()
result = 31 * result + lastMessageTime.hashCode()
return result
}
}
)

sealed class NotificationMessage(open val messageId: String, open val author: NotificationMessageAuthor?, open val time: Long) {
data class ObfuscatedMessage(
Expand Down Expand Up @@ -107,28 +77,7 @@ sealed class NotificationMessage(open val messageId: String, open val author: No
) : NotificationMessage(messageId, author, time)
}

data class NotificationMessageAuthor(val name: String, val image: ByteArray?) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as NotificationMessageAuthor

if (name != other.name) return false
if (image != null) {
if (other.image == null) return false
if (!image.contentEquals(other.image)) return false
} else if (other.image != null) return false

return true
}

override fun hashCode(): Int {
var result = name.hashCode()
result = 31 * result + (image?.contentHashCode() ?: 0)
return result
}
}
data class NotificationMessageAuthor(val name: String)

enum class CommentResId(@StringRes val value: Int) {
PICTURE(R.string.notification_shared_picture),
Expand All @@ -148,7 +97,6 @@ fun LocalNotification.Conversation.intoNotificationConversation(): NotificationC
return NotificationConversation(
id = id.toString(),
name = conversationName,
image = null, // TODO
messages = notificationMessages,
isOneToOneConversation = isOneToOneConversation,
lastMessageTime = lastMessageTime
Expand All @@ -162,7 +110,7 @@ fun LocalNotificationMessage.intoNotificationMessage(): NotificationMessage {

return when (this) {
is LocalNotificationMessage.Text -> {
val notificationMessageAuthor = NotificationMessageAuthor(author.name, null) // TODO image
val notificationMessageAuthor = NotificationMessageAuthor(author.name)
NotificationMessage.Text(
messageId = messageId,
author = notificationMessageAuthor,
Expand All @@ -173,7 +121,7 @@ fun LocalNotificationMessage.intoNotificationMessage(): NotificationMessage {
}

is LocalNotificationMessage.Comment -> {
val notificationMessageAuthor = NotificationMessageAuthor(author.name, null) // TODO image
val notificationMessageAuthor = NotificationMessageAuthor(author.name)
NotificationMessage.Comment(
messageId,
notificationMessageAuthor,
Expand All @@ -183,7 +131,7 @@ fun LocalNotificationMessage.intoNotificationMessage(): NotificationMessage {
}

is LocalNotificationMessage.ConnectionRequest -> {
val notificationMessageAuthor = NotificationMessageAuthor(author.name, null) // TODO image
val notificationMessageAuthor = NotificationMessageAuthor(author.name)
NotificationMessage.ConnectionRequest(
messageId,
notificationMessageAuthor,
Expand All @@ -193,7 +141,7 @@ fun LocalNotificationMessage.intoNotificationMessage(): NotificationMessage {
}

is LocalNotificationMessage.ConversationDeleted -> {
val notificationMessageAuthor = NotificationMessageAuthor(author.name, null) // TODO image
val notificationMessageAuthor = NotificationMessageAuthor(author.name)
NotificationMessage.ConversationDeleted(
messageId,
notificationMessageAuthor,
Expand All @@ -202,7 +150,7 @@ fun LocalNotificationMessage.intoNotificationMessage(): NotificationMessage {
}

is LocalNotificationMessage.Knock -> {
val notificationMessageAuthor = NotificationMessageAuthor(author.name, null) // TODO image
val notificationMessageAuthor = NotificationMessageAuthor(author.name)
NotificationMessage.Knock(
messageId,
notificationMessageAuthor,
Expand Down

0 comments on commit 2dca015

Please sign in to comment.