mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-10 13:33:40 +00:00
feat: add the last seen
This commit is contained in:
parent
548862c37d
commit
fdd70ec6d0
@ -1 +1 @@
|
|||||||
Subproject commit 943dc8a32fccd0de02028f9ff7344a5effbce0d2
|
Subproject commit 4930086a348d175cff4a41e804c84f23d048951e
|
@ -123,26 +123,27 @@ class BatchMessageReceiveJob(
|
|||||||
async {
|
async {
|
||||||
// The LinkedHashMap should preserve insertion order
|
// The LinkedHashMap should preserve insertion order
|
||||||
val messageIds = linkedMapOf<Long, Pair<Boolean, Boolean>>()
|
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) ->
|
messages.forEach { (parameters, message, proto) ->
|
||||||
try {
|
try {
|
||||||
when (message) {
|
when (message) {
|
||||||
is VisibleMessage -> {
|
is VisibleMessage -> {
|
||||||
val messageId = MessageReceiver.handleVisibleMessage(message, proto, openGroupID,
|
val isUserBlindedSender = message.sender == serverPublicKey?.let { SodiumUtilities.blindedKeyPair(it, MessagingModuleConfiguration.shared.getUserED25519KeyPair()!!) }?.let { SessionId(
|
||||||
runIncrement = false,
|
IdPrefix.BLINDED, it.publicKey.asBytes).hexString }
|
||||||
runThreadUpdate = false,
|
val sentTimestamp = message.sentTimestamp!!
|
||||||
runProfileUpdate = true
|
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) {
|
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(
|
messageIds[messageId] = Pair(
|
||||||
(message.sender == localUserPublicKey || isUserBlindedSender),
|
(message.sender == localUserPublicKey || isUserBlindedSender),
|
||||||
message.hasMention
|
message.hasMention
|
||||||
@ -176,7 +177,12 @@ class BatchMessageReceiveJob(
|
|||||||
}
|
}
|
||||||
// increment unreads, notify, and update thread
|
// 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)
|
// 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)
|
storage.updateThread(threadId, true)
|
||||||
SSKEnvironment.shared.notificationManager.updateNotification(context, threadId)
|
SSKEnvironment.shared.notificationManager.updateNotification(context, threadId)
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,6 @@ class VisibleMessage : Message() {
|
|||||||
var openGroupInvitation: OpenGroupInvitation? = null
|
var openGroupInvitation: OpenGroupInvitation? = null
|
||||||
var reaction: Reaction? = null
|
var reaction: Reaction? = null
|
||||||
var hasMention: Boolean = false
|
var hasMention: Boolean = false
|
||||||
|
|
||||||
override val isSelfSendValid: Boolean = true
|
override val isSelfSendValid: Boolean = true
|
||||||
|
|
||||||
// region Validation
|
// region Validation
|
||||||
|
@ -67,8 +67,8 @@ fun MessageReceiver.handle(message: Message, proto: SignalServiceProtos.Content,
|
|||||||
is ConfigurationMessage -> handleConfigurationMessage(message)
|
is ConfigurationMessage -> handleConfigurationMessage(message)
|
||||||
is UnsendRequest -> handleUnsendRequest(message)
|
is UnsendRequest -> handleUnsendRequest(message)
|
||||||
is MessageRequestResponse -> handleMessageRequestResponse(message)
|
is MessageRequestResponse -> handleMessageRequestResponse(message)
|
||||||
is VisibleMessage -> handleVisibleMessage(message, proto, openGroupID,
|
is VisibleMessage -> handleVisibleMessage(
|
||||||
runIncrement = true,
|
message, proto, openGroupID,
|
||||||
runThreadUpdate = true,
|
runThreadUpdate = true,
|
||||||
runProfileUpdate = true
|
runProfileUpdate = true
|
||||||
)
|
)
|
||||||
@ -214,12 +214,13 @@ fun handleMessageRequestResponse(message: MessageRequestResponse) {
|
|||||||
}
|
}
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
fun MessageReceiver.handleVisibleMessage(message: VisibleMessage,
|
fun MessageReceiver.handleVisibleMessage(
|
||||||
proto: SignalServiceProtos.Content,
|
message: VisibleMessage,
|
||||||
openGroupID: String?,
|
proto: SignalServiceProtos.Content,
|
||||||
runIncrement: Boolean,
|
openGroupID: String?,
|
||||||
runThreadUpdate: Boolean,
|
runThreadUpdate: Boolean,
|
||||||
runProfileUpdate: Boolean): Long? {
|
runProfileUpdate: Boolean
|
||||||
|
): Long? {
|
||||||
val storage = MessagingModuleConfiguration.shared.storage
|
val storage = MessagingModuleConfiguration.shared.storage
|
||||||
val context = MessagingModuleConfiguration.shared.context
|
val context = MessagingModuleConfiguration.shared.context
|
||||||
val userPublicKey = storage.getUserPublicKey()
|
val userPublicKey = storage.getUserPublicKey()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user