making non overriden properties immutable by passing the values intro the constructor

This commit is contained in:
Adam Brown 2021-10-07 11:23:23 +01:00
parent 51f7dee952
commit 81da185d8b
5 changed files with 52 additions and 61 deletions

View File

@ -18,16 +18,16 @@ package im.vector.app.features.notifications
import androidx.core.app.NotificationCompat
data class InviteNotifiableEvent(
var matrixID: String?,
val matrixID: String?,
override val eventId: String,
override val editedEventId: String?,
var roomId: String,
val roomId: String,
override var noisy: Boolean,
val title: String,
val description: String,
val type: String?,
val timestamp: Long,
var soundName: String?,
val soundName: String?,
override var isPushGatewayEvent: Boolean = false) : NotifiableEvent {
override var isRedacted: Boolean = false

View File

@ -142,7 +142,7 @@ class NotifiableEventResolver @Inject constructor(
val roomName = stringProvider.getString(R.string.notification_unknown_room_name)
val senderDisplayName = event.senderInfo.disambiguatedDisplayName
val notifiableEvent = NotifiableMessageEvent(
return NotifiableMessageEvent(
eventId = event.root.eventId!!,
editedEventId = event.getEditedEventId(),
timestamp = event.root.originServerTs ?: 0,
@ -151,10 +151,9 @@ class NotifiableEventResolver @Inject constructor(
senderId = event.root.senderId,
body = body.toString(),
roomId = event.root.roomId!!,
roomName = roomName)
notifiableEvent.matrixID = session.myUserId
return notifiableEvent
roomName = roomName,
matrixID = session.myUserId
)
} else {
if (event.root.isEncrypted() && event.root.mxDecryptionResult == null) {
// TODO use a global event decryptor? attache to session and that listen to new sessionId?
@ -175,7 +174,7 @@ class NotifiableEventResolver @Inject constructor(
val roomName = room.roomSummary()?.displayName ?: ""
val senderDisplayName = event.senderInfo.disambiguatedDisplayName
val notifiableEvent = NotifiableMessageEvent(
return NotifiableMessageEvent(
eventId = event.root.eventId!!,
editedEventId = event.getEditedEventId(),
timestamp = event.root.originServerTs ?: 0,
@ -185,25 +184,20 @@ class NotifiableEventResolver @Inject constructor(
body = body,
roomId = event.root.roomId!!,
roomName = roomName,
roomIsDirect = room.roomSummary()?.isDirect ?: false)
notifiableEvent.matrixID = session.myUserId
notifiableEvent.soundName = null
// Get the avatars URL
notifiableEvent.roomAvatarPath = session.contentUrlResolver()
.resolveThumbnail(room.roomSummary()?.avatarUrl,
250,
250,
ContentUrlResolver.ThumbnailMethod.SCALE)
notifiableEvent.senderAvatarPath = session.contentUrlResolver()
.resolveThumbnail(event.senderInfo.avatarUrl,
250,
250,
ContentUrlResolver.ThumbnailMethod.SCALE)
return notifiableEvent
roomIsDirect = room.roomSummary()?.isDirect ?: false,
roomAvatarPath = session.contentUrlResolver()
.resolveThumbnail(room.roomSummary()?.avatarUrl,
250,
250,
ContentUrlResolver.ThumbnailMethod.SCALE),
senderAvatarPath = session.contentUrlResolver()
.resolveThumbnail(event.senderInfo.avatarUrl,
250,
250,
ContentUrlResolver.ThumbnailMethod.SCALE),
matrixID = session.myUserId,
soundName = null
)
}
}

View File

@ -23,33 +23,30 @@ data class NotifiableMessageEvent(
override val editedEventId: String?,
override var noisy: Boolean,
val timestamp: Long,
var senderName: String?,
var senderId: String?,
var body: String?,
var roomId: String,
var roomName: String?,
var roomIsDirect: Boolean = false
val senderName: String?,
val senderId: String?,
val body: String?,
val roomId: String,
val roomName: String?,
val roomIsDirect: Boolean = false,
val roomAvatarPath: String? = null,
val senderAvatarPath: String? = null,
val matrixID: String? = null,
val soundName: String? = null,
// This is used for >N notification, as the result of a smart reply
val outGoingMessage: Boolean = false,
val outGoingMessageFailed: Boolean = false
) : NotifiableEvent {
var matrixID: String? = null
var soundName: String? = null
override var lockScreenVisibility = NotificationCompat.VISIBILITY_PUBLIC
override var hasBeenDisplayed: Boolean = false
override var isRedacted: Boolean = false
var roomAvatarPath: String? = null
var senderAvatarPath: String? = null
override var isPushGatewayEvent: Boolean = false
val type: String = EventType.MESSAGE
val description: String
get() = body ?: ""
val description: String = body ?: ""
val title: String = senderName ?: ""
// This is used for >N notification, as the result of a smart reply
var outGoingMessage = false
var outGoingMessageFailed = false
}

View File

@ -130,19 +130,19 @@ class NotificationBroadcastReceiver : BroadcastReceiver() {
val notifiableMessageEvent = NotifiableMessageEvent(
// Generate a Fake event id
UUID.randomUUID().toString(),
null,
false,
System.currentTimeMillis(),
session.getRoomMember(session.myUserId, room.roomId)?.displayName
eventId = UUID.randomUUID().toString(),
editedEventId = null,
noisy = false,
timestamp = System.currentTimeMillis(),
senderName = session.getRoomMember(session.myUserId, room.roomId)?.displayName
?: context?.getString(R.string.notification_sender_me),
session.myUserId,
message,
room.roomId,
room.roomSummary()?.displayName ?: room.roomId,
room.roomSummary()?.isDirect == true
senderId = session.myUserId,
body = message,
roomId = room.roomId,
roomName = room.roomSummary()?.displayName ?: room.roomId,
roomIsDirect = room.roomSummary()?.isDirect == true,
outGoingMessage = true
)
notifiableMessageEvent.outGoingMessage = true
notificationDrawerManager.onNotifiableEventReceived(notifiableMessageEvent)
notificationDrawerManager.refreshNotificationDrawer()

View File

@ -18,7 +18,7 @@ package im.vector.app.features.notifications
import androidx.core.app.NotificationCompat
data class SimpleNotifiableEvent(
var matrixID: String?,
val matrixID: String?,
override val eventId: String,
override val editedEventId: String?,
override var noisy: Boolean,
@ -26,7 +26,7 @@ data class SimpleNotifiableEvent(
val description: String,
val type: String?,
val timestamp: Long,
var soundName: String?,
val soundName: String?,
override var isPushGatewayEvent: Boolean = false) : NotifiableEvent {
override var hasBeenDisplayed: Boolean = false