-
Notifications
You must be signed in to change notification settings - Fork 1
/
PostEntity.kt
82 lines (77 loc) · 2.75 KB
/
PostEntity.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.dluvian.voyage.data.room.entity
import androidx.room.Entity
import androidx.room.Index
import com.dluvian.nostr_kt.RelayUrl
import com.dluvian.voyage.core.EventIdHex
import com.dluvian.voyage.core.PubkeyHex
import com.dluvian.voyage.data.event.ValidatedCrossPost
import com.dluvian.voyage.data.event.ValidatedPost
import com.dluvian.voyage.data.event.ValidatedReply
import com.dluvian.voyage.data.event.ValidatedRootPost
@Entity(
tableName = "post",
primaryKeys = ["id"],
indices = [
Index(value = ["parentId"], unique = false),
Index(value = ["createdAt"], unique = false),
Index(value = ["pubkey"], unique = false),
],
)
data class PostEntity(
val id: EventIdHex,
val pubkey: PubkeyHex,
val parentId: EventIdHex?,
val subject: String?,
val content: String,
val createdAt: Long,
val relayUrl: RelayUrl,
val crossPostedId: EventIdHex?,
val crossPostedPubkey: PubkeyHex?,
val json: String?
) {
companion object {
fun from(post: ValidatedPost): PostEntity {
return when (post) {
is ValidatedRootPost -> PostEntity(
id = post.id,
pubkey = post.pubkey,
parentId = null,
subject = post.subject,
content = post.content,
createdAt = post.createdAt,
relayUrl = post.relayUrl,
crossPostedId = null,
crossPostedPubkey = null,
json = post.json
)
is ValidatedReply -> PostEntity(
id = post.id,
pubkey = post.pubkey,
parentId = post.parentId,
subject = null,
content = post.content,
createdAt = post.createdAt,
relayUrl = post.relayUrl,
crossPostedId = null,
crossPostedPubkey = null,
json = post.json
)
is ValidatedCrossPost -> PostEntity(
id = post.id,
pubkey = post.pubkey,
parentId = null,
subject = post.crossPosted.subject,
content = when (post.crossPosted) {
is ValidatedRootPost -> post.crossPosted.content
is ValidatedReply -> post.crossPosted.content
},
createdAt = post.createdAt,
relayUrl = post.relayUrl,
crossPostedId = post.crossPosted.id,
crossPostedPubkey = post.crossPosted.pubkey,
json = null
)
}
}
}
}