Skip to content

Commit 6ae794a

Browse files
Merge pull request #10 from QuickBlox/Release-0.1.6
Release 0.1.6
2 parents 5f717d9 + 63ed1c8 commit 6ae794a

File tree

14 files changed

+87
-20
lines changed

14 files changed

+87
-20
lines changed

Sources/QuickBloxData/DTO/File/LocalFileDTO.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ public struct LocalFileDTO: DataStringConvertible {
2020
public var type: FileType = .file
2121
public var data: Data = Data()
2222
public var path: FilePath = FilePath()
23+
public var uid: String = ""
2324
}

Sources/QuickBloxData/DTO/File/RemoteFileDTO.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public struct RemoteFileDTO: DataStringConvertible {
1717
public var type: FileType = .file
1818
public var data: Data = Data()
1919
public var path: FilePath = FilePath()
20+
public var uid: String = ""
2021

2122
public var `public`: Bool = false
2223
}

Sources/QuickBloxData/DTO/Message/LocalMessageDTO.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ public struct LocalFileInfoDTO: Equatable, Identifiable, Hashable {
3535
var ext: FileExtension = .json
3636
var name: String = ""
3737
var path: FilePath = FilePath()
38+
public var uid: String = ""
3839
}

Sources/QuickBloxData/DTO/Message/RemoteMessageDTO.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ public struct RemoteFileInfoDTO: Equatable {
3939
var name = ""
4040
var type = ""
4141
var path = ""
42+
var uid = ""
4243
}

Sources/QuickBloxData/Repository/FilesRepository.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ private extension LocalFileDTO {
7676
type = value.type
7777
data = value.data
7878
path = value.path
79+
uid = value.uid
7980
}
8081
}
8182

@@ -85,7 +86,8 @@ private extension File {
8586
info = FileInfo(id: value.id,
8687
ext: value.ext,
8788
name: value.name,
88-
path: value.path)
89+
path: value.path,
90+
uid: value.uid)
8991
data = value.data
9092
}
9193
}
@@ -96,7 +98,8 @@ private extension File {
9698
info = FileInfo(id: value.id,
9799
ext: value.ext,
98100
name: value.name,
99-
path: value.path)
101+
path: value.path,
102+
uid: value.uid)
100103
data = value.data
101104
}
102105
}
@@ -109,5 +112,6 @@ private extension LocalFileDTO {
109112
type = value.info.type
110113
path = value.info.path
111114
data = value.data
115+
uid = value.info.uid
112116
}
113117
}

Sources/QuickBloxData/Repository/MessagesRepository.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ extension LocalMessageDTO {
4444
fileInfo?.name = new.name
4545
fileInfo?.ext = new.ext
4646
fileInfo?.path = new.path
47+
fileInfo?.uid = new.uid
4748
}
4849
}
4950
}
@@ -68,7 +69,8 @@ private extension RemoteMessageDTO {
6869
id: file.id,
6970
name: file.name,
7071
type: file.ext.type.rawValue,
71-
path: file.path.remote
72+
path: file.path.remote,
73+
uid: file.uid
7274
))
7375
}
7476
}
@@ -105,6 +107,7 @@ extension Message {
105107
name: filesInfo.name)
106108
}
107109
fileInfo?.path.remote = filesInfo.path
110+
fileInfo?.uid = filesInfo.uid
108111
}
109112
}
110113

@@ -126,6 +129,7 @@ extension Message {
126129
ext: info.ext,
127130
name: info.name)
128131
fileInfo?.path = info.path
132+
fileInfo?.uid = info.uid
129133
}
130134
}
131135
}

Sources/QuickBloxData/Source/Entity/File.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public struct FileInfo: FileInfoEntity {
3030
public var name: String
3131
public var type: FileType
3232
public var path: FilePath
33+
public var uid: String
3334

3435
public init(id: String,
3536
ext: FileExtension,
@@ -44,6 +45,7 @@ public struct FileInfo: FileInfoEntity {
4445
}
4546
type = ext.type
4647
path = FilePath()
48+
uid = ""
4749
}
4850
}
4951

@@ -52,7 +54,8 @@ public extension FileInfo {
5254
self.init(id: value.id,
5355
ext: value.ext,
5456
name: value.name,
55-
path: FilePath(value.path))
57+
path: FilePath(value.path),
58+
uid: value.uid)
5659
}
5760
}
5861

Sources/QuickBloxData/Source/Remote/RemoteDataSource.swift

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,6 @@ extension RemoteDataSource {
556556
system.dateSent = Date()
557557

558558
system.recipientID = QBSession.current.currentUserID
559-
// await stream.process(system)
560559

561560
for id in dto.participantsIds {
562561
system.recipientID = UInt(id) ?? 0
@@ -893,6 +892,7 @@ extension RemoteDataSource {
893892

894893
let fileName = blob.name ?? "file"
895894
let fileId = String(blob.id)
895+
let fileUID = blob.uid ?? ""
896896

897897
var fileExtension: FileExtension
898898
if let extStr = fileName.components(separatedBy: ".").last,
@@ -916,7 +916,8 @@ extension RemoteDataSource {
916916
name: fileName,
917917
type: fileExtension.type,
918918
data: dto.data,
919-
path: filePath)
919+
path: filePath,
920+
uid: fileUID)
920921
} catch let nsError as NSError {
921922
throw try nsError.convertToRemoteException()
922923
} catch {
@@ -974,6 +975,7 @@ extension RemoteDataSource {
974975
uploaded.name = fileName
975976
uploaded.type = fileExtension.type
976977
uploaded.path = filePath
978+
uploaded.uid = uuid
977979
return uploaded
978980
} catch let nsError as NSError {
979981
throw try nsError.convertToRemoteException()
@@ -982,6 +984,10 @@ extension RemoteDataSource {
982984
}
983985
} else {
984986
var uploaded = try await get(fileWithPath: dto.id)
987+
if uploaded.name.contains("json"), uploaded.ext != .json {
988+
uploaded.name = uploaded.name.replacingOccurrences(of: "json",
989+
with: uploaded.ext.rawValue)
990+
}
985991
if dto.name.contains(dto.ext.rawValue) {
986992
let fileName = dto.name.replacingOccurrences(of: dto.ext.rawValue,
987993
with: "")
@@ -1425,7 +1431,8 @@ private extension QBRequest {
14251431
name: fileName,
14261432
type: fileExt.type,
14271433
data: data,
1428-
path: filePath)
1434+
path: filePath,
1435+
uid: uuid ?? "")
14291436
}
14301437

14311438
static func delete(file id: UInt) async throws {
@@ -1645,7 +1652,9 @@ extension QBChatMessage {
16451652
}
16461653

16471654
attachments = value.filesInfo.compactMap {
1648-
return QBChatAttachment($0)
1655+
var attachment = QBChatAttachment($0)
1656+
attachment["uid"] = $0.uid
1657+
return attachment
16491658
}
16501659

16511660
delayed = value.delayed
@@ -1658,15 +1667,26 @@ extension QBChatMessage {
16581667

16591668
private extension RemoteFileInfoDTO {
16601669
init (_ value: QBChatAttachment) throws {
1661-
guard let id = value.id else {
1662-
let info = "\(String(describing: QBChatAttachment.self)) id is missing"
1663-
throw MapperException.incorrectData(description: info)
1670+
if let id = value.id {
1671+
self.id = id
1672+
} else {
1673+
if let urlPath = value.url, let url = URL(string: urlPath) {
1674+
self.id = url.lastPathComponent
1675+
}
1676+
if let uid = value.customParameters?["uid"] {
1677+
self.id = uid
1678+
}
1679+
if let contentType = value["content-type"] {
1680+
type = contentType
1681+
}
16641682
}
1665-
self.id = id
16661683

16671684
name = value.name ?? ""
16681685
type = value.type ?? ""
16691686
path = value.url ?? ""
1687+
if let uid = value.customParameters?["uid"] {
1688+
self.uid = uid
1689+
}
16701690
}
16711691
}
16721692

Sources/QuickBloxDomain/Entity/FileEntity.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public protocol FileInfoEntity: Entity {
2828
var name: String { get set }
2929
var type: FileType { get set }
3030
var path: PathItem { get set }
31+
var uid: String { get set }
3132

3233
init(id: String, ext: FileExtension, name: String)
3334
}
@@ -36,12 +37,13 @@ extension FileInfoEntity {
3637
public init(id: String,
3738
ext: FileExtension,
3839
name: String,
39-
path: PathItem) {
40+
path: PathItem,
41+
uid: String) {
4042
self.init(id: id, ext: ext, name: name)
4143
self.name = name
42-
self.name = name
4344
self.type = ext.type
4445
self.path = path
46+
self.uid = uid
4547
}
4648
}
4749

Sources/QuickBloxUIKit/SwiftUIView/Dialog/GroupDialogView.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,12 @@ public struct GroupDialogView<ViewModel: DialogViewModelProtocol>: View {
7979
if action == .play {
8080
viewModel.playAudio(data, action: action)
8181
tappedMessage = message
82-
} else {
82+
} else if action == .stop {
8383
viewModel.stopPlayng()
8484
tappedMessage = nil
85+
} else if action == .save {
86+
self.fileUrl = url
87+
isFileExporterPresented = true
8588
}
8689
}
8790
}, onAIFeature: { type, message in
@@ -188,9 +191,9 @@ public struct GroupDialogView<ViewModel: DialogViewModelProtocol>: View {
188191
viewModel.sendStopTyping()
189192
viewModel.stopPlayng()
190193
isInfoPresented = true
191-
}))
192-
193-
.sheet(isPresented: $isFileExporterPresented) {
194+
}))
195+
196+
.sheet(isPresented: $isFileExporterPresented) {
194197
if let fileUrl = fileUrl {
195198
ActivityViewController(activityItems: [fileUrl.lastPathComponent , fileUrl])
196199
}

0 commit comments

Comments
 (0)