Skip to content

Commit

Permalink
fix(chat): fix infinite loop when loading chat
Browse files Browse the repository at this point in the history
  • Loading branch information
outadoc committed Oct 14, 2024
1 parent ed353a0 commit 8b92857
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,20 +292,20 @@ internal class ChatViewModel(
}
}
.distinctUntilChanged()
.onEach { userId ->
twitchRepository.markChannelAsVisited(
userId = userId,
visitedAt = clock.now(),
)
}
.flatMapLatest { userId ->
twitchRepository.getUserById(userId)
}
.onEach { result ->
result
.onSuccess { user ->
actions.emit(Action.UpdateUser(user))

twitchRepository.markChannelAsVisited(
channel = user,
visitedAt = clock.now(),
)

createShortcutForChannel(user)
actions.emit(Action.UpdateUser(user))
}
.onFailure { exception ->
logError<ChatViewModel>(exception) { "Failed to load user" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal interface TwitchRepository {
timeZone: TimeZone,
): Flow<FullSchedule>

suspend fun markChannelAsVisited(channel: User, visitedAt: Instant)
suspend fun markChannelAsVisited(userId: String, visitedAt: Instant)

suspend fun getGlobalBadges(): Result<List<TwitchBadge>>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ internal class TwitchRepositoryImpl(
}
}

override suspend fun markChannelAsVisited(channel: User, visitedAt: Instant) {
override suspend fun markChannelAsVisited(userId: String, visitedAt: Instant) {
withContext(DispatchersProvider.io) {
localUsersApi.saveUser(
userId = channel.id,
userId = userId,
visitedAt = visitedAt,
)
}
Expand Down

0 comments on commit 8b92857

Please sign in to comment.