Skip to content

Commit

Permalink
Merge branch 'develop' into fix/url-link
Browse files Browse the repository at this point in the history
  • Loading branch information
JcMinarro committed Jul 5, 2024
2 parents 11d6f07 + 418d012 commit 38c1d01
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 10 deletions.
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 @@ -81,6 +85,7 @@
## stream-chat-android-compose
### 🐞 Fixed
- Fixed the url used when click on the link. [#5314](https://github.com/GetStream/stream-chat-android/pull/5314)
- 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

0 comments on commit 38c1d01

Please sign in to comment.