Skip to content

Commit

Permalink
[PBE-5250] Remove url property from Attachment class (#5325)
Browse files Browse the repository at this point in the history
* Remove `url` property from `Attachment` class

* Update CHANGELOG.md

* Increase database version
  • Loading branch information
JcMinarro authored Jul 22, 2024
1 parent 1ebc251 commit 2a08e7d
Show file tree
Hide file tree
Showing 23 changed files with 43 additions and 98 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
### ✅ Added

### ⚠️ Changed
- `Attachment` class doesn't use `url` property anymore. Use `assetUrl` instead. [#5325](https://github.com/GetStream/stream-chat-android/pull/5325)

### ❌ Removed
- Removed `url` property of `Attachment` class. Use `assetUrl` instead. [#5325](https://github.com/GetStream/stream-chat-android/pull/5325)

## stream-chat-android-offline
### 🐞 Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ internal fun Attachment.toDto(): AttachmentDto =
title_link = titleLink,
author_link = authorLink,
type = type,
url = url,
original_height = originalHeight,
original_width = originalWidth,
extraData = extraData,
Expand All @@ -59,7 +58,6 @@ internal fun AttachmentDto.toDomain(): Attachment =
title = title,
titleLink = title_link,
type = type,
url = url,
originalHeight = original_height,
originalWidth = original_width,
extraData = extraData.toMutableMap(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ internal data class AttachmentDto(
val title: String?,
val title_link: String?,
val type: String?,
val url: String?,
val original_height: Int?,
val original_width: Int?,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public class AttachmentUploader(private val client: ChatClient = ChatClient.inst
progressCallback: ProgressCallback?,
): Result<Attachment> {
logger.d { "[onSuccessfulUpload] #uploader; attachment ${augmentedAttachment.uploadId} uploaded successfully" }
progressCallback?.onSuccess(augmentedAttachment.url)
progressCallback?.onSuccess(augmentedAttachment.assetUrl)
return Result.Success(augmentedAttachment.copy(uploadState = Attachment.UploadState.Success))
}

Expand Down Expand Up @@ -256,7 +256,6 @@ public class AttachmentUploader(private val client: ChatClient = ChatClient.inst
name = file.name,
fileSize = file.length().toInt(),
mimeType = mimeType,
url = uploadedFile.file,
uploadState = Attachment.UploadState.Success,
title = title.takeUnless { it.isNullOrBlank() } ?: file.name,
thumbUrl = uploadedFile.thumbUrl,
Expand All @@ -266,10 +265,7 @@ public class AttachmentUploader(private val client: ChatClient = ChatClient.inst
AttachmentType.VIDEO -> uploadedFile.thumbUrl
else -> imageUrl
},
assetUrl = when (attachmentType) {
AttachmentType.IMAGE -> assetUrl
else -> uploadedFile.file
},
assetUrl = uploadedFile.file,
extraData = extraData + uploadedFile.extraData,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,13 @@ import io.getstream.chat.android.positiveRandomInt
import io.getstream.chat.android.randomFile
import io.getstream.chat.android.randomString
import io.getstream.chat.android.test.TestCall
import io.getstream.result.Error
import io.getstream.result.Result
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import org.amshove.kluent.shouldBeEqualTo
import org.amshove.kluent.shouldBeInstanceOf
import org.amshove.kluent.shouldBeNull
import org.amshove.kluent.shouldNotBeNull
import org.junit.Before
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.any
Expand All @@ -61,30 +58,6 @@ internal class AttachmentUploaderTests {
.addExtensionMimeTypMapping("jpg", "image/jpeg")
}

@Test
@Ignore("Current logic doesn't work so. Need to rewrite test")
fun `Should return attachment with properly filled data when sending file has failed`(): Unit = runTest {
val error = Error.GenericError(message = "")
val attachment = randomAttachments(size = 1).first()

val sut = Fixture()
.givenMockedFileUploads(channelType, channelId, Result.Failure(error))
.get()

val result = sut.uploadAttachment(channelType, channelId, attachment) as Result.Success

with(result.value) {
name shouldBeEqualTo attachment.upload!!.name
fileSize.shouldNotBeNull()
type.shouldNotBeNull()
mimeType.shouldNotBeNull()
uploadState shouldBeEqualTo Attachment.UploadState.Failed(error)
url.shouldBeNull()
imageUrl.shouldBeNull()
assetUrl.shouldBeNull()
}
}

@Test
fun `Should return attachment with properly filled data when successfully sent file`() = runTest {
val attachment = randomAttachments(size = 1).first()
Expand Down Expand Up @@ -147,7 +120,6 @@ internal class AttachmentUploaderTests {
val url = attachment.upload!!.absolutePath
val expectedAttachment = attachment.copy(
assetUrl = url,
url = url,
type = "file",
mimeType = "",
name = attachment.upload!!.name,
Expand All @@ -173,7 +145,6 @@ internal class AttachmentUploaderTests {
val url = attachment.upload!!.absolutePath
val expectedAttachment = attachment.copy(
assetUrl = url,
url = url,
type = "file",
mimeType = "",
name = attachment.upload!!.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ internal object AttachmentDtoTestData {
"title": "title",
"title_link": "titleLink",
"type": "type",
"url": "url",
"original_height": 100,
"original_width": 100,
"draft": true
Expand All @@ -61,7 +60,6 @@ internal object AttachmentDtoTestData {
title = "title",
title_link = "titleLink",
type = "type",
url = "url",
original_height = 100,
original_width = 100,
extraData = mapOf("draft" to true),
Expand Down Expand Up @@ -89,7 +87,6 @@ internal object AttachmentDtoTestData {
title = null,
title_link = null,
type = null,
url = null,
original_width = null,
original_height = null,
extraData = emptyMap(),
Expand Down
2 changes: 1 addition & 1 deletion stream-chat-android-compose/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<ID>LongParameterList:MediaAttachmentContent.kt$( attachment: Attachment, message: Message, skipEnrichUrl: Boolean, onMediaGalleryPreviewResult: (MediaGalleryPreviewResult?) -> Unit = {}, onLongItemClick: (Message) -> Unit, onContentItemClick: ( mediaGalleryPreviewLauncher: ManagedActivityResultLauncher&lt;MediaGalleryPreviewContract.Input, MediaGalleryPreviewResult?>, message: Message, attachmentPosition: Int, videoThumbnailsEnabled: Boolean, streamCdnImageResizing: StreamCdnImageResizing, skipEnrichUrl: Boolean, ) -> Unit, overlayContent: @Composable (attachmentType: String?) -> Unit, )</ID>
<ID>LongParameterList:MediaAttachmentContent.kt$( mediaGalleryPreviewLauncher: ManagedActivityResultLauncher&lt;MediaGalleryPreviewContract.Input, MediaGalleryPreviewResult?>, message: Message, attachmentPosition: Int, videoThumbnailsEnabled: Boolean, streamCdnImageResizing: StreamCdnImageResizing, skipEnrichUrl: Boolean, )</ID>
<ID>LongParameterList:MediaGalleryPreviewActivity.kt$MediaGalleryPreviewActivity$( context: Context, mediaGalleryPreviewAction: MediaGalleryPreviewAction, currentPage: Int, attachments: List&lt;Attachment>, writePermissionState: PermissionState, downloadPayload: MutableState&lt;Attachment?>, )</ID>
<ID>LongParameterList:MediaGalleryPreviewActivityAttachmentState.kt$MediaGalleryPreviewActivityAttachmentState$( val name: String?, val url: String?, val thumbUrl: String?, val imageUrl: String?, val assetUrl: String?, val originalWidth: Int?, val originalHeight: Int?, val type: String?, )</ID>
<ID>LongParameterList:MediaGalleryPreviewActivityAttachmentState.kt$MediaGalleryPreviewActivityAttachmentState$( val name: String?, val thumbUrl: String?, val imageUrl: String?, val assetUrl: String?, val originalWidth: Int?, val originalHeight: Int?, val type: String?, )</ID>
<ID>LongParameterList:MessageComposer.kt$( value: String, coolDownTime: Int, attachments: List&lt;Attachment>, validationErrors: List&lt;ValidationError>, ownCapabilities: Set&lt;String>, isInEditMode: Boolean, onSendMessage: (String, List&lt;Attachment>) -> Unit, onRecordingSaved: (Attachment) -> Unit, statefulStreamMediaRecorder: StatefulStreamMediaRecorder?, )</ID>
<ID>LongParameterList:MessagesScreen.kt$( listViewModel: MessageListViewModel, composerViewModel: MessageComposerViewModel, selectedMessageState: SelectedMessageState?, selectedMessage: Message, skipPushNotification: Boolean, skipEnrichUrl: Boolean, )</ID>
<ID>MagicNumber:AudioRecording.kt$2.5f</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import kotlinx.parcelize.Parcelize
* for the proper functioning of the Media Gallery Preview screen.
*
* @param name The name of the attachment.
* @param url The URL of the file.
* @param thumbUrl The URL for the thumbnail version of the attachment,
* given the attachment has a visual quality, e.g. is a video, an image,
* a link to a website or similar.
Expand All @@ -45,7 +44,6 @@ import kotlinx.parcelize.Parcelize
@Parcelize
internal class MediaGalleryPreviewActivityAttachmentState(
val name: String?,
val url: String?,
val thumbUrl: String?,
val imageUrl: String?,
val assetUrl: String?,
Expand All @@ -60,7 +58,6 @@ internal class MediaGalleryPreviewActivityAttachmentState(
internal fun Attachment.toMediaGalleryPreviewActivityAttachmentState(): MediaGalleryPreviewActivityAttachmentState =
MediaGalleryPreviewActivityAttachmentState(
name = this.name,
url = this.url,
thumbUrl = this.thumbUrl,
imageUrl = this.imageUrl,
assetUrl = this.assetUrl,
Expand All @@ -74,7 +71,6 @@ internal fun Attachment.toMediaGalleryPreviewActivityAttachmentState(): MediaGal
*/
internal fun MediaGalleryPreviewActivityAttachmentState.toAttachment(): Attachment = Attachment(
name = this.name,
url = this.url,
thumbUrl = this.thumbUrl,
imageUrl = this.imageUrl,
assetUrl = this.assetUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class UrlAttachmentPreviewHandler(private val context: Context) : Attachm
else -> imageUrl
}
}
else -> url
else -> assetUrl
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public class MediaGalleryPreviewViewModel(
if (message.text.isNotEmpty() || numberOfAttachments > 1) {
message = message.copy(
attachments = attachments.filterNot {
it.url == currentMediaAttachment.url
it.assetUrl == currentMediaAttachment.assetUrl
},
skipEnrichUrl = skipEnrichUrl,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,15 @@ internal class MediaGalleryPreviewViewModelTest {
* [MediaGalleryPreviewViewModel.deleteCurrentMediaAttachment] uses the URL field to compare attachments.
*/
private val attachment1 =
Attachment(type = "image", imageUrl = "http://example.com/img1.png", url = "http://example.com/img1.png")
Attachment(
type = "image",
imageUrl = "http://example.com/img1.png",
assetUrl = "http://example.com/img1.png",
)
private val attachment2 =
Attachment(type = "video", url = "http://example.com/img2.png")
Attachment(
type = "video",
assetUrl = "http://example.com/img2.png",
)
}
}
19 changes: 8 additions & 11 deletions stream-chat-android-core/api/stream-chat-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -156,31 +156,30 @@ public final class io/getstream/chat/android/models/AppSettings$Companion {

public final class io/getstream/chat/android/models/Attachment : io/getstream/chat/android/models/CustomObject {
public fun <init> ()V
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/io/File;Lio/getstream/chat/android/models/Attachment$UploadState;Ljava/util/Map;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/io/File;Lio/getstream/chat/android/models/Attachment$UploadState;Ljava/util/Map;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/io/File;Lio/getstream/chat/android/models/Attachment$UploadState;Ljava/util/Map;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/io/File;Lio/getstream/chat/android/models/Attachment$UploadState;Ljava/util/Map;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ljava/lang/String;
public final fun component10 ()Ljava/lang/String;
public final fun component11 ()Ljava/lang/String;
public final fun component12 ()Ljava/lang/String;
public final fun component13 ()Ljava/lang/String;
public final fun component14 ()Ljava/lang/String;
public final fun component15 ()Ljava/lang/String;
public final fun component16 ()Ljava/lang/String;
public final fun component16 ()Ljava/lang/Integer;
public final fun component17 ()Ljava/lang/Integer;
public final fun component18 ()Ljava/lang/Integer;
public final fun component19 ()Ljava/io/File;
public final fun component18 ()Ljava/io/File;
public final fun component19 ()Lio/getstream/chat/android/models/Attachment$UploadState;
public final fun component2 ()Ljava/lang/String;
public final fun component20 ()Lio/getstream/chat/android/models/Attachment$UploadState;
public final fun component21 ()Ljava/util/Map;
public final fun component20 ()Ljava/util/Map;
public final fun component3 ()Ljava/lang/String;
public final fun component4 ()Ljava/lang/String;
public final fun component5 ()Ljava/lang/String;
public final fun component6 ()Ljava/lang/String;
public final fun component7 ()Ljava/lang/String;
public final fun component8 ()Ljava/lang/String;
public final fun component9 ()I
public final fun copy (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/io/File;Lio/getstream/chat/android/models/Attachment$UploadState;Ljava/util/Map;)Lio/getstream/chat/android/models/Attachment;
public static synthetic fun copy$default (Lio/getstream/chat/android/models/Attachment;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/io/File;Lio/getstream/chat/android/models/Attachment$UploadState;Ljava/util/Map;ILjava/lang/Object;)Lio/getstream/chat/android/models/Attachment;
public final fun copy (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/io/File;Lio/getstream/chat/android/models/Attachment$UploadState;Ljava/util/Map;)Lio/getstream/chat/android/models/Attachment;
public static synthetic fun copy$default (Lio/getstream/chat/android/models/Attachment;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/io/File;Lio/getstream/chat/android/models/Attachment$UploadState;Ljava/util/Map;ILjava/lang/Object;)Lio/getstream/chat/android/models/Attachment;
public fun equals (Ljava/lang/Object;)Z
public final fun getAssetUrl ()Ljava/lang/String;
public final fun getAuthorLink ()Ljava/lang/String;
Expand All @@ -203,7 +202,6 @@ public final class io/getstream/chat/android/models/Attachment : io/getstream/ch
public final fun getType ()Ljava/lang/String;
public final fun getUpload ()Ljava/io/File;
public final fun getUploadState ()Lio/getstream/chat/android/models/Attachment$UploadState;
public final fun getUrl ()Ljava/lang/String;
public fun hashCode ()I
public final fun newBuilder ()Lio/getstream/chat/android/models/Attachment$Builder;
public fun toString ()Ljava/lang/String;
Expand Down Expand Up @@ -233,7 +231,6 @@ public final class io/getstream/chat/android/models/Attachment$Builder {
public final fun withType (Ljava/lang/String;)Lio/getstream/chat/android/models/Attachment$Builder;
public final fun withUpload (Ljava/io/File;)Lio/getstream/chat/android/models/Attachment$Builder;
public final fun withUploadState (Lio/getstream/chat/android/models/Attachment$UploadState;)Lio/getstream/chat/android/models/Attachment$Builder;
public final fun withUrl (Ljava/lang/String;)Lio/getstream/chat/android/models/Attachment$Builder;
}

public abstract class io/getstream/chat/android/models/Attachment$UploadState {
Expand Down
Loading

0 comments on commit 2a08e7d

Please sign in to comment.