Skip to content

Commit

Permalink
feature #68 : 멘티 화면 입장 시, 멘토와의 채팅 목록을 가져올 때 Lottie 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn committed Jun 27, 2024
1 parent 48500ab commit bf84dd5
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ class PostAiMessageUseCase @Inject constructor(
chattingRoomId = roomId,
messageFrom = ChattingRole.USER.name,
messageTo = ChattingRole.ASSISTANT.name,
content = chatLog.get(chatLog.size - 1).content,
content = chatLog[chatLog.size - 1].content,
createdAt = generateNowDateTime().toISOLocalDateTimeString(),
)

aiChattingRepository.insertChattingRoom(
id = roomId,
lastChatting = chatLog.get(chatLog.size - 1).content,
lastChatting = chatLog[chatLog.size - 1].content,
updatedAt = generateNowDateTime().toISOLocalDateTimeString(),
)

Expand All @@ -35,13 +35,13 @@ class PostAiMessageUseCase @Inject constructor(
chattingRoomId = roomId,
messageFrom = ChattingRole.ASSISTANT.name,
messageTo = ChattingRole.USER.name,
content = it.aiMessages.get(it.aiMessages.size - 1).content,
content = it.aiMessages[it.aiMessages.size - 1].content,
createdAt = generateNowDateTime().plusSeconds(1).toISOLocalDateTimeString(),
)

aiChattingRepository.insertChattingRoom(
id = roomId,
lastChatting = it.aiMessages.get(it.aiMessages.size - 1).content,
lastChatting = it.aiMessages[it.aiMessages.size - 1].content,
updatedAt = generateNowDateTime().toISOLocalDateTimeString(),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ class SearchStringInListUseCase @Inject constructor() {
if (isUp) {
for (index in (startIndex - 1) downTo 0) {
if (messages[index] is AiMessage && shouldSkipMessage(messages[index] as AiMessage)) continue

if (messages[index] is AiMessage && index == 1) continue
if (Regex(searchText).containsMatchIn(messages[index].content)) {
return index
}
}
} else {
for (index in (startIndex + 1) until messages.size) {
if (messages[index] is AiMessage && shouldSkipMessage(messages[index] as AiMessage)) continue

if (messages[index] is AiMessage && index == 1) continue
if (Regex(searchText).containsMatchIn(messages[index].content)) {
return index
}
Expand All @@ -69,7 +69,7 @@ class SearchStringInListUseCase @Inject constructor() {
private fun findFirstSearch(messages: List<MessageContentProvider>, searchText: String): Int? {
for (index in messages.indices.reversed()) {
if (messages[index] is AiMessage && shouldSkipMessage(messages[index] as AiMessage)) continue

if (messages[index] is AiMessage && index == 1) continue
if (Regex(searchText).containsMatchIn(messages[index].content)) {
return index
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.tgyuu.chatting.ai
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.WindowInsets
Expand Down Expand Up @@ -182,13 +181,14 @@ internal fun AiChattingScreen(

LazyColumn(
state = listState,
verticalArrangement = Arrangement.spacedBy(20.dp),
contentPadding = PaddingValues(horizontal = 25.dp),
modifier = Modifier
.fillMaxSize()
.padding(top = topBarHeight, bottom = textFieldHeight + 20.dp),
) {
itemsIndexed(items = chatLog) { idx, message ->
if (idx == 1) { return@itemsIndexed }

val speechBubbleType = when (message.role) {
ChattingRole.USER -> SpeechBubbleType.AI_USER
ChattingRole.ASSISTANT -> SpeechBubbleType.AI_CHAT
Expand All @@ -204,6 +204,7 @@ internal fun AiChattingScreen(
BaekyoungSpeechBubble(
type = speechBubbleType,
text = styledText,
modifier = Modifier.padding(bottom = if(idx < chatLog.size-1) 20.dp else 0.dp),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,8 @@ class AiChattingViewModel @Inject constructor(

private val _userInformation = MutableStateFlow(UserInformation())

val chatLog: SnapshotStateList<AiMessage> = mutableStateListOf(
AiMessage(
content = INIT_MESSAGE,
role = ChattingRole.SYSTEM,
),
)
val chatLog: SnapshotStateList<AiMessage> =
mutableStateListOf(AiMessage(content = INIT_MESSAGE, role = ChattingRole.SYSTEM))

private val _chatState: MutableStateFlow<UiState<Unit>> =
MutableStateFlow(UiState.Success(Unit))
Expand Down Expand Up @@ -104,12 +100,30 @@ class AiChattingViewModel @Inject constructor(
}

private fun getUserInformation() = viewModelScope.launch {
_chatState.value = UiState.Loading

getUserInformationUseCase("-1")
.onSuccess { _userInformation.value = it }
.onSuccess {
_userInformation.value = it

chatLog.add(
AiMessage(
content = "안녕하세요. 저는 ${it.major} ${it.grade}학년 ${it.gender} 학생입니다. 진로 상담 해주세요.",
role = ChattingRole.USER,
),
)

postAiMessageUseCase(chatLog = chatLog.toList(), roomId = _roomId.value)
.onSuccess { chatLog.addAll(it.aiMessages) }
.onFailure { Log.d("test", "onFailure : " + it.toString()) }
.also { _chatState.value = UiState.Success(Unit) }
}
.onFailure { }
}

fun postUserChatting() = viewModelScope.launch {
_chatState.value = UiState.Loading

chatLog.add(
AiMessage(
content = _chatText.value,
Expand All @@ -118,7 +132,6 @@ class AiChattingViewModel @Inject constructor(
)

_chatText.value = ""
_chatState.value = UiState.Loading

postAiMessageUseCase(chatLog = chatLog.toList(), roomId = _roomId.value)
.onSuccess { chatLog.addAll(it.aiMessages) }
Expand All @@ -133,9 +146,9 @@ class AiChattingViewModel @Inject constructor(
"정체: 고래\n" +
"성격: 친절함\n" +
"‘백경이' 는 항상 한국어 존댓말로 답변해.\n" +
"아래 정보는 유저가 우리대학(부경대학교)에서 진로 및 취업이나 공모전 관련해서 도움받을 수 있나고 질문할때만 참고해. 일반적인 대화상황에서는 참고하지마.\n" +
"아래 정보는 유저가 우리대학(부경대학교)에서 진로 및 취업이나 공모전 관련해서 도움받을 수 있나고 질문할때만 참고해. 일반적인 대화상황에서는 아래 내용은 참고하지마.\n" +
"\"부경대학교 학생역량개발과\": 부경대학교 진로관련 부서\n" +
"\"웨일비\"사이트: 부경대학교의 비교과 통합 플랫폼으로써 공모전과 같은 대외활동 정보를 얻을 수 있다.\n" +
"\"부경대학교 진로취업길라잡이\"사이트: 진로·취업 상담을 신청할 수 있다. 입사서류·면접 컨설팅을 신청할 수 있다. 다양한 취업 및 채용 정보를 볼 수 있다. 다양한 진로 취업 프로그램들을 알아볼 수 있다. 워크넷 공채, 사람인 공채, 잡코리아 공채 확인 가능하다."
"\"웨일비\"사이트: 부경대학교의 비교과 통합 플랫폼으로써 공모전과 같은 대외활동 정보를 얻을 수 있음\n" +
"\"부경대학교 진로취업길라잡이\"사이트: 진로·취업 상담 신청 가능, 입사서류·면접 컨설팅 신청 가능, 다양한 취업 및 채용 정보를 볼 수 있음, 다양한 진로 취업 프로그램들을 알아볼 수 있음, 워크넷 공채, 사람인 공채, 잡코리아 공채 확인 가능"
}
}
Loading

0 comments on commit bf84dd5

Please sign in to comment.