kopia lustrzana https://github.com/vitorpamplona/amethyst
Uses cached functions for isFollowing calculations
rodzic
625b8c3bce
commit
97d9e96e2b
|
@ -236,7 +236,13 @@ class User(val pubkeyHex: String) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isFollowing(user: User): Boolean {
|
fun isFollowing(user: User): Boolean {
|
||||||
return (latestContactList)?.unverifiedFollowKeySet()?.toSet()?.let {
|
return latestContactList?.unverifiedFollowKeySet()?.toSet()?.let {
|
||||||
|
return user.pubkeyHex in it
|
||||||
|
} ?: false
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isFollowingCached(user: User): Boolean {
|
||||||
|
return latestContactList?.verifiedFollowKeySet?.let {
|
||||||
return user.pubkeyHex in it
|
return user.pubkeyHex in it
|
||||||
} ?: false
|
} ?: false
|
||||||
}
|
}
|
||||||
|
|
|
@ -277,7 +277,7 @@ fun ChatroomMessageCompose(
|
||||||
val eventContent = accountViewModel.decrypt(note)
|
val eventContent = accountViewModel.decrypt(note)
|
||||||
|
|
||||||
val canPreview = note.author == accountUser ||
|
val canPreview = note.author == accountUser ||
|
||||||
(note.author?.let { accountUser.isFollowing(it) } ?: true) ||
|
(note.author?.let { accountUser.isFollowingCached(it) } ?: true) ||
|
||||||
!noteForReports.hasAnyReports()
|
!noteForReports.hasAnyReports()
|
||||||
|
|
||||||
if (eventContent != null) {
|
if (eventContent != null) {
|
||||||
|
|
|
@ -299,7 +299,7 @@ fun NoteCompose(
|
||||||
val sortedMentions = noteEvent.mentions()
|
val sortedMentions = noteEvent.mentions()
|
||||||
.map { LocalCache.getOrCreateUser(it) }
|
.map { LocalCache.getOrCreateUser(it) }
|
||||||
.toSet()
|
.toSet()
|
||||||
.sortedBy { account.userProfile().isFollowing(it) }
|
.sortedBy { account.userProfile().isFollowingCached(it) }
|
||||||
|
|
||||||
val replyingDirectlyTo = note.replyTo?.lastOrNull()
|
val replyingDirectlyTo = note.replyTo?.lastOrNull()
|
||||||
if (replyingDirectlyTo != null && unPackReply) {
|
if (replyingDirectlyTo != null && unPackReply) {
|
||||||
|
@ -328,7 +328,7 @@ fun NoteCompose(
|
||||||
val sortedMentions = noteEvent.mentions()
|
val sortedMentions = noteEvent.mentions()
|
||||||
.map { LocalCache.getOrCreateUser(it) }
|
.map { LocalCache.getOrCreateUser(it) }
|
||||||
.toSet()
|
.toSet()
|
||||||
.sortedBy { account.userProfile().isFollowing(it) }
|
.sortedBy { account.userProfile().isFollowingCached(it) }
|
||||||
|
|
||||||
note.channel()?.let {
|
note.channel()?.let {
|
||||||
ReplyInformationChannel(note.replyTo, sortedMentions, it, navController)
|
ReplyInformationChannel(note.replyTo, sortedMentions, it, navController)
|
||||||
|
@ -453,7 +453,7 @@ fun NoteCompose(
|
||||||
val eventContent = accountViewModel.decrypt(note)
|
val eventContent = accountViewModel.decrypt(note)
|
||||||
|
|
||||||
val canPreview = note.author == account.userProfile() ||
|
val canPreview = note.author == account.userProfile() ||
|
||||||
(note.author?.let { account.userProfile().isFollowing(it) } ?: true) ||
|
(note.author?.let { account.userProfile().isFollowingCached(it) } ?: true) ||
|
||||||
!noteForReports.hasAnyReports()
|
!noteForReports.hasAnyReports()
|
||||||
|
|
||||||
if (eventContent != null) {
|
if (eventContent != null) {
|
||||||
|
@ -747,7 +747,7 @@ fun UserPicture(
|
||||||
val accountState by baseUserAccount.live().follows.observeAsState()
|
val accountState by baseUserAccount.live().follows.observeAsState()
|
||||||
val accountUser = accountState?.user ?: return
|
val accountUser = accountState?.user ?: return
|
||||||
|
|
||||||
if (accountUser.isFollowing(user) || user == accountUser) {
|
if (accountUser.isFollowingCached(user) || user == accountUser) {
|
||||||
Box(
|
Box(
|
||||||
Modifier
|
Modifier
|
||||||
.width(size.div(3.5f))
|
.width(size.div(3.5f))
|
||||||
|
@ -786,7 +786,7 @@ fun NoteDropDownMenu(note: Note, popupExpanded: Boolean, onDismiss: () -> Unit,
|
||||||
expanded = popupExpanded,
|
expanded = popupExpanded,
|
||||||
onDismissRequest = onDismiss
|
onDismissRequest = onDismiss
|
||||||
) {
|
) {
|
||||||
if (note.author != accountViewModel.accountLiveData.value?.account?.userProfile() && !accountViewModel.accountLiveData.value?.account?.userProfile()!!.isFollowing(note.author!!)) {
|
if (!accountViewModel.isFollowing(note.author!!)) {
|
||||||
DropdownMenuItem(onClick = {
|
DropdownMenuItem(onClick = {
|
||||||
accountViewModel.follow(
|
accountViewModel.follow(
|
||||||
note.author ?: return@DropdownMenuItem
|
note.author ?: return@DropdownMenuItem
|
||||||
|
|
|
@ -30,7 +30,7 @@ fun ReplyInformation(replyTo: List<Note>?, mentions: List<User>?, account: Accou
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ReplyInformation(replyTo: List<Note>?, dupMentions: List<User>?, account: Account, prefix: String = "", onUserTagClick: (User) -> Unit) {
|
fun ReplyInformation(replyTo: List<Note>?, dupMentions: List<User>?, account: Account, prefix: String = "", onUserTagClick: (User) -> Unit) {
|
||||||
val mentions = dupMentions?.toSet()?.sortedBy { !account.userProfile().isFollowing(it) }
|
val mentions = dupMentions?.toSet()?.sortedBy { !account.userProfile().isFollowingCached(it) }
|
||||||
var expanded by remember { mutableStateOf((mentions?.size ?: 0) <= 2) }
|
var expanded by remember { mutableStateOf((mentions?.size ?: 0) <= 2) }
|
||||||
|
|
||||||
FlowRow() {
|
FlowRow() {
|
||||||
|
|
|
@ -72,7 +72,7 @@ fun UserCompose(baseUser: User, accountViewModel: AccountViewModel, navControlle
|
||||||
ShowUserButton {
|
ShowUserButton {
|
||||||
account.showUser(baseUser.pubkeyHex)
|
account.showUser(baseUser.pubkeyHex)
|
||||||
}
|
}
|
||||||
} else if (userFollows.isFollowing(baseUser)) {
|
} else if (userFollows.isFollowingCached(baseUser)) {
|
||||||
UnfollowButton { coroutineScope.launch(Dispatchers.IO) { account.unfollow(baseUser) } }
|
UnfollowButton { coroutineScope.launch(Dispatchers.IO) { account.unfollow(baseUser) } }
|
||||||
} else {
|
} else {
|
||||||
FollowButton { coroutineScope.launch(Dispatchers.IO) { account.follow(baseUser) } }
|
FollowButton { coroutineScope.launch(Dispatchers.IO) { account.follow(baseUser) } }
|
||||||
|
|
|
@ -117,7 +117,7 @@ fun ZapNoteCompose(baseNote: Pair<Note, Note>, accountViewModel: AccountViewMode
|
||||||
ShowUserButton {
|
ShowUserButton {
|
||||||
account.showUser(baseAuthor.pubkeyHex)
|
account.showUser(baseAuthor.pubkeyHex)
|
||||||
}
|
}
|
||||||
} else if (userFollows.isFollowing(baseAuthor)) {
|
} else if (userFollows.isFollowingCached(baseAuthor)) {
|
||||||
UnfollowButton { coroutineScope.launch(Dispatchers.IO) { account.unfollow(baseAuthor) } }
|
UnfollowButton { coroutineScope.launch(Dispatchers.IO) { account.unfollow(baseAuthor) } }
|
||||||
} else {
|
} else {
|
||||||
FollowButton { coroutineScope.launch(Dispatchers.IO) { account.follow(baseAuthor) } }
|
FollowButton { coroutineScope.launch(Dispatchers.IO) { account.follow(baseAuthor) } }
|
||||||
|
|
|
@ -328,7 +328,7 @@ fun NoteMaster(
|
||||||
val eventContent = note.event?.content()
|
val eventContent = note.event?.content()
|
||||||
|
|
||||||
val canPreview = note.author == account.userProfile() ||
|
val canPreview = note.author == account.userProfile() ||
|
||||||
(note.author?.let { account.userProfile().isFollowing(it) } ?: true) ||
|
(note.author?.let { account.userProfile().isFollowingCached(it) } ?: true) ||
|
||||||
!noteForReports.hasAnyReports()
|
!noteForReports.hasAnyReports()
|
||||||
|
|
||||||
if (eventContent != null) {
|
if (eventContent != null) {
|
||||||
|
|
|
@ -125,8 +125,12 @@ class AccountViewModel(private val account: Account) : ViewModel() {
|
||||||
account.unfollow(user)
|
account.unfollow(user)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isLoggedUser(user: User): Boolean {
|
||||||
|
return account.userProfile() == user
|
||||||
|
}
|
||||||
|
|
||||||
fun isFollowing(user: User): Boolean {
|
fun isFollowing(user: User): Boolean {
|
||||||
return account.userProfile().isFollowing(user)
|
return account.userProfile().isFollowingCached(user)
|
||||||
}
|
}
|
||||||
|
|
||||||
val hideDeleteRequestDialog: Boolean
|
val hideDeleteRequestDialog: Boolean
|
||||||
|
|
|
@ -373,7 +373,7 @@ private fun ProfileHeader(
|
||||||
ShowUserButton {
|
ShowUserButton {
|
||||||
account.showUser(baseUser.pubkeyHex)
|
account.showUser(baseUser.pubkeyHex)
|
||||||
}
|
}
|
||||||
} else if (accountUser.isFollowing(baseUser)) {
|
} else if (accountUser.isFollowingCached(baseUser)) {
|
||||||
UnfollowButton { coroutineScope.launch(Dispatchers.IO) { account.unfollow(baseUser) } }
|
UnfollowButton { coroutineScope.launch(Dispatchers.IO) { account.unfollow(baseUser) } }
|
||||||
} else {
|
} else {
|
||||||
FollowButton { coroutineScope.launch(Dispatchers.IO) { account.follow(baseUser) } }
|
FollowButton { coroutineScope.launch(Dispatchers.IO) { account.follow(baseUser) } }
|
||||||
|
|
Ładowanie…
Reference in New Issue