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

[PBE-4795] fix pinned messages on message deletion #5315

Merged
merged 2 commits into from
Jul 5, 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- Added `ChatClient.getThreads` to fetch threads for the current users. [#5264](https://github.com/GetStream/stream-chat-android/pull/5264)
- Added `ChatClient.sendPoll`, `ChatClient.castVotePoll`, `ChatClient.closePoll` and `ChatClient.removePollVote` methods to interact with Polls. [#5273](https://github.com/GetStream/stream-chat-android/pull/5273)
- Added new `ChatEvents` related with Polls. [#5273](https://github.com/GetStream/stream-chat-android/pull/5273)
- Added pinned messages parsing. [#5306](https://github.com/GetStream/stream-chat-android/pull/5306)

### ⚠️ Changed

Expand All @@ -44,8 +45,10 @@
### ⬆️ Improved

### ✅ Added
- Added `ChannelState.pinnedMessage` to obtain the pinned message in a channel. [#5306](https://github.com/GetStream/stream-chat-android/pull/5306)

### ⚠️ Changed
- Delete a pinned message from the pinned list if it was deleted. [#5315](https://github.com/GetStream/stream-chat-android/pull/5315)

### ❌ Removed

Expand All @@ -56,6 +59,7 @@
### ⬆️ Improved

### ✅ Added
- Added pinned messages support to `MessageListController`. [#5306](https://github.com/GetStream/stream-chat-android/pull/5306)

### ⚠️ Changed

Expand All @@ -80,6 +84,7 @@

## stream-chat-android-compose
### 🐞 Fixed
- Fixed deleted pinned messages being highlighted as pinned. [#5315](https://github.com/GetStream/stream-chat-android/pull/5315)

### ⬆️ Improved
- Enabled Strong Skipping Mode for Compose compiler and improved Compose performance. [#5303](https://github.com/GetStream/stream-chat-android/pull/5303)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2864,6 +2864,7 @@ public final class io/getstream/chat/android/client/utils/message/MessageUtils {
public static final fun isGiphy (Lio/getstream/chat/android/models/Message;)Z
public static final fun isGiphyEphemeral (Lio/getstream/chat/android/models/Message;)Z
public static final fun isModerationError (Lio/getstream/chat/android/models/Message;Ljava/lang/String;)Z
public static final fun isPinnedAndNotDeleted (Lio/getstream/chat/android/models/Message;)Z
public static final fun isRegular (Lio/getstream/chat/android/models/Message;)Z
public static final fun isReply (Lio/getstream/chat/android/models/Message;)Z
public static final fun isSystem (Lio/getstream/chat/android/models/Message;)Z
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import androidx.work.workDataOf
import io.getstream.chat.android.client.ChatClient
import io.getstream.chat.android.client.R
import io.getstream.chat.android.client.api.models.QueryChannelRequest
import io.getstream.log.StreamLog
import io.getstream.log.taggedLogger
import io.getstream.result.call.zipWith

Expand All @@ -41,7 +42,7 @@ internal class LoadNotificationDataWorker(
workerParams: WorkerParameters,
) : CoroutineWorker(context, workerParams) {

private val logger by taggedLogger("Chat:Notifications-Loader")
private val logger by taggedLogger(TAG)

override suspend fun doWork(): Result {
val channelId: String = inputData.getString(DATA_CHANNEL_ID)!!
Expand All @@ -50,6 +51,8 @@ internal class LoadNotificationDataWorker(

setForeground(createForegroundInfo())

logger.d { "[doWork] cid: $channelType:$channelId, messageId: $messageId" }

return try {
val client: ChatClient = ChatClient.instance()
val getMessage = client.getMessage(messageId)
Expand All @@ -72,15 +75,16 @@ internal class LoadNotificationDataWorker(
client.getMessage(messageParentId).await()
}
ChatClient.displayNotification(channel = channel, message = message)
logger.v { "[doWork] completed" }
Result.success()
}
is io.getstream.result.Result.Failure -> {
logger.e { "Error while loading notification data: ${result.value}" }
logger.e { "[doWork] failed: ${result.value}" }
Result.failure()
}
}
} catch (exception: IllegalStateException) {
logger.e { "Error while loading notification data: ${exception.message}" }
logger.e { "[doWork] failed unexpectedly: ${exception.message}" }
Result.failure()
}
}
Expand Down Expand Up @@ -133,6 +137,7 @@ internal class LoadNotificationDataWorker(
}

internal companion object {
private const val TAG = "Chat:Notifications-Loader"
private const val DATA_CHANNEL_TYPE = "DATA_CHANNEL_TYPE"
private const val DATA_CHANNEL_ID = "DATA_CHANNEL_ID"
private const val DATA_MESSAGE_ID = "DATA_MESSAGE_ID"
Expand All @@ -146,6 +151,7 @@ internal class LoadNotificationDataWorker(
channelType: String,
messageId: String,
) {
StreamLog.d(TAG) { "/start/ cid: $channelType:$channelId, messageId: $messageId" }
val syncMessagesWork = OneTimeWorkRequestBuilder<LoadNotificationDataWorker>()
.setInputData(
workDataOf(
Expand All @@ -166,6 +172,7 @@ internal class LoadNotificationDataWorker(
}

fun cancel(context: Context) {
StreamLog.d(TAG) { "/cancel/ no args" }
WorkManager.getInstance(context).cancelUniqueWork(LOAD_NOTIFICATION_DATA_WORK_NAME)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public fun Message.isErrorOrFailed(): Boolean = isError() || isFailed()
*/
public fun Message.isDeleted(): Boolean = deletedAt != null

/**
* @return If the message is pinned and not deleted.
*/
public fun Message.isPinnedAndNotDeleted(): Boolean = pinned && !isDeleted()

/**
* @return If the message type is regular.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
import io.getstream.chat.android.client.utils.message.isDeleted
import io.getstream.chat.android.client.utils.message.isGiphyEphemeral
import io.getstream.chat.android.client.utils.message.isPinnedAndNotDeleted
import io.getstream.chat.android.client.utils.message.isThreadStart
import io.getstream.chat.android.compose.R
import io.getstream.chat.android.compose.state.mediagallerypreview.MediaGalleryPreviewResult
Expand Down Expand Up @@ -166,8 +167,10 @@ public fun MessageItem(
)
}

val backgroundColor =
if (focusState is MessageFocused || message.pinned) ChatTheme.colors.highlight else Color.Transparent
val backgroundColor = when (focusState is MessageFocused || message.isPinnedAndNotDeleted()) {
true -> ChatTheme.colors.highlight
else -> Color.Transparent
}
val shouldAnimateBackground = !message.pinned && focusState != null

val color = if (shouldAnimateBackground) {
Expand Down Expand Up @@ -270,7 +273,7 @@ internal fun DefaultMessageItemHeaderContent(
val message = messageItem.message
val currentUser = messageItem.currentUser

if (message.pinned) {
if (message.isPinnedAndNotDeleted()) {
val pinnedByUser = if (message.pinnedBy?.id == currentUser?.id) {
stringResource(id = R.string.stream_compose_message_list_you)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,17 @@ internal class ChannelLogic(
}

internal fun deleteMessage(message: Message) {
logger.d { "[deleteMessage] message.id: ${message.id}, message.text: ${message.text}" }
channelStateLogic.deleteMessage(message)
}

internal fun upsertMessage(message: Message) = channelStateLogic.upsertMessage(message)
internal fun upsertMessage(message: Message) {
logger.d { "[upsertMessage] message.id: ${message.id}, message.text: ${message.text}" }
channelStateLogic.upsertMessage(message)
}

internal fun upsertMessages(messages: List<Message>) {
logger.d { "[upsertMessages] messages.size: ${messages.size}" }
channelStateLogic.upsertMessages(messages)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import io.getstream.chat.android.client.events.UserStartWatchingEvent
import io.getstream.chat.android.client.events.UserStopWatchingEvent
import io.getstream.chat.android.client.extensions.internal.NEVER
import io.getstream.chat.android.client.setup.state.ClientState
import io.getstream.chat.android.client.utils.message.isDeleted
import io.getstream.chat.android.client.utils.message.isPinnedAndNotDeleted
import io.getstream.chat.android.client.utils.message.isReply
import io.getstream.chat.android.models.Channel
import io.getstream.chat.android.models.ChannelData
Expand Down Expand Up @@ -233,10 +235,10 @@ internal class ChannelStateLogic(

override fun delsertPinnedMessage(message: Message) {
logger.d {
"[delsertPinnedMessage] pinned: ${message.pinned}, message.id: ${message.id}" +
", message.text: ${message.text}"
"[delsertPinnedMessage] pinned: ${message.pinned}, deleted: ${message.isDeleted()}" +
", message.id: ${message.id}, message.text: ${message.text}"
}
if (message.pinned) {
if (message.isPinnedAndNotDeleted()) {
upsertPinnedMessages(listOf(message), false)
} else {
mutableState.deletePinnedMessage(message)
Expand Down
Loading