Skip to content

Commit 8aedb16

Browse files
authored
Merge pull request #146 from rbqks529/refactor/#145_QA
[FEAT] 미확인 알림 여부 확인 api 연결
2 parents 5b5996f + 363c9a8 commit 8aedb16

File tree

7 files changed

+52
-12
lines changed

7 files changed

+52
-12
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.texthip.thip.data.model.notification.response
2+
3+
import kotlinx.serialization.SerialName
4+
import kotlinx.serialization.Serializable
5+
6+
@Serializable
7+
data class NotificationExistsUncheckedResponse(
8+
@SerialName("exists") val exists: Boolean
9+
)

app/src/main/java/com/texthip/thip/data/repository/NotificationRepository.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.texthip.thip.data.model.notification.request.NotificationCheckRequest
99
import com.texthip.thip.data.model.notification.response.NotificationEnabledResponse
1010
import com.texthip.thip.data.model.notification.response.NotificationListResponse
1111
import com.texthip.thip.data.model.notification.response.NotificationCheckResponse
12+
import com.texthip.thip.data.model.notification.response.NotificationExistsUncheckedResponse
1213
import com.texthip.thip.data.service.NotificationService
1314
import com.texthip.thip.utils.auth.getAppScopeDeviceId
1415
import dagger.hilt.android.qualifiers.ApplicationContext
@@ -108,4 +109,11 @@ class NotificationRepository @Inject constructor(
108109
fun onNotificationReceived() {
109110
_notificationRefreshFlow.tryEmit(Unit)
110111
}
112+
113+
suspend fun existsUncheckedNotifications(): Result<NotificationExistsUncheckedResponse?> {
114+
return runCatching {
115+
val response = notificationService.existsUncheckedNotifications()
116+
response.handleBaseResponse().getOrNull()
117+
}
118+
}
111119
}

app/src/main/java/com/texthip/thip/data/service/NotificationService.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.texthip.thip.data.model.notification.request.NotificationCheckRequest
77
import com.texthip.thip.data.model.notification.response.NotificationEnabledResponse
88
import com.texthip.thip.data.model.notification.response.NotificationListResponse
99
import com.texthip.thip.data.model.notification.response.NotificationCheckResponse
10+
import com.texthip.thip.data.model.notification.response.NotificationExistsUncheckedResponse
1011
import com.texthip.thip.data.model.base.BaseResponse
1112
import retrofit2.http.Body
1213
import retrofit2.http.DELETE
@@ -46,4 +47,7 @@ interface NotificationService {
4647
suspend fun checkNotification(
4748
@Body request: NotificationCheckRequest
4849
): BaseResponse<NotificationCheckResponse>
50+
51+
@GET("notifications/exists-unchecked")
52+
suspend fun existsUncheckedNotifications(): BaseResponse<NotificationExistsUncheckedResponse>
4953
}

app/src/main/java/com/texthip/thip/ui/common/alarmpage/viewmodel/AlarmUiState.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ data class AlarmUiState(
99
val isLoading: Boolean = false,
1010
val isLoadingMore: Boolean = false,
1111
val hasMore: Boolean = true,
12-
val error: String? = null
12+
val error: String? = null,
13+
val hasUnreadNotifications: Boolean = false // API에서 가져온 읽지 않은 알림 존재 여부
1314
) {
1415
val canLoadMore: Boolean get() = !isLoading && !isLoadingMore && hasMore
15-
val hasUnreadNotifications: Boolean get() = notifications.any { !it.isChecked }
1616
}

app/src/main/java/com/texthip/thip/ui/common/alarmpage/viewmodel/AlarmViewModel.kt

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,20 @@ class AlarmViewModel @Inject constructor(
3131
}
3232

3333
init {
34-
loadNotifications(reset = true)
34+
checkUnreadNotifications()
3535

3636
// Repository의 알림 업데이트 이벤트 구독
3737
viewModelScope.launch {
3838
repository.notificationUpdateFlow.collect { notificationId ->
3939
updateNotificationAsRead(notificationId)
40+
checkUnreadNotifications()
4041
}
4142
}
4243

43-
// 푸시 알림 도착 시 새로고침 이벤트 구독
44+
// 푸시 알림 도착 시 아이콘 상태만 갱신
4445
viewModelScope.launch {
4546
repository.notificationRefreshFlow.collect {
46-
refreshData()
47+
checkUnreadNotifications()
4748
}
4849
}
4950
}
@@ -54,14 +55,14 @@ class AlarmViewModel @Inject constructor(
5455
loadJob?.cancel()
5556
loadJob = null
5657
}
57-
58+
5859
// 중복 로드 방지 (reset이 아닌 경우에만)
5960
if (isLoadingData && !reset) return
6061
if (isLastPage && !reset) return
6162

6263
// launch 전에 isLoadingData 선반영 (플리커 방지)
6364
isLoadingData = true
64-
65+
6566
// UI 상태 즉시 반영
6667
if (reset) {
6768
updateState {
@@ -126,6 +127,7 @@ class AlarmViewModel @Inject constructor(
126127

127128
fun refreshData() {
128129
loadNotifications(reset = true)
130+
checkUnreadNotifications()
129131
}
130132

131133
fun changeNotificationType(notificationType: NotificationType) {
@@ -161,4 +163,21 @@ class AlarmViewModel @Inject constructor(
161163
}
162164
updateState { it.copy(notifications = updatedNotifications) }
163165
}
166+
167+
fun checkUnreadNotifications() {
168+
viewModelScope.launch {
169+
repository.existsUncheckedNotifications()
170+
.onSuccess { response ->
171+
response?.let {
172+
updateState { state ->
173+
state.copy(hasUnreadNotifications = it.exists)
174+
}
175+
}
176+
}
177+
.onFailure { exception ->
178+
// 에러 발생 시 기존 상태 유지 (로그만 남김)
179+
updateState { it.copy(error = exception.message) }
180+
}
181+
}
182+
}
164183
}

app/src/main/java/com/texthip/thip/ui/feed/screen/FeedScreen.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ fun FeedScreen(
224224
LaunchedEffect(onFeedTabReselected) {
225225
if (onFeedTabReselected > 0) {
226226
feedViewModel.refreshOnBottomNavReselect()
227-
alarmViewModel.refreshData()
227+
alarmViewModel.checkUnreadNotifications()
228228
currentListState.scrollToItem(0)
229229
}
230230
}
@@ -288,7 +288,7 @@ fun FeedScreen(
288288
onChangeFeedSave = feedViewModel::changeFeedSave,
289289
onPullToRefresh = {
290290
feedViewModel.pullToRefresh()
291-
alarmViewModel.refreshData()
291+
alarmViewModel.checkUnreadNotifications()
292292
}
293293
)
294294
}

app/src/main/java/com/texthip/thip/ui/group/screen/GroupScreen.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fun GroupScreen(
6464
// 화면 재진입 시 데이터 새로고침
6565
LaunchedEffect(Unit) {
6666
viewModel.resetToInitialState()
67-
alarmViewModel.refreshData()
67+
alarmViewModel.checkUnreadNotifications()
6868
}
6969
val uiState by viewModel.uiState.collectAsState()
7070
val alarmUiState by alarmViewModel.uiState.collectAsState()
@@ -80,9 +80,9 @@ fun GroupScreen(
8080
onNavigateToGroupRecruit = onNavigateToGroupRecruit,
8181
onNavigateToGroupRoom = onNavigateToGroupRoom,
8282
onNavigateToGroupSearchAllRooms = onNavigateToGroupSearchAllRooms,
83-
onRefreshGroupData = {
83+
onRefreshGroupData = {
8484
viewModel.refreshGroupData()
85-
alarmViewModel.refreshData()
85+
alarmViewModel.checkUnreadNotifications()
8686
},
8787
onCardVisible = { cardIndex -> viewModel.loadMoreGroups() },
8888
onSelectGenre = { genreIndex -> viewModel.selectGenre(genreIndex) },

0 commit comments

Comments
 (0)