Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter Thread Message when LastMessageAt is calculated #5245

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Shadowed messages are filtered. [#5234](https://github.com/GetStream/stream-chat-android/pull/5234)

### ⬆️ Improved
- `Channel.lastMessageAt` is not updated when there is a new message within a thread. [#5245](https://github.com/GetStream/stream-chat-android/pull/5245)

### ✅ Added

Expand Down Expand Up @@ -59,6 +60,7 @@
### 🐞 Fixed

### ⬆️ Improved
- Channel List is not updated with new messages within a thread. [#5245](https://github.com/GetStream/stream-chat-android/pull/5245)

### ✅ Added
- Added a Button to jump to the first unread message in the channel. [#5236](https://github.com/GetStream/stream-chat-android/pull/5236)
Expand All @@ -72,6 +74,7 @@
- Fixed `ChannelsState.isLoadingMore` being stuck. [#5239](https://github.com/GetStream/stream-chat-android/pull/5239)

### ⬆️ Improved
- Channel List is not updated with new messages within a thread. [#5245](https://github.com/GetStream/stream-chat-android/pull/5245)

### ✅ Added

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ public fun Channel.updateLastMessage(
)
}
return this.copy(
lastMessageAt = newMessages.last().let { it.createdAt ?: it.createdLocallyAt },
lastMessageAt = newMessages
.filterNot { it.parentId != null && !it.showInChannel }
.last()
.let { it.createdAt ?: it.createdLocallyAt },
messages = newMessages,
read = newReads,
).syncUnreadCountWithReads()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public data class ChannelData(
cooldown = cooldown,
lastMessageAt = messagesList
.filterNot { it.shadowed }
.filterNot { it.parentId != null && !it.showInChannel }
.lastOrNull()
?.let { it.createdAt ?: it.createdLocallyAt },
createdBy = createdBy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,11 @@ internal class DatabaseChannelRepository(
insertChannel(
it.copy(
messages = listOf(lastMessage),
lastMessageAt = lastMessage.createdAt ?: lastMessage.createdLocallyAt ?: Date(0),
lastMessageAt = it.lastMessageAt
.takeIf { lastMessage.parentId != null && !lastMessage.showInChannel }
?: lastMessage.createdAt
?: lastMessage.createdLocallyAt
?: Date(0),
),
)
}
Expand All @@ -242,7 +246,10 @@ internal class DatabaseChannelRepository(
lastMessageAt = maxOf(
lastMessageAt,
cachedChannel.lastMessageAt,
messages.lastOrNull()?.let { it.createdAt ?: it.createdLocallyAt ?: Date(0) },
messages
.filterNot { it.parentId != null && !it.showInChannel }
.lastOrNull()
?.let { it.createdAt ?: it.createdLocallyAt ?: Date(0) },
),
hiddenMessagesBefore = hideMessagesBefore,
members = members,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ internal class ChannelRepositoryImplTest {
@Test
fun `Given channel without messages in DB, Should insert channel with updated last message`() = runTest {
val channel = randomChannel(messages = emptyList())
val lastMessage = randomMessage(createdAt = Date())
val lastMessage = randomMessage(createdAt = Date(), parentId = null)
whenever(channelDao.select("cid")) doReturn channel.toEntity()

channelRepository.updateLastMessageForChannel("cid", lastMessage)
Expand All @@ -89,8 +89,8 @@ internal class ChannelRepositoryImplTest {
fun `Given channel with outdated lastMessage in DB, Should insert channel with updated last message`() = runTest {
val before = Date(1000)
val after = Date(2000)
val outdatedMessage = randomMessage(id = "messageId1", createdAt = before)
val newLastMessage = randomMessage(id = "messageId2", createdAt = after)
val outdatedMessage = randomMessage(id = "messageId1", createdAt = before, parentId = null)
val newLastMessage = randomMessage(id = "messageId2", createdAt = after, parentId = null)
val channel = randomChannel(messages = listOf(outdatedMessage), lastMessageAt = before)
whenever(channelDao.select(cid = "cid")) doReturn channel.toEntity()

Expand Down
Loading