Correcting the user's room for the notification marker
This commit is contained in:
@@ -909,15 +909,7 @@ class Account(
|
|||||||
fun decryptContent(note: Note): String? {
|
fun decryptContent(note: Note): String? {
|
||||||
val event = note.event
|
val event = note.event
|
||||||
return if (event is PrivateDmEvent && loggedIn.privKey != null) {
|
return if (event is PrivateDmEvent && loggedIn.privKey != null) {
|
||||||
var pubkeyToUse = event.pubKey
|
event.plainContent(loggedIn.privKey!!, event.talkingWith(userProfile().pubkeyHex).hexToByteArray())
|
||||||
|
|
||||||
val recepientPK = event.verifiedRecipientPubKey()
|
|
||||||
|
|
||||||
if (note.author == userProfile() && recepientPK != null) {
|
|
||||||
pubkeyToUse = recepientPK
|
|
||||||
}
|
|
||||||
|
|
||||||
event.plainContent(loggedIn.privKey!!, pubkeyToUse.hexToByteArray())
|
|
||||||
} else if (event is LnZapRequestEvent && loggedIn.privKey != null) {
|
} else if (event is LnZapRequestEvent && loggedIn.privKey != null) {
|
||||||
decryptZapContentAuthor(note)?.content()
|
decryptZapContentAuthor(note)?.content()
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -29,6 +29,10 @@ class PrivateDmEvent(
|
|||||||
|
|
||||||
fun verifiedRecipientPubKey() = recipientPubKey()?.runCatching { Hex.decode(this[1]).toHexKey() }?.getOrNull() // makes sure its a valid one
|
fun verifiedRecipientPubKey() = recipientPubKey()?.runCatching { Hex.decode(this[1]).toHexKey() }?.getOrNull() // makes sure its a valid one
|
||||||
|
|
||||||
|
fun talkingWith(oneSideHex: String): HexKey {
|
||||||
|
return if (pubKey == oneSideHex) verifiedRecipientPubKey() ?: pubKey else pubKey
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To be fully compatible with nip-04, we read e-tags that are in violation to nip-18.
|
* To be fully compatible with nip-04, we read e-tags that are in violation to nip-18.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -72,10 +72,7 @@ object ChatroomListKnownFeedFilter : AdditiveFeedFilter<Note>() {
|
|||||||
|
|
||||||
newRelevantPrivateMessages.forEach { newNotePair ->
|
newRelevantPrivateMessages.forEach { newNotePair ->
|
||||||
oldList.forEach { oldNote ->
|
oldList.forEach { oldNote ->
|
||||||
val oldAuthor = oldNote.author?.pubkeyHex
|
val oldRoom = (oldNote.event as? PrivateDmEvent)?.talkingWith(me.pubkeyHex)
|
||||||
val oldRecipient = (oldNote.event as? PrivateDmEvent)?.verifiedRecipientPubKey()
|
|
||||||
|
|
||||||
val oldRoom = if (oldAuthor == me.pubkeyHex) oldRecipient else oldAuthor
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(newNotePair.key == oldRoom) && (newNotePair.value.createdAt() ?: 0) > (oldNote.createdAt() ?: 0)
|
(newNotePair.key == oldRoom) && (newNotePair.value.createdAt() ?: 0) > (oldNote.createdAt() ?: 0)
|
||||||
@@ -132,13 +129,10 @@ object ChatroomListKnownFeedFilter : AdditiveFeedFilter<Note>() {
|
|||||||
|
|
||||||
val newRelevantPrivateMessages = mutableMapOf<String, Note>()
|
val newRelevantPrivateMessages = mutableMapOf<String, Note>()
|
||||||
newItems.filter { it.event is PrivateDmEvent }.forEach { newNote ->
|
newItems.filter { it.event is PrivateDmEvent }.forEach { newNote ->
|
||||||
val newAuthor = newNote.author?.pubkeyHex
|
val roomUserHex = (newNote.event as? PrivateDmEvent)?.talkingWith(me.pubkeyHex)
|
||||||
val newRecipient = (newNote.event as? PrivateDmEvent)?.verifiedRecipientPubKey()
|
|
||||||
|
|
||||||
val roomUserHex = if (newAuthor == me.pubkeyHex) newRecipient else newAuthor
|
|
||||||
val roomUser = roomUserHex?.let { LocalCache.users[it] }
|
val roomUser = roomUserHex?.let { LocalCache.users[it] }
|
||||||
|
|
||||||
if (roomUserHex != null && (newAuthor == me.pubkeyHex || roomUserHex in followingKeySet || me.hasSentMessagesTo(roomUser)) && !account.isHidden(roomUserHex)) {
|
if (roomUserHex != null && (newNote.author?.pubkeyHex == me.pubkeyHex || roomUserHex in followingKeySet || me.hasSentMessagesTo(roomUser)) && !account.isHidden(roomUserHex)) {
|
||||||
val lastNote = newRelevantPrivateMessages.get(roomUserHex)
|
val lastNote = newRelevantPrivateMessages.get(roomUserHex)
|
||||||
if (lastNote != null) {
|
if (lastNote != null) {
|
||||||
if ((newNote.createdAt() ?: 0) > (lastNote.createdAt() ?: 0)) {
|
if ((newNote.createdAt() ?: 0) > (lastNote.createdAt() ?: 0)) {
|
||||||
|
|||||||
@@ -189,7 +189,9 @@ object MessagesLatestItem : LatestItem() {
|
|||||||
|
|
||||||
val newestItem = updateNewestItem(newNotes, account, ChatroomListKnownFeedFilter)
|
val newestItem = updateNewestItem(newNotes, account, ChatroomListKnownFeedFilter)
|
||||||
|
|
||||||
val lastTime = cache.load("Room/${newestItem?.author?.pubkeyHex}")
|
val roomUserHex = (newestItem?.event as? PrivateDmEvent)?.talkingWith(account.userProfile().pubkeyHex)
|
||||||
|
|
||||||
|
val lastTime = cache.load("Room/$roomUserHex")
|
||||||
|
|
||||||
return (newestItem?.createdAt() ?: 0) > lastTime
|
return (newestItem?.createdAt() ?: 0) > lastTime
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import androidx.compose.ui.res.painterResource
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.vitorpamplona.amethyst.NotificationCache
|
import com.vitorpamplona.amethyst.NotificationCache
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
|
import com.vitorpamplona.amethyst.service.model.PrivateDmEvent
|
||||||
import com.vitorpamplona.amethyst.ui.screen.MessageSetCard
|
import com.vitorpamplona.amethyst.ui.screen.MessageSetCard
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
import com.vitorpamplona.amethyst.ui.theme.newItemBackgroundColor
|
import com.vitorpamplona.amethyst.ui.theme.newItemBackgroundColor
|
||||||
@@ -99,9 +100,11 @@ fun MessageSetCompose(messageSetCard: MessageSetCard, routeForLastRead: String,
|
|||||||
MessageIcon()
|
MessageIcon()
|
||||||
|
|
||||||
Column(modifier = remember { Modifier.padding(start = 10.dp) }) {
|
Column(modifier = remember { Modifier.padding(start = 10.dp) }) {
|
||||||
|
val routeForLastRead = "Room/${(baseNote.event as? PrivateDmEvent)?.talkingWith(loggedIn.pubkeyHex)}"
|
||||||
|
|
||||||
NoteCompose(
|
NoteCompose(
|
||||||
baseNote = baseNote,
|
baseNote = baseNote,
|
||||||
routeForLastRead = null,
|
routeForLastRead = routeForLastRead,
|
||||||
isBoostedNote = true,
|
isBoostedNote = true,
|
||||||
addMarginTop = false,
|
addMarginTop = false,
|
||||||
parentBackgroundColor = backgroundColor,
|
parentBackgroundColor = backgroundColor,
|
||||||
|
|||||||
@@ -442,20 +442,7 @@ fun routeFor(note: Note, loggedIn: User): String? {
|
|||||||
return "Channel/${it.idHex}"
|
return "Channel/${it.idHex}"
|
||||||
}
|
}
|
||||||
} else if (noteEvent is PrivateDmEvent) {
|
} else if (noteEvent is PrivateDmEvent) {
|
||||||
val replyAuthorBase =
|
return "Room/${noteEvent.talkingWith(loggedIn.pubkeyHex)}"
|
||||||
(note.event as? PrivateDmEvent)
|
|
||||||
?.verifiedRecipientPubKey()
|
|
||||||
?.let { LocalCache.getOrCreateUser(it) }
|
|
||||||
|
|
||||||
var userToComposeOn = note.author!!
|
|
||||||
|
|
||||||
if (replyAuthorBase != null) {
|
|
||||||
if (note.author == loggedIn) {
|
|
||||||
userToComposeOn = replyAuthorBase
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return "Room/${userToComposeOn.pubkeyHex}"
|
|
||||||
} else {
|
} else {
|
||||||
return "Note/${note.idHex}"
|
return "Note/${note.idHex}"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user