fix(chat): 대화 초기화 성공 시 방별 로컬 데이터(배경/공지/메시지) 삭제 처리
- ChatMessageDao: deleteMessagesByRoomId(roomId) 추가 - ChatRepository: clearMessagesByRoom(roomId) 추가 - ChatRoomActivity: clearLocalPrefsForRoom(roomId) 구현 및 reset 플로우에 Prefs/DB 삭제 체인 연결 - 요구사항: 대화 초기화 API 성공 시 해당 방의 배경 데이터와 로컬 메시지 등 모든 관련 데이터 제거
This commit is contained in:
		@@ -210,4 +210,13 @@ class ChatRepository(
 | 
			
		||||
            .subscribeOn(Schedulers.io())
 | 
			
		||||
            .map { ensureSuccess(it) }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 방별 로컬 메시지 전체 삭제
 | 
			
		||||
     */
 | 
			
		||||
    fun clearMessagesByRoom(roomId: Long): Completable {
 | 
			
		||||
        return Completable.fromAction {
 | 
			
		||||
            kotlinx.coroutines.runBlocking { chatDao.deleteMessagesByRoomId(roomId) }
 | 
			
		||||
        }.subscribeOn(Schedulers.io())
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -884,6 +884,18 @@ class ChatRoomActivity : BaseActivity<ActivityChatRoomBinding>(
 | 
			
		||||
        return if (id > 0) id else null
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private fun clearLocalPrefsForRoom(roomId: Long) {
 | 
			
		||||
        val keys = listOf(
 | 
			
		||||
            "chat_bg_visible_room_$roomId",
 | 
			
		||||
            "chat_bg_url_room_$roomId",
 | 
			
		||||
            "chat_bg_image_id_room_$roomId",
 | 
			
		||||
            noticePrefKey(roomId)
 | 
			
		||||
        )
 | 
			
		||||
        prefs.edit {
 | 
			
		||||
            keys.forEach { remove(it) }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fun onResetChatRequested() {
 | 
			
		||||
        val title = "대화 초기화"
 | 
			
		||||
        val desc = "지금까지의 대화가 모두 초기화 되고 새롭게 대화를 시작합니다."
 | 
			
		||||
@@ -896,6 +908,12 @@ class ChatRoomActivity : BaseActivity<ActivityChatRoomBinding>(
 | 
			
		||||
            confirmButtonClick = {
 | 
			
		||||
                val token = "Bearer ${SharedPreferenceManager.token}"
 | 
			
		||||
                val disposable = chatRepository.resetChatRoom(token = token, roomId = roomId)
 | 
			
		||||
                    .flatMap { response ->
 | 
			
		||||
                        // 로컬 데이터(이 방) 삭제: Prefs + DB
 | 
			
		||||
                        clearLocalPrefsForRoom(roomId)
 | 
			
		||||
                        chatRepository.clearMessagesByRoom(roomId)
 | 
			
		||||
                            .andThen(io.reactivex.rxjava3.core.Single.just(response))
 | 
			
		||||
                    }
 | 
			
		||||
                    .observeOn(AndroidSchedulers.mainThread())
 | 
			
		||||
                    .subscribe({ response ->
 | 
			
		||||
                        val intent = newIntent(this, response.chatRoomId)
 | 
			
		||||
 
 | 
			
		||||
@@ -37,4 +37,7 @@ interface ChatMessageDao {
 | 
			
		||||
 | 
			
		||||
    @Query("SELECT DISTINCT roomId FROM chat_messages")
 | 
			
		||||
    suspend fun getAllRoomIds(): List<Long>
 | 
			
		||||
 | 
			
		||||
    @Query("DELETE FROM chat_messages WHERE roomId = :roomId")
 | 
			
		||||
    suspend fun deleteMessagesByRoomId(roomId: Long)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user