extract actions from amethyst
This commit is contained in:
+9
-36
@@ -44,16 +44,8 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.window.Dialog
|
||||
import com.vitorpamplona.amethyst.commons.account.AccountState
|
||||
import com.vitorpamplona.amethyst.commons.actions.PublishAction
|
||||
import com.vitorpamplona.amethyst.desktop.network.DesktopRelayConnectionManager
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.events.ETag
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.events.eTag
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.hashtags.hashtags
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.people.PTag
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.people.pTag
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.references.references
|
||||
import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent
|
||||
import com.vitorpamplona.quartz.nip10Notes.content.findHashtags
|
||||
import com.vitorpamplona.quartz.nip10Notes.content.findURLs
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
@@ -187,35 +179,16 @@ private suspend fun publishNote(
|
||||
withContext(Dispatchers.IO) {
|
||||
println("[ComposeNoteDialog] Starting publishNote: content length=${content.length}")
|
||||
|
||||
// Build TextNoteEvent using Quartz
|
||||
val template =
|
||||
TextNoteEvent.build(content) {
|
||||
// If replying, add e-tag and p-tag
|
||||
if (replyTo != null) {
|
||||
val etag = ETag(replyTo.id)
|
||||
etag.relay = null
|
||||
etag.author = replyTo.pubKey
|
||||
eTag(etag)
|
||||
pTag(PTag(replyTo.pubKey, relayHint = null))
|
||||
}
|
||||
// Check read-only mode
|
||||
if (account.isReadOnly) {
|
||||
println("[ComposeNoteDialog] Error: Cannot post in read-only mode")
|
||||
throw IllegalStateException("Cannot post in read-only mode")
|
||||
}
|
||||
|
||||
// Extract hashtags and URLs from content
|
||||
hashtags(findHashtags(content))
|
||||
references(findURLs(content))
|
||||
}
|
||||
println("[ComposeNoteDialog] Signing event with pubkey: ${account.pubKeyHex.take(8)}...")
|
||||
|
||||
// Sign the event
|
||||
val signedEvent =
|
||||
if (account.isReadOnly) {
|
||||
// Read-only mode - can't sign events
|
||||
println("[ComposeNoteDialog] Error: Cannot post in read-only mode")
|
||||
throw IllegalStateException("Cannot post in read-only mode")
|
||||
} else {
|
||||
// Sign with nsec (full key)
|
||||
val signer = account.signer
|
||||
println("[ComposeNoteDialog] Signing event with pubkey: ${account.pubKeyHex.take(8)}...")
|
||||
signer.sign(template)
|
||||
}
|
||||
// Use shared PublishAction from commons
|
||||
val signedEvent = PublishAction.publishTextNote(content, account.signer, replyTo)
|
||||
|
||||
println("[ComposeNoteDialog] Event signed successfully, ID: ${signedEvent.id.take(8)}...")
|
||||
|
||||
|
||||
@@ -40,14 +40,12 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.vitorpamplona.amethyst.commons.account.AccountState
|
||||
import com.vitorpamplona.amethyst.commons.actions.ReactionAction
|
||||
import com.vitorpamplona.amethyst.commons.actions.RepostAction
|
||||
import com.vitorpamplona.amethyst.commons.icons.Reply
|
||||
import com.vitorpamplona.amethyst.commons.icons.Repost
|
||||
import com.vitorpamplona.amethyst.desktop.network.DesktopRelayConnectionManager
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.hints.EventHintBundle
|
||||
import com.vitorpamplona.quartz.nip18Reposts.GenericRepostEvent
|
||||
import com.vitorpamplona.quartz.nip18Reposts.RepostEvent
|
||||
import com.vitorpamplona.quartz.nip25Reactions.ReactionEvent
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
@@ -163,12 +161,8 @@ private suspend fun reactToNote(
|
||||
relayManager: DesktopRelayConnectionManager,
|
||||
) {
|
||||
withContext(Dispatchers.IO) {
|
||||
// Build reaction event
|
||||
val reactedTo = EventHintBundle(event, null)
|
||||
val template = ReactionEvent.like(reactedTo)
|
||||
|
||||
// Sign with user's key
|
||||
val signedEvent = account.signer.sign(template)
|
||||
// Use shared ReactionAction from commons
|
||||
val signedEvent = ReactionAction.reactTo(event, reaction, account.signer)
|
||||
|
||||
// Broadcast to all relays
|
||||
relayManager.broadcastToAll(signedEvent)
|
||||
@@ -184,26 +178,8 @@ private suspend fun repostNote(
|
||||
relayManager: DesktopRelayConnectionManager,
|
||||
) {
|
||||
withContext(Dispatchers.IO) {
|
||||
// Build repost event
|
||||
val template =
|
||||
if (event.kind == 1) {
|
||||
// Text note - use RepostEvent (kind 6)
|
||||
RepostEvent.build(
|
||||
boostedPost = event,
|
||||
eventSourceRelay = null,
|
||||
authorHomeRelay = null,
|
||||
)
|
||||
} else {
|
||||
// Other kinds - use GenericRepostEvent (kind 16)
|
||||
GenericRepostEvent.build(
|
||||
boostedPost = event,
|
||||
eventSourceRelay = null,
|
||||
authorHomeRelay = null,
|
||||
)
|
||||
}
|
||||
|
||||
// Sign with user's key
|
||||
val signedEvent = account.signer.sign(template)
|
||||
// Use shared RepostAction from commons
|
||||
val signedEvent = RepostAction.repost(event, account.signer)
|
||||
|
||||
// Broadcast to all relays
|
||||
relayManager.broadcastToAll(signedEvent)
|
||||
|
||||
+6
-26
@@ -62,6 +62,7 @@ import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.vitorpamplona.amethyst.commons.account.AccountState
|
||||
import com.vitorpamplona.amethyst.commons.actions.FollowAction
|
||||
import com.vitorpamplona.amethyst.commons.ui.components.LoadingState
|
||||
import com.vitorpamplona.amethyst.desktop.network.DesktopRelayConnectionManager
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
@@ -71,8 +72,6 @@ import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.people.isTaggedUser
|
||||
import com.vitorpamplona.quartz.nip02FollowList.ContactListEvent
|
||||
import com.vitorpamplona.quartz.nip02FollowList.ReadWrite
|
||||
import com.vitorpamplona.quartz.nip02FollowList.tags.ContactTag
|
||||
import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent
|
||||
import com.vitorpamplona.quartz.nip19Bech32.toNpub
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -531,24 +530,8 @@ private suspend fun followUser(
|
||||
withContext(Dispatchers.IO) {
|
||||
println("[UserProfile] Starting followUser: target=${pubKeyHex.take(8)}...")
|
||||
|
||||
val updatedEvent =
|
||||
if (currentContactList != null) {
|
||||
println("[UserProfile] Adding to existing contact list")
|
||||
// Add to existing contact list
|
||||
ContactListEvent.followUser(
|
||||
earlierVersion = currentContactList,
|
||||
pubKeyHex = pubKeyHex,
|
||||
signer = account.signer,
|
||||
)
|
||||
} else {
|
||||
println("[UserProfile] Creating new contact list")
|
||||
// Create new contact list with this user
|
||||
ContactListEvent.createFromScratch(
|
||||
followUsers = listOf(ContactTag(pubKeyHex)),
|
||||
relayUse = emptyMap<String, ReadWrite>(),
|
||||
signer = account.signer,
|
||||
)
|
||||
}
|
||||
// Use shared FollowAction from commons
|
||||
val updatedEvent = FollowAction.follow(pubKeyHex, account.signer, currentContactList)
|
||||
|
||||
println("[UserProfile] ContactListEvent created, broadcasting...")
|
||||
relayManager.broadcastToAll(updatedEvent)
|
||||
@@ -570,12 +553,9 @@ private suspend fun unfollowUser(
|
||||
|
||||
if (currentContactList != null) {
|
||||
println("[UserProfile] Removing from existing contact list")
|
||||
val updatedEvent =
|
||||
ContactListEvent.unfollowUser(
|
||||
earlierVersion = currentContactList,
|
||||
pubKeyHex = pubKeyHex,
|
||||
signer = account.signer,
|
||||
)
|
||||
|
||||
// Use shared FollowAction from commons
|
||||
val updatedEvent = FollowAction.unfollow(pubKeyHex, account.signer, currentContactList)
|
||||
|
||||
println("[UserProfile] ContactListEvent updated, broadcasting...")
|
||||
relayManager.broadcastToAll(updatedEvent)
|
||||
|
||||
Reference in New Issue
Block a user