List who a profile is following if that data is available.
This commit is contained in:
@@ -1,25 +1,16 @@
|
||||
package ac.cord.auxiliary.compose.database.dao
|
||||
|
||||
import ac.cord.auxiliary.compose.database.model.Connection
|
||||
import ac.cord.auxiliary.compose.database.model.intermdiate.LocalFollowers
|
||||
import ac.cord.auxiliary.compose.database.model.intermdiate.LocalFollowing
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import androidx.room.Upsert
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface ConnectionDao {
|
||||
@Query("SELECT * FROM Connection LIMIT :limit")
|
||||
fun getAllConnections(limit: Int = 21): List<Connection>
|
||||
|
||||
@Query("SELECT * FROM Connection WHERE sourcePublicKey = :sourcePublicKey")
|
||||
fun observePublicKeyFollowing(sourcePublicKey: String): Flow<LocalFollowing?>
|
||||
|
||||
@Query("SELECT * FROM Connection WHERE destinationPublicKey = :destinationPublicKey")
|
||||
fun observePublicKeyFollowers(destinationPublicKey: String): Flow<LocalFollowers?>
|
||||
|
||||
|
||||
@Insert
|
||||
suspend fun insertPlaceholderProfile(connection: Connection)
|
||||
|
||||
@@ -9,6 +9,7 @@ import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy.Companion.IGNORE
|
||||
import androidx.room.Query
|
||||
import androidx.room.Upsert
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface ProfileDao {
|
||||
@@ -22,10 +23,10 @@ interface ProfileDao {
|
||||
fun getProfileByPublicKey(publicKey: String): Profile?
|
||||
|
||||
@Query("SELECT * FROM NostrEvent WHERE kind = 0 AND pubKey = :publicKey")
|
||||
fun observeProfileWithFollowersByPublicKey(publicKey: String): LocalProfileWithFollowers?
|
||||
fun observeProfileWithFollowersByPublicKey(publicKey: String): Flow<LocalProfileWithFollowers?>
|
||||
|
||||
@Query("SELECT * FROM NostrEvent WHERE kind = 0 AND pubKey = :publicKey")
|
||||
fun observeProfileWithFollowingByPublicKey(publicKey: String): LocalProfileWithFollowing?
|
||||
fun observeProfileWithFollowingByPublicKey(publicKey: String): Flow<LocalProfileWithFollowing?>
|
||||
|
||||
@Insert
|
||||
suspend fun insertPlaceholderProfile(profile: Profile)
|
||||
|
||||
@@ -14,8 +14,8 @@ interface SynchronizeNostrEventRequestDao {
|
||||
@Query("SELECT * FROM SynchronizeNostrEventRequest WHERE status = :status AND createdAt > :createdAt")
|
||||
fun observeSynchronizeNostrEventRequestsByStatus(status: String, createdAt: Instant = Clock.System.now()): Flow<SynchronizeNostrEventRequest?>
|
||||
|
||||
@Query("SELECT COUNT(*) FROM SynchronizeNostrEventRequest WHERE purpose = :purpose AND status IN (:status)")
|
||||
fun observeSynchronizeNostrEventRequestByPurposeAndStatusCount(purpose: String, status: List<String>): Flow<Int>
|
||||
@Query("SELECT COUNT(*) FROM SynchronizeNostrEventRequest WHERE purpose = :purpose AND status IN (:status) AND createdAt > :createdAt")
|
||||
fun observeSynchronizeNostrEventRequestByPurposeAndStatusCount(purpose: String, status: List<String>, createdAt: Instant = Clock.System.now()): Flow<Int>
|
||||
|
||||
@Upsert
|
||||
fun upsert(synchronizeNostrEventRequest: SynchronizeNostrEventRequest)
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
package ac.cord.auxiliary.compose.database.model.intermdiate
|
||||
|
||||
import ac.cord.auxiliary.compose.database.model.Profile
|
||||
import ac.cord.auxiliary.compose.database.model.Connection
|
||||
import androidx.room.Embedded
|
||||
import androidx.room.Junction
|
||||
import androidx.room.Relation
|
||||
|
||||
data class LocalFollowers(
|
||||
@Embedded val connection: Connection,
|
||||
|
||||
@Relation(
|
||||
parentColumn = "destinationPublicKey",
|
||||
entityColumn = "publicKey",
|
||||
)
|
||||
val followers: List<Profile>
|
||||
)
|
||||
@@ -1,17 +0,0 @@
|
||||
package ac.cord.auxiliary.compose.database.model.intermdiate
|
||||
|
||||
import ac.cord.auxiliary.compose.database.model.Profile
|
||||
import ac.cord.auxiliary.compose.database.model.Connection
|
||||
import androidx.room.Embedded
|
||||
import androidx.room.Junction
|
||||
import androidx.room.Relation
|
||||
|
||||
data class LocalFollowing(
|
||||
@Embedded val connection: Connection,
|
||||
|
||||
@Relation(
|
||||
parentColumn = "sourcePublicKey",
|
||||
entityColumn = "publicKey",
|
||||
)
|
||||
val following: List<Profile>
|
||||
)
|
||||
@@ -25,5 +25,5 @@ data class LocalProfileWithFollowing(
|
||||
entityColumn = "destinationPublicKey"
|
||||
)
|
||||
)
|
||||
val followers: List<Profile>
|
||||
val following: List<Profile>
|
||||
)
|
||||
|
||||
@@ -13,9 +13,9 @@ import ac.cord.auxiliary.compose.database.model.UnsignedNostrEvent
|
||||
import ac.cord.auxiliary.compose.database.model.intermdiate.LocalBroadcastNostrEventRequest
|
||||
import ac.cord.auxiliary.compose.database.model.intermdiate.LocalNostrEvent
|
||||
import ac.cord.auxiliary.compose.database.model.intermdiate.LocalAccount
|
||||
import ac.cord.auxiliary.compose.database.model.intermdiate.LocalFollowers
|
||||
import ac.cord.auxiliary.compose.database.model.intermdiate.LocalFollowing
|
||||
import ac.cord.auxiliary.compose.database.model.intermdiate.LocalProfile
|
||||
import ac.cord.auxiliary.compose.database.model.intermdiate.LocalProfileWithFollowers
|
||||
import ac.cord.auxiliary.compose.database.model.intermdiate.LocalProfileWithFollowing
|
||||
import ac.cord.auxiliary.compose.database.model.typealiases.SynchronizationFilterArray
|
||||
import ac.cord.auxiliary.compose.database.model.types.SynchronizationFilter
|
||||
import ac.cord.auxiliary.compose.nostr.Relays
|
||||
@@ -375,13 +375,15 @@ class DatabaseNostrRepository(
|
||||
return database.profileDao().filterProfiles(searchTerm = searchTerm)
|
||||
}
|
||||
|
||||
override suspend fun observeProfileFollowers(publicKey: String): Flow<LocalFollowers?> {
|
||||
return database.connectionDao().observePublicKeyFollowers(publicKey)
|
||||
|
||||
override suspend fun observeProfileWithFollowers(publicKey: String): Flow<LocalProfileWithFollowers?> {
|
||||
return database.profileDao().observeProfileWithFollowersByPublicKey(publicKey)
|
||||
}
|
||||
|
||||
override suspend fun observeProfileFollowing(publicKey: String): Flow<LocalFollowing?> {
|
||||
return database.connectionDao().observePublicKeyFollowing(publicKey)
|
||||
override suspend fun observeProfileWithFollowing(publicKey: String): Flow<LocalProfileWithFollowing?> {
|
||||
return database.profileDao().observeProfileWithFollowingByPublicKey(publicKey)
|
||||
}
|
||||
|
||||
override suspend fun getRecentSearches(): List<RecentSearch> {
|
||||
return database.recentSearchDao().getAllRecentSearches()
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ import ac.cord.auxiliary.compose.database.model.UnsignedNostrEvent
|
||||
import ac.cord.auxiliary.compose.database.model.intermdiate.LocalBroadcastNostrEventRequest
|
||||
import ac.cord.auxiliary.compose.database.model.intermdiate.LocalNostrEvent
|
||||
import ac.cord.auxiliary.compose.database.model.intermdiate.LocalAccount
|
||||
import ac.cord.auxiliary.compose.database.model.intermdiate.LocalFollowers
|
||||
import ac.cord.auxiliary.compose.database.model.intermdiate.LocalFollowing
|
||||
import ac.cord.auxiliary.compose.database.model.intermdiate.LocalProfile
|
||||
import ac.cord.auxiliary.compose.database.model.intermdiate.LocalProfileWithFollowers
|
||||
import ac.cord.auxiliary.compose.database.model.intermdiate.LocalProfileWithFollowing
|
||||
import ac.cord.auxiliary.compose.database.model.typealiases.SynchronizationFilterArray
|
||||
import ac.cord.auxiliary.compose.database.model.types.SynchronizationFilter
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
@@ -83,9 +83,9 @@ interface NostrRepository {
|
||||
|
||||
suspend fun filterProfiles(searchTerm: String): List<LocalProfile>
|
||||
|
||||
suspend fun observeProfileFollowing(publicKey: String): Flow<LocalFollowing?>
|
||||
suspend fun observeProfileWithFollowers(publicKey: String): Flow<LocalProfileWithFollowers?>
|
||||
|
||||
suspend fun observeProfileFollowers(publicKey: String): Flow<LocalFollowers?>
|
||||
suspend fun observeProfileWithFollowing(publicKey: String): Flow<LocalProfileWithFollowing?>
|
||||
|
||||
suspend fun getRecentSearches(): List<RecentSearch>
|
||||
|
||||
@@ -196,11 +196,11 @@ interface NostrRepository {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun observeProfileFollowing(publicKey: String): Flow<LocalFollowing?> {
|
||||
override suspend fun observeProfileWithFollowers(publicKey: String): Flow<LocalProfileWithFollowers?> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun observeProfileFollowers(publicKey: String): Flow<LocalFollowers?> {
|
||||
override suspend fun observeProfileWithFollowing(publicKey: String): Flow<LocalProfileWithFollowing?> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ class FollowersListViewModel(
|
||||
fun observeLocalNostrFeed() {
|
||||
logger.d("observeLocalNostrFeed")
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
nostrRepository.observeProfileFollowers(
|
||||
nostrRepository.observeProfileWithFollowers(
|
||||
publicKey
|
||||
).collect { localFollowers ->
|
||||
followersListUIState = FollowersListUIState.Loaded(
|
||||
|
||||
@@ -58,7 +58,7 @@ class FollowingListViewModel(
|
||||
fun observeLocalNostrFeed() {
|
||||
logger.d("observeLocalNostrFeed")
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
nostrRepository.observeProfileFollowing(
|
||||
nostrRepository.observeProfileWithFollowing(
|
||||
publicKey
|
||||
).collect { localFollowing ->
|
||||
followingListUIState = FollowingListUIState.Loaded(
|
||||
|
||||
Reference in New Issue
Block a user