Skip to content

Commit ee8a57e

Browse files
committed
chore(fc): add message content modeling for reactions and replies
Signed-off-by: Brandon McAnsh <[email protected]>
1 parent a564b54 commit ee8a57e

File tree

7 files changed

+95
-90
lines changed

7 files changed

+95
-90
lines changed

libs/models/src/main/kotlin/com/getcode/model/chat/MessageContent.kt

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.getcode.model.chat
22

33
import com.getcode.model.EncryptedData
44
import com.getcode.model.GenericAmount
5+
import com.getcode.model.ID
56
import com.getcode.utils.base64
67
import kotlinx.serialization.Serializable
78
import kotlinx.serialization.encodeToString
@@ -209,6 +210,74 @@ sealed interface MessageContent {
209210
override val content: String = data
210211
}
211212

213+
@Serializable
214+
data class Reaction(
215+
val emoji: String,
216+
val originalMessageId: ID,
217+
override val isFromSelf: Boolean,
218+
) : MessageContent {
219+
override val kind: Int = 7
220+
221+
override fun hashCode(): Int {
222+
var result = emoji.hashCode()
223+
result += originalMessageId.hashCode()
224+
result += isFromSelf.hashCode()
225+
result += kind.hashCode()
226+
227+
return result
228+
}
229+
230+
override fun equals(other: Any?): Boolean {
231+
if (this === other) return true
232+
if (javaClass != other?.javaClass) return false
233+
234+
other as Reaction
235+
236+
if (emoji != other.emoji) return false
237+
if (originalMessageId != other.originalMessageId) return false
238+
if (isFromSelf != other.isFromSelf) return false
239+
if (kind != other.kind) return false
240+
241+
return true
242+
}
243+
244+
override val content: String = emoji
245+
}
246+
247+
@Serializable
248+
data class Reply(
249+
val text: String,
250+
val originalMessageId: ID,
251+
override val isFromSelf: Boolean,
252+
) : MessageContent {
253+
override val kind: Int = 8
254+
255+
override fun hashCode(): Int {
256+
var result = text.hashCode()
257+
result += originalMessageId.hashCode()
258+
result += isFromSelf.hashCode()
259+
result += kind.hashCode()
260+
261+
return result
262+
}
263+
264+
override fun equals(other: Any?): Boolean {
265+
if (this === other) return true
266+
if (javaClass != other?.javaClass) return false
267+
268+
other as Reaction
269+
270+
if (text != other.emoji) return false
271+
if (originalMessageId != other.originalMessageId) return false
272+
if (isFromSelf != other.isFromSelf) return false
273+
if (kind != other.kind) return false
274+
275+
return true
276+
}
277+
278+
override val content: String = text
279+
}
280+
212281
companion object {
213282
fun fromData(type: Int, content: String, isFromSelf: Boolean): MessageContent {
214283
return when (type) {
@@ -218,6 +287,8 @@ sealed interface MessageContent {
218287
3 -> Json.decodeFromString(content)
219288
4 -> Announcement(content, isFromSelf)
220289
6 -> Decrypted(content, isFromSelf)
290+
7 -> Json.decodeFromString(content)
291+
8 -> Json.decodeFromString(content)
221292
else -> throw IllegalArgumentException()
222293
}
223294
}

services/code/src/main/java/com/getcode/model/extensions/ChatMessage.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ fun ChatMessage.decryptingUsing(keyPair: Ed25519.KeyPair): ChatMessage {
2626
}
2727
}
2828

29-
29+
is MessageContent.Reaction -> it
30+
is MessageContent.Reply -> it
3031
}
3132
}
3233
)

services/flipchat/chat/src/main/kotlin/xyz/flipchat/services/internal/db/ConversationMessageDao.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ interface ConversationMessageDao {
3737
3838
LEFT JOIN members ON messages.senderIdBase58 = members.memberIdBase58
3939
AND messages.conversationIdBase58 = members.conversationIdBase58
40-
WHERE messages.conversationIdBase58 = :id
40+
WHERE messages.conversationIdBase58 = :id AND type IN (1, 4)
4141
ORDER BY messages.dateMillis DESC
4242
LIMIT :limit OFFSET :offset
4343
""")

services/flipchat/chat/src/main/kotlin/xyz/flipchat/services/internal/protomapping/MessageContent.kt

Lines changed: 12 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -15,63 +15,23 @@ operator fun MessageContent.Companion.invoke(
1515
value = proto.localizedAnnouncement.keyOrText
1616
)
1717

18-
// Model.Content.TypeCase.EXCHANGE_DATA -> {
19-
// val verb = com.getcode.model.chat.Verb(proto.exchangeData.verb)
20-
// when (proto.exchangeData.exchangeDataCase) {
21-
// ChatService.ExchangeDataContent.ExchangeDataCase.EXACT -> {
22-
// val exact = proto.exchangeData.exact
23-
// val currency =
24-
// com.getcode.model.CurrencyCode.tryValueOf(exact.currency) ?: return null
25-
// val kinAmount = KinAmount.newInstance(
26-
// kin = Kin.fromQuarks(exact.quarks),
27-
// rate = Rate(
28-
// fx = exact.exchangeRate,
29-
// currency = currency
30-
// )
31-
// )
32-
//
33-
//
34-
// val reference = com.getcode.model.chat.Reference(proto.exchangeData)
35-
// MessageContent.Exchange(
36-
// isFromSelf = isFromSelf,
37-
// amount = GenericAmount.Exact(kinAmount),
38-
// verb = verb,
39-
// reference = reference,
40-
// hasInteracted = false,
41-
// )
42-
// }
43-
//
44-
// ChatService.ExchangeDataContent.ExchangeDataCase.PARTIAL -> {
45-
// val partial = proto.exchangeData.partial
46-
// val currency =
47-
// com.getcode.model.CurrencyCode.tryValueOf(partial.currency) ?: return null
48-
//
49-
// val fiat = Fiat(
50-
// currency = currency,
51-
// amount = partial.nativeAmount
52-
// )
53-
//
54-
// val reference = com.getcode.model.chat.Reference(proto.exchangeData)
55-
//
56-
// MessageContent.Exchange(
57-
// isFromSelf = isFromSelf,
58-
// amount = GenericAmount.Partial(fiat),
59-
// verb = verb,
60-
// reference = reference,
61-
// hasInteracted = false
62-
// )
63-
// }
64-
//
65-
// ChatService.ExchangeDataContent.ExchangeDataCase.EXCHANGEDATA_NOT_SET -> return null
66-
// else -> return null
67-
// }
68-
// }
69-
7018
Model.Content.TypeCase.TEXT -> MessageContent.RawText(
7119
isFromSelf = isFromSelf,
7220
value = proto.text.text
7321
)
7422

23+
Model.Content.TypeCase.REACTION -> MessageContent.Reaction(
24+
emoji = proto.reaction.emoji,
25+
originalMessageId = proto.reaction.originalMessageId.value.toList(),
26+
isFromSelf = isFromSelf
27+
)
28+
29+
Model.Content.TypeCase.REPLY -> MessageContent.Reply(
30+
text = proto.reply.replyText,
31+
originalMessageId = proto.reply.originalMessageId.value.toList(),
32+
isFromSelf = isFromSelf
33+
)
34+
7535
Model.Content.TypeCase.TYPE_NOT_SET -> return null
7636
else -> return null
7737
}

services/flipchat/payments/src/main/kotlin/com/getcode/model/extensions/ChatMessage.kt

Lines changed: 0 additions & 33 deletions
This file was deleted.

ui/components/src/main/kotlin/com/getcode/ui/components/chat/MessageNode.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import androidx.compose.animation.core.exponentialDecay
55
import androidx.compose.animation.core.tween
66
import androidx.compose.animation.fadeIn
77
import androidx.compose.animation.fadeOut
8-
import androidx.compose.animation.rememberSplineBasedDecay
98
import androidx.compose.animation.scaleIn
109
import androidx.compose.animation.scaleOut
1110
import androidx.compose.foundation.ExperimentalFoundationApi
@@ -15,7 +14,6 @@ import androidx.compose.foundation.gestures.AnchoredDraggableState
1514
import androidx.compose.foundation.gestures.DraggableAnchors
1615
import androidx.compose.foundation.gestures.Orientation
1716
import androidx.compose.foundation.gestures.anchoredDraggable
18-
import androidx.compose.foundation.gestures.animateTo
1917
import androidx.compose.foundation.gestures.snapTo
2018
import androidx.compose.foundation.layout.Arrangement
2119
import androidx.compose.foundation.layout.Box
@@ -46,7 +44,6 @@ import androidx.compose.runtime.setValue
4644
import androidx.compose.ui.Alignment
4745
import androidx.compose.ui.Modifier
4846
import androidx.compose.ui.draw.clip
49-
import androidx.compose.ui.geometry.Offset
5047
import androidx.compose.ui.graphics.Color
5148
import androidx.compose.ui.graphics.ColorFilter
5249
import androidx.compose.ui.graphics.CompositingStrategy
@@ -394,6 +391,9 @@ fun MessageNode(
394391
text = contents.localizedText
395392
)
396393
}
394+
395+
is MessageContent.Reaction -> Unit
396+
is MessageContent.Reply -> Unit
397397
}
398398
}
399399
}

ui/components/src/main/kotlin/com/getcode/ui/components/chat/utils/LocalizedText.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ fun MessageContent.localizedText(
109109

110110
resources.getString(resId, "some username")
111111
}
112+
113+
is MessageContent.Reaction -> content.emoji
114+
is MessageContent.Reply -> content.text
112115
}
113116
}
114117

@@ -187,6 +190,9 @@ val MessageContent.localizedText: String
187190
is MessageContent.RawText -> content.value
188191
is MessageContent.Announcement -> { content.value
189192
}
193+
194+
is MessageContent.Reaction -> content.emoji
195+
is MessageContent.Reply -> content.text
190196
}
191197
}
192198

0 commit comments

Comments
 (0)