Skip to content

Commit 114141b

Browse files
authored
Fix draft attachments being sent with local file urls to the server (#964)
* Fix draft attachments sent to the server with local file url * Add test coverage * Update CHANGELOG.md
1 parent ed139b4 commit 114141b

File tree

4 files changed

+456
-2
lines changed

4 files changed

+456
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1212
- Fix composer not showing images in the composer when editing signed attachments [#956](https://github.com/GetStream/stream-chat-swiftui/pull/956)
1313
- Fix replacing an image while editing a message not showing the new image in the message list [#956](https://github.com/GetStream/stream-chat-swiftui/pull/956)
1414
- Improve precision when scrolling to the newest message with long text [#958](https://github.com/GetStream/stream-chat-swiftui/pull/958)
15+
- Fix draft attachments being sent with local file urls to the server [#964](https://github.com/GetStream/stream-chat-swiftui/pull/964)
1516
### 🔄 Changed
1617
- Change the gallery header view to show the message timestamp instead of online status [#962](https://github.com/GetStream/stream-chat-swiftui/pull/962)
1718

Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerViewModel.swift

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,9 @@ class MessageAttachmentsConverter {
10411041
guard let filePayload = attachment.attachment(payloadType: FileAttachmentPayload.self) else {
10421042
return nil
10431043
}
1044+
if let localUrl = attachment.uploadingState?.localFileURL {
1045+
return FileAddedAsset(url: localUrl)
1046+
}
10441047
return FileAddedAsset(
10451048
url: filePayload.assetURL,
10461049
payload: filePayload.payload
@@ -1053,7 +1056,20 @@ class MessageAttachmentsConverter {
10531056
guard let videoAttachment = attachment.attachment(payloadType: VideoAttachmentPayload.self) else {
10541057
return nil
10551058
}
1056-
guard let thumbnail = attachment.imageThumbnail(for: videoAttachment.payload) else { return nil }
1059+
guard let thumbnail = attachment.imageThumbnail(for: videoAttachment.payload) else {
1060+
return nil
1061+
}
1062+
1063+
if let localUrl = attachment.uploadingState?.localFileURL {
1064+
return AddedAsset(
1065+
image: thumbnail,
1066+
id: videoAttachment.id.rawValue,
1067+
url: localUrl,
1068+
type: .video,
1069+
extraData: videoAttachment.extraData ?? [:]
1070+
)
1071+
}
1072+
10571073
return AddedAsset(
10581074
image: thumbnail,
10591075
id: videoAttachment.id.rawValue,
@@ -1072,6 +1088,20 @@ class MessageAttachmentsConverter {
10721088
return completion(nil)
10731089
}
10741090

1091+
if let localFileUrl = attachment.uploadingState?.localFileURL,
1092+
let imageData = try? Data(contentsOf: localFileUrl),
1093+
let image = UIImage(data: imageData) {
1094+
let imageAsset = AddedAsset(
1095+
image: image,
1096+
id: imageAttachment.id.rawValue,
1097+
url: localFileUrl,
1098+
type: .image,
1099+
extraData: imageAttachment.extraData ?? [:]
1100+
)
1101+
completion(imageAsset)
1102+
return
1103+
}
1104+
10751105
utils.imageLoader.loadImage(
10761106
url: imageAttachment.imageURL,
10771107
imageCDN: utils.imageCDN,

StreamChatSwiftUI.xcodeproj/project.pbxproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@
527527
AD3AB65C2CB730090014D4D7 /* Shimmer.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD3AB65B2CB730090014D4D7 /* Shimmer.swift */; };
528528
AD3AB65E2CB731360014D4D7 /* ChatThreadListLoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD3AB65D2CB731360014D4D7 /* ChatThreadListLoadingView.swift */; };
529529
AD3AB6602CB7403C0014D4D7 /* ChatThreadListHeaderViewModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD3AB65F2CB7403C0014D4D7 /* ChatThreadListHeaderViewModifier.swift */; };
530+
AD3DB8342E7C7BD50023D377 /* MessageAttachmentsConverter_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD3DB8332E7C7BD50023D377 /* MessageAttachmentsConverter_Tests.swift */; };
530531
AD3DB82F2E7C2E190023D377 /* GalleryHeaderViewDateFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD3DB82E2E7C2E190023D377 /* GalleryHeaderViewDateFormatter.swift */; };
531532
AD51D9182DB9543A0068D0B0 /* MessageViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD51D9172DB9543A0068D0B0 /* MessageViewModel.swift */; };
532533
AD5C0A5F2D6FDD9700E1E500 /* BouncedMessageActionsModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD5C0A5E2D6FDD8600E1E500 /* BouncedMessageActionsModifier.swift */; };
@@ -1141,6 +1142,7 @@
11411142
AD3AB65B2CB730090014D4D7 /* Shimmer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shimmer.swift; sourceTree = "<group>"; };
11421143
AD3AB65D2CB731360014D4D7 /* ChatThreadListLoadingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatThreadListLoadingView.swift; sourceTree = "<group>"; };
11431144
AD3AB65F2CB7403C0014D4D7 /* ChatThreadListHeaderViewModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatThreadListHeaderViewModifier.swift; sourceTree = "<group>"; };
1145+
AD3DB8332E7C7BD50023D377 /* MessageAttachmentsConverter_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageAttachmentsConverter_Tests.swift; sourceTree = "<group>"; };
11441146
AD3DB82E2E7C2E190023D377 /* GalleryHeaderViewDateFormatter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GalleryHeaderViewDateFormatter.swift; sourceTree = "<group>"; };
11451147
AD51D9172DB9543A0068D0B0 /* MessageViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageViewModel.swift; sourceTree = "<group>"; };
11461148
AD5C0A5E2D6FDD8600E1E500 /* BouncedMessageActionsModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BouncedMessageActionsModifier.swift; sourceTree = "<group>"; };
@@ -2165,9 +2167,10 @@
21652167
84C94D472758BDB2007FE2B9 /* ChatChannel */ = {
21662168
isa = PBXGroup;
21672169
children = (
2168-
AD9138AF2E7241D900581EB0 /* FileAttachmentView_Tests.swift */,
21692170
846B15F22817E7440017F7A1 /* ChannelInfo */,
21702171
8423C340277CB5C70092DCF1 /* Suggestions */,
2172+
AD3DB8332E7C7BD50023D377 /* MessageAttachmentsConverter_Tests.swift */,
2173+
AD9138AF2E7241D900581EB0 /* FileAttachmentView_Tests.swift */,
21712174
84779C742AEBBACD000A6A68 /* BottomReactionsView_Tests.swift */,
21722175
ADA77F042E1EC2B700A3641F /* MessageAvatarView_Tests.swift */,
21732176
844D1D672851DE58000CCCB9 /* ChannelControllerFactory_Tests.swift */,
@@ -3095,6 +3098,7 @@
30953098
84E04796284A444E00BAFA17 /* EventBatcherMock.swift in Sources */,
30963099
ADE442F22CBDAAC40066CDF7 /* ChatThreadListItemView_Tests.swift in Sources */,
30973100
84E57C5B28103822002213C1 /* TestDataModel.xcdatamodeld in Sources */,
3101+
AD3DB8342E7C7BD50023D377 /* MessageAttachmentsConverter_Tests.swift in Sources */,
30983102
84E04792284A444E00BAFA17 /* MockBackgroundTaskScheduler.swift in Sources */,
30993103
84C94D1327578BF2007FE2B9 /* XCTestCase+MockJSON.swift in Sources */,
31003104
84C94D5E275A3AA9007FE2B9 /* ImageCDN_Tests.swift in Sources */,

0 commit comments

Comments
 (0)