kopia lustrzana https://github.com/vitorpamplona/amethyst
removed AmberUtils.signEvent
rodzic
9f9f158709
commit
c42944e15b
|
@ -413,13 +413,17 @@ class Account(
|
|||
val emojiUrl = EmojiUrl.decode(reaction)
|
||||
if (emojiUrl != null) {
|
||||
note.event?.let {
|
||||
val event = ReactionEvent.create(emojiUrl, it, keyPair)
|
||||
var event = ReactionEvent.create(emojiUrl, it, keyPair)
|
||||
if (loginWithAmber) {
|
||||
AmberUtils.signEvent(event)
|
||||
} else {
|
||||
Client.send(event)
|
||||
LocalCache.consume(event)
|
||||
AmberUtils.openAmber(event)
|
||||
val content = AmberUtils.content[event.id] ?: ""
|
||||
if (content.isBlank()) {
|
||||
return
|
||||
}
|
||||
event = ReactionEvent.create(event, content)
|
||||
}
|
||||
Client.send(event)
|
||||
LocalCache.consume(event)
|
||||
}
|
||||
|
||||
return
|
||||
|
@ -427,13 +431,17 @@ class Account(
|
|||
}
|
||||
|
||||
note.event?.let {
|
||||
val event = ReactionEvent.create(reaction, it, keyPair)
|
||||
var event = ReactionEvent.create(reaction, it, keyPair)
|
||||
if (loginWithAmber) {
|
||||
AmberUtils.signEvent(event)
|
||||
} else {
|
||||
Client.send(event)
|
||||
LocalCache.consume(event)
|
||||
AmberUtils.openAmber(event)
|
||||
val content = AmberUtils.content[event.id] ?: ""
|
||||
if (content.isBlank()) {
|
||||
return
|
||||
}
|
||||
event = ReactionEvent.create(event, content)
|
||||
}
|
||||
Client.send(event)
|
||||
LocalCache.consume(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -680,13 +688,22 @@ class Account(
|
|||
val myNotes = notes.filter { it.author == userProfile() }.map { it.idHex }
|
||||
|
||||
if (myNotes.isNotEmpty()) {
|
||||
val event = DeletionEvent.create(myNotes, keyPair)
|
||||
var event = DeletionEvent.create(myNotes, keyPair)
|
||||
if (loginWithAmber) {
|
||||
AmberUtils.signEvent(event)
|
||||
} else {
|
||||
Client.send(event)
|
||||
LocalCache.consume(event)
|
||||
AmberUtils.openAmber(event)
|
||||
val eventContent = AmberUtils.content[event.id] ?: ""
|
||||
if (eventContent.isBlank()) return
|
||||
event = DeletionEvent(
|
||||
event.id,
|
||||
event.pubKey,
|
||||
event.createdAt,
|
||||
event.tags,
|
||||
event.content,
|
||||
eventContent
|
||||
)
|
||||
}
|
||||
Client.send(event)
|
||||
LocalCache.consume(event)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -715,21 +732,39 @@ class Account(
|
|||
|
||||
note.event?.let {
|
||||
if (it.kind() == 1) {
|
||||
val event = RepostEvent.create(it, keyPair)
|
||||
var event = RepostEvent.create(it, keyPair)
|
||||
if (loginWithAmber) {
|
||||
AmberUtils.signEvent(event)
|
||||
} else {
|
||||
Client.send(event)
|
||||
LocalCache.consume(event)
|
||||
AmberUtils.openAmber(event)
|
||||
val eventContent = AmberUtils.content[event.id] ?: ""
|
||||
if (eventContent.isBlank()) return
|
||||
event = RepostEvent(
|
||||
event.id,
|
||||
event.pubKey,
|
||||
event.createdAt,
|
||||
event.tags,
|
||||
event.content,
|
||||
eventContent
|
||||
)
|
||||
}
|
||||
Client.send(event)
|
||||
LocalCache.consume(event)
|
||||
} else {
|
||||
val event = GenericRepostEvent.create(it, keyPair)
|
||||
var event = GenericRepostEvent.create(it, keyPair)
|
||||
if (loginWithAmber) {
|
||||
AmberUtils.signEvent(event)
|
||||
} else {
|
||||
Client.send(event)
|
||||
LocalCache.consume(event)
|
||||
AmberUtils.openAmber(event)
|
||||
val eventContent = AmberUtils.content[event.id] ?: ""
|
||||
if (eventContent.isBlank()) return
|
||||
event = GenericRepostEvent(
|
||||
event.id,
|
||||
event.pubKey,
|
||||
event.createdAt,
|
||||
event.tags,
|
||||
event.content,
|
||||
eventContent
|
||||
)
|
||||
}
|
||||
Client.send(event)
|
||||
LocalCache.consume(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,13 +12,9 @@ import com.vitorpamplona.amethyst.Amethyst
|
|||
import com.vitorpamplona.amethyst.R
|
||||
import com.vitorpamplona.amethyst.ServiceManager
|
||||
import com.vitorpamplona.amethyst.model.Account
|
||||
import com.vitorpamplona.amethyst.model.LocalCache
|
||||
import com.vitorpamplona.amethyst.service.relays.Client
|
||||
import com.vitorpamplona.amethyst.ui.MainActivity
|
||||
import com.vitorpamplona.quartz.encoders.HexKey
|
||||
import com.vitorpamplona.quartz.encoders.toHexKey
|
||||
import com.vitorpamplona.quartz.encoders.toNpub
|
||||
import com.vitorpamplona.quartz.events.Event
|
||||
import com.vitorpamplona.quartz.events.EventInterface
|
||||
import com.vitorpamplona.quartz.events.LnZapRequestEvent
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
|
@ -44,7 +40,6 @@ object AmberUtils {
|
|||
private lateinit var activityResultLauncher: ActivityResultLauncher<Intent>
|
||||
private lateinit var decryptResultLauncher: ActivityResultLauncher<Intent>
|
||||
private lateinit var blockListResultLauncher: ActivityResultLauncher<Intent>
|
||||
private lateinit var signEventResultLauncher: ActivityResultLauncher<Intent>
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
fun requestRejectedToast() {
|
||||
|
@ -69,24 +64,6 @@ object AmberUtils {
|
|||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
fun start(activity: MainActivity) {
|
||||
signEventResultLauncher = activity.registerForActivityResult(
|
||||
ActivityResultContracts.StartActivityForResult()
|
||||
) {
|
||||
if (it.resultCode != Activity.RESULT_OK) {
|
||||
requestRejectedToast()
|
||||
} else {
|
||||
val json = it.data?.getStringExtra("event") ?: ""
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
val signedEvent = Event.fromJson(json)
|
||||
if (signedEvent.hasValidSignature()) {
|
||||
Client.send(signedEvent)
|
||||
LocalCache.verifyAndConsume(signedEvent, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
default()
|
||||
}
|
||||
|
||||
activityResultLauncher = activity.registerForActivityResult(
|
||||
ActivityResultContracts.StartActivityForResult()
|
||||
) {
|
||||
|
@ -198,19 +175,6 @@ object AmberUtils {
|
|||
}
|
||||
}
|
||||
|
||||
fun signEvent(event: EventInterface) {
|
||||
checkNotInMainThread()
|
||||
ServiceManager.shouldPauseService = false
|
||||
isActivityRunning = true
|
||||
openAmber(
|
||||
event.toJson(),
|
||||
SignerType.SIGN_EVENT,
|
||||
signEventResultLauncher,
|
||||
account.keyPair.pubKey.toHexKey(),
|
||||
event.id()
|
||||
)
|
||||
}
|
||||
|
||||
fun decryptBlockList(encryptedContent: String, pubKey: HexKey, id: String, signerType: SignerType = SignerType.NIP04_DECRYPT) {
|
||||
val result = getDataFromResolver(signerType, arrayOf(encryptedContent, pubKey))
|
||||
if (result !== null) {
|
||||
|
|
|
@ -8,8 +8,6 @@ import com.vitorpamplona.amethyst.service.relays.EOSEAccount
|
|||
import com.vitorpamplona.amethyst.service.relays.JsonFilter
|
||||
import com.vitorpamplona.amethyst.service.relays.Relay
|
||||
import com.vitorpamplona.amethyst.service.relays.TypedFilter
|
||||
import com.vitorpamplona.quartz.encoders.toHexKey
|
||||
import com.vitorpamplona.quartz.encoders.toNpub
|
||||
import com.vitorpamplona.quartz.events.AdvertisedRelayListEvent
|
||||
import com.vitorpamplona.quartz.events.BadgeAwardEvent
|
||||
import com.vitorpamplona.quartz.events.BadgeProfilesEvent
|
||||
|
@ -26,7 +24,6 @@ import com.vitorpamplona.quartz.events.MetadataEvent
|
|||
import com.vitorpamplona.quartz.events.PeopleListEvent
|
||||
import com.vitorpamplona.quartz.events.PollNoteEvent
|
||||
import com.vitorpamplona.quartz.events.ReactionEvent
|
||||
import com.vitorpamplona.quartz.events.RelayAuthEvent
|
||||
import com.vitorpamplona.quartz.events.ReportEvent
|
||||
import com.vitorpamplona.quartz.events.RepostEvent
|
||||
import com.vitorpamplona.quartz.events.SealedGossipEvent
|
||||
|
@ -220,26 +217,12 @@ object NostrAccountDataSource : NostrDataSource("AccountData") {
|
|||
super.auth(relay, challenge)
|
||||
|
||||
if (this::account.isInitialized) {
|
||||
if (account.loginWithAmber) {
|
||||
val event = RelayAuthEvent.create(relay.url, challenge, account.keyPair.pubKey.toHexKey(), account.keyPair.privKey)
|
||||
val result = AmberUtils.getDataFromResolver(SignerType.SIGN_EVENT, arrayOf(event.toJson(), account.keyPair.pubKey.toNpub()), "event")
|
||||
if (result !== null) {
|
||||
val signedEvent = Event.fromJson(result)
|
||||
Client.send(
|
||||
signedEvent,
|
||||
relay.url
|
||||
)
|
||||
return
|
||||
}
|
||||
AmberUtils.signEvent(event)
|
||||
} else {
|
||||
val event = account.createAuthEvent(relay, challenge)
|
||||
if (event != null) {
|
||||
Client.send(
|
||||
event,
|
||||
relay.url
|
||||
)
|
||||
}
|
||||
val event = account.createAuthEvent(relay, challenge)
|
||||
if (event != null) {
|
||||
Client.send(
|
||||
event,
|
||||
relay.url
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue