diff --git a/CHANGELOG.md b/CHANGELOG.md index a59900a53a7..8e54c76f565 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ - Added `ChatClient.inviteMembers` to invite members to an existing channel. [#4816](https://github.com/GetStream/stream-chat-android/pull/4816) - Added `ChannelClient.inviteMembers` to invite members to an existing channel. [#4816](https://github.com/GetStream/stream-chat-android/pull/4816) - Added `ChannelUserBannedEvent.shadow` property to know if the user is shadow-banned or standard banned. [#4836](https://github.com/GetStream/stream-chat-android/pull/4836) +- Added `AttachmentsVerifier` to verify if the uploaded attachments are valid. [#4852](https://github.com/GetStream/stream-chat-android/pull/4852) ### ⚠️ Changed - Changed `newMessageIntent` lambda's signature of `NotificationHandlerFactory.createNotificationHandler()`. It receives the whole `Message`/`Channel` entity to help you create a more complex navigation intent. diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/attachment/AttachmentsVerifier.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/attachment/AttachmentsVerifier.kt index 39ac1e92a11..fd00bd215ba 100644 --- a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/attachment/AttachmentsVerifier.kt +++ b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/attachment/AttachmentsVerifier.kt @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2014-2023 Stream.io Inc. All rights reserved. + * + * Licensed under the Stream License; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://github.com/GetStream/stream-chat-android/blob/main/LICENSE + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package io.getstream.chat.android.client.attachment import io.getstream.chat.android.models.Message @@ -15,15 +31,13 @@ internal class AttachmentsVerifier { val corruptedAttachment = message.attachments.find { it.upload != null && it.imageUrl == null && it.assetUrl == null } - if (corruptedAttachment != null) { + return if (corruptedAttachment == null) result else { logger.e { "[verifyAttachments] #uploader; message(${message.id}) has corrupted attachment: $corruptedAttachment" } - return Result.Failure( + Result.Failure( Error.GenericError("Message(${message.id}) contains corrupted attachment: $corruptedAttachment") ) } - return result } - -} \ No newline at end of file +} diff --git a/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/attachment/AttachmentsVerifierTests.kt b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/attachment/AttachmentsVerifierTests.kt index 79c1b463f89..54a515a5705 100644 --- a/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/attachment/AttachmentsVerifierTests.kt +++ b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/attachment/AttachmentsVerifierTests.kt @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2014-2023 Stream.io Inc. All rights reserved. + * + * Licensed under the Stream License; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://github.com/GetStream/stream-chat-android/blob/main/LICENSE + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package io.getstream.chat.android.client.attachment import io.getstream.chat.android.client.test.randomMessage @@ -58,5 +74,4 @@ internal class AttachmentsVerifierTests { /* Then */ verified.isFailure `should be equal to` true } - -} \ No newline at end of file +}