mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-22 18:02:05 +02:00
Storing and Counting followers of the main account.
This commit is contained in:
@@ -18,7 +18,7 @@ class User(val pubkey: ByteArray) {
|
|||||||
val follows = Collections.synchronizedSet(mutableSetOf<User>())
|
val follows = Collections.synchronizedSet(mutableSetOf<User>())
|
||||||
val taggedPosts = Collections.synchronizedSet(mutableSetOf<Note>())
|
val taggedPosts = Collections.synchronizedSet(mutableSetOf<Note>())
|
||||||
|
|
||||||
var follower: Number? = null
|
val followers = Collections.synchronizedSet(mutableSetOf<User>())
|
||||||
|
|
||||||
fun toBestDisplayName(): String {
|
fun toBestDisplayName(): String {
|
||||||
return bestDisplayName() ?: bestUsername() ?: pubkeyDisplayHex
|
return bestDisplayName() ?: bestUsername() ?: pubkeyDisplayHex
|
||||||
@@ -37,9 +37,26 @@ class User(val pubkey: ByteArray) {
|
|||||||
return info.picture ?: "https://robohash.org/${pubkeyHex}.png"
|
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) {
|
fun updateFollows(newFollows: List<User>, updateAt: Long) {
|
||||||
follows.clear()
|
val toBeAdded = newFollows - follows
|
||||||
follows.addAll(newFollows)
|
val toBeRemoved = follows - newFollows
|
||||||
|
|
||||||
|
toBeAdded.forEach {
|
||||||
|
follow(it)
|
||||||
|
}
|
||||||
|
toBeRemoved.forEach {
|
||||||
|
unfollow(it)
|
||||||
|
}
|
||||||
|
|
||||||
updatedFollowsAt = updateAt
|
updatedFollowsAt = updateAt
|
||||||
|
|
||||||
live.refresh()
|
live.refresh()
|
||||||
|
@@ -2,8 +2,11 @@ package com.vitorpamplona.amethyst.service
|
|||||||
|
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
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 java.util.Collections
|
||||||
import nostr.postr.JsonFilter
|
import nostr.postr.JsonFilter
|
||||||
|
import nostr.postr.events.TextNoteEvent
|
||||||
|
|
||||||
object NostrSingleEventDataSource: NostrDataSource("SingleEventFeed") {
|
object NostrSingleEventDataSource: NostrDataSource("SingleEventFeed") {
|
||||||
val eventsToWatch = Collections.synchronizedList(mutableListOf<String>())
|
val eventsToWatch = Collections.synchronizedList(mutableListOf<String>())
|
||||||
@@ -15,7 +18,9 @@ object NostrSingleEventDataSource: NostrDataSource("SingleEventFeed") {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// downloads all the reactions to a given event.
|
||||||
return JsonFilter(
|
return JsonFilter(
|
||||||
|
kinds = listOf(TextNoteEvent.kind, ReactionEvent.kind, RepostEvent.kind),
|
||||||
tags = mapOf("e" to reactionsToWatch)
|
tags = mapOf("e" to reactionsToWatch)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -39,6 +44,7 @@ object NostrSingleEventDataSource: NostrDataSource("SingleEventFeed") {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// downloads linked events to this event.
|
||||||
return JsonFilter(
|
return JsonFilter(
|
||||||
ids = interestedEvents
|
ids = interestedEvents
|
||||||
)
|
)
|
||||||
|
@@ -118,11 +118,11 @@ fun ProfileContent(accountUser: User?, modifier: Modifier = Modifier) {
|
|||||||
Text(" @${accountUser?.bestUsername()}", color = Color.LightGray)
|
Text(" @${accountUser?.bestUsername()}", color = Color.LightGray)
|
||||||
Row(modifier = Modifier.padding(top = 15.dp)) {
|
Row(modifier = Modifier.padding(top = 15.dp)) {
|
||||||
Row() {
|
Row() {
|
||||||
Text("${accountUser?.follows?.size}", fontWeight = FontWeight.Bold)
|
Text("${accountUser?.follows?.size ?: "--"}", fontWeight = FontWeight.Bold)
|
||||||
Text(" Following")
|
Text(" Following")
|
||||||
}
|
}
|
||||||
Row(modifier = Modifier.padding(start = 10.dp)) {
|
Row(modifier = Modifier.padding(start = 10.dp)) {
|
||||||
Text("${accountUser?.follower ?: "--"}", fontWeight = FontWeight.Bold)
|
Text("${accountUser?.followers?.size ?: "--"}", fontWeight = FontWeight.Bold)
|
||||||
Text(" Followers")
|
Text(" Followers")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user