diff --git a/CatchMate/data/src/main/java/com/catchmate/data/datasource/remote/BoardService.kt b/CatchMate/data/src/main/java/com/catchmate/data/datasource/remote/BoardService.kt index 43a6974b..5b024f35 100644 --- a/CatchMate/data/src/main/java/com/catchmate/data/datasource/remote/BoardService.kt +++ b/CatchMate/data/src/main/java/com/catchmate/data/datasource/remote/BoardService.kt @@ -64,7 +64,7 @@ interface BoardService { @Path("boardId") boardId: Long, ): Response - @GET("api/bookmarks/me") + @GET("api/bookmarks") suspend fun getLikedBoard( @Query("page") page: Int, @Query("size") size: Int = 10, diff --git a/CatchMate/data/src/main/java/com/catchmate/data/datasource/remote/ChattingService.kt b/CatchMate/data/src/main/java/com/catchmate/data/datasource/remote/ChattingService.kt index 83f143a6..8009a98d 100644 --- a/CatchMate/data/src/main/java/com/catchmate/data/datasource/remote/ChattingService.kt +++ b/CatchMate/data/src/main/java/com/catchmate/data/datasource/remote/ChattingService.kt @@ -1,15 +1,12 @@ package com.catchmate.data.datasource.remote -import com.catchmate.data.dto.chatting.ChatRoomInfoDTO -import com.catchmate.data.dto.chatting.DeleteChattingCrewKickOutResponseDTO -import com.catchmate.data.dto.chatting.DeleteChattingRoomResponseDTO import com.catchmate.data.dto.chatting.GetChattingCrewListResponseDTO -import com.catchmate.data.dto.chatting.GetChattingHistoryResponseDTO +import com.catchmate.data.dto.chatting.GetChattingMessagesResponseDTO import com.catchmate.data.dto.chatting.GetChattingRoomListResponseDTO -import com.catchmate.data.dto.chatting.PatchChattingRoomImageResponseDTO -import com.catchmate.data.dto.chatting.PutChattingRoomAlarmResponseDTO +import com.catchmate.data.dto.chatting.PutChattingRoomAlarmRequestDTO import okhttp3.MultipartBody import retrofit2.Response +import retrofit2.http.Body import retrofit2.http.DELETE import retrofit2.http.GET import retrofit2.http.Multipart @@ -26,44 +23,39 @@ interface ChattingService { @Query("size") size: Int, ): Response - @GET("chat-rooms/{chatRoomId}/user-list") + @GET("api/chat/rooms/{chatRoomId}/members") suspend fun getChattingCrewList( @Path("chatRoomId") chatRoomId: Long, - ): Response - - @GET("chat-rooms/{chatRoomId}") - suspend fun getChattingRoomInfo( - @Path("chatRoomId") chatRoomId: Long, - ): Response + ): Response?> @Multipart - @PATCH("chat-rooms/{chatRoomId}/image") + @PATCH("api/chat/rooms/{roomId}/image") suspend fun patchChattingRoomImage( - @Path("chatRoomId") chatRoomId: Long, + @Path("roomId") roomId: Long, @Part chatRoomImage: MultipartBody.Part, - ): Response + ): Response - @PUT("chat-rooms/{chatRoomId}/notification") + @PUT("api/chat/rooms/{roomId}/notifications") suspend fun putChattingRoomAlarm( - @Path("chatRoomId") chatRoomId: Long, - @Query("enable") enable: Boolean, - ): Response + @Path("roomId") roomId: Long, + @Body putChattingRoomAlarmRequestDTO: PutChattingRoomAlarmRequestDTO, + ): Response - @DELETE("chat-rooms/{chatRoomId}") + @DELETE("api/chat/rooms/{roomId}") suspend fun deleteChattingRoom( - @Path("chatRoomId") chatRoomId: Long, - ): Response - - @DELETE("chat-rooms/{chatRoomId}/users/{userId}") - suspend fun deleteChattingCrewKickOut( - @Path("chatRoomId") chatRoomId: Long, - @Path("userId") userId: Long, - ): Response - - @GET("chats/{chatRoomId}") - suspend fun getChattingHistory( - @Path("chatRoomId") chatRoomId: Long, - @Query("lastMessageId") lastMessageId: String?, - @Query("size") size: Int?, // default = 20 - ): Response + @Path("roomId") roomId: Long, + ): Response + + @DELETE("api/chat/rooms/{roomId}/members/{targetUserId}") + suspend fun deleteChattingCrew( + @Path("roomId") roomId: Long, + @Path("targetUserId") targetUserId: Long, + ): Response + + @GET("api/chat/rooms/{roomId}/messages") + suspend fun getChattingMessages( + @Path("roomId") roomId: Long, + @Query("lastMessageId") lastMessageId: Long?, + @Query("size") size: Int, // default = 20 + ): Response?> } diff --git a/CatchMate/data/src/main/java/com/catchmate/data/dto/board/GetBoardResponseDTO.kt b/CatchMate/data/src/main/java/com/catchmate/data/dto/board/GetBoardResponseDTO.kt index 7475889a..e7615a33 100644 --- a/CatchMate/data/src/main/java/com/catchmate/data/dto/board/GetBoardResponseDTO.kt +++ b/CatchMate/data/src/main/java/com/catchmate/data/dto/board/GetBoardResponseDTO.kt @@ -15,7 +15,7 @@ data class GetBoardResponseDTO( val liftUpDate: String, val bookMarked: Boolean, val buttonStatus: String, - val myEnrollId: Long, + val myEnrollId: Long?, val chatRoomId: Long, val cheerClub: ClubDTO, val game: GameInfoDTO, diff --git a/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/ChatMessageIdDTO.kt b/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/ChatMessageIdDTO.kt deleted file mode 100644 index a46d5a8a..00000000 --- a/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/ChatMessageIdDTO.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.catchmate.data.dto.chatting - -data class ChatMessageIdDTO( - val timestamp: Long? = null, - val date: String, -) diff --git a/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/ChatMessageInfoDTO.kt b/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/ChatMessageInfoDTO.kt deleted file mode 100644 index 2340f9de..00000000 --- a/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/ChatMessageInfoDTO.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.catchmate.data.dto.chatting - -data class ChatMessageInfoDTO( - val id: ChatMessageIdDTO, - val chatMessageId: String, - val roomId: Long? = null, - val content: String, - val senderId: Long, - val messageType: String, -) diff --git a/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/ChatRoomInfoDTO.kt b/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/ChatRoomInfoDTO.kt index eb278368..f9bc0514 100644 --- a/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/ChatRoomInfoDTO.kt +++ b/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/ChatRoomInfoDTO.kt @@ -6,5 +6,8 @@ data class ChatRoomInfoDTO( val chatRoomId: Long, val board: BoardDTO, val lastMessage: LastMessageInfoDto?, + val unreadCount: Long, + val chatRoomImageUrl: String?, val createdAt: String, + val notificationOn: Boolean, ) diff --git a/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/DeleteChattingCrewKickOutResponseDTO.kt b/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/DeleteChattingCrewKickOutResponseDTO.kt deleted file mode 100644 index 51b65f59..00000000 --- a/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/DeleteChattingCrewKickOutResponseDTO.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.catchmate.data.dto.chatting - -data class DeleteChattingCrewKickOutResponseDTO( - val state: Boolean, -) diff --git a/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/DeleteChattingRoomResponseDTO.kt b/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/DeleteChattingRoomResponseDTO.kt deleted file mode 100644 index 562fc54b..00000000 --- a/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/DeleteChattingRoomResponseDTO.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.catchmate.data.dto.chatting - -data class DeleteChattingRoomResponseDTO( - val state: Boolean, -) diff --git a/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/GetChattingCrewListResponseDTO.kt b/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/GetChattingCrewListResponseDTO.kt index 995d1c85..64e67f2e 100644 --- a/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/GetChattingCrewListResponseDTO.kt +++ b/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/GetChattingCrewListResponseDTO.kt @@ -1,7 +1,9 @@ package com.catchmate.data.dto.chatting -import com.catchmate.data.dto.user.GetUserProfileResponseDTO - data class GetChattingCrewListResponseDTO( - val userInfoList: List, + val memberId: Long, + val userId: Long, + val nickName: String, + val profileImageUrl: String, + val joinedAt: String, ) diff --git a/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/GetChattingHistoryResponseDTO.kt b/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/GetChattingHistoryResponseDTO.kt deleted file mode 100644 index ab8c3943..00000000 --- a/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/GetChattingHistoryResponseDTO.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.catchmate.data.dto.chatting - -data class GetChattingHistoryResponseDTO( - val chatMessageInfoList: List, - val isFirst: Boolean, - val isLast: Boolean, - val lastMessageId: String?, -) diff --git a/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/GetChattingMessagesResponseDTO.kt b/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/GetChattingMessagesResponseDTO.kt new file mode 100644 index 00000000..70b32af6 --- /dev/null +++ b/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/GetChattingMessagesResponseDTO.kt @@ -0,0 +1,12 @@ +package com.catchmate.data.dto.chatting + +data class GetChattingMessagesResponseDTO( + val messageId: Long, + val chatRoomId: Long, + val senderId: Long, + val senderNickName: String, + val senderProfileImageUrl: String, + val content: String, + val messageType: String, + val createdAt: String, +) diff --git a/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/PatchChattingRoomImageResponseDTO.kt b/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/PatchChattingRoomImageResponseDTO.kt deleted file mode 100644 index 1fbd96e0..00000000 --- a/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/PatchChattingRoomImageResponseDTO.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.catchmate.data.dto.chatting - -data class PatchChattingRoomImageResponseDTO( - val state: Boolean, -) diff --git a/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/PutChattingRoomAlarmRequestDTO.kt b/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/PutChattingRoomAlarmRequestDTO.kt new file mode 100644 index 00000000..adc9b0d8 --- /dev/null +++ b/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/PutChattingRoomAlarmRequestDTO.kt @@ -0,0 +1,5 @@ +package com.catchmate.data.dto.chatting + +data class PutChattingRoomAlarmRequestDTO( + val on: Boolean, +) diff --git a/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/PutChattingRoomAlarmResponseDTO.kt b/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/PutChattingRoomAlarmResponseDTO.kt deleted file mode 100644 index e778cbad..00000000 --- a/CatchMate/data/src/main/java/com/catchmate/data/dto/chatting/PutChattingRoomAlarmResponseDTO.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.catchmate.data.dto.chatting - -data class PutChattingRoomAlarmResponseDTO( - val state: Boolean, -) diff --git a/CatchMate/data/src/main/java/com/catchmate/data/mapper/ChattingMapper.kt b/CatchMate/data/src/main/java/com/catchmate/data/mapper/ChattingMapper.kt index 220023f5..c9e5adeb 100644 --- a/CatchMate/data/src/main/java/com/catchmate/data/mapper/ChattingMapper.kt +++ b/CatchMate/data/src/main/java/com/catchmate/data/mapper/ChattingMapper.kt @@ -1,29 +1,18 @@ package com.catchmate.data.mapper -import com.catchmate.data.dto.chatting.ChatMessageIdDTO -import com.catchmate.data.dto.chatting.ChatMessageInfoDTO import com.catchmate.data.dto.chatting.ChatRoomInfoDTO -import com.catchmate.data.dto.chatting.DeleteChattingCrewKickOutResponseDTO -import com.catchmate.data.dto.chatting.DeleteChattingRoomResponseDTO import com.catchmate.data.dto.chatting.GetChattingCrewListResponseDTO -import com.catchmate.data.dto.chatting.GetChattingHistoryResponseDTO +import com.catchmate.data.dto.chatting.GetChattingMessagesResponseDTO import com.catchmate.data.dto.chatting.GetChattingRoomListResponseDTO import com.catchmate.data.dto.chatting.LastMessageInfoDto -import com.catchmate.data.dto.chatting.PatchChattingRoomImageResponseDTO -import com.catchmate.data.dto.chatting.PutChattingRoomAlarmResponseDTO +import com.catchmate.data.dto.chatting.PutChattingRoomAlarmRequestDTO import com.catchmate.data.mapper.BoardMapper.toBoard -import com.catchmate.data.mapper.UserMapper.toGetUserProfileResponse -import com.catchmate.domain.model.chatting.ChatMessageId -import com.catchmate.domain.model.chatting.ChatMessageInfo import com.catchmate.domain.model.chatting.ChatRoomInfo -import com.catchmate.domain.model.chatting.DeleteChattingCrewKickOutResponse -import com.catchmate.domain.model.chatting.DeleteChattingRoomResponse import com.catchmate.domain.model.chatting.GetChattingCrewListResponse -import com.catchmate.domain.model.chatting.GetChattingHistoryResponse +import com.catchmate.domain.model.chatting.GetChattingMessagesResponse import com.catchmate.domain.model.chatting.GetChattingRoomListResponse import com.catchmate.domain.model.chatting.LastMessageInfo -import com.catchmate.domain.model.chatting.PatchChattingRoomImageResponse -import com.catchmate.domain.model.chatting.PutChattingRoomAlarmResponse +import com.catchmate.domain.model.chatting.PutChattingRoomAlarmRequest object ChattingMapper { fun toGetChattingRoomListResponse(dto: GetChattingRoomListResponseDTO): GetChattingRoomListResponse = @@ -40,7 +29,10 @@ object ChattingMapper { chatRoomId = dto.chatRoomId, board = toBoard(dto.board), lastMessage = toLastMessageInfo(dto.lastMessage), + unreadCount = dto.unreadCount, + chatRoomImageUrl = dto.chatRoomImageUrl, createdAt = dto.createdAt, + notificationOn = dto.notificationOn, ) private fun toLastMessageInfo(dto: LastMessageInfoDto?): LastMessageInfo? = @@ -57,52 +49,29 @@ object ChattingMapper { ) } - fun toGetChattingHistoryResponse(dto: GetChattingHistoryResponseDTO): GetChattingHistoryResponse = - GetChattingHistoryResponse( - chatMessageInfoList = dto.chatMessageInfoList.map { toChatMessageInfo(it) }, - isFirst = dto.isFirst, - isLast = dto.isLast, - lastMessageId = dto.lastMessageId, - ) - - private fun toChatMessageInfo(dto: ChatMessageInfoDTO): ChatMessageInfo = - ChatMessageInfo( - id = toChatMessageId(dto.id), - chatMessageId = dto.chatMessageId, - roomId = dto.roomId, - content = dto.content, + fun toGetChattingHistoryResponse(dto: GetChattingMessagesResponseDTO): GetChattingMessagesResponse = + GetChattingMessagesResponse( + messageId = dto.messageId, + chatRoomId = dto.chatRoomId, senderId = dto.senderId, + senderNickName = dto.senderNickName, + senderProfileImageUrl = dto.senderProfileImageUrl, + content = dto.content, messageType = dto.messageType, - ) - - private fun toChatMessageId(dto: ChatMessageIdDTO): ChatMessageId = - ChatMessageId( - timestamp = dto.timestamp, - date = dto.date, + createdAt = dto.createdAt, ) fun toGetChattingCrewListResponse(dto: GetChattingCrewListResponseDTO): GetChattingCrewListResponse = GetChattingCrewListResponse( - userInfoList = dto.userInfoList.map { toGetUserProfileResponse(it) }, - ) - - fun toDeleteChattingRoomResponse(dto: DeleteChattingRoomResponseDTO): DeleteChattingRoomResponse = - DeleteChattingRoomResponse( - state = dto.state, - ) - - fun toDeleteChattingCrewKickOutResponse(dto: DeleteChattingCrewKickOutResponseDTO): DeleteChattingCrewKickOutResponse = - DeleteChattingCrewKickOutResponse( - state = dto.state, - ) - - fun toPatchChattingRoomImageResponse(dto: PatchChattingRoomImageResponseDTO): PatchChattingRoomImageResponse = - PatchChattingRoomImageResponse( - state = dto.state, + memberId = dto.memberId, + userId = dto.userId, + nickName = dto.nickName, + profileImageUrl = dto.profileImageUrl, + joinedAt = dto.joinedAt, ) - fun toPutChattingRoomAlarmResponse(dto: PutChattingRoomAlarmResponseDTO): PutChattingRoomAlarmResponse = - PutChattingRoomAlarmResponse( - state = dto.state, + fun toPutChattingRoomAlarmRequestDTO(request: PutChattingRoomAlarmRequest): PutChattingRoomAlarmRequestDTO = + PutChattingRoomAlarmRequestDTO( + on = request.on, ) } diff --git a/CatchMate/data/src/main/java/com/catchmate/data/repository/ChattingRepositoryImpl.kt b/CatchMate/data/src/main/java/com/catchmate/data/repository/ChattingRepositoryImpl.kt index ceb08bda..bd4877c3 100644 --- a/CatchMate/data/src/main/java/com/catchmate/data/repository/ChattingRepositoryImpl.kt +++ b/CatchMate/data/src/main/java/com/catchmate/data/repository/ChattingRepositoryImpl.kt @@ -4,14 +4,10 @@ import com.catchmate.data.datasource.remote.ChattingService import com.catchmate.data.datasource.remote.RetrofitClient import com.catchmate.data.mapper.ChattingMapper import com.catchmate.data.util.ApiResponseHandleUtil.apiCall -import com.catchmate.domain.model.chatting.ChatRoomInfo -import com.catchmate.domain.model.chatting.DeleteChattingCrewKickOutResponse -import com.catchmate.domain.model.chatting.DeleteChattingRoomResponse import com.catchmate.domain.model.chatting.GetChattingCrewListResponse -import com.catchmate.domain.model.chatting.GetChattingHistoryResponse +import com.catchmate.domain.model.chatting.GetChattingMessagesResponse import com.catchmate.domain.model.chatting.GetChattingRoomListResponse -import com.catchmate.domain.model.chatting.PatchChattingRoomImageResponse -import com.catchmate.domain.model.chatting.PutChattingRoomAlarmResponse +import com.catchmate.domain.model.chatting.PutChattingRoomAlarmRequest import com.catchmate.domain.repository.ChattingRepository import okhttp3.MultipartBody import javax.inject.Inject @@ -34,65 +30,71 @@ class ChattingRepositoryImpl transform = { ChattingMapper.toGetChattingRoomListResponse(it!!) }, ) - override suspend fun getChattingCrewList(chatRoomId: Long): Result = + override suspend fun getChattingCrewList(chatRoomId: Long): Result> = apiCall( tag = this.tag, apiFunction = { chattingApi.getChattingCrewList(chatRoomId) }, - transform = { ChattingMapper.toGetChattingCrewListResponse(it!!) }, - ) - - override suspend fun getChattingRoomInfo(chatRoomId: Long): Result = - apiCall( - tag = this.tag, - apiFunction = { chattingApi.getChattingRoomInfo(chatRoomId) }, - transform = { ChattingMapper.toChatRoomInfo(it!!) }, + transform = { list -> + list?.map { crew -> + ChattingMapper.toGetChattingCrewListResponse(crew) + } ?: emptyList() + }, ) override suspend fun patchChattingRoomImage( - chatRoomId: Long, + roomId: Long, chatRoomImage: MultipartBody.Part, - ): Result = + ): Result = apiCall( tag = this.tag, - apiFunction = { chattingApi.patchChattingRoomImage(chatRoomId, chatRoomImage) }, - transform = { ChattingMapper.toPatchChattingRoomImageResponse(it!!) }, + apiFunction = { chattingApi.patchChattingRoomImage(roomId, chatRoomImage) }, + transform = { it }, ) override suspend fun putChattingRoomAlarm( - chatRoomId: Long, - enable: Boolean, - ): Result = + roomId: Long, + request: PutChattingRoomAlarmRequest, + ): Result = apiCall( tag = this.tag, - apiFunction = { chattingApi.putChattingRoomAlarm(chatRoomId, enable) }, - transform = { ChattingMapper.toPutChattingRoomAlarmResponse(it!!) }, + apiFunction = { + chattingApi.putChattingRoomAlarm( + roomId, + ChattingMapper.toPutChattingRoomAlarmRequestDTO(request), + ) + }, + transform = { it }, ) - override suspend fun deleteChattingRoom(chatRoomId: Long): Result = + override suspend fun deleteChattingRoom(roomId: Long): Result = apiCall( tag = this.tag, - apiFunction = { chattingApi.deleteChattingRoom(chatRoomId) }, - transform = { ChattingMapper.toDeleteChattingRoomResponse(it!!) }, + apiFunction = { chattingApi.deleteChattingRoom(roomId) }, + transform = { it }, ) - override suspend fun deleteChattingCrewKickOut( + override suspend fun deleteChattingCrew( chatRoomId: Long, - userId: Long, - ): Result = + targetUserId: Long, + ): Result = apiCall( tag = this.tag, - apiFunction = { chattingApi.deleteChattingCrewKickOut(chatRoomId, userId) }, - transform = { ChattingMapper.toDeleteChattingCrewKickOutResponse(it!!) }, + apiFunction = { chattingApi.deleteChattingCrew(chatRoomId, targetUserId) }, + transform = { it }, ) - override suspend fun getChattingHistory( + override suspend fun getChattingMessages( chatRoomId: Long, - lastMessageId: String?, - size: Int?, - ): Result = + lastMessageId: Long?, + size: Int, + ): Result> = apiCall( tag = this.tag, - apiFunction = { chattingApi.getChattingHistory(chatRoomId, lastMessageId, size) }, - transform = { ChattingMapper.toGetChattingHistoryResponse(it!!) }, + apiFunction = { chattingApi.getChattingMessages(chatRoomId, lastMessageId, size) }, + transform = { list -> + list?.map { message -> + ChattingMapper.toGetChattingHistoryResponse(message) + } ?: emptyList() + }, ) } diff --git a/CatchMate/domain/src/main/java/com/catchmate/domain/model/board/GetBoardResponse.kt b/CatchMate/domain/src/main/java/com/catchmate/domain/model/board/GetBoardResponse.kt index dd88ac28..2066e874 100644 --- a/CatchMate/domain/src/main/java/com/catchmate/domain/model/board/GetBoardResponse.kt +++ b/CatchMate/domain/src/main/java/com/catchmate/domain/model/board/GetBoardResponse.kt @@ -18,7 +18,7 @@ data class GetBoardResponse( val liftUpDate: String, val bookMarked: Boolean, val buttonStatus: String, - val myEnrollId: Long, + val myEnrollId: Long?, val chatRoomId: Long, val cheerClub: Club, val game: GameInfo, diff --git a/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/ChatMessageId.kt b/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/ChatMessageId.kt deleted file mode 100644 index cc5c3d2e..00000000 --- a/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/ChatMessageId.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.catchmate.domain.model.chatting - -data class ChatMessageId( - val timestamp: Long? = null, - val date: String, -) diff --git a/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/ChatMessageInfo.kt b/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/ChatMessageInfo.kt deleted file mode 100644 index 99eba8cb..00000000 --- a/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/ChatMessageInfo.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.catchmate.domain.model.chatting - -data class ChatMessageInfo( - val id: ChatMessageId? = null, - val chatMessageId: String, - val roomId: Long? = null, - val content: String, - val senderId: Long, - val messageType: String, -) diff --git a/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/ChatRoomInfo.kt b/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/ChatRoomInfo.kt index a21c26eb..adf43ccb 100644 --- a/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/ChatRoomInfo.kt +++ b/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/ChatRoomInfo.kt @@ -1,10 +1,16 @@ package com.catchmate.domain.model.chatting +import android.os.Parcelable import com.catchmate.domain.model.board.Board +import kotlinx.parcelize.Parcelize +@Parcelize data class ChatRoomInfo( val chatRoomId: Long, val board: Board, val lastMessage: LastMessageInfo?, + val unreadCount: Long, + val chatRoomImageUrl: String?, val createdAt: String, -) + val notificationOn: Boolean, +) : Parcelable diff --git a/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/DeleteChattingCrewKickOutResponse.kt b/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/DeleteChattingCrewKickOutResponse.kt deleted file mode 100644 index 8cd36be2..00000000 --- a/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/DeleteChattingCrewKickOutResponse.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.catchmate.domain.model.chatting - -data class DeleteChattingCrewKickOutResponse( - val state: Boolean, -) diff --git a/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/DeleteChattingRoomResponse.kt b/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/DeleteChattingRoomResponse.kt deleted file mode 100644 index 33b6a57e..00000000 --- a/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/DeleteChattingRoomResponse.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.catchmate.domain.model.chatting - -data class DeleteChattingRoomResponse( - val state: Boolean, -) diff --git a/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/GetChattingCrewListResponse.kt b/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/GetChattingCrewListResponse.kt index 5ec28e7d..8b6fd78d 100644 --- a/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/GetChattingCrewListResponse.kt +++ b/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/GetChattingCrewListResponse.kt @@ -1,10 +1,13 @@ package com.catchmate.domain.model.chatting import android.os.Parcelable -import com.catchmate.domain.model.user.GetUserProfileResponse import kotlinx.parcelize.Parcelize @Parcelize data class GetChattingCrewListResponse( - val userInfoList: List, + val memberId: Long, + val userId: Long, + val nickName: String, + val profileImageUrl: String, + val joinedAt: String, ) : Parcelable diff --git a/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/GetChattingHistoryResponse.kt b/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/GetChattingHistoryResponse.kt deleted file mode 100644 index 7e9489ee..00000000 --- a/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/GetChattingHistoryResponse.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.catchmate.domain.model.chatting - -data class GetChattingHistoryResponse( - val chatMessageInfoList: List, - val isFirst: Boolean, - val isLast: Boolean, - val lastMessageId: String?, -) diff --git a/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/GetChattingMessagesResponse.kt b/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/GetChattingMessagesResponse.kt new file mode 100644 index 00000000..e065d421 --- /dev/null +++ b/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/GetChattingMessagesResponse.kt @@ -0,0 +1,12 @@ +package com.catchmate.domain.model.chatting + +data class GetChattingMessagesResponse( + val messageId: Long, + val chatRoomId: Long, + val senderId: Long, + val senderNickName: String, + val senderProfileImageUrl: String, + val content: String, + val messageType: String, + val createdAt: String, +) diff --git a/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/LastMessageInfo.kt b/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/LastMessageInfo.kt index 55c88a63..14d612e3 100644 --- a/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/LastMessageInfo.kt +++ b/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/LastMessageInfo.kt @@ -1,5 +1,9 @@ package com.catchmate.domain.model.chatting +import android.os.Parcelable +import kotlinx.parcelize.Parcelize + +@Parcelize data class LastMessageInfo( val messageId: Long, val chatRoomId: Long, @@ -9,4 +13,4 @@ data class LastMessageInfo( val content: String, val messageType: String, val createdAt: String, -) +) : Parcelable diff --git a/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/PatchChattingRoomImageResponse.kt b/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/PatchChattingRoomImageResponse.kt deleted file mode 100644 index ef20a7cf..00000000 --- a/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/PatchChattingRoomImageResponse.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.catchmate.domain.model.chatting - -data class PatchChattingRoomImageResponse( - val state: Boolean, -) diff --git a/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/PutChattingRoomAlarmRequest.kt b/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/PutChattingRoomAlarmRequest.kt new file mode 100644 index 00000000..b5c853d1 --- /dev/null +++ b/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/PutChattingRoomAlarmRequest.kt @@ -0,0 +1,5 @@ +package com.catchmate.domain.model.chatting + +data class PutChattingRoomAlarmRequest( + val on: Boolean, +) diff --git a/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/PutChattingRoomAlarmResponse.kt b/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/PutChattingRoomAlarmResponse.kt deleted file mode 100644 index 20a61bcf..00000000 --- a/CatchMate/domain/src/main/java/com/catchmate/domain/model/chatting/PutChattingRoomAlarmResponse.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.catchmate.domain.model.chatting - -data class PutChattingRoomAlarmResponse( - val state: Boolean, -) diff --git a/CatchMate/domain/src/main/java/com/catchmate/domain/model/enumclass/ChatMessageType.kt b/CatchMate/domain/src/main/java/com/catchmate/domain/model/enumclass/ChatMessageType.kt index 1b9a028c..67976507 100644 --- a/CatchMate/domain/src/main/java/com/catchmate/domain/model/enumclass/ChatMessageType.kt +++ b/CatchMate/domain/src/main/java/com/catchmate/domain/model/enumclass/ChatMessageType.kt @@ -1,8 +1,7 @@ package com.catchmate.domain.model.enumclass enum class ChatMessageType { - TALK, DATE, - ENTER, - LEAVE, + SYSTEM, + TEXT, } diff --git a/CatchMate/domain/src/main/java/com/catchmate/domain/repository/ChattingRepository.kt b/CatchMate/domain/src/main/java/com/catchmate/domain/repository/ChattingRepository.kt index 08ffd9b6..fff585be 100644 --- a/CatchMate/domain/src/main/java/com/catchmate/domain/repository/ChattingRepository.kt +++ b/CatchMate/domain/src/main/java/com/catchmate/domain/repository/ChattingRepository.kt @@ -1,13 +1,9 @@ package com.catchmate.domain.repository -import com.catchmate.domain.model.chatting.ChatRoomInfo -import com.catchmate.domain.model.chatting.DeleteChattingCrewKickOutResponse -import com.catchmate.domain.model.chatting.DeleteChattingRoomResponse import com.catchmate.domain.model.chatting.GetChattingCrewListResponse -import com.catchmate.domain.model.chatting.GetChattingHistoryResponse +import com.catchmate.domain.model.chatting.GetChattingMessagesResponse import com.catchmate.domain.model.chatting.GetChattingRoomListResponse -import com.catchmate.domain.model.chatting.PatchChattingRoomImageResponse -import com.catchmate.domain.model.chatting.PutChattingRoomAlarmResponse +import com.catchmate.domain.model.chatting.PutChattingRoomAlarmRequest import okhttp3.MultipartBody interface ChattingRepository { @@ -16,30 +12,28 @@ interface ChattingRepository { size: Int, ): Result - suspend fun getChattingCrewList(chatRoomId: Long): Result - - suspend fun getChattingRoomInfo(chatRoomId: Long): Result + suspend fun getChattingCrewList(chatRoomId: Long): Result> suspend fun patchChattingRoomImage( - chatRoomId: Long, + roomId: Long, chatRoomImage: MultipartBody.Part, - ): Result + ): Result suspend fun putChattingRoomAlarm( - chatRoomId: Long, - enable: Boolean, - ): Result + roomId: Long, + dto: PutChattingRoomAlarmRequest, + ): Result - suspend fun deleteChattingRoom(chatRoomId: Long): Result + suspend fun deleteChattingRoom(roomId: Long): Result - suspend fun deleteChattingCrewKickOut( + suspend fun deleteChattingCrew( chatRoomId: Long, - userId: Long, - ): Result + targetUserId: Long, + ): Result - suspend fun getChattingHistory( + suspend fun getChattingMessages( chatRoomId: Long, - lastMessageId: String?, - size: Int?, - ): Result + lastMessageId: Long?, + size: Int, + ): Result> } diff --git a/CatchMate/domain/src/main/java/com/catchmate/domain/usecase/chatting/GetChattingCrewListUseCase.kt b/CatchMate/domain/src/main/java/com/catchmate/domain/usecase/chatting/GetChattingCrewListUseCase.kt index 3aaa09dd..1a865968 100644 --- a/CatchMate/domain/src/main/java/com/catchmate/domain/usecase/chatting/GetChattingCrewListUseCase.kt +++ b/CatchMate/domain/src/main/java/com/catchmate/domain/usecase/chatting/GetChattingCrewListUseCase.kt @@ -9,6 +9,6 @@ class GetChattingCrewListUseCase constructor( private val chattingRepository: ChattingRepository, ) { - suspend operator fun invoke(chatRoomId: Long): Result = + suspend operator fun invoke(chatRoomId: Long): Result> = chattingRepository.getChattingCrewList(chatRoomId) } diff --git a/CatchMate/domain/src/main/java/com/catchmate/domain/usecase/chatting/GetChattingHistoryUseCase.kt b/CatchMate/domain/src/main/java/com/catchmate/domain/usecase/chatting/GetChattingMessagesUseCase.kt similarity index 51% rename from CatchMate/domain/src/main/java/com/catchmate/domain/usecase/chatting/GetChattingHistoryUseCase.kt rename to CatchMate/domain/src/main/java/com/catchmate/domain/usecase/chatting/GetChattingMessagesUseCase.kt index cbe1a09f..b95f677b 100644 --- a/CatchMate/domain/src/main/java/com/catchmate/domain/usecase/chatting/GetChattingHistoryUseCase.kt +++ b/CatchMate/domain/src/main/java/com/catchmate/domain/usecase/chatting/GetChattingMessagesUseCase.kt @@ -1,17 +1,17 @@ package com.catchmate.domain.usecase.chatting -import com.catchmate.domain.model.chatting.GetChattingHistoryResponse +import com.catchmate.domain.model.chatting.GetChattingMessagesResponse import com.catchmate.domain.repository.ChattingRepository import javax.inject.Inject -class GetChattingHistoryUseCase +class GetChattingMessagesUseCase @Inject constructor( private val chattingRepository: ChattingRepository, ) { suspend operator fun invoke( chatRoomId: Long, - lastMessageId: String?, - size: Int?, - ): Result = chattingRepository.getChattingHistory(chatRoomId, lastMessageId, size) + lastMessageId: Long?, + size: Int, + ): Result> = chattingRepository.getChattingMessages(chatRoomId, lastMessageId, size) } diff --git a/CatchMate/domain/src/main/java/com/catchmate/domain/usecase/chatting/GetChattingRoomInfoUseCase.kt b/CatchMate/domain/src/main/java/com/catchmate/domain/usecase/chatting/GetChattingRoomInfoUseCase.kt deleted file mode 100644 index 5a175061..00000000 --- a/CatchMate/domain/src/main/java/com/catchmate/domain/usecase/chatting/GetChattingRoomInfoUseCase.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.catchmate.domain.usecase.chatting - -import com.catchmate.domain.model.chatting.ChatRoomInfo -import com.catchmate.domain.repository.ChattingRepository -import javax.inject.Inject - -class GetChattingRoomInfoUseCase - @Inject - constructor( - private val chattingRepository: ChattingRepository, - ) { - suspend operator fun invoke(chatRoomId: Long): Result = chattingRepository.getChattingRoomInfo(chatRoomId) - } diff --git a/CatchMate/domain/src/main/java/com/catchmate/domain/usecase/chatting/KickOutChattingCrewUseCase.kt b/CatchMate/domain/src/main/java/com/catchmate/domain/usecase/chatting/KickOutChattingCrewUseCase.kt index c293a58c..e9dbd0e1 100644 --- a/CatchMate/domain/src/main/java/com/catchmate/domain/usecase/chatting/KickOutChattingCrewUseCase.kt +++ b/CatchMate/domain/src/main/java/com/catchmate/domain/usecase/chatting/KickOutChattingCrewUseCase.kt @@ -1,6 +1,5 @@ package com.catchmate.domain.usecase.chatting -import com.catchmate.domain.model.chatting.DeleteChattingCrewKickOutResponse import com.catchmate.domain.repository.ChattingRepository import javax.inject.Inject @@ -11,6 +10,6 @@ class KickOutChattingCrewUseCase ) { suspend operator fun invoke( chatRoomId: Long, - userId: Long, - ): Result = chattingRepository.deleteChattingCrewKickOut(chatRoomId, userId) + targetUserId: Long, + ): Result = chattingRepository.deleteChattingCrew(chatRoomId, targetUserId) } diff --git a/CatchMate/domain/src/main/java/com/catchmate/domain/usecase/chatting/LeaveChattingRoomUseCase.kt b/CatchMate/domain/src/main/java/com/catchmate/domain/usecase/chatting/LeaveChattingRoomUseCase.kt index a71c4a42..86c92963 100644 --- a/CatchMate/domain/src/main/java/com/catchmate/domain/usecase/chatting/LeaveChattingRoomUseCase.kt +++ b/CatchMate/domain/src/main/java/com/catchmate/domain/usecase/chatting/LeaveChattingRoomUseCase.kt @@ -1,6 +1,5 @@ package com.catchmate.domain.usecase.chatting -import com.catchmate.domain.model.chatting.DeleteChattingRoomResponse import com.catchmate.domain.repository.ChattingRepository import javax.inject.Inject @@ -9,6 +8,5 @@ class LeaveChattingRoomUseCase constructor( private val chattingRepository: ChattingRepository, ) { - suspend operator fun invoke(chatRoomId: Long): Result = - chattingRepository.deleteChattingRoom(chatRoomId) + suspend operator fun invoke(roomId: Long): Result = chattingRepository.deleteChattingRoom(roomId) } diff --git a/CatchMate/domain/src/main/java/com/catchmate/domain/usecase/chatting/PatchChattingRoomImageUseCase.kt b/CatchMate/domain/src/main/java/com/catchmate/domain/usecase/chatting/PatchChattingRoomImageUseCase.kt index 03d5879d..242814d5 100644 --- a/CatchMate/domain/src/main/java/com/catchmate/domain/usecase/chatting/PatchChattingRoomImageUseCase.kt +++ b/CatchMate/domain/src/main/java/com/catchmate/domain/usecase/chatting/PatchChattingRoomImageUseCase.kt @@ -1,6 +1,5 @@ package com.catchmate.domain.usecase.chatting -import com.catchmate.domain.model.chatting.PatchChattingRoomImageResponse import com.catchmate.domain.repository.ChattingRepository import okhttp3.MultipartBody import javax.inject.Inject @@ -11,7 +10,7 @@ class PatchChattingRoomImageUseCase private val chattingRepository: ChattingRepository, ) { suspend operator fun invoke( - chatRoomId: Long, + roomId: Long, chatRoomImage: MultipartBody.Part, - ): Result = chattingRepository.patchChattingRoomImage(chatRoomId, chatRoomImage) + ): Result = chattingRepository.patchChattingRoomImage(roomId, chatRoomImage) } diff --git a/CatchMate/domain/src/main/java/com/catchmate/domain/usecase/chatting/PutChattingRoomAlarmUseCase.kt b/CatchMate/domain/src/main/java/com/catchmate/domain/usecase/chatting/PutChattingRoomAlarmUseCase.kt index 48589e2d..c2f7d6e2 100644 --- a/CatchMate/domain/src/main/java/com/catchmate/domain/usecase/chatting/PutChattingRoomAlarmUseCase.kt +++ b/CatchMate/domain/src/main/java/com/catchmate/domain/usecase/chatting/PutChattingRoomAlarmUseCase.kt @@ -1,6 +1,6 @@ package com.catchmate.domain.usecase.chatting -import com.catchmate.domain.model.chatting.PutChattingRoomAlarmResponse +import com.catchmate.domain.model.chatting.PutChattingRoomAlarmRequest import com.catchmate.domain.repository.ChattingRepository import javax.inject.Inject @@ -10,7 +10,7 @@ class PutChattingRoomAlarmUseCase private val chattingRepository: ChattingRepository, ) { suspend operator fun invoke( - chatRoomId: Long, - enable: Boolean, - ): Result = chattingRepository.putChattingRoomAlarm(chatRoomId, enable) + roomId: Long, + request: PutChattingRoomAlarmRequest, + ): Result = chattingRepository.putChattingRoomAlarm(roomId, request) } diff --git a/CatchMate/presentation/src/main/java/com/catchmate/presentation/interaction/OnChattingRoomSelectedListener.kt b/CatchMate/presentation/src/main/java/com/catchmate/presentation/interaction/OnChattingRoomSelectedListener.kt index a4d3f1fe..3a90775c 100644 --- a/CatchMate/presentation/src/main/java/com/catchmate/presentation/interaction/OnChattingRoomSelectedListener.kt +++ b/CatchMate/presentation/src/main/java/com/catchmate/presentation/interaction/OnChattingRoomSelectedListener.kt @@ -1,8 +1,7 @@ package com.catchmate.presentation.interaction +import com.catchmate.domain.model.chatting.ChatRoomInfo + interface OnChattingRoomSelectedListener { - fun onChattingRoomSelected( - chatRoomId: Long, - isNewChatRoom: Boolean, - ) + fun onChattingRoomSelected(chatRoomInfo: ChatRoomInfo) } diff --git a/CatchMate/presentation/src/main/java/com/catchmate/presentation/util/DateUtils.kt b/CatchMate/presentation/src/main/java/com/catchmate/presentation/util/DateUtils.kt index 5c11060b..0b343424 100644 --- a/CatchMate/presentation/src/main/java/com/catchmate/presentation/util/DateUtils.kt +++ b/CatchMate/presentation/src/main/java/com/catchmate/presentation/util/DateUtils.kt @@ -5,7 +5,6 @@ import java.time.Duration import java.time.Instant import java.time.LocalDateTime import java.time.ZoneId -import java.time.ZonedDateTime import java.time.format.DateTimeFormatter import java.time.format.DateTimeFormatterBuilder import java.time.temporal.ChronoField @@ -116,7 +115,8 @@ object DateUtils { val parsedTime = LocalDateTime .parse(dateTime, formatter) - .atZone(ZoneId.of("Asia/Seoul")) + .atZone(ZoneId.of("UTC")) + .withZoneSameInstant(ZoneId.of("Asia/Seoul")) .toInstant() val now = Instant.now() val duration = Duration.between(parsedTime, now) @@ -152,20 +152,26 @@ object DateUtils { // 채팅 전송 시간 포맷하는 함수 fun formatChatSendTime(dateTime: String): String { - val formatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME - val parsedTime = - ZonedDateTime - .parse(dateTime, formatter) - .withZoneSameInstant(ZoneId.of("Asia/Seoul")) // 시스템 시간대로 변환 - - val outputFormatter = DateTimeFormatter.ofPattern("a h:mm") // "오전 4:55" 형식 - return parsedTime.format(outputFormatter) - } - - // 채팅 수신 시 날짜값 포맷하는 함수 - fun getCurrentTimeFormatted(): String { - val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX") - return ZonedDateTime.now().format(formatter) + val tFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSS") + val spaceFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss") + val outputFormatter = DateTimeFormatter.ofPattern("a h:mm") + return try { + // 시간대 정보가 없는 문자열을 LocalDateTime으로 파싱 + val localDateTime = + if (dateTime.contains("T")) { + LocalDateTime.parse(dateTime) + } else { + LocalDateTime.parse(dateTime, spaceFormatter) + } + + localDateTime + .atZone(ZoneId.of("UTC")) + .withZoneSameInstant(ZoneId.of("Asia/Seoul")) + .format(outputFormatter) + } catch (e: Exception) { + e.printStackTrace() + "" // 에러 발생 시 빈 문자열 또는 기본값 반환 + } } fun checkIsFinishedGame(dateTime: String): Boolean { diff --git a/CatchMate/presentation/src/main/java/com/catchmate/presentation/view/chatting/ChatListAdapter.kt b/CatchMate/presentation/src/main/java/com/catchmate/presentation/view/chatting/ChatListAdapter.kt index 62080b5d..60adeb0b 100644 --- a/CatchMate/presentation/src/main/java/com/catchmate/presentation/view/chatting/ChatListAdapter.kt +++ b/CatchMate/presentation/src/main/java/com/catchmate/presentation/view/chatting/ChatListAdapter.kt @@ -1,5 +1,6 @@ package com.catchmate.presentation.view.chatting +import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -7,9 +8,9 @@ import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView import com.bumptech.glide.Glide -import com.catchmate.domain.model.chatting.ChatMessageInfo +import com.catchmate.domain.model.chatting.GetChattingCrewListResponse +import com.catchmate.domain.model.chatting.GetChattingMessagesResponse import com.catchmate.domain.model.enumclass.ChatMessageType -import com.catchmate.domain.model.user.GetUserProfileResponse import com.catchmate.presentation.R import com.catchmate.presentation.databinding.ItemReceivedChatBinding import com.catchmate.presentation.databinding.ItemSendChatBinding @@ -19,34 +20,34 @@ import com.catchmate.presentation.util.DateUtils.formatChatSendTime class ChatListAdapter( private val userId: Long, - private val chattingCrewList: List, -) : ListAdapter(diffUtil) { + private val chattingCrewList: List, +) : ListAdapter(diffUtil) { inner class SendChatViewHolder( private val binding: ItemSendChatBinding, ) : RecyclerView.ViewHolder(binding.root) { - fun bind(chatMessageInfo: ChatMessageInfo) { - binding.tvSendChatMessage.text = chatMessageInfo.content - binding.tvSendChatTime.text = formatChatSendTime(chatMessageInfo.id?.date!!) + fun bind(chat: GetChattingMessagesResponse) { + binding.tvSendChatMessage.text = chat.content + binding.tvSendChatTime.text = formatChatSendTime(chat.createdAt) } } inner class ReceivedChatViewHolder( private val binding: ItemReceivedChatBinding, ) : RecyclerView.ViewHolder(binding.root) { - fun bind(chatMessageInfo: ChatMessageInfo) { + fun bind(chat: GetChattingMessagesResponse) { // 현재 메시지가 리스트의 마지막인지 확인 val isLastMessage = absoluteAdapterPosition == currentList.lastIndex // 현재 메시지와 다음 메시지의 senderId가 같은지 비교 val isSameSenderAsNext = absoluteAdapterPosition < currentList.lastIndex && - currentList[absoluteAdapterPosition + 1].senderId == chatMessageInfo.senderId + currentList[absoluteAdapterPosition + 1].senderId == chat.senderId if (isLastMessage || !isSameSenderAsNext) { // 마지막 메시지(서버에서 주는 데이터를 역순으로 스크롤하게 출력했기 때문에 마지막 메시지인지 판단)이거나 다음 메시지와 보낸 사람이 다르면 프로필과 닉네임 표시 binding.ivReceivedChatProfile.visibility = View.VISIBLE binding.tvReceivedChatNickname.visibility = View.VISIBLE val currentUserInfo = - chattingCrewList.firstOrNull { it.userId == chatMessageInfo.senderId } + chattingCrewList.firstOrNull { it.userId == chat.senderId } binding.tvReceivedChatNickname.text = currentUserInfo?.nickName ?: "알수없음" Glide .with(binding.root) @@ -58,35 +59,24 @@ class ChatListAdapter( binding.ivReceivedChatProfile.visibility = View.GONE binding.tvReceivedChatNickname.visibility = View.GONE } - binding.tvReceivedChatMessage.text = chatMessageInfo.content - binding.tvReceivedChatTime.text = formatChatSendTime(chatMessageInfo.id?.date!!) + binding.tvReceivedChatMessage.text = chat.content + binding.tvReceivedChatTime.text = formatChatSendTime(chat.createdAt) } } inner class ChattingDateViewHolder( private val binding: ViewChattingDateBinding, ) : RecyclerView.ViewHolder(binding.root) { - fun bind(chatMessageInfo: ChatMessageInfo) { - binding.tvChattingDate.text = chatMessageInfo.content + fun bind(chat: GetChattingMessagesResponse) { + binding.tvChattingDate.text = chat.content } } inner class ChattingParticipantViewHolder( private val binding: ViewChattingParticipantAlertBinding, ) : RecyclerView.ViewHolder(binding.root) { - fun bind( - chatMessageInfo: ChatMessageInfo, - viewType: Int, - ) { - val nickname = - chattingCrewList.firstOrNull { it.userId == chatMessageInfo.senderId }?.nickName ?: "알수없음" - val message = - if (viewType == ENTER) { - "$nickname 님이 채팅에 참여했어요" - } else { - "$nickname 님이 나갔어요" - } - binding.tvChattingParticipantAlert.text = message + fun bind(chat: GetChattingMessagesResponse) { + binding.tvChattingParticipantAlert.text = chat.content } } @@ -144,13 +134,13 @@ class ChatListAdapter( MY_CHAT -> (holder as SendChatViewHolder).bind(currentList[position]) OTHER_CHAT -> (holder as ReceivedChatViewHolder).bind(currentList[position]) DATE -> (holder as ChattingDateViewHolder).bind(currentList[position]) - ENTER, LEAVE -> (holder as ChattingParticipantViewHolder).bind(currentList[position], getItemViewType(position)) + SYSTEM -> (holder as ChattingParticipantViewHolder).bind(currentList[position]) } } override fun getItemViewType(position: Int): Int = when (currentList[position].messageType) { - ChatMessageType.TALK.name -> { + ChatMessageType.TEXT.name -> { if (currentList[position].senderId == userId) { MY_CHAT } else { @@ -162,33 +152,32 @@ class ChatListAdapter( DATE } - ChatMessageType.ENTER.name -> { - ENTER + ChatMessageType.SYSTEM.name -> { + SYSTEM } else -> { - LEAVE + SYSTEM } } companion object { val diffUtil = - object : DiffUtil.ItemCallback() { + object : DiffUtil.ItemCallback() { override fun areItemsTheSame( - oldItem: ChatMessageInfo, - newItem: ChatMessageInfo, + oldItem: GetChattingMessagesResponse, + newItem: GetChattingMessagesResponse, ): Boolean = oldItem == newItem override fun areContentsTheSame( - oldItem: ChatMessageInfo, - newItem: ChatMessageInfo, + oldItem: GetChattingMessagesResponse, + newItem: GetChattingMessagesResponse, ): Boolean = oldItem == newItem } private const val MY_CHAT = 1 private const val OTHER_CHAT = 2 private const val DATE = 3 - private const val ENTER = 4 - private const val LEAVE = 5 + private const val SYSTEM = 4 } } diff --git a/CatchMate/presentation/src/main/java/com/catchmate/presentation/view/chatting/ChattingCrewListAdapter.kt b/CatchMate/presentation/src/main/java/com/catchmate/presentation/view/chatting/ChattingCrewListAdapter.kt index 590828d6..12ab712e 100644 --- a/CatchMate/presentation/src/main/java/com/catchmate/presentation/view/chatting/ChattingCrewListAdapter.kt +++ b/CatchMate/presentation/src/main/java/com/catchmate/presentation/view/chatting/ChattingCrewListAdapter.kt @@ -7,7 +7,7 @@ import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView import com.bumptech.glide.Glide -import com.catchmate.domain.model.user.GetUserProfileResponse +import com.catchmate.domain.model.chatting.GetChattingCrewListResponse import com.catchmate.presentation.databinding.ItemChattingParticipantBinding import com.catchmate.presentation.interaction.OnKickOutClickListener @@ -16,11 +16,11 @@ class ChattingCrewListAdapter( private val writerId: Long, private val pageType: String, private val onKickOutClickListener: OnKickOutClickListener? = null, -) : ListAdapter(diffUtil) { +) : ListAdapter(diffUtil) { inner class CrewViewHolder( private val binding: ItemChattingParticipantBinding, ) : RecyclerView.ViewHolder(binding.root) { - fun bind(profile: GetUserProfileResponse) { + fun bind(profile: GetChattingCrewListResponse) { binding.apply { Glide .with(root) @@ -76,15 +76,15 @@ class ChattingCrewListAdapter( companion object { val diffUtil = - object : DiffUtil.ItemCallback() { + object : DiffUtil.ItemCallback() { override fun areItemsTheSame( - oldItem: GetUserProfileResponse, - newItem: GetUserProfileResponse, + oldItem: GetChattingCrewListResponse, + newItem: GetChattingCrewListResponse, ): Boolean = oldItem == newItem override fun areContentsTheSame( - oldItem: GetUserProfileResponse, - newItem: GetUserProfileResponse, + oldItem: GetChattingCrewListResponse, + newItem: GetChattingCrewListResponse, ): Boolean = oldItem == newItem } } diff --git a/CatchMate/presentation/src/main/java/com/catchmate/presentation/view/chatting/ChattingHomeFragment.kt b/CatchMate/presentation/src/main/java/com/catchmate/presentation/view/chatting/ChattingHomeFragment.kt index 9e79a24d..8e06ddde 100644 --- a/CatchMate/presentation/src/main/java/com/catchmate/presentation/view/chatting/ChattingHomeFragment.kt +++ b/CatchMate/presentation/src/main/java/com/catchmate/presentation/view/chatting/ChattingHomeFragment.kt @@ -11,6 +11,7 @@ import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.bumptech.glide.Glide +import com.catchmate.domain.model.chatting.ChatRoomInfo import com.catchmate.presentation.R import com.catchmate.presentation.databinding.FragmentChattingHomeBinding import com.catchmate.presentation.databinding.LayoutAlertDialogBinding @@ -20,7 +21,6 @@ import com.catchmate.presentation.interaction.OnListItemAllRemovedListener import com.catchmate.presentation.util.ReissueUtil.NAVIGATE_CODE_REISSUE import com.catchmate.presentation.view.base.BaseFragment import com.catchmate.presentation.viewmodel.ChattingHomeViewModel -import com.catchmate.presentation.viewmodel.LocalDataViewModel import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.snackbar.Snackbar import dagger.hilt.android.AndroidEntryPoint @@ -32,11 +32,9 @@ class ChattingHomeFragment : OnItemSwipeListener, OnListItemAllRemovedListener { private val chattingHomeViewModel: ChattingHomeViewModel by viewModels() - private val localDataViewModel: LocalDataViewModel by viewModels() private var currentPage: Int = 0 private var hasNext = true private var isLoading = false - private var isFirstLoad = true private var deletedItemPos: Int = -1 private lateinit var chattingRoomListAdapter: ChattingRoomListAdapter @@ -51,32 +49,23 @@ class ChattingHomeFragment : val deletedChatRoomId = bundle.getLong("chatRoomId") deleteChatRoom(deletedChatRoomId) } - localDataViewModel.getAccessToken() initHeader() initRecyclerView() initViewModel() - - if (isFirstLoad) { - getChattingRoomList() - isFirstLoad = false - } // (requireActivity() as MainActivity).refreshNotificationStatus() } override fun onResume() { super.onResume() - // 화면이 다시 보일 때만 새로고침 (최초 실행 시에는 제외) - if (!isFirstLoad) { - Log.d("ChattingHomeFragment", "onResume: 채팅방 목록 새로고침") - // 페이지 초기화 - currentPage = 0 - hasNext = true - isLoading = false - - chattingRoomListAdapter.submitList(emptyList()) - // 채팅방 목록 새로 불러오기 - getChattingRoomList() - } + Log.d("ChattingHomeFragment", "onResume: 채팅방 목록 새로고침") + // 페이지 초기화 + currentPage = 0 + hasNext = true + isLoading = false + + chattingRoomListAdapter.submitList(emptyList()) + // 채팅방 목록 새로 불러오기 + getChattingRoomList() } override fun onDestroyView() { @@ -93,9 +82,6 @@ class ChattingHomeFragment : } private fun initViewModel() { - localDataViewModel.accessToken.observe(viewLifecycleOwner) { token -> -// chattingHomeViewModel.connectToWebSocket(token) - } chattingHomeViewModel.getChattingRoomListResponse.observe(viewLifecycleOwner) { response -> isLoading = false if (!response.hasNext && response.totalElements == 0) { @@ -146,11 +132,8 @@ class ChattingHomeFragment : } } chattingHomeViewModel.leaveChattingRoomResponse.observe(viewLifecycleOwner) { response -> - if (response.state) { - chattingRoomListAdapter.removeItem(deletedItemPos) - } else { - Snackbar.make(requireView(), R.string.chatting_leave_room_fail, Snackbar.LENGTH_SHORT).show() - } + Log.i("채팅방 나가기 성공", "$response") + chattingRoomListAdapter.removeItem(deletedItemPos) } } @@ -220,14 +203,11 @@ class ChattingHomeFragment : dialog.show() } - override fun onChattingRoomSelected( - chatRoomId: Long, - isNewChatRoom: Boolean, - ) { + override fun onChattingRoomSelected(chatRoomInfo: ChatRoomInfo) { val bundle = Bundle() - bundle.putLong("chatRoomId", chatRoomId) + bundle.putParcelable("chatRoomInfo", chatRoomInfo) findNavController().navigate(R.id.action_chattingHomeFragment_to_chattingRoomFragment, bundle) - if (isNewChatRoom) { + if (chatRoomInfo.lastMessage == null) { showChattingSystemAlertDialog() } } diff --git a/CatchMate/presentation/src/main/java/com/catchmate/presentation/view/chatting/ChattingRoomFragment.kt b/CatchMate/presentation/src/main/java/com/catchmate/presentation/view/chatting/ChattingRoomFragment.kt index c3197788..beeead61 100644 --- a/CatchMate/presentation/src/main/java/com/catchmate/presentation/view/chatting/ChattingRoomFragment.kt +++ b/CatchMate/presentation/src/main/java/com/catchmate/presentation/view/chatting/ChattingRoomFragment.kt @@ -1,8 +1,10 @@ package com.catchmate.presentation.view.chatting +import android.os.Build import android.os.Bundle import android.os.Handler import android.os.Looper +import android.os.Parcelable import android.text.Editable import android.text.TextWatcher import android.util.Log @@ -18,8 +20,9 @@ import androidx.navigation.fragment.findNavController import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.catchmate.domain.model.chatting.ChatRoomInfo +import com.catchmate.domain.model.chatting.GetChattingCrewListResponse +import com.catchmate.domain.model.chatting.PutChattingRoomAlarmRequest import com.catchmate.domain.model.enumclass.ChatMessageType -import com.catchmate.domain.model.user.GetUserProfileResponse import com.catchmate.presentation.R import com.catchmate.presentation.databinding.FragmentChattingRoomBinding import com.catchmate.presentation.databinding.LayoutChattingSideSheetBinding @@ -40,13 +43,12 @@ class ChattingRoomFragment : BaseFragment(FragmentC private val chattingRoomViewModel: ChattingRoomViewModel by viewModels() private val localDataViewModel: LocalDataViewModel by viewModels() private var userId: Long = -1L - private var lastChatMessageId: String? = null + private var lastMessageId: Long? = null private var isLastPage = false private var isLoading = false private var isApiCalled = false private var isFirstLoad = true - private val chatRoomId by lazy { arguments?.getLong("chatRoomId") ?: -1L } - private val isPendingIntent by lazy { arguments?.getBoolean("isPendingIntent") ?: false } + private val isPendingIntent by lazy { arguments?.getBoolean("isPendingIntent") == true } private var isNotificationEnabled = false private lateinit var chatListAdapter: ChatListAdapter @@ -57,7 +59,7 @@ class ChattingRoomFragment : BaseFragment(FragmentC super.onViewCreated(view, savedInstanceState) localDataViewModel.getUserId() initViewModel() - chattingRoomViewModel.getChattingRoomInfo(chatRoomId) + getChatRoomInfo() initChatBox() initSendBtn() onBackPressedAction = { setOnBackPressedAction() } @@ -69,53 +71,53 @@ class ChattingRoomFragment : BaseFragment(FragmentC chattingRoomViewModel.stompClient?.disconnect() } + private fun getChatRoomInfo() { + val chatRoomInfo = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + arguments?.getParcelable("chatRoomInfo", ChatRoomInfo::class.java) + } else { + arguments?.getParcelable("chatRoomInfo") + } + chatRoomInfo?.let { info -> + chattingRoomViewModel.setChatRoomInfo(info) + } + } + private fun initViewModel() { - chattingRoomViewModel.getChattingHistoryResponse.observe(viewLifecycleOwner) { response -> - if (response.isFirst && response.isLast && response.chatMessageInfoList.isEmpty()) { + chattingRoomViewModel.getChattingMessagesResponse.observe(viewLifecycleOwner) { response -> + if (response.isEmpty()) { Log.d("빈 채팅방 목록", "empty") } else { - Log.i("👀observer", "work \n ${response.chatMessageInfoList.size}") + Log.i("👀observer", "work \n ${response.size}") if (isApiCalled) { val currentList = chatListAdapter.currentList.toMutableList() Log.d("IS API CALLED", "🅾️") - currentList.addAll(response.chatMessageInfoList) + currentList.addAll(response) chatListAdapter.submitList(currentList) isApiCalled = false } else { - chatListAdapter.submitList(response.chatMessageInfoList) { + chatListAdapter.submitList(response) { // 수신 메시지 추가 후 콜백을 통해 최신 메시지로 스크롤 이동 binding.rvChattingRoomChatList.smoothScrollToPosition(0) isApiCalled = false } } - isLastPage = response.isLast + isLastPage = response.size < 20 isLoading = false } } chattingRoomViewModel.getChattingCrewListResponse.observe(viewLifecycleOwner) { response -> if (response != null) { - initRecyclerView(response.userInfoList) + initRecyclerView(response) } } chattingRoomViewModel.chattingRoomInfo.observe(viewLifecycleOwner) { info -> if (info != null) { -// isNotificationEnabled = info.isNotificationEnabled + isNotificationEnabled = info.notificationOn initChatRoomInfo(info) initHeader(info) } } - chattingRoomViewModel.deleteChattingRoomResponse.observe(viewLifecycleOwner) { response -> - response?.let { - if (it.state) { - Log.d("채팅방 나가기 성공", "나가기 성공") - setFragmentResult("deleteChattingRoomResultKey", bundleOf("chatRoomId" to chatRoomId)) - findNavController().popBackStack() - } else { - Log.d("채팅방 오류", "나가기 실패") - showAlertSnackbar(R.string.chatting_leave_room_fail) - } - } - } chattingRoomViewModel.navigateToLogin.observe(viewLifecycleOwner) { isTrue -> if (isTrue) { val navOptions = @@ -136,10 +138,10 @@ class ChattingRoomFragment : BaseFragment(FragmentC localDataViewModel.userId.observe(viewLifecycleOwner) { id -> userId = id localDataViewModel.getAccessToken() - chattingRoomViewModel.getChattingCrewList(chatRoomId) + chattingRoomViewModel.getChattingCrewList(chattingRoomViewModel.chattingRoomInfo.value?.chatRoomId ?: -1) } localDataViewModel.accessToken.observe(viewLifecycleOwner) { token -> - chattingRoomViewModel.connectToWebSocket(chatRoomId, userId, token) + chattingRoomViewModel.connectToWebSocket(chattingRoomViewModel.chattingRoomInfo.value?.chatRoomId ?: -1, token) } chattingRoomViewModel.isMessageSent.observe(viewLifecycleOwner) { isSent -> if (isSent) { @@ -148,6 +150,17 @@ class ChattingRoomFragment : BaseFragment(FragmentC showAlertSnackbar(R.string.chatting_message_send_fail) } } + chattingRoomViewModel.isLeft.observe(viewLifecycleOwner) { isSent -> + if (isSent) { + Log.d("채팅방 나가기 성공", "나가기 성공") + val chatRoomId = chattingRoomViewModel.chattingRoomInfo.value?.chatRoomId ?: -1 + setFragmentResult("deleteChattingRoomResultKey", bundleOf("chatRoomId" to chatRoomId)) + findNavController().popBackStack() + } else { + Log.d("채팅방 오류", "나가기 실패") + showAlertSnackbar(R.string.chatting_leave_room_fail) + } + } chattingRoomViewModel.isInstability.observe(viewLifecycleOwner) { isTrue -> if (isTrue) { showAlertSnackbar(R.string.chatting_connect_instability) @@ -155,7 +168,7 @@ class ChattingRoomFragment : BaseFragment(FragmentC } } - private fun initRecyclerView(list: List) { + private fun initRecyclerView(list: List) { Log.i("userID", userId.toString()) chatListAdapter = ChatListAdapter(userId, list) binding.rvChattingRoomChatList.apply { @@ -179,7 +192,7 @@ class ChattingRoomFragment : BaseFragment(FragmentC lastVisibleItemPosition >= 0 && lastVisibleItemPosition < chatListAdapter.currentList.size ) { - lastChatMessageId = chatListAdapter.currentList[lastVisibleItemPosition].chatMessageId + lastMessageId = chatListAdapter.currentList[lastVisibleItemPosition].messageId getChattingHistory() } } @@ -197,7 +210,11 @@ class ChattingRoomFragment : BaseFragment(FragmentC Log.i("api 호출", "호출 $isLoading $isLastPage") if (isLoading || isLastPage) return isLoading = true - chattingRoomViewModel.getChattingHistory(chatRoomId, lastChatMessageId) + chattingRoomViewModel.getChattingMessages( + chatRoomId = chattingRoomViewModel.chattingRoomInfo.value?.chatRoomId ?: -1, + lastMessageId = lastMessageId, + userId = userId, + ) isApiCalled = true } @@ -251,15 +268,14 @@ class ChattingRoomFragment : BaseFragment(FragmentC private fun initSendBtn() { binding.btnChattingRoomChatBoxSend.setOnClickListener { - val message = + val request = JSONObject() .apply { - put("messageType", ChatMessageType.TALK.name) + put("chatRoomId", chattingRoomViewModel.chattingRoomInfo.value?.chatRoomId ?: -1) put("content", binding.edtChattingRoomChatBox.text.toString()) - put("senderId", userId) + put("messageType", ChatMessageType.TEXT) }.toString() - - chattingRoomViewModel.sendMessage(chatRoomId, message) + chattingRoomViewModel.sendMessage(request) } } @@ -320,7 +336,12 @@ class ChattingRoomFragment : BaseFragment(FragmentC adapter = crewAdapter layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) } - crewAdapter.submitList(chattingRoomViewModel.getChattingCrewListResponse.value?.userInfoList) + crewAdapter.submitList( + ( + chattingRoomViewModel.getChattingCrewListResponse.value + ?: emptyList() + ), + ) // 버튼 기능 ivSideSheetLeaveChattingRoom.setOnClickListener { @@ -333,11 +354,14 @@ class ChattingRoomFragment : BaseFragment(FragmentC // 채팅방 이미지 url, 참여자 목록, 로그인 유저 id, 게시글 작성자 id, 채팅방 id 넘김 val bundle = Bundle().apply { -// putString("chattingRoomImage", info.chatRoomImage) - putParcelable("chattingCrewList", chattingRoomViewModel.getChattingCrewListResponse.value) + putString("chattingRoomImage", info.chatRoomImageUrl) + putParcelableArrayList( + "chattingCrewList", + chattingRoomViewModel.getChattingCrewListResponse.value as ArrayList?, + ) putLong("loginUserId", userId) putLong("writerId", info.board.userResponse.userId) - putLong("chatRoomId", chatRoomId) + putLong("chatRoomId", chattingRoomViewModel.chattingRoomInfo.value?.chatRoomId ?: -1) } findNavController().navigate(R.id.action_chattingRoomFragment_to_chattingSettingFragment, bundle) sideSheetDialog.dismiss() @@ -349,7 +373,12 @@ class ChattingRoomFragment : BaseFragment(FragmentC toggleSideSheetChattingRoomNotification.setOnClickListener { isNotificationEnabled = !isNotificationEnabled toggleSideSheetChattingRoomNotification.isChecked = isNotificationEnabled - chattingRoomViewModel.putChattingRoomAlarm(chatRoomId, isNotificationEnabled) + chattingRoomViewModel.putChattingRoomAlarm( + chattingRoomViewModel.chattingRoomInfo.value?.chatRoomId ?: -1, + PutChattingRoomAlarmRequest( + isNotificationEnabled, + ), + ) } layoutSideSheetPostInfo.setOnClickListener { val bundle = Bundle() @@ -397,7 +426,12 @@ class ChattingRoomFragment : BaseFragment(FragmentC ContextCompat.getColor(requireContext(), R.color.brand500), ) setOnClickListener { - chattingRoomViewModel.deleteChattingRoom(chatRoomId) + val request = + JSONObject() + .apply { + put("chatRoomId", chattingRoomViewModel.chattingRoomInfo.value?.chatRoomId ?: -1) + }.toString() + chattingRoomViewModel.leaveChattingRoom(request) dialog.dismiss() } } diff --git a/CatchMate/presentation/src/main/java/com/catchmate/presentation/view/chatting/ChattingRoomListAdapter.kt b/CatchMate/presentation/src/main/java/com/catchmate/presentation/view/chatting/ChattingRoomListAdapter.kt index 2c214b7a..a50b5139 100644 --- a/CatchMate/presentation/src/main/java/com/catchmate/presentation/view/chatting/ChattingRoomListAdapter.kt +++ b/CatchMate/presentation/src/main/java/com/catchmate/presentation/view/chatting/ChattingRoomListAdapter.kt @@ -47,76 +47,53 @@ class ChattingRoomListAdapter( fun bind(chatRoomInfo: ChatRoomInfo) { binding.apply { root.setOnClickListener { - onChattingRoomSelectedListener.onChattingRoomSelected(chatRoomInfo.chatRoomId, chatRoomInfo.lastMessage == null) + onChattingRoomSelectedListener.onChattingRoomSelected(chatRoomInfo) + } + if (chatRoomInfo.chatRoomImageUrl == null) { + val clubId = chatRoomInfo.board.cheerClub.clubId + val logoResource = convertTeamLogo(clubId) + ivChattingItemLogo.visibility = View.VISIBLE + Glide + .with(root.context) + .load(logoResource) + .into(ivChattingItemLogo) + DrawableCompat + .setTint( + ivChattingItemBg.drawable, + convertTeamColor( + root.context, + clubId, + true, + "chattingHome", + ), + ) + } else { + ivChattingItemLogo.visibility = View.GONE + Glide + .with(root.context) + .load(chatRoomInfo.chatRoomImageUrl) + .into(ivChattingItemBg) } - // 채팅방 이미지가 변경된 적 없는 경우 chatRoomImage에 cheerTeamId가 String으로 담겨옴 - // 해당 변수를 int로 변환할 때 예외 처리를 통해 변경된 적 있을 경우의 imageUrl을 imageView에 표시 -// try { -// val clubId = chatRoomInfo.chatRoomImage.toInt() -// val logoResource = convertTeamLogo(clubId) -// ivChattingItemLogo.visibility = View.VISIBLE -// Glide -// .with(root.context) -// .load(logoResource) -// .into(ivChattingItemLogo) -// DrawableCompat -// .setTint( -// ivChattingItemBg.drawable, -// convertTeamColor( -// root.context, -// clubId, -// true, -// "chattingHome", -// ), -// ) -// } catch (e: Exception) { -// ivChattingItemLogo.visibility = View.GONE -// Glide -// .with(root.context) -// .load(chatRoomInfo.chatRoomImage) -// .into(ivChattingItemBg) -// } - val clubId = chatRoomInfo.board.cheerClub.clubId - val logoResource = convertTeamLogo(clubId) - ivChattingItemLogo.visibility = View.VISIBLE - Glide - .with(root.context) - .load(logoResource) - .into(ivChattingItemLogo) - DrawableCompat - .setTint( - ivChattingItemBg.drawable, - convertTeamColor( - root.context, - clubId, - true, - "chattingHome", - ), - ) tvChattingItemTitle.text = chatRoomInfo.board.title if (chatRoomInfo.lastMessage == null) { tvChattingItemNew.visibility = View.VISIBLE tvChattingItemPeopleCount.visibility = View.GONE + tvChattingItemLastChat.text = root.context.getString(R.string.chatting_start_message) + tvChattingItemUnreadMessageCount.visibility = View.GONE + tvChattingItemTime.text = formatLastChatTime(chatRoomInfo.createdAt) } else { tvChattingItemNew.visibility = View.GONE tvChattingItemPeopleCount.visibility = View.VISIBLE tvChattingItemPeopleCount.text = chatRoomInfo.board.currentPerson.toString() - } - - if (chatRoomInfo.lastMessage == null) { - tvChattingItemLastChat.text = root.context.getString(R.string.chatting_start_message) - tvChattingItemTime.text = "방금" - tvChattingItemUnreadMessageCount.visibility = View.GONE - } else { tvChattingItemLastChat.text = chatRoomInfo.lastMessage?.content tvChattingItemTime.text = formatLastChatTime(chatRoomInfo.lastMessage?.createdAt!!) -// if (chatRoomInfo.unreadMessageCount == 0) { -// tvChattingItemUnreadMessageCount.visibility = View.GONE -// } else { -// tvChattingItemUnreadMessageCount.visibility = View.VISIBLE -// tvChattingItemUnreadMessageCount.text = chatRoomInfo.unreadMessageCount.toString() -// } + if (chatRoomInfo.unreadCount == 0L) { + tvChattingItemUnreadMessageCount.visibility = View.GONE + } else { + tvChattingItemUnreadMessageCount.visibility = View.VISIBLE + tvChattingItemUnreadMessageCount.text = chatRoomInfo.unreadCount.toString() + } } } } diff --git a/CatchMate/presentation/src/main/java/com/catchmate/presentation/view/chatting/ChattingSettingFragment.kt b/CatchMate/presentation/src/main/java/com/catchmate/presentation/view/chatting/ChattingSettingFragment.kt index 7650175f..0ad8e065 100644 --- a/CatchMate/presentation/src/main/java/com/catchmate/presentation/view/chatting/ChattingSettingFragment.kt +++ b/CatchMate/presentation/src/main/java/com/catchmate/presentation/view/chatting/ChattingSettingFragment.kt @@ -17,7 +17,6 @@ import androidx.navigation.fragment.findNavController import androidx.recyclerview.widget.LinearLayoutManager import com.bumptech.glide.Glide import com.catchmate.domain.model.chatting.GetChattingCrewListResponse -import com.catchmate.domain.model.user.GetUserProfileResponse import com.catchmate.presentation.R import com.catchmate.presentation.databinding.FragmentChattingSettingBinding import com.catchmate.presentation.interaction.OnKickOutClickListener @@ -38,7 +37,7 @@ class ChattingSettingFragment : private lateinit var chattingCrewAdapter: ChattingCrewListAdapter private lateinit var chattingRoomImage: String - private lateinit var chattingCrewList: MutableList + private lateinit var chattingCrewList: MutableList private var loginUserId: Long = -1L private var writerId: Long = -1L private var chatRoomId: Long = -1L @@ -69,12 +68,16 @@ class ChattingSettingFragment : private fun getChattingRoomImage(): String = arguments?.getString("chattingRoomImage") ?: "" - private fun getChattingCrewList(): MutableList? = + private fun getChattingCrewList(): MutableList? = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - arguments?.getParcelable("chattingCrewList", GetChattingCrewListResponse::class.java)?.userInfoList?.toMutableList() + arguments + ?.getParcelableArrayList( + "chattingCrewList", + GetChattingCrewListResponse::class.java, + )?.toMutableList() } else { - val parcelable = arguments?.getParcelable("chattingCrewList") as GetChattingCrewListResponse? - parcelable?.userInfoList?.toMutableList() + val parcelable = arguments?.getParcelableArrayList("chattingCrewList") + parcelable?.toMutableList() } private fun getLoginUserId(): Long = arguments?.getLong("loginUserId") ?: -1L @@ -95,18 +98,14 @@ class ChattingSettingFragment : private fun initViewModel() { chattingSettingViewModel.kickOutChattingCrewResponse.observe(viewLifecycleOwner) { response -> - if (response.state) { - Log.i("강퇴 성공", "✅ $deletedCrewId \n $chattingCrewList") - chattingCrewList = chattingCrewList.filter { it.userId != deletedCrewId }.toMutableList() - Log.i("crew list", "$chattingCrewList") - chattingCrewAdapter.submitList(chattingCrewList) - } + Log.i("강퇴 성공", "✅ $deletedCrewId \n $chattingCrewList") + chattingCrewList = chattingCrewList.filter { it.userId != deletedCrewId }.toMutableList() + Log.i("crew list", "$chattingCrewList") + chattingCrewAdapter.submitList(chattingCrewList) } chattingSettingViewModel.patchChattingRoomImageResponse.observe(viewLifecycleOwner) { response -> - if (response.state) { - Log.d("📸채팅방 프로필 변경 성공", "성공") - binding.ivChattingSettingThumbnail.setImageBitmap(updatedBitmap) - } + Log.d("📸채팅방 프로필 변경 성공", "성공") + binding.ivChattingSettingThumbnail.setImageBitmap(updatedBitmap) } chattingSettingViewModel.navigateToLogin.observe(viewLifecycleOwner) { isTrue -> if (isTrue) { diff --git a/CatchMate/presentation/src/main/java/com/catchmate/presentation/view/post/ReadPostFragment.kt b/CatchMate/presentation/src/main/java/com/catchmate/presentation/view/post/ReadPostFragment.kt index db1379ae..c5676bf4 100644 --- a/CatchMate/presentation/src/main/java/com/catchmate/presentation/view/post/ReadPostFragment.kt +++ b/CatchMate/presentation/src/main/java/com/catchmate/presentation/view/post/ReadPostFragment.kt @@ -17,8 +17,10 @@ import androidx.fragment.app.viewModels import androidx.navigation.NavOptions import androidx.navigation.fragment.findNavController import com.bumptech.glide.Glide +import com.catchmate.domain.model.board.Board import com.catchmate.domain.model.board.BoardMode import com.catchmate.domain.model.board.GetBoardResponse +import com.catchmate.domain.model.chatting.ChatRoomInfo import com.catchmate.domain.model.enroll.PostEnrollRequest import com.catchmate.domain.model.enumclass.EnrollState import com.catchmate.domain.model.user.GetUserProfileResponse @@ -219,8 +221,29 @@ class ReadPostFragment : BaseFragment(FragmentReadPostB } EnrollState.VIEW_CHAT -> { + val chatRoomInfo = + ChatRoomInfo( + chatRoomId = readPostViewModel.getBoardResponse.value?.chatRoomId!!, + board = + Board( + boardId = readPostViewModel.getBoardResponse.value?.boardId!!, + title = readPostViewModel.getBoardResponse.value?.title!!, + content = readPostViewModel.getBoardResponse.value?.content!!, + currentPerson = readPostViewModel.getBoardResponse.value?.currentPerson!!, + maxPerson = readPostViewModel.getBoardResponse.value?.maxPerson!!, + bookMarked = readPostViewModel.getBoardResponse.value?.bookMarked!!, + cheerClub = readPostViewModel.getBoardResponse.value?.cheerClub!!, + gameResponse = readPostViewModel.getBoardResponse.value?.game!!, + userResponse = readPostViewModel.getBoardResponse.value?.user!!, + ), + lastMessage = null, + unreadCount = 0, + chatRoomImageUrl = null, + createdAt = "", + notificationOn = true, + ) val bundle = Bundle() - bundle.putLong("chatRoomId", readPostViewModel.getBoardResponse.value?.chatRoomId!!) + bundle.putParcelable("chatRoomInfo", chatRoomInfo) findNavController().navigate(R.id.action_readPostFragment_to_chattingRoomFragment, bundle) } diff --git a/CatchMate/presentation/src/main/java/com/catchmate/presentation/viewmodel/ChattingHomeViewModel.kt b/CatchMate/presentation/src/main/java/com/catchmate/presentation/viewmodel/ChattingHomeViewModel.kt index 653327d5..190279de 100644 --- a/CatchMate/presentation/src/main/java/com/catchmate/presentation/viewmodel/ChattingHomeViewModel.kt +++ b/CatchMate/presentation/src/main/java/com/catchmate/presentation/viewmodel/ChattingHomeViewModel.kt @@ -1,26 +1,20 @@ package com.catchmate.presentation.viewmodel import android.util.Log -import androidx.core.content.ContextCompat -import androidx.core.content.ContextCompat.getString import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.catchmate.domain.exception.ReissueFailureException -import com.catchmate.domain.model.chatting.DeleteChattingRoomResponse import com.catchmate.domain.model.chatting.GetChattingRoomListResponse -import com.catchmate.domain.model.chatting.LastMessageInfo import com.catchmate.domain.usecase.chatting.GetChattingRoomListUseCase import com.catchmate.domain.usecase.chatting.LeaveChattingRoomUseCase import com.catchmate.presentation.BuildConfig -import com.catchmate.presentation.R import dagger.hilt.android.lifecycle.HiltViewModel import io.reactivex.disposables.Disposable import kotlinx.coroutines.launch import okhttp3.OkHttpClient import okhttp3.logging.HttpLoggingInterceptor -import org.json.JSONObject import ua.naiksoftware.stomp.Stomp import ua.naiksoftware.stomp.StompClient import ua.naiksoftware.stomp.dto.LifecycleEvent @@ -41,8 +35,8 @@ class ChattingHomeViewModel val getChattingRoomListResponse: LiveData get() = _getChattingRoomListResponse - private val _leaveChattingRoomResponse = MutableLiveData() - val leaveChattingRoomResponse: LiveData + private val _leaveChattingRoomResponse = MutableLiveData() + val leaveChattingRoomResponse: LiveData get() = _leaveChattingRoomResponse private val _errorMessage = MutableLiveData() @@ -158,9 +152,9 @@ class ChattingHomeViewModel } } - fun leaveChattingRoom(chatRoomId: Long) { + fun leaveChattingRoom(roomId: Long) { viewModelScope.launch { - val result = leaveChattingRoomUseCase(chatRoomId) + val result = leaveChattingRoomUseCase(roomId) result .onSuccess { response -> _leaveChattingRoomResponse.value = response diff --git a/CatchMate/presentation/src/main/java/com/catchmate/presentation/viewmodel/ChattingRoomViewModel.kt b/CatchMate/presentation/src/main/java/com/catchmate/presentation/viewmodel/ChattingRoomViewModel.kt index cebd5daf..ef1ebc9b 100644 --- a/CatchMate/presentation/src/main/java/com/catchmate/presentation/viewmodel/ChattingRoomViewModel.kt +++ b/CatchMate/presentation/src/main/java/com/catchmate/presentation/viewmodel/ChattingRoomViewModel.kt @@ -6,21 +6,14 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.catchmate.domain.exception.ReissueFailureException -import com.catchmate.domain.model.chatting.ChatMessageId -import com.catchmate.domain.model.chatting.ChatMessageInfo import com.catchmate.domain.model.chatting.ChatRoomInfo -import com.catchmate.domain.model.chatting.DeleteChattingRoomResponse import com.catchmate.domain.model.chatting.GetChattingCrewListResponse -import com.catchmate.domain.model.chatting.GetChattingHistoryResponse -import com.catchmate.domain.model.chatting.PutChattingRoomAlarmResponse -import com.catchmate.domain.model.enumclass.ChatMessageType +import com.catchmate.domain.model.chatting.GetChattingMessagesResponse +import com.catchmate.domain.model.chatting.PutChattingRoomAlarmRequest import com.catchmate.domain.usecase.chatting.GetChattingCrewListUseCase -import com.catchmate.domain.usecase.chatting.GetChattingHistoryUseCase -import com.catchmate.domain.usecase.chatting.GetChattingRoomInfoUseCase -import com.catchmate.domain.usecase.chatting.LeaveChattingRoomUseCase +import com.catchmate.domain.usecase.chatting.GetChattingMessagesUseCase import com.catchmate.domain.usecase.chatting.PutChattingRoomAlarmUseCase import com.catchmate.presentation.BuildConfig -import com.catchmate.presentation.util.DateUtils.getCurrentTimeFormatted import dagger.hilt.android.lifecycle.HiltViewModel import io.reactivex.disposables.Disposable import kotlinx.coroutines.launch @@ -30,40 +23,39 @@ import org.json.JSONObject import ua.naiksoftware.stomp.Stomp import ua.naiksoftware.stomp.StompClient import ua.naiksoftware.stomp.dto.LifecycleEvent +import ua.naiksoftware.stomp.dto.StompHeader import javax.inject.Inject @HiltViewModel class ChattingRoomViewModel @Inject constructor( - private val getChattingHistoryUseCase: GetChattingHistoryUseCase, + private val getChattingMessagesUseCase: GetChattingMessagesUseCase, private val getChattingCrewListUseCase: GetChattingCrewListUseCase, - private val getChattingRoomInfoUseCase: GetChattingRoomInfoUseCase, - private val deleteChattingRoomUseCase: LeaveChattingRoomUseCase, private val putChattingRoomAlarmUseCase: PutChattingRoomAlarmUseCase, ) : ViewModel() { var topic: Disposable? = null var stompClient: StompClient? = null private var okHttpClient: OkHttpClient? = null - private val _getChattingHistoryResponse = MutableLiveData() - val getChattingHistoryResponse: LiveData - get() = _getChattingHistoryResponse + private val _getChattingMessagesResponse = MutableLiveData>() + val getChattingMessagesResponse: LiveData> + get() = _getChattingMessagesResponse - private val _getChattingCrewListResponse = MutableLiveData() - val getChattingCrewListResponse: LiveData + private val _getChattingCrewListResponse = MutableLiveData>() + val getChattingCrewListResponse: LiveData> get() = _getChattingCrewListResponse private val _chattingRoomInfo = MutableLiveData() val chattingRoomInfo: LiveData get() = _chattingRoomInfo - private val _deleteChattingRoomResponse = MutableLiveData() - val deleteChattingRoomResponse: LiveData - get() = _deleteChattingRoomResponse + private val _isLeft = MutableLiveData() + val isLeft: LiveData + get() = _isLeft - private val _putChattingRoomAlarmResponse = MutableLiveData() - val putChattingRoomAlarmResponse: LiveData + private val _putChattingRoomAlarmResponse = MutableLiveData() + val putChattingRoomAlarmResponse: LiveData get() = _putChattingRoomAlarmResponse private val _errorMessage = MutableLiveData() @@ -82,10 +74,13 @@ class ChattingRoomViewModel val isInstability: LiveData get() = _isInstability + fun setChatRoomInfo(info: ChatRoomInfo) { + _chattingRoomInfo.value = info + } + /** WebSocket 연결 */ fun connectToWebSocket( chatRoomId: Long, - userId: Long, accessToken: String, ) { viewModelScope.launch { @@ -100,8 +95,7 @@ class ChattingRoomViewModel val headerMap = mapOf( - "AccessToken" to accessToken, - "ChatRoomId" to chatRoomId.toString(), + "Authorization" to accessToken, ) stompClient = @@ -116,13 +110,16 @@ class ChattingRoomViewModel withServerHeartbeat(35000) } - stompClient?.connect() + val stompHeaders = + listOf( + StompHeader("Authorization", accessToken), + ) stompClient?.lifecycle()?.subscribe({ event -> when (event.type) { LifecycleEvent.Type.OPENED -> { Log.d("Web Socket✅", "연결 성공") - handleWebSocketOpened(chatRoomId, userId) + handleWebSocketOpened(chatRoomId) } LifecycleEvent.Type.CLOSED -> { @@ -130,7 +127,7 @@ class ChattingRoomViewModel } LifecycleEvent.Type.ERROR -> { - Log.i("Web Socket", "${event.exception.message}") + Log.i("Web Socket", "${event.exception}") _isInstability.postValue(true) } @@ -140,83 +137,58 @@ class ChattingRoomViewModel Log.i("Web Socket", "${error.message}") _isInstability.postValue(true) }) + + stompClient?.connect(stompHeaders) } } - private fun handleWebSocketOpened( - chatRoomId: Long, - userId: Long, - ) { + private fun handleWebSocketOpened(chatRoomId: Long) { // 채팅방 구독 topic = - stompClient?.topic("/topic/chat.$chatRoomId")?.subscribe({ message -> + stompClient?.topic("/sub/chat/room/$chatRoomId")?.subscribe({ message -> Log.i("✅ Msg", message.payload) val jsonObject = JSONObject(message.payload) + val messageId = jsonObject.getLong("messageId") + val roomId = jsonObject.getLong("roomId") + val senderId = jsonObject.getLong("senderId") + val senderNickname = jsonObject.getString("senderNickname") + val senderProfileImage = jsonObject.getString("senderProfileImage") + val content = jsonObject.getString("content") val messageType = jsonObject.getString("messageType") - val chatMessageInfo: ChatMessageInfo = - when (messageType) { - ChatMessageType.DATE.name -> { - val roomId = jsonObject.getString("chatRoomId").toLong() - val content = jsonObject.getString("content") - val senderId = jsonObject.getString("senderId").toLong() - ChatMessageInfo( - chatMessageId = "", - roomId = roomId, - content = content, - senderId = senderId, - messageType = messageType, - ) - } - - ChatMessageType.TALK.name -> { - val chatMessageId = jsonObject.getString("chatMessageId") - val senderId = jsonObject.getString("senderId").toLong() - val content = jsonObject.getString("content") - val roomId = jsonObject.getString("roomId").toLong() - val id = ChatMessageId(date = getCurrentTimeFormatted()) - ChatMessageInfo( - id = id, - chatMessageId = chatMessageId, - roomId = roomId, - content = content, - senderId = senderId, - messageType = messageType, - ) - } - - else -> { // 채팅방 나가고 들어올때 메시지 처리하기 - ChatMessageInfo(chatMessageId = "", roomId = -1L, content = "", senderId = -1L, messageType = "") - } - } - addChatMessage(chatMessageInfo) - sendIsMsgRead(chatRoomId, userId) + val createdAt = jsonObject.getString("createdAt") + val chatMessage = + GetChattingMessagesResponse( + messageId = messageId, + chatRoomId = roomId, + senderId = senderId, + senderNickName = senderNickname, + senderProfileImageUrl = senderProfileImage, + content = content, + messageType = messageType, + createdAt = createdAt, + ) + addChatMessage(chatMessage) + sendIsMsgRead(chatRoomId) }, { error -> Log.i("ws opened", "chatroom subscribe error / ${error.printStackTrace()}", error) }) } - private fun sendIsMsgRead( - chatRoomId: Long, - userId: Long, - ) { + private fun sendIsMsgRead(chatRoomId: Long) { viewModelScope.launch { val msg = JSONObject() .apply { put("chatRoomId", chatRoomId) - put("userId", userId) }.toString() - stompClient?.send("/app/chat/read", msg)?.subscribe() + stompClient?.send("/pub/chat/read", msg)?.subscribe() } } - fun sendMessage( - chatRoomId: Long, - message: String, - ) { + fun sendMessage(request: String) { // 전달 성공 시 view의 edt 텍스트 비우기 viewModelScope.launch { - stompClient?.send("/app/chat.$chatRoomId", message)?.subscribe({ + stompClient?.send("/pub/chat/message", request)?.subscribe({ Log.d("Web Socket📬", "메시지 전달") _isMessageSent.value = true }, { error -> @@ -226,39 +198,64 @@ class ChattingRoomViewModel } } + fun leaveChattingRoom(request: String) { + viewModelScope.launch { + stompClient?.send("/pub/chat/leave", request)?.subscribe({ + Log.d("Web Socket🚪", "방 탈퇴") + _isLeft.value = true + }, { error -> + Log.d("Web Socket🚪❌", "방 탈퇴 실패", error) + _isLeft.value = false + }) + } + } + + fun sendEnterRequest(chatRoomId: Long) { + viewModelScope.launch { + val request = + JSONObject() + .apply { + put("chatRoomId", chatRoomId) + }.toString() + stompClient?.send("/pub/chat/enter", request)?.subscribe({ + Log.d("Web Socket🪟", "입장 알림 성공") + }, { error -> + Log.d("Web Socket🪟❌", "입장 알림 실패", error) + }) + } + } + override fun onCleared() { super.onCleared() topic?.dispose() stompClient?.disconnect() } - private fun addChatMessage(chatMessageInfo: ChatMessageInfo) { - val currentList = _getChattingHistoryResponse.value?.chatMessageInfoList ?: emptyList() - val updatedList = listOf(chatMessageInfo) + currentList - - val updatedResponse = - _getChattingHistoryResponse.value?.copy( - chatMessageInfoList = updatedList, - ) ?: GetChattingHistoryResponse( - chatMessageInfoList = updatedList, - isFirst = true, - isLast = true, - lastMessageId = updatedList.last().chatMessageId, - ) - - _getChattingHistoryResponse.postValue(updatedResponse) + private fun addChatMessage(chatMessage: GetChattingMessagesResponse) { + val currentList = _getChattingMessagesResponse.value ?: emptyList() + val updatedList = listOf(chatMessage) + currentList + + _getChattingMessagesResponse.postValue(updatedList) } - fun getChattingHistory( + fun getChattingMessages( chatRoomId: Long, - lastMessageId: String? = null, - size: Int? = 20, + lastMessageId: Long? = null, + size: Int = 20, + userId: Long, ) { viewModelScope.launch { - val result = getChattingHistoryUseCase(chatRoomId, lastMessageId, size) + val result = getChattingMessagesUseCase(chatRoomId, lastMessageId, size) result .onSuccess { response -> - _getChattingHistoryResponse.value = response + _getChattingMessagesResponse.value = response + val hasEnterMsg = + response.any { + it.messageType == "SYSTEM" && it.senderId == userId + } + if (response.isEmpty() || !hasEnterMsg) { + sendEnterRequest(chatRoomId) + } }.onFailure { exception -> if (exception is ReissueFailureException) { _navigateToLogin.value = true @@ -285,44 +282,12 @@ class ChattingRoomViewModel } } - fun getChattingRoomInfo(chatRoomId: Long) { - viewModelScope.launch { - val result = getChattingRoomInfoUseCase(chatRoomId) - result - .onSuccess { info -> - _chattingRoomInfo.value = info - }.onFailure { exception -> - if (exception is ReissueFailureException) { - _navigateToLogin.value = true - } else { - _errorMessage.value = exception.message - } - } - } - } - - fun deleteChattingRoom(chatRoomId: Long) { - viewModelScope.launch { - val result = deleteChattingRoomUseCase(chatRoomId) - result - .onSuccess { response -> - _deleteChattingRoomResponse.value = response - }.onFailure { exception -> - if (exception is ReissueFailureException) { - _navigateToLogin.value = true - } else { - _errorMessage.value = exception.message - } - } - } - } - fun putChattingRoomAlarm( - chatRoomId: Long, - enable: Boolean, + roomId: Long, + request: PutChattingRoomAlarmRequest, ) { viewModelScope.launch { - val result = putChattingRoomAlarmUseCase(chatRoomId, enable) + val result = putChattingRoomAlarmUseCase(roomId, request) result .onSuccess { response -> _putChattingRoomAlarmResponse.value = response diff --git a/CatchMate/presentation/src/main/java/com/catchmate/presentation/viewmodel/ChattingSettingViewModel.kt b/CatchMate/presentation/src/main/java/com/catchmate/presentation/viewmodel/ChattingSettingViewModel.kt index 47be0931..f155905c 100644 --- a/CatchMate/presentation/src/main/java/com/catchmate/presentation/viewmodel/ChattingSettingViewModel.kt +++ b/CatchMate/presentation/src/main/java/com/catchmate/presentation/viewmodel/ChattingSettingViewModel.kt @@ -5,8 +5,6 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.catchmate.domain.exception.ReissueFailureException -import com.catchmate.domain.model.chatting.DeleteChattingCrewKickOutResponse -import com.catchmate.domain.model.chatting.PatchChattingRoomImageResponse import com.catchmate.domain.usecase.chatting.KickOutChattingCrewUseCase import com.catchmate.domain.usecase.chatting.PatchChattingRoomImageUseCase import dagger.hilt.android.lifecycle.HiltViewModel @@ -21,12 +19,12 @@ class ChattingSettingViewModel private val kickOutChattingCrewUseCase: KickOutChattingCrewUseCase, private val patchChattingRoomImageUseCase: PatchChattingRoomImageUseCase, ) : ViewModel() { - private val _kickOutChattingCrewResponse = MutableLiveData() - val kickOutChattingCrewResponse: LiveData + private val _kickOutChattingCrewResponse = MutableLiveData() + val kickOutChattingCrewResponse: LiveData get() = _kickOutChattingCrewResponse - private val _patchChattingRoomImageResponse = MutableLiveData() - val patchChattingRoomImageResponse: LiveData + private val _patchChattingRoomImageResponse = MutableLiveData() + val patchChattingRoomImageResponse: LiveData get() = _patchChattingRoomImageResponse private val _errorMessage = MutableLiveData() @@ -57,11 +55,11 @@ class ChattingSettingViewModel } fun patchChattingRoomImage( - chatRoomId: Long, + roomId: Long, chatRoomImage: MultipartBody.Part, ) { viewModelScope.launch { - val result = patchChattingRoomImageUseCase(chatRoomId, chatRoomImage) + val result = patchChattingRoomImageUseCase(roomId, chatRoomImage) result .onSuccess { response -> _patchChattingRoomImageResponse.value = response