mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2024-09-30 00:40:49 +00:00
add signerdialog to boosts
This commit is contained in:
parent
10b15226a1
commit
c31fa116ca
@ -431,25 +431,35 @@ class Account(
|
|||||||
return HTTPAuthorizationEvent.create(url, method, body, keyPair.privKey!!)
|
return HTTPAuthorizationEvent.create(url, method, body, keyPair.privKey!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun boost(note: Note) {
|
fun boost(note: Note, signEvent: Boolean = true): Event? {
|
||||||
if (!isWriteable()) return
|
if (!isWriteable() && signEvent) return null
|
||||||
|
|
||||||
if (note.hasBoostedInTheLast5Minutes(userProfile())) {
|
if (note.hasBoostedInTheLast5Minutes(userProfile())) {
|
||||||
// has already bosted in the past 5mins
|
// has already bosted in the past 5mins
|
||||||
return
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
note.event?.let {
|
note.event?.let {
|
||||||
if (it.kind() == 1) {
|
if (it.kind() == 1) {
|
||||||
|
if (!signEvent) {
|
||||||
|
return RepostEvent.create(it, keyPair.pubKey.toHexKey())
|
||||||
|
}
|
||||||
|
|
||||||
val event = RepostEvent.create(it, keyPair.privKey!!)
|
val event = RepostEvent.create(it, keyPair.privKey!!)
|
||||||
Client.send(event)
|
Client.send(event)
|
||||||
LocalCache.consume(event)
|
LocalCache.consume(event)
|
||||||
|
return null
|
||||||
} else {
|
} else {
|
||||||
|
if (!signEvent) {
|
||||||
|
return GenericRepostEvent.create(it, keyPair.pubKey.toHexKey())
|
||||||
|
}
|
||||||
val event = GenericRepostEvent.create(it, keyPair.privKey!!)
|
val event = GenericRepostEvent.create(it, keyPair.privKey!!)
|
||||||
Client.send(event)
|
Client.send(event)
|
||||||
LocalCache.consume(event)
|
LocalCache.consume(event)
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun broadcast(note: Note) {
|
fun broadcast(note: Note) {
|
||||||
|
@ -29,6 +29,24 @@ class GenericRepostEvent(
|
|||||||
companion object {
|
companion object {
|
||||||
const val kind = 16
|
const val kind = 16
|
||||||
|
|
||||||
|
fun create(boostedPost: EventInterface, pubKey: HexKey, createdAt: Long = TimeUtils.now()): GenericRepostEvent {
|
||||||
|
val content = boostedPost.toJson()
|
||||||
|
|
||||||
|
val replyToPost = listOf("e", boostedPost.id())
|
||||||
|
val replyToAuthor = listOf("p", boostedPost.pubKey())
|
||||||
|
|
||||||
|
var tags: List<List<String>> = listOf(replyToPost, replyToAuthor)
|
||||||
|
|
||||||
|
if (boostedPost is AddressableEvent) {
|
||||||
|
tags = tags + listOf(listOf("a", boostedPost.address().toTag()))
|
||||||
|
}
|
||||||
|
|
||||||
|
tags = tags + listOf(listOf("k", "${boostedPost.kind()}"))
|
||||||
|
|
||||||
|
val id = generateId(pubKey, createdAt, kind, tags, content)
|
||||||
|
return GenericRepostEvent(id.toHexKey(), pubKey, createdAt, tags, content, "")
|
||||||
|
}
|
||||||
|
|
||||||
fun create(boostedPost: EventInterface, privateKey: ByteArray, createdAt: Long = TimeUtils.now()): GenericRepostEvent {
|
fun create(boostedPost: EventInterface, privateKey: ByteArray, createdAt: Long = TimeUtils.now()): GenericRepostEvent {
|
||||||
val content = boostedPost.toJson()
|
val content = boostedPost.toJson()
|
||||||
|
|
||||||
|
@ -29,6 +29,22 @@ class RepostEvent(
|
|||||||
companion object {
|
companion object {
|
||||||
const val kind = 6
|
const val kind = 6
|
||||||
|
|
||||||
|
fun create(boostedPost: EventInterface, pubKey: HexKey, createdAt: Long = TimeUtils.now()): RepostEvent {
|
||||||
|
val content = boostedPost.toJson()
|
||||||
|
|
||||||
|
val replyToPost = listOf("e", boostedPost.id())
|
||||||
|
val replyToAuthor = listOf("p", boostedPost.pubKey())
|
||||||
|
|
||||||
|
var tags: List<List<String>> = listOf(replyToPost, replyToAuthor)
|
||||||
|
|
||||||
|
if (boostedPost is AddressableEvent) {
|
||||||
|
tags = tags + listOf(listOf("a", boostedPost.address().toTag()))
|
||||||
|
}
|
||||||
|
|
||||||
|
val id = generateId(pubKey, createdAt, kind, tags, content)
|
||||||
|
return RepostEvent(id.toHexKey(), pubKey, createdAt, tags, content, "")
|
||||||
|
}
|
||||||
|
|
||||||
fun create(boostedPost: EventInterface, privateKey: ByteArray, createdAt: Long = TimeUtils.now()): RepostEvent {
|
fun create(boostedPost: EventInterface, privateKey: ByteArray, createdAt: Long = TimeUtils.now()): RepostEvent {
|
||||||
val content = boostedPost.toJson()
|
val content = boostedPost.toJson()
|
||||||
|
|
||||||
|
@ -678,6 +678,25 @@ fun BoostReaction(
|
|||||||
val iconButtonModifier = remember {
|
val iconButtonModifier = remember {
|
||||||
Modifier.size(iconSize)
|
Modifier.size(iconSize)
|
||||||
}
|
}
|
||||||
|
var event by remember {
|
||||||
|
mutableStateOf<Event?>(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event != null) {
|
||||||
|
SignerDialog(
|
||||||
|
onClose = {
|
||||||
|
event = null
|
||||||
|
},
|
||||||
|
onPost = {
|
||||||
|
scope.launch(Dispatchers.IO) {
|
||||||
|
Client.send(it)
|
||||||
|
LocalCache.verifyAndConsume(it, null)
|
||||||
|
event = null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
event = event!!
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
IconButton(
|
IconButton(
|
||||||
modifier = iconButtonModifier,
|
modifier = iconButtonModifier,
|
||||||
@ -691,12 +710,22 @@ fun BoostReaction(
|
|||||||
wantsToBoost = true
|
wantsToBoost = true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
scope.launch {
|
if (PackageUtils.isAmberInstalled(context)) {
|
||||||
Toast.makeText(
|
if (accountViewModel.hasBoosted(baseNote)) {
|
||||||
context,
|
scope.launch(Dispatchers.IO) {
|
||||||
context.getString(R.string.login_with_a_private_key_to_be_able_to_boost_posts),
|
event = accountViewModel.deleteBoostsTo(baseNote, false)
|
||||||
Toast.LENGTH_SHORT
|
}
|
||||||
).show()
|
} else {
|
||||||
|
wantsToBoost = true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
scope.launch {
|
||||||
|
Toast.makeText(
|
||||||
|
context,
|
||||||
|
context.getString(R.string.login_with_a_private_key_to_be_able_to_boost_posts),
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -714,6 +743,11 @@ fun BoostReaction(
|
|||||||
onQuote = {
|
onQuote = {
|
||||||
wantsToBoost = false
|
wantsToBoost = false
|
||||||
onQuotePress()
|
onQuotePress()
|
||||||
|
},
|
||||||
|
onRepost = {
|
||||||
|
scope.launch(Dispatchers.IO) {
|
||||||
|
event = accountViewModel.boost(baseNote, false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -1266,7 +1300,7 @@ private fun DrawViewCount(
|
|||||||
|
|
||||||
@OptIn(ExperimentalLayoutApi::class)
|
@OptIn(ExperimentalLayoutApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
private fun BoostTypeChoicePopup(baseNote: Note, accountViewModel: AccountViewModel, onDismiss: () -> Unit, onQuote: () -> Unit) {
|
private fun BoostTypeChoicePopup(baseNote: Note, accountViewModel: AccountViewModel, onDismiss: () -> Unit, onQuote: () -> Unit, onRepost: () -> Unit) {
|
||||||
Popup(
|
Popup(
|
||||||
alignment = Alignment.BottomCenter,
|
alignment = Alignment.BottomCenter,
|
||||||
offset = IntOffset(0, -50),
|
offset = IntOffset(0, -50),
|
||||||
@ -1277,8 +1311,13 @@ private fun BoostTypeChoicePopup(baseNote: Note, accountViewModel: AccountViewMo
|
|||||||
Button(
|
Button(
|
||||||
modifier = Modifier.padding(horizontal = 3.dp),
|
modifier = Modifier.padding(horizontal = 3.dp),
|
||||||
onClick = {
|
onClick = {
|
||||||
scope.launch(Dispatchers.IO) {
|
if (accountViewModel.isWriteable()) {
|
||||||
accountViewModel.boost(baseNote)
|
scope.launch(Dispatchers.IO) {
|
||||||
|
accountViewModel.boost(baseNote)
|
||||||
|
onDismiss()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
onRepost()
|
||||||
onDismiss()
|
onDismiss()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -119,8 +119,8 @@ class AccountViewModel(val account: Account) : ViewModel() {
|
|||||||
return account.hasBoosted(baseNote)
|
return account.hasBoosted(baseNote)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteBoostsTo(note: Note) {
|
fun deleteBoostsTo(note: Note, signEvent: Boolean = true): DeletionEvent? {
|
||||||
account.delete(account.boostsTo(note))
|
return account.delete(account.boostsTo(note), signEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun calculateIfNoteWasZappedByAccount(zappedNote: Note): Boolean {
|
fun calculateIfNoteWasZappedByAccount(zappedNote: Note): Boolean {
|
||||||
@ -211,8 +211,8 @@ class AccountViewModel(val account: Account) : ViewModel() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun boost(note: Note) {
|
fun boost(note: Note, signEvent: Boolean = true): Event? {
|
||||||
account.boost(note)
|
return account.boost(note, signEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun removeEmojiPack(usersEmojiList: Note, emojiList: Note) {
|
fun removeEmojiPack(usersEmojiList: Note, emojiList: Note) {
|
||||||
|
Loading…
Reference in New Issue
Block a user