sign unfollow event
This commit is contained in:
@@ -618,12 +618,20 @@ class Account(
|
|||||||
LocalCache.consume(event)
|
LocalCache.consume(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unfollow(user: User) {
|
fun unfollow(user: User, signEvent: Boolean = true): ContactListEvent? {
|
||||||
if (!isWriteable()) return
|
if (!isWriteable() && signEvent) return null
|
||||||
|
|
||||||
val contactList = migrateCommunitiesAndChannelsIfNeeded(userProfile().latestContactList)
|
val contactList = migrateCommunitiesAndChannelsIfNeeded(userProfile().latestContactList)
|
||||||
|
|
||||||
if (contactList != null && contactList.tags.isNotEmpty()) {
|
if (contactList != null && contactList.tags.isNotEmpty()) {
|
||||||
|
if (!signEvent) {
|
||||||
|
return ContactListEvent.unfollowUser(
|
||||||
|
contactList,
|
||||||
|
user.pubkeyHex,
|
||||||
|
keyPair.pubKey.toHexKey()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
val event = ContactListEvent.unfollowUser(
|
val event = ContactListEvent.unfollowUser(
|
||||||
contactList,
|
contactList,
|
||||||
user.pubkeyHex,
|
user.pubkeyHex,
|
||||||
@@ -633,6 +641,8 @@ class Account(
|
|||||||
Client.send(event)
|
Client.send(event)
|
||||||
LocalCache.consume(event)
|
LocalCache.consume(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unfollowHashtag(tag: String) {
|
fun unfollowHashtag(tag: String) {
|
||||||
|
|||||||
@@ -3,7 +3,15 @@ package com.vitorpamplona.amethyst.service
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
|
||||||
object PackageUtils {
|
object PackageUtils {
|
||||||
fun isPackageInstalled(context: Context, target: String): Boolean {
|
private fun isPackageInstalled(context: Context, target: String): Boolean {
|
||||||
return context.packageManager.getInstalledApplications(0).find { info -> info.packageName == target } != null
|
return context.packageManager.getInstalledApplications(0).find { info -> info.packageName == target } != null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isOrbotInstalled(context: Context): Boolean {
|
||||||
|
return isPackageInstalled(context, "org.torproject.android")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isAmberInstalled(context: Context): Boolean {
|
||||||
|
return isPackageInstalled(context, "com.greenart7c3.nostrsigner")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -165,6 +165,17 @@ class ContactListEvent(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun unfollowUser(earlierVersion: ContactListEvent, pubKeyHex: String, pubKey: HexKey, createdAt: Long = TimeUtils.now()): ContactListEvent {
|
||||||
|
if (!earlierVersion.isTaggedUser(pubKeyHex)) return earlierVersion
|
||||||
|
|
||||||
|
return create(
|
||||||
|
content = earlierVersion.content,
|
||||||
|
tags = earlierVersion.tags.filter { it.size > 1 && it[1] != pubKeyHex },
|
||||||
|
pubKey = pubKey,
|
||||||
|
createdAt = createdAt
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fun unfollowUser(earlierVersion: ContactListEvent, pubKeyHex: String, privateKey: ByteArray, createdAt: Long = TimeUtils.now()): ContactListEvent {
|
fun unfollowUser(earlierVersion: ContactListEvent, pubKeyHex: String, privateKey: ByteArray, createdAt: Long = TimeUtils.now()): ContactListEvent {
|
||||||
if (!earlierVersion.isTaggedUser(pubKeyHex)) return earlierVersion
|
if (!earlierVersion.isTaggedUser(pubKeyHex)) return earlierVersion
|
||||||
|
|
||||||
|
|||||||
@@ -768,6 +768,9 @@ private fun DisplayFollowUnfollowButton(
|
|||||||
if (isLoggedInFollowingUser) {
|
if (isLoggedInFollowingUser) {
|
||||||
UnfollowButton {
|
UnfollowButton {
|
||||||
if (!accountViewModel.isWriteable()) {
|
if (!accountViewModel.isWriteable()) {
|
||||||
|
if (PackageUtils.isAmberInstalled(context)) {
|
||||||
|
event = accountViewModel.account.unfollow(baseUser, false)
|
||||||
|
} else {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
Toast
|
Toast
|
||||||
.makeText(
|
.makeText(
|
||||||
@@ -777,6 +780,7 @@ private fun DisplayFollowUnfollowButton(
|
|||||||
)
|
)
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
scope.launch(Dispatchers.IO) {
|
scope.launch(Dispatchers.IO) {
|
||||||
accountViewModel.account.unfollow(baseUser)
|
accountViewModel.account.unfollow(baseUser)
|
||||||
@@ -787,6 +791,9 @@ private fun DisplayFollowUnfollowButton(
|
|||||||
if (isUserFollowingLoggedIn) {
|
if (isUserFollowingLoggedIn) {
|
||||||
FollowButton(R.string.follow_back) {
|
FollowButton(R.string.follow_back) {
|
||||||
if (!accountViewModel.isWriteable()) {
|
if (!accountViewModel.isWriteable()) {
|
||||||
|
if (PackageUtils.isAmberInstalled(context)) {
|
||||||
|
event = accountViewModel.account.follow(baseUser, false)
|
||||||
|
} else {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
Toast
|
Toast
|
||||||
.makeText(
|
.makeText(
|
||||||
@@ -796,6 +803,7 @@ private fun DisplayFollowUnfollowButton(
|
|||||||
)
|
)
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
scope.launch(Dispatchers.IO) {
|
scope.launch(Dispatchers.IO) {
|
||||||
accountViewModel.account.follow(baseUser)
|
accountViewModel.account.follow(baseUser)
|
||||||
@@ -805,7 +813,7 @@ private fun DisplayFollowUnfollowButton(
|
|||||||
} else {
|
} else {
|
||||||
FollowButton(R.string.follow) {
|
FollowButton(R.string.follow) {
|
||||||
if (!accountViewModel.isWriteable()) {
|
if (!accountViewModel.isWriteable()) {
|
||||||
if (PackageUtils.isPackageInstalled(context, "com.greenart7c3.nostrsigner")) {
|
if (PackageUtils.isAmberInstalled(context)) {
|
||||||
event = accountViewModel.account.follow(baseUser, false)
|
event = accountViewModel.account.follow(baseUser, false)
|
||||||
} else {
|
} else {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ fun LoginPage(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PackageUtils.isPackageInstalled(context, "org.torproject.android")) {
|
if (PackageUtils.isOrbotInstalled(context)) {
|
||||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
Checkbox(
|
Checkbox(
|
||||||
checked = useProxy.value,
|
checked = useProxy.value,
|
||||||
|
|||||||
Reference in New Issue
Block a user