feat: add the last seen

This commit is contained in:
0x330a 2023-02-22 13:56:18 +11:00
parent 548862c37d
commit fdd70ec6d0
No known key found for this signature in database
GPG Key ID: 267811D6E6A2698C
4 changed files with 30 additions and 24 deletions

@ -1 +1 @@
Subproject commit 943dc8a32fccd0de02028f9ff7344a5effbce0d2
Subproject commit 4930086a348d175cff4a41e804c84f23d048951e

View File

@ -123,26 +123,27 @@ class BatchMessageReceiveJob(
async {
// The LinkedHashMap should preserve insertion order
val messageIds = linkedMapOf<Long, Pair<Boolean, Boolean>>()
var myLastSeen = storage.getLastSeen(threadId)
val myLastSeen = storage.getLastSeen(threadId)
var newLastSeen = myLastSeen
messages.forEach { (parameters, message, proto) ->
try {
when (message) {
is VisibleMessage -> {
val messageId = MessageReceiver.handleVisibleMessage(message, proto, openGroupID,
runIncrement = false,
runThreadUpdate = false,
runProfileUpdate = true
val isUserBlindedSender = message.sender == serverPublicKey?.let { SodiumUtilities.blindedKeyPair(it, MessagingModuleConfiguration.shared.getUserED25519KeyPair()!!) }?.let { SessionId(
IdPrefix.BLINDED, it.publicKey.asBytes).hexString }
val sentTimestamp = message.sentTimestamp!!
if (message.sender == localUserPublicKey || isUserBlindedSender) {
if (sentTimestamp > newLastSeen) {
newLastSeen = sentTimestamp // use sent timestamp here since that is technically the last one we have
}
}
val messageId = MessageReceiver.handleVisibleMessage(
message, proto, openGroupID,
runThreadUpdate = false,
runProfileUpdate = true
)
if (messageId != null && message.reaction == null) {
val isUserBlindedSender = message.sender == serverPublicKey?.let { SodiumUtilities.blindedKeyPair(it, MessagingModuleConfiguration.shared.getUserED25519KeyPair()!!) }?.let { SessionId(
IdPrefix.BLINDED, it.publicKey.asBytes).hexString }
if (message.sender == localUserPublicKey || isUserBlindedSender) {
val sentTimestamp = message.sentTimestamp
if (sentTimestamp != null && sentTimestamp > myLastSeen) {
myLastSeen = sentTimestamp // use sent timestamp here since that is technically the last one we have
}
}
messageIds[messageId] = Pair(
(message.sender == localUserPublicKey || isUserBlindedSender),
message.hasMention
@ -176,7 +177,12 @@ class BatchMessageReceiveJob(
}
// increment unreads, notify, and update thread
// last seen will be the current last seen if not changed (re-computes the read counts for thread record)
storage.markConversationAsRead(threadId, myLastSeen)
// might have been updated from a different thread at this point
val currentLastSeen = storage.getLastSeen(threadId)
if (currentLastSeen > newLastSeen) {
newLastSeen = currentLastSeen
}
storage.markConversationAsRead(threadId, newLastSeen)
storage.updateThread(threadId, true)
SSKEnvironment.shared.notificationManager.updateNotification(context, threadId)
}

View File

@ -25,7 +25,6 @@ class VisibleMessage : Message() {
var openGroupInvitation: OpenGroupInvitation? = null
var reaction: Reaction? = null
var hasMention: Boolean = false
override val isSelfSendValid: Boolean = true
// region Validation

View File

@ -67,8 +67,8 @@ fun MessageReceiver.handle(message: Message, proto: SignalServiceProtos.Content,
is ConfigurationMessage -> handleConfigurationMessage(message)
is UnsendRequest -> handleUnsendRequest(message)
is MessageRequestResponse -> handleMessageRequestResponse(message)
is VisibleMessage -> handleVisibleMessage(message, proto, openGroupID,
runIncrement = true,
is VisibleMessage -> handleVisibleMessage(
message, proto, openGroupID,
runThreadUpdate = true,
runProfileUpdate = true
)
@ -214,12 +214,13 @@ fun handleMessageRequestResponse(message: MessageRequestResponse) {
}
//endregion
fun MessageReceiver.handleVisibleMessage(message: VisibleMessage,
proto: SignalServiceProtos.Content,
openGroupID: String?,
runIncrement: Boolean,
runThreadUpdate: Boolean,
runProfileUpdate: Boolean): Long? {
fun MessageReceiver.handleVisibleMessage(
message: VisibleMessage,
proto: SignalServiceProtos.Content,
openGroupID: String?,
runThreadUpdate: Boolean,
runProfileUpdate: Boolean
): Long? {
val storage = MessagingModuleConfiguration.shared.storage
val context = MessagingModuleConfiguration.shared.context
val userPublicKey = storage.getUserPublicKey()