tgyuuAn / BaekyoungE

μžμ—°μ–΄ 처리 기반 μ§„λ‘œ 상담 chat bot μ–΄ν”Œλ¦¬μΌ€μ΄μ…˜
7 stars 0 forks source link

Feature/#50 #51

Closed tgyuuAn closed 5 months ago

tgyuuAn commented 5 months ago

1. πŸ“„ κ΄€λ ¨λœ 이슈 및 μ†Œκ°œ

2. πŸ”₯λ³€κ²½λœ 점

3. πŸ“Έ μŠ€ν¬λ¦°μƒ·(선택)

4. πŸ’‘μ•Œκ²Œλœ ν˜Ήμ€ κΆκΈˆν•œ 사항듀

νŽ˜μ΄μ§•μ„ μ μš©ν•΄μ„œ ν•¨μˆ˜λ₯Ό ν˜ΈμΆœν•˜λ €κ³  ν•˜λŠ”λ°, μƒκ°λŒ€λ‘œ μ•ˆλ˜λŠ”λ°μš” ?

var previousChatTime by remember { mutableStateOf("") }

    LaunchedEffect(chatLog.size) {
        if (previousChatTime != (chatLog.lastOrNull()?.createdAt ?: "")) {
            coroutineScope.launch {
                listState.scrollToItem(chatLog.size)
                previousChatTime = chatLog.last().createdAt
            }
        }
    }

    LaunchedEffect(listState.firstVisibleItemIndex) {
        if (listState.firstVisibleItemIndex <= 3 && !isFirstPage) {
            getPreviousMessages()
        }
    }

λ‚΄κ°€ λ³΄κ³ μžˆλŠ” μ±„νŒ…μ°½μ˜ LazyColumn 의 Item μΈλ±μŠ€κ°€ 3μ΄ν•˜μΌ 경우,

μƒˆλ‘­κ²Œ 이전 μ±„νŒ… 데이터λ₯Ό ν˜ΈμΆœν•΄μ„œ 30개 정도λ₯Ό ν˜ΈμΆœν•˜λ €κ³  ν–ˆλŠ”λ°.

근데, 이걸 계속 ν˜ΈμΆœν•΄λ²„λ¦¬λ‹ˆκΉŒ λ˜‘κ°™μ€ μ±„νŒ… 데이터λ₯Ό μ—¬λŸ¬ 번 λ°›μ•„λ²„λ¦¬λ”λΌκ³ μš”..







κ·Έλž˜μ„œ 일단 μ•„λž˜ 처럼 atomicBoolean을 μ¨μ„œ 쀑볡 ν˜ΈμΆœμ„ λ§‰μ•„λ‘¬μ„œ ν•΄κ²°ν•˜κΈ΄ ν–ˆλŠ”λ°,,,

쑰금 더 쒋은 κ²½μš°κ°€ μžˆλŠ” μ§€λŠ” κ³„μ†ν•΄μ„œ 탐색해봐야 μ•Œ 것 κ°™λ”°.

    fun getPreviousMessages() = viewModelScope.launch {
        if (!isLoading.get()) {
            isLoading.getAndSet(true)
            getPreviousMentoringMessagesUseCase(
                _roomId.value,
                _pagingTimeStamp.value,
            )
                .onSuccess {
                    if (it.size < PAGING_SIZE) {
                        _isFirstPage.value = true
                    }

                    chatLog.addAll(0, it)

                    if (it.size != 0) {
                        _pagingTimeStamp.value = chatLog[0].createdAt
                    }
                }
                .onFailure { Log.d("test", "onFailure : " + it.toString()) }
                .also { isLoading.getAndSet(false) }

        }
    }

κΈ°λ˜₯μ°¬ firestore μ±„νŒ…λ°© 레퍼런슀