Skip to content

Commit

Permalink
Merge pull request #369 from apeun-gidaechi/feature/368-chatting-emoji
Browse files Browse the repository at this point in the history
Feature/Chatting Emoji
  • Loading branch information
8954sood authored Nov 26, 2024
2 parents 819ab2d + ca609d1 commit 845a0af
Show file tree
Hide file tree
Showing 19 changed files with 1,155 additions and 334 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ interface MessageRepository {
suspend fun collectStompLifecycle(): Flow<Result<MessageStompLifecycleModel>>

suspend fun sendText(text: String): Flow<Result<String>>

suspend fun putEmoji(messageId: String, roomId: String, emojiId: Int): Flow<Result<Boolean>>

suspend fun deleteEmoji(messageId: String, roomId: String, emojiId: Int): Flow<Result<Boolean>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ internal fun MessageRoomEventResponse.MessageParent.Message.toModel(userId: Long
"IMG" -> {
val text = message.split("::")
MessageRoomEvent.MessageParent.Img(
id = id,
chatRoomId = chatRoomId,
url = text[0],
fileName = text[1],
timestamp = timestamp,
Expand All @@ -282,11 +284,14 @@ internal fun MessageRoomEventResponse.MessageParent.Message.toModel(userId: Long
uuid = uuid,
isFirst = false,
isLast = false,
emojiList = emojiList.map { it.toModel() }.toImmutableList(),
)
}
"FILE" -> {
val text = message.split("::")
MessageRoomEvent.MessageParent.File(
id = id,
chatRoomId = chatRoomId,
url = text[0],
fileName = text[1],
fileSize = text[2].toLong(),
Expand All @@ -296,6 +301,7 @@ internal fun MessageRoomEventResponse.MessageParent.Message.toModel(userId: Long
uuid = uuid,
isFirst = false,
isLast = false,
emojiList = emojiList.map { it.toModel() }.toImmutableList(),
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,47 @@
package com.seugi.data.message.model

import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList

data class MessageEmojiModel(
val emojiId: Int,
val userId: ImmutableList<Int>,
val userId: ImmutableList<Long>,
)

fun List<MessageEmojiModel>.addEmoji(userId: Long, emojiId: Int): List<MessageEmojiModel> {
val emojiItems = this.toMutableList()
emojiItems.forEachIndexed { index, messageEmojiModel ->
if (messageEmojiModel.emojiId != emojiId) return@forEachIndexed
emojiItems[index] = messageEmojiModel.copy(
userId = messageEmojiModel.userId.toMutableList().apply {
add(userId)
}.toSet().toImmutableList(),
)
return emojiItems
}
emojiItems.add(
MessageEmojiModel(
emojiId = emojiId,
userId = persistentListOf(userId),
),
)
return emojiItems
}

fun List<MessageEmojiModel>.minusEmoji(userId: Long, emojiId: Int): List<MessageEmojiModel> {
val emojiItems = this.toMutableList()

emojiItems.forEachIndexed { index, messageEmojiModel ->
if (messageEmojiModel.emojiId != emojiId) return@forEachIndexed

val userIds = messageEmojiModel.userId.minus(userId)
if (userIds.isEmpty()) {
emojiItems.removeAt(index)
return emojiItems
}
emojiItems[index] = messageEmojiModel.copy(userId = userIds.toImmutableList())
return emojiItems
}
return emojiItems
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import com.seugi.data.core.model.MealModel
import com.seugi.data.core.model.NotificationModel
import com.seugi.data.core.model.TimetableModel
import com.seugi.data.core.model.UserInfoModel
import com.seugi.data.message.model.MessageRoomEvent.MessageParent
import java.time.LocalDateTime
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList

sealed class MessageRoomEvent(
@Transient open val type: MessageType,
Expand Down Expand Up @@ -192,10 +194,13 @@ sealed class MessageRoomEvent(
}

data class File(
val id: String,
val chatRoomId: String,
val url: String,
val fileName: String,
val fileSize: Long,
val uuid: String?,
val emojiList: ImmutableList<MessageEmojiModel>,
override val timestamp: LocalDateTime,
override val type: MessageType,
override val userId: Long,
Expand All @@ -204,9 +209,12 @@ sealed class MessageRoomEvent(
) : MessageParent(timestamp, type, userId)

data class Img(
val id: String,
val chatRoomId: String,
val url: String,
val fileName: String,
val uuid: String?,
val emojiList: ImmutableList<MessageEmojiModel>,
override val timestamp: LocalDateTime,
override val type: MessageType,
override val userId: Long,
Expand Down Expand Up @@ -264,14 +272,14 @@ sealed class MessageRoomEvent(
override val type: MessageType,
override val userId: Long,
val messageId: String,
val emojiId: Long,
val emojiId: Int,
) : MessageRoomEvent(type, userId)

data class RemoveEmoji(
override val type: MessageType,
override val userId: Long,
val messageId: String,
val emojiId: Long,
val emojiId: Int,
) : MessageRoomEvent(type, userId)

data class TransperAdmin(
Expand Down Expand Up @@ -503,3 +511,103 @@ fun MessageRoomEvent.MessageParent.BOT.TeamBuild.getVisibleMessage(members: List
}
return visibleMessage
}

fun MessageRoomEvent.MessageParent.addEmoji(userId: Long, emojiId: Int): MessageRoomEvent.MessageParent = when (this) {
is MessageRoomEvent.MessageParent.BOT.DrawLots -> this.copy(
emojiList = this.emojiList.addEmoji(userId, emojiId = emojiId).toImmutableList(),
)

is MessageRoomEvent.MessageParent.BOT.Etc -> this.copy(
emojiList = this.emojiList.addEmoji(userId, emojiId = emojiId).toImmutableList(),
)

is MessageRoomEvent.MessageParent.BOT.Meal -> this.copy(
emojiList = this.emojiList.addEmoji(userId, emojiId = emojiId).toImmutableList(),
)

is MessageRoomEvent.MessageParent.BOT.NotSupport -> this.copy(
emojiList = this.emojiList.addEmoji(userId, emojiId = emojiId).toImmutableList(),
)

is MessageRoomEvent.MessageParent.BOT.Notification -> this.copy(
emojiList = this.emojiList.addEmoji(userId, emojiId = emojiId).toImmutableList(),
)

is MessageRoomEvent.MessageParent.BOT.TeamBuild -> this.copy(
emojiList = this.emojiList.addEmoji(userId, emojiId = emojiId).toImmutableList(),
)

is MessageRoomEvent.MessageParent.BOT.Timetable -> this.copy(
emojiList = this.emojiList.addEmoji(userId, emojiId = emojiId).toImmutableList(),
)

is MessageRoomEvent.MessageParent.File -> this.copy(
emojiList = this.emojiList.addEmoji(userId, emojiId = emojiId).toImmutableList(),
)

is MessageRoomEvent.MessageParent.Img -> this.copy(
emojiList = this.emojiList.addEmoji(userId, emojiId = emojiId).toImmutableList(),
)

is MessageRoomEvent.MessageParent.Me -> this.copy(
emojiList = this.emojiList.addEmoji(userId, emojiId = emojiId).toImmutableList(),
)

is MessageRoomEvent.MessageParent.Other -> this.copy(
emojiList = this.emojiList.addEmoji(userId, emojiId = emojiId).toImmutableList(),
)

else -> this
}

fun MessageRoomEvent.MessageParent.minusEmoji(userId: Long, emojiId: Int): MessageRoomEvent.MessageParent = when (this) {
is MessageRoomEvent.MessageParent.BOT.DrawLots -> this.copy(
emojiList = this.emojiList.minusEmoji(userId, emojiId = emojiId).toImmutableList(),
)
is MessageRoomEvent.MessageParent.BOT.Etc -> this.copy(
emojiList = this.emojiList.minusEmoji(userId, emojiId = emojiId).toImmutableList(),
)
is MessageRoomEvent.MessageParent.BOT.Meal -> this.copy(
emojiList = this.emojiList.minusEmoji(userId, emojiId = emojiId).toImmutableList(),
)
is MessageRoomEvent.MessageParent.BOT.NotSupport -> this.copy(
emojiList = this.emojiList.minusEmoji(userId, emojiId = emojiId).toImmutableList(),
)
is MessageRoomEvent.MessageParent.BOT.Notification -> this.copy(
emojiList = this.emojiList.minusEmoji(userId, emojiId = emojiId).toImmutableList(),
)
is MessageRoomEvent.MessageParent.BOT.TeamBuild -> this.copy(
emojiList = this.emojiList.minusEmoji(userId, emojiId = emojiId).toImmutableList(),
)
is MessageRoomEvent.MessageParent.BOT.Timetable -> this.copy(
emojiList = this.emojiList.minusEmoji(userId, emojiId = emojiId).toImmutableList(),
)
is MessageRoomEvent.MessageParent.File -> this.copy(
emojiList = this.emojiList.minusEmoji(userId, emojiId = emojiId).toImmutableList(),
)
is MessageRoomEvent.MessageParent.Img -> this.copy(
emojiList = this.emojiList.minusEmoji(userId, emojiId = emojiId).toImmutableList(),
)
is MessageRoomEvent.MessageParent.Me -> this.copy(
emojiList = this.emojiList.minusEmoji(userId, emojiId = emojiId).toImmutableList(),
)
is MessageRoomEvent.MessageParent.Other -> this.copy(
emojiList = this.emojiList.minusEmoji(userId, emojiId = emojiId).toImmutableList(),
)
else -> this
}

fun MessageRoomEvent.MessageParent.equalsMessageId(messageId: String): Boolean = when (this) {
is MessageParent.BOT.DrawLots -> this.id == messageId
is MessageParent.BOT.Etc -> this.id == messageId
is MessageParent.BOT.Meal -> this.id == messageId
is MessageParent.BOT.NotSupport -> this.id == messageId
is MessageParent.BOT.Notification -> this.id == messageId
is MessageParent.BOT.TeamBuild -> this.id == messageId
is MessageParent.BOT.Timetable -> this.id == messageId
is MessageParent.File -> this.id == messageId
is MessageParent.Img -> this.id == messageId
is MessageParent.Me -> this.id == messageId
is MessageParent.Other -> this.id == messageId
else -> false
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,28 @@ class MessageRepositoryImpl @Inject constructor(
}
.flowOn(dispatcher)
.asResult()

override suspend fun putEmoji(messageId: String, roomId: String, emojiId: Int): Flow<Result<Boolean>> = flow {
val response = datasource.putEmoji(
messageId = messageId,
roomId = roomId,
emojiId = emojiId,
).safeResponse()

emit(response)
}
.flowOn(dispatcher)
.asResult()

override suspend fun deleteEmoji(messageId: String, roomId: String, emojiId: Int): Flow<Result<Boolean>> = flow {
val response = datasource.deleteEmoji(
messageId = messageId,
roomId = roomId,
emojiId = emojiId,
).safeResponse()

emit(response)
}
.flowOn(dispatcher)
.asResult()
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.ui.unit.dp
import com.seugi.designsystem.component.chat.ChatItemType
import com.seugi.designsystem.component.chat.SeugiChatItem
import com.seugi.designsystem.theme.SeugiTheme
import kotlinx.collections.immutable.persistentListOf

@Composable
fun ChatItem() {
Expand All @@ -32,6 +33,8 @@ fun ChatItem() {
count = 1,
onDateClick = {},
onChatLongClick = {},
emojis = persistentListOf(),
onEmojiClick = {},
),
)
Spacer(modifier = Modifier.height(8.dp))
Expand All @@ -46,6 +49,8 @@ fun ChatItem() {
count = 1,
onDateClick = {},
onChatLongClick = {},
emojis = persistentListOf(),
onEmojiClick = {},
),
)
Spacer(modifier = Modifier.height(32.dp))
Expand All @@ -58,6 +63,8 @@ fun ChatItem() {
count = 1,
onDateClick = {},
onChatLongClick = {},
emojis = persistentListOf(),
onEmojiClick = {},
),
)
Spacer(modifier = Modifier.height(8.dp))
Expand All @@ -70,6 +77,8 @@ fun ChatItem() {
count = 1,
onDateClick = {},
onChatLongClick = {},
emojis = persistentListOf(),
onEmojiClick = {},
),
)
Spacer(modifier = Modifier.height(32.dp))
Expand All @@ -88,6 +97,8 @@ fun ChatItem() {
count = 1,
onDateClick = {},
onChatLongClick = {},
emojis = persistentListOf(),
onEmojiClick = {},
),
)
Spacer(modifier = Modifier.height(8.dp))
Expand All @@ -100,6 +111,8 @@ fun ChatItem() {
count = 1,
onDateClick = {},
onChatLongClick = {},
emojis = persistentListOf(),
onEmojiClick = {},
),
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.seugi.designsystem.component

import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.seugi.designsystem.animation.bounceClick
import com.seugi.designsystem.theme.SeugiTheme

@Composable
fun SeugiEmoji(modifier: Modifier = Modifier, emoji: String, count: Int, isChecked: Boolean, onClick: () -> Unit) {
Box(
modifier = Modifier.bounceClick(onClick),
) {
Row(
modifier = modifier
.background(
color = if (isChecked) SeugiTheme.colors.primary100 else SeugiTheme.colors.gray100,
shape = RoundedCornerShape(8.dp),
)
.border(
width = 1.dp,
color = if (isChecked) SeugiTheme.colors.primary300 else SeugiTheme.colors.gray200,
shape = RoundedCornerShape(8.dp),
),
verticalAlignment = Alignment.CenterVertically,
) {
Spacer(modifier = Modifier.width(8.dp))
Text(
modifier = Modifier.padding(
vertical = 4.dp,
),
text = emoji,
color = SeugiTheme.colors.black,
style = SeugiTheme.typography.subtitle2,
)
Spacer(modifier = Modifier.width(4.dp))
Text(
text = count.toString(),
color = SeugiTheme.colors.gray600,
style = SeugiTheme.typography.body1,
)
Spacer(modifier = Modifier.width(8.dp))
}
}
}
Loading

0 comments on commit 845a0af

Please sign in to comment.