Allowing replies of PMs from Notifications.

This commit is contained in:
Vitor Pamplona
2023-04-04 16:09:54 -04:00
parent 83bcf53583
commit a8a3915c8d
3 changed files with 6 additions and 3 deletions

View File

@@ -419,12 +419,12 @@ class Account(
LocalCache.consume(signedEvent, null) LocalCache.consume(signedEvent, null)
} }
fun sendPrivateMessage(message: String, toUser: String, replyingTo: Note? = null) { fun sendPrivateMessage(message: String, toUser: String, replyingTo: Note? = null, mentions: List<User>?) {
if (!isWriteable()) return if (!isWriteable()) return
val user = LocalCache.users[toUser] ?: return val user = LocalCache.users[toUser] ?: return
val repliesToHex = listOfNotNull(replyingTo?.idHex).ifEmpty { null } val repliesToHex = listOfNotNull(replyingTo?.idHex).ifEmpty { null }
val mentionsHex = emptyList<String>() val mentionsHex = mentions?.map { it.pubkeyHex }
val signedEvent = PrivateDmEvent.create( val signedEvent = PrivateDmEvent.create(
recipientPubKey = user.pubkey(), recipientPubKey = user.pubkey(),

View File

@@ -13,6 +13,7 @@ import androidx.compose.ui.text.input.TextFieldValue
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.vitorpamplona.amethyst.model.* import com.vitorpamplona.amethyst.model.*
import com.vitorpamplona.amethyst.service.model.PrivateDmEvent
import com.vitorpamplona.amethyst.service.model.TextNoteEvent import com.vitorpamplona.amethyst.service.model.TextNoteEvent
import com.vitorpamplona.amethyst.service.nip19.Nip19 import com.vitorpamplona.amethyst.service.nip19.Nip19
import com.vitorpamplona.amethyst.ui.components.isValidURL import com.vitorpamplona.amethyst.ui.components.isValidURL
@@ -152,6 +153,8 @@ open class NewPostViewModel : ViewModel() {
account?.sendPoll(newMessage, replyTos, mentions, pollOptions, valueMaximum, valueMinimum, consensusThreshold, closedAt) account?.sendPoll(newMessage, replyTos, mentions, pollOptions, valueMaximum, valueMinimum, consensusThreshold, closedAt)
} else if (originalNote?.channel() != null) { } else if (originalNote?.channel() != null) {
account?.sendChannelMessage(newMessage, originalNote!!.channel()!!.idHex, originalNote!!, mentions) account?.sendChannelMessage(newMessage, originalNote!!.channel()!!.idHex, originalNote!!, mentions)
} else if (originalNote?.event is PrivateDmEvent) {
account?.sendPrivateMessage(newMessage, originalNote!!.author!!.pubkeyHex, originalNote!!, mentions)
} else { } else {
account?.sendPost(newMessage, replyTos, mentions) account?.sendPost(newMessage, replyTos, mentions)
} }

View File

@@ -177,7 +177,7 @@ fun ChatroomScreen(userId: String?, accountViewModel: AccountViewModel, navContr
trailingIcon = { trailingIcon = {
PostButton( PostButton(
onPost = { onPost = {
account.sendPrivateMessage(chatRoomScreenModel.message.text, userId, replyTo.value) account.sendPrivateMessage(chatRoomScreenModel.message.text, userId, replyTo.value, null)
chatRoomScreenModel.message = TextFieldValue("") chatRoomScreenModel.message = TextFieldValue("")
replyTo.value = null replyTo.value = null
feedViewModel.invalidateData() // Don't wait a full second before updating feedViewModel.invalidateData() // Don't wait a full second before updating