-
Notifications
You must be signed in to change notification settings - Fork 1
/
ProfileDao.kt
59 lines (49 loc) · 2.12 KB
/
ProfileDao.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.dluvian.voyage.data.room.dao
import androidx.room.Dao
import androidx.room.Query
import com.dluvian.voyage.core.PubkeyHex
import com.dluvian.voyage.data.room.view.AdvancedProfileView
import kotlinx.coroutines.flow.Flow
@Dao
interface ProfileDao {
@Query("SELECT * FROM AdvancedProfileView WHERE pubkey = :pubkey")
fun getAdvancedProfileFlow(pubkey: PubkeyHex): Flow<AdvancedProfileView?>
@Query("SELECT * FROM AdvancedProfileView WHERE pubkey IN (:pubkeys)")
fun getAdvancedProfilesFlow(pubkeys: Collection<PubkeyHex>): Flow<List<AdvancedProfileView>>
@Query("SELECT name FROM profile WHERE pubkey = :pubkey")
suspend fun getName(pubkey: PubkeyHex): String?
@Query("SELECT createdAt FROM profile WHERE pubkey = :pubkey")
suspend fun getMaxCreatedAt(pubkey: PubkeyHex): Long?
suspend fun getProfilesByName(name: String, limit: Int): List<AdvancedProfileView> {
if (limit <= 0) return emptyList()
return internalGetProfilesWithNameLike(name = name, somewhere = "%$name%", limit = limit)
}
@Query(
"SELECT DISTINCT pubkey AS pk " +
"FROM post " +
"WHERE pk NOT IN (SELECT friendPubkey FROM friend) " +
"AND pk NOT IN (SELECT pubkey FROM account) " +
"AND pk IN (SELECT webOfTrustPubkey FROM weboftrust) " +
"GROUP BY pk " +
"ORDER BY COUNT(pk) DESC " +
"LIMIT :limit"
)
suspend fun getPopularUnfollowedPubkeys(limit: Int): List<PubkeyHex>
@Query(
"SELECT DISTINCT pubkey " +
"FROM profile " +
"WHERE pubkey IN (:pubkeys)"
)
suspend fun filterKnownProfiles(pubkeys: Collection<PubkeyHex>): List<PubkeyHex>
@Query(
"SELECT * FROM AdvancedProfileView WHERE name = :name AND name != ''" +
"UNION " +
"SELECT * FROM AdvancedProfileView WHERE name LIKE :somewhere AND name != ''" +
"LIMIT :limit"
)
suspend fun internalGetProfilesWithNameLike(
name: String,
somewhere: String,
limit: Int
): List<AdvancedProfileView>
}