Storing and Counting followers of the main account.

pull/3/head
Vitor Pamplona 2023-01-14 10:16:36 -05:00
rodzic d130a43358
commit f580fdd216
3 zmienionych plików z 28 dodań i 5 usunięć

Wyświetl plik

@ -18,7 +18,7 @@ class User(val pubkey: ByteArray) {
val follows = Collections.synchronizedSet(mutableSetOf<User>())
val taggedPosts = Collections.synchronizedSet(mutableSetOf<Note>())
var follower: Number? = null
val followers = Collections.synchronizedSet(mutableSetOf<User>())
fun toBestDisplayName(): String {
return bestDisplayName() ?: bestUsername() ?: pubkeyDisplayHex
@ -37,9 +37,26 @@ class User(val pubkey: ByteArray) {
return info.picture ?: "https://robohash.org/${pubkeyHex}.png"
}
fun follow(user: User) {
follows.add(user)
user.followers.add(this)
}
fun unfollow(user: User) {
follows.remove(user)
user.followers.remove(this)
}
fun updateFollows(newFollows: List<User>, updateAt: Long) {
follows.clear()
follows.addAll(newFollows)
val toBeAdded = newFollows - follows
val toBeRemoved = follows - newFollows
toBeAdded.forEach {
follow(it)
}
toBeRemoved.forEach {
unfollow(it)
}
updatedFollowsAt = updateAt
live.refresh()

Wyświetl plik

@ -2,8 +2,11 @@ package com.vitorpamplona.amethyst.service
import com.vitorpamplona.amethyst.model.LocalCache
import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.service.model.ReactionEvent
import com.vitorpamplona.amethyst.service.model.RepostEvent
import java.util.Collections
import nostr.postr.JsonFilter
import nostr.postr.events.TextNoteEvent
object NostrSingleEventDataSource: NostrDataSource("SingleEventFeed") {
val eventsToWatch = Collections.synchronizedList(mutableListOf<String>())
@ -15,7 +18,9 @@ object NostrSingleEventDataSource: NostrDataSource("SingleEventFeed") {
return null
}
// downloads all the reactions to a given event.
return JsonFilter(
kinds = listOf(TextNoteEvent.kind, ReactionEvent.kind, RepostEvent.kind),
tags = mapOf("e" to reactionsToWatch)
)
}
@ -39,6 +44,7 @@ object NostrSingleEventDataSource: NostrDataSource("SingleEventFeed") {
return null
}
// downloads linked events to this event.
return JsonFilter(
ids = interestedEvents
)

Wyświetl plik

@ -118,11 +118,11 @@ fun ProfileContent(accountUser: User?, modifier: Modifier = Modifier) {
Text(" @${accountUser?.bestUsername()}", color = Color.LightGray)
Row(modifier = Modifier.padding(top = 15.dp)) {
Row() {
Text("${accountUser?.follows?.size}", fontWeight = FontWeight.Bold)
Text("${accountUser?.follows?.size ?: "--"}", fontWeight = FontWeight.Bold)
Text(" Following")
}
Row(modifier = Modifier.padding(start = 10.dp)) {
Text("${accountUser?.follower ?: "--"}", fontWeight = FontWeight.Bold)
Text("${accountUser?.followers?.size ?: "--"}", fontWeight = FontWeight.Bold)
Text(" Followers")
}
}