Corrects a bug of not showing the user's own messages on chat

This commit is contained in:
Vitor Pamplona
2025-07-22 12:46:05 -04:00
parent a3ec4d4260
commit 0f13202f84
10 changed files with 30 additions and 20 deletions

View File

@@ -1424,8 +1424,6 @@ class Account(
template: EventTemplate<ChatMessageEvent>, template: EventTemplate<ChatMessageEvent>,
draftTag: String? = null, draftTag: String? = null,
) { ) {
if (!isWriteable()) return
if (draftTag != null) { if (draftTag != null) {
if (template.content.isEmpty()) { if (template.content.isEmpty()) {
deleteDraft(draftTag) deleteDraft(draftTag)

View File

@@ -42,8 +42,6 @@ class Chatroom {
@Synchronized @Synchronized
fun addMessageSync(msg: Note) { fun addMessageSync(msg: Note) {
checkNotInMainThread()
if (msg !in roomMessages) { if (msg !in roomMessages) {
roomMessages = roomMessages + msg roomMessages = roomMessages + msg

View File

@@ -53,8 +53,9 @@ abstract class FeedViewModel(
init { init {
Log.d("Init", "Starting new Model: ${this.javaClass.simpleName}") Log.d("Init", "Starting new Model: ${this.javaClass.simpleName}")
collectorJob = collectorJob =
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.Default) {
LocalCache.live.newEventBundles.collect { newNotes -> LocalCache.live.newEventBundles.collect { newNotes ->
Log.d("Rendering Metrics", "Update feeds: ${this@FeedViewModel.javaClass.simpleName} with ${newNotes.size}")
feedState.updateFeedWith(newNotes) feedState.updateFeedWith(newNotes)
} }
} }

View File

@@ -765,6 +765,23 @@ class AccountViewModel(
R.string.unauthorized_exception, R.string.unauthorized_exception,
R.string.unauthorized_exception_description, R.string.unauthorized_exception_description,
) )
} catch (e: SignerExceptions.SignerNotFoundException) {
toastManager.toast(
R.string.signer_not_found_exception,
R.string.signer_not_found_exception_description,
)
} catch (e: SignerExceptions.TimedOutException) {
Log.w("AccountViewModel", "TimedOutException", e)
} catch (e: SignerExceptions.NothingToDecrypt) {
Log.w("AccountViewModel", "NothingToDecrypt", e)
} catch (e: SignerExceptions.CouldNotPerformException) {
Log.w("AccountViewModel", "CouldNotPerformException", e)
} catch (e: SignerExceptions.ManuallyUnauthorizedException) {
Log.w("AccountViewModel", "ManuallyUnauthorizedException", e)
} catch (e: SignerExceptions.AutomaticallyUnauthorizedException) {
Log.w("AccountViewModel", "AutomaticallyUnauthorizedException", e)
} catch (e: SignerExceptions.RunningOnBackgroundWithoutAutomaticPermissionException) {
Log.w("AccountViewModel", "TimedOutRunningOnBackgroundWithoutAutomaticPermissionExceptionException", e)
} }
} }
} }

View File

@@ -56,8 +56,6 @@ import com.vitorpamplona.amethyst.ui.theme.placeholderText
import com.vitorpamplona.quartz.nip17Dm.base.ChatroomKey import com.vitorpamplona.quartz.nip17Dm.base.ChatroomKey
import com.vitorpamplona.quartz.nip17Dm.messages.ChatMessageEvent import com.vitorpamplona.quartz.nip17Dm.messages.ChatMessageEvent
import com.vitorpamplona.quartz.nip17Dm.messages.changeSubject import com.vitorpamplona.quartz.nip17Dm.messages.changeSubject
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@Composable @Composable
fun NewChatroomSubjectDialog( fun NewChatroomSubjectDialog(
@@ -100,7 +98,7 @@ fun NewChatroomSubjectDialog(
PostButton( PostButton(
onPost = { onPost = {
scope.launch(Dispatchers.IO) { accountViewModel.runIOCatching {
val template = val template =
ChatMessageEvent.build( ChatMessageEvent.build(
message.value, message.value,

View File

@@ -345,13 +345,6 @@ class ChatNewMessageViewModel :
nip17 = draftEvent is NIP17Group nip17 = draftEvent is NIP17Group
} }
fun sendPost(onDone: () -> Unit) {
viewModelScope.launch(Dispatchers.IO) {
sendPostSync()
onDone()
}
}
suspend fun sendPostSync() { suspend fun sendPostSync() {
innerSendPost(null) innerSendPost(null)
accountViewModel.deleteDraft(draftTag.current) accountViewModel.deleteDraft(draftTag.current)

View File

@@ -70,7 +70,6 @@ import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.core.net.toUri import androidx.core.net.toUri
import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewModelScope
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import com.vitorpamplona.amethyst.Amethyst import com.vitorpamplona.amethyst.Amethyst
import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.R
@@ -174,7 +173,7 @@ fun NewGroupDMScreen(
onCancel = { onCancel = {
// uses the accountViewModel scope to avoid cancelling this // uses the accountViewModel scope to avoid cancelling this
// function when the postViewModel is released // function when the postViewModel is released
accountViewModel.viewModelScope.launch(Dispatchers.IO) { accountViewModel.runIOCatching {
postViewModel.sendDraftSync() postViewModel.sendDraftSync()
delay(100) delay(100)
nav.popBack() nav.popBack()
@@ -184,7 +183,7 @@ fun NewGroupDMScreen(
onPost = { onPost = {
// uses the accountViewModel scope to avoid cancelling this // uses the accountViewModel scope to avoid cancelling this
// function when the postViewModel is released // function when the postViewModel is released
accountViewModel.viewModelScope.launch(Dispatchers.IO) { accountViewModel.runIOCatching {
postViewModel.sendPostSync() postViewModel.sendPostSync()
postViewModel.room?.let { postViewModel.room?.let {
nav.nav(routeToMessage(it, null, null, null, accountViewModel)) nav.nav(routeToMessage(it, null, null, null, accountViewModel))

View File

@@ -145,7 +145,10 @@ fun EditField(
isActive = channelScreenModel.canPost(), isActive = channelScreenModel.canPost(),
modifier = EditFieldTrailingIconModifier, modifier = EditFieldTrailingIconModifier,
) { ) {
channelScreenModel.sendPost(onSendNewMessage) accountViewModel.runIOCatching {
channelScreenModel.sendPostSync()
onSendNewMessage()
}
} }
}, },
leadingIcon = { leadingIcon = {

View File

@@ -63,6 +63,9 @@
<string name="unauthorized_exception">Unauthorized Decryption</string> <string name="unauthorized_exception">Unauthorized Decryption</string>
<string name="unauthorized_exception_description">The signer did not authorize a decryption that is required to make this operation. Activate NIP-44 decryptions in your signer app and try again</string> <string name="unauthorized_exception_description">The signer did not authorize a decryption that is required to make this operation. Activate NIP-44 decryptions in your signer app and try again</string>
<string name="signer_not_found_exception">Signer not found</string>
<string name="signer_not_found_exception_description">Was the Signer app uninstalled? Check if the signer is installed and has this account. Log off and Log in again of the signer app has changed.</string>
<string name="zaps">Zaps</string> <string name="zaps">Zaps</string>
<string name="view_count">View count</string> <string name="view_count">View count</string>

View File

@@ -69,7 +69,7 @@ open class BaseDMGroupEvent(
return result return result
} }
override fun isIncluded(pubKey: HexKey) = tags.any(PTag::isTagged, pubKey) override fun isIncluded(pubKey: HexKey) = pubKey == this.pubKey || tags.any(PTag::isTagged, pubKey)
override fun groupMembers() = recipientsPubKey().plus(pubKey).toSet() override fun groupMembers() = recipientsPubKey().plus(pubKey).toSet()