From 0f13202f847e8ab6996e42409fe37c6fc9706ba0 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Tue, 22 Jul 2025 12:46:05 -0400 Subject: [PATCH] Corrects a bug of not showing the user's own messages on chat --- .../com/vitorpamplona/amethyst/model/Account.kt | 2 -- .../amethyst/model/privateChats/Chatroom.kt | 2 -- .../amethyst/ui/screen/FeedViewModel.kt | 3 ++- .../ui/screen/loggedIn/AccountViewModel.kt | 17 +++++++++++++++++ .../header/NewChatroomSubjectDialog.kt | 4 +--- .../privateDM/send/ChatNewMessageViewModel.kt | 7 ------- .../chats/privateDM/send/NewGroupDMScreen.kt | 5 ++--- .../send/PrivateMessageEditFieldRow.kt | 5 ++++- amethyst/src/main/res/values/strings.xml | 3 +++ .../quartz/nip17Dm/base/BaseDMGroupEvent.kt | 2 +- 10 files changed, 30 insertions(+), 20 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt index e4480525c..32c66aab6 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt @@ -1424,8 +1424,6 @@ class Account( template: EventTemplate, draftTag: String? = null, ) { - if (!isWriteable()) return - if (draftTag != null) { if (template.content.isEmpty()) { deleteDraft(draftTag) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/privateChats/Chatroom.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/privateChats/Chatroom.kt index 07e0b77bf..d956b21dc 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/privateChats/Chatroom.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/privateChats/Chatroom.kt @@ -42,8 +42,6 @@ class Chatroom { @Synchronized fun addMessageSync(msg: Note) { - checkNotInMainThread() - if (msg !in roomMessages) { roomMessages = roomMessages + msg diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/FeedViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/FeedViewModel.kt index 8df48eb4f..094f9486c 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/FeedViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/FeedViewModel.kt @@ -53,8 +53,9 @@ abstract class FeedViewModel( init { Log.d("Init", "Starting new Model: ${this.javaClass.simpleName}") collectorJob = - viewModelScope.launch(Dispatchers.IO) { + viewModelScope.launch(Dispatchers.Default) { LocalCache.live.newEventBundles.collect { newNotes -> + Log.d("Rendering Metrics", "Update feeds: ${this@FeedViewModel.javaClass.simpleName} with ${newNotes.size}") feedState.updateFeedWith(newNotes) } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt index 6810476c9..ba4798ba2 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt @@ -765,6 +765,23 @@ class AccountViewModel( R.string.unauthorized_exception, 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) } } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/header/NewChatroomSubjectDialog.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/header/NewChatroomSubjectDialog.kt index ec79a82c6..6f59c7f16 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/header/NewChatroomSubjectDialog.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/header/NewChatroomSubjectDialog.kt @@ -56,8 +56,6 @@ import com.vitorpamplona.amethyst.ui.theme.placeholderText import com.vitorpamplona.quartz.nip17Dm.base.ChatroomKey import com.vitorpamplona.quartz.nip17Dm.messages.ChatMessageEvent import com.vitorpamplona.quartz.nip17Dm.messages.changeSubject -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch @Composable fun NewChatroomSubjectDialog( @@ -100,7 +98,7 @@ fun NewChatroomSubjectDialog( PostButton( onPost = { - scope.launch(Dispatchers.IO) { + accountViewModel.runIOCatching { val template = ChatMessageEvent.build( message.value, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/send/ChatNewMessageViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/send/ChatNewMessageViewModel.kt index f2503744d..6d713786e 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/send/ChatNewMessageViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/send/ChatNewMessageViewModel.kt @@ -345,13 +345,6 @@ class ChatNewMessageViewModel : nip17 = draftEvent is NIP17Group } - fun sendPost(onDone: () -> Unit) { - viewModelScope.launch(Dispatchers.IO) { - sendPostSync() - onDone() - } - } - suspend fun sendPostSync() { innerSendPost(null) accountViewModel.deleteDraft(draftTag.current) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/send/NewGroupDMScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/send/NewGroupDMScreen.kt index c47094f16..0b079e56d 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/send/NewGroupDMScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/send/NewGroupDMScreen.kt @@ -70,7 +70,6 @@ import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.unit.dp import androidx.core.net.toUri import androidx.lifecycle.compose.collectAsStateWithLifecycle -import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewmodel.compose.viewModel import com.vitorpamplona.amethyst.Amethyst import com.vitorpamplona.amethyst.R @@ -174,7 +173,7 @@ fun NewGroupDMScreen( onCancel = { // uses the accountViewModel scope to avoid cancelling this // function when the postViewModel is released - accountViewModel.viewModelScope.launch(Dispatchers.IO) { + accountViewModel.runIOCatching { postViewModel.sendDraftSync() delay(100) nav.popBack() @@ -184,7 +183,7 @@ fun NewGroupDMScreen( onPost = { // uses the accountViewModel scope to avoid cancelling this // function when the postViewModel is released - accountViewModel.viewModelScope.launch(Dispatchers.IO) { + accountViewModel.runIOCatching { postViewModel.sendPostSync() postViewModel.room?.let { nav.nav(routeToMessage(it, null, null, null, accountViewModel)) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/send/PrivateMessageEditFieldRow.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/send/PrivateMessageEditFieldRow.kt index 0d489578b..cc557c2d0 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/send/PrivateMessageEditFieldRow.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/send/PrivateMessageEditFieldRow.kt @@ -145,7 +145,10 @@ fun EditField( isActive = channelScreenModel.canPost(), modifier = EditFieldTrailingIconModifier, ) { - channelScreenModel.sendPost(onSendNewMessage) + accountViewModel.runIOCatching { + channelScreenModel.sendPostSync() + onSendNewMessage() + } } }, leadingIcon = { diff --git a/amethyst/src/main/res/values/strings.xml b/amethyst/src/main/res/values/strings.xml index 141ca6b28..a9cdda2ec 100644 --- a/amethyst/src/main/res/values/strings.xml +++ b/amethyst/src/main/res/values/strings.xml @@ -63,6 +63,9 @@ Unauthorized Decryption 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 + Signer not found + 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. + Zaps View count diff --git a/quartz/src/main/java/com/vitorpamplona/quartz/nip17Dm/base/BaseDMGroupEvent.kt b/quartz/src/main/java/com/vitorpamplona/quartz/nip17Dm/base/BaseDMGroupEvent.kt index 3b1ef9ecb..b47e875ce 100644 --- a/quartz/src/main/java/com/vitorpamplona/quartz/nip17Dm/base/BaseDMGroupEvent.kt +++ b/quartz/src/main/java/com/vitorpamplona/quartz/nip17Dm/base/BaseDMGroupEvent.kt @@ -69,7 +69,7 @@ open class BaseDMGroupEvent( 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()