Skip to content

Commit 2a8fe80

Browse files
Merge pull request #16 from QuickBlox/Release-0.3.3
Release 0.3.3
2 parents 68de442 + 6592d01 commit 2a8fe80

File tree

74 files changed

+1842
-1350
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1842
-1350
lines changed

Sources/QuickBloxData/DTO/Message/RemoteOriginalMessageDTO.swift

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ public struct RemoteOriginalMessageDTO: Codable {
2929
senderId: UInt = 0,
3030
dateSent: Int64,
3131
attachments: [RemoteOriginalFileInfoDTO] = [],
32-
createdAt: Date,
33-
updatedAt: Date,
34-
deliveredIds: [UInt],
35-
readIds: [UInt]) {
32+
createdAt: Date = Date(),
33+
updatedAt: Date = Date(),
34+
deliveredIds: [UInt] = [],
35+
readIds: [UInt] = []) {
3636
self.id = id
3737
self.dialogId = dialogId
3838
self.text = text
@@ -62,11 +62,11 @@ public struct RemoteOriginalMessageDTO: Codable {
6262
}
6363

6464
public struct RemoteOriginalFileInfoDTO: Codable {
65-
var id: String
66-
var name: String
67-
var type: String
68-
var url: String
69-
var uid: String
65+
var id: String = ""
66+
var name: String = ""
67+
var type: String = ""
68+
var url: String = ""
69+
var uid: String = ""
7070
}
7171

7272
extension RemoteOriginalFileInfoDTO {
@@ -98,10 +98,6 @@ extension RemoteOriginalMessageDTO {
9898
}
9999

100100
private extension Date {
101-
var timeStampString: String {
102-
return String(Int64(self.timeIntervalSince1970 * 1000))
103-
}
104-
105101
var timeStampInt: Int64 {
106102
return Int64(self.timeIntervalSince1970 * 1000)
107103
}

Sources/QuickBloxData/Repository/MessagesRepository.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ private extension RemoteMessageDTO {
8181
if let originSenderName = value.originSenderName {
8282
self.originSenderName = originSenderName
8383
}
84+
8485
originalMessages = value.originalMessages.compactMap { RemoteMessageDTO($0) }
8586
relatedId = value.relatedId
8687
}

Sources/QuickBloxData/Source/Remote/Extension/RemoteMessageDTO+QBChatMessage.swift

Lines changed: 80 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,17 @@ extension RemoteMessageDTO {
3535
if let attachments = value.attachments {
3636
self.filesInfo = attachments.compactMap {
3737
do {
38-
return try RemoteFileInfoDTO($0)
38+
var fileInfo = try RemoteFileInfoDTO($0)
39+
if text.contains("MediaContentEntity|") {
40+
var separated: [String] = text.components(separatedBy: "|")
41+
separated.removeLast()
42+
if let uid = separated.last {
43+
fileInfo.id = uid
44+
fileInfo.uid = uid
45+
fileInfo.path = ""
46+
}
47+
}
48+
return fileInfo
3949
} catch {
4050
prettyLog(error)
4151
return nil
@@ -57,15 +67,11 @@ extension RemoteMessageDTO {
5767

5868
if let originalMessages = value.customParameters[QBChatMessage.Key.originalMessages] as? String {
5969
self.originalMessages = originaldMessages(originalMessages, messageId: id,
60-
dateSent: dateSent,
70+
date: dateSent,
6171
actionType: actionType,
6272
originSenderName: originSenderName)
6373
}
6474

65-
if self.originalMessages.isEmpty == true {
66-
actionType = .none
67-
}
68-
6975
let current = String(QBSession.current.currentUserID)
7076
isOwnedByCurrentUser = senderId == current
7177
if isOwnedByCurrentUser {
@@ -87,30 +93,73 @@ extension RemoteMessageDTO {
8793

8894
private func originaldMessages(_ jsonString: String,
8995
messageId: String,
90-
dateSent: Date,
96+
date: Date,
9197
actionType: MessageAction,
9298
originSenderName: String) -> [RemoteMessageDTO] {
93-
guard let data = jsonString.data(using: .utf8) else { return [] }
94-
let jsonDecoder = JSONDecoder()
95-
jsonDecoder.dateDecodingStrategy = .iso8601
96-
do {
97-
let decodedOriginalMessages = try jsonDecoder.decode([RemoteOriginalMessageDTO].self, from: data)
98-
var originalMessages: [RemoteMessageDTO] = []
99-
for (i, decodedOriginalMessage) in decodedOriginalMessages.enumerated() {
100-
var originalMessage = RemoteMessageDTO(decodedOriginalMessage)
101-
originalMessage.actionType = actionType
102-
originalMessage.relatedId = messageId
103-
originalMessage.dateSent = dateSent
104-
if i == 0 {
105-
originalMessage.originSenderName = originSenderName
99+
guard let decodedOriginalMessages = jsonString.toJSON() as? [[String: AnyObject]] else { return [] }
100+
var originalMessages: [RemoteMessageDTO] = []
101+
for (i, object) in decodedOriginalMessages.enumerated() {
102+
let id = object[RemoteOriginalMessageDTO.CodingKeys.id.stringValue] as? String ?? ""
103+
let dialogId = object[RemoteOriginalMessageDTO.CodingKeys.dialogId.stringValue] as? String ?? ""
104+
let text = object[RemoteOriginalMessageDTO.CodingKeys.text.stringValue] as? String ?? ""
105+
let senderId = object[RemoteOriginalMessageDTO.CodingKeys.senderId.stringValue] as? UInt ?? 0
106+
let dateSent = object[RemoteOriginalMessageDTO.CodingKeys.dateSent.stringValue] as? Int64 ?? 0
107+
var attachments: [RemoteOriginalFileInfoDTO] = []
108+
if let decodedAttachments = object[RemoteOriginalMessageDTO.CodingKeys.attachments.stringValue] as? [[String: AnyObject]] {
109+
for decodedAttachment in decodedAttachments {
110+
var fileInfoDTO = RemoteOriginalFileInfoDTO()
111+
if let id = decodedAttachment["id"] as? String {
112+
fileInfoDTO.id = id
113+
} else {
114+
if let urlPath = decodedAttachment["url"] as? String,
115+
let url = URL(string: urlPath) {
116+
fileInfoDTO.id = url.lastPathComponent
117+
}
118+
if let uid = decodedAttachment["uid"] as? String {
119+
fileInfoDTO.id = uid
120+
}
121+
if let contentType = decodedAttachment["content-type"] as? String {
122+
fileInfoDTO.type = contentType
123+
}
124+
}
125+
if let name = decodedAttachment["name"] as? String {
126+
fileInfoDTO.name = name
127+
}
128+
if let type = decodedAttachment["type"] as? String {
129+
fileInfoDTO.type = type
130+
if type == "audio/mp4" { // fix voice message from Safari
131+
fileInfoDTO.type = "audio/mp3"
132+
fileInfoDTO.name = fileInfoDTO.name.replacingOccurrences(of: "mp4", with: "mp3")
133+
}
134+
}
135+
if let url = decodedAttachment["url"] as? String {
136+
fileInfoDTO.url = url
137+
}
138+
if let uid = decodedAttachment["uid"] as? String {
139+
fileInfoDTO.uid = uid
140+
}
141+
142+
attachments.append(fileInfoDTO)
106143
}
107-
originalMessages.append(originalMessage)
108144
}
109-
return originalMessages
110-
} catch {
111-
print("Error: \(error.localizedDescription)")
112-
return []
145+
146+
let decodedOriginalMessage = RemoteOriginalMessageDTO(id: id,
147+
dialogId: dialogId,
148+
text: text,
149+
senderId: senderId,
150+
dateSent: dateSent,
151+
attachments: attachments)
152+
var originalMessage = RemoteMessageDTO(decodedOriginalMessage)
153+
originalMessage.actionType = actionType
154+
originalMessage.relatedId = messageId
155+
originalMessage.dateSent = date
156+
if i == 0 {
157+
originalMessage.originSenderName = originSenderName
158+
}
159+
160+
originalMessages.append(originalMessage)
113161
}
162+
return originalMessages
114163
}
115164

116165
static func eventMessage(_ text: String,
@@ -168,8 +217,6 @@ extension RemoteMessageDTO {
168217
senderId = value.senderId != 0 ? String(value.senderId) : ""
169218
recipientId = value.recipientId != 0 ? String(value.recipientId) : ""
170219
dateSent = value.dateSent.dateTimeIntervalSince1970
171-
createdAt = value.createdAt
172-
updatedAt = value.updatedAt
173220

174221
if value.attachments.isEmpty == false {
175222
self.filesInfo = value.attachments.compactMap{ RemoteFileInfoDTO($0) }
@@ -201,3 +248,9 @@ private extension Int64 {
201248
return Date(timeIntervalSince1970: timestampInSeconds)
202249
}
203250
}
251+
252+
extension String {
253+
func toJSON() -> Any? {
254+
guard let data = self.data(using: .utf8, allowLossyConversion: false) else { return nil }
255+
return try? JSONSerialization.jsonObject(with: data, options: .mutableContainers)
256+
}}

Sources/QuickBloxData/Utils.swift

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,6 @@ extension ComparisonResult {
2525
}
2626
}
2727

28-
extension Array where Element: Hashable {
29-
mutating func removeDuplicates() {
30-
var set = Set<Element>()
31-
var newArray = [Element]()
32-
33-
for element in self {
34-
if !set.contains(element) {
35-
newArray.append(element)
36-
set.insert(element)
37-
}
38-
}
39-
40-
self = newArray
41-
}
42-
}
43-
4428
extension Array where Element: Dated, Element: Identifiable, Element: Hashable {
4529
mutating func insertElement(_ new: Element, withSorting order: ComparisonResult) {
4630
if isEmpty {
@@ -70,7 +54,6 @@ extension Array where Element: Dated, Element: Identifiable, Element: Hashable {
7054
append(new)
7155
}
7256
}
73-
self.removeDuplicates()
7457
}
7558
}
7659
}

Sources/QuickBloxDomain/UseCase/Dialog/SyncDialog.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ where Dialog == DialogsRepo.DialogEntityItem,
5858

5959
if let usersRepo = self?.usersRepo,
6060
let users = try? await usersRepo.get(usersFromRemote: ids),
61-
users.isEmpty != false {
61+
users.isEmpty == false {
6262
try? await usersRepo.save(usersToLocal: users)
6363
}
6464
try await dialogsRepo.save(dialogToLocal: dialog)

Sources/QuickBloxDomain/UseCase/SyncData.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,6 @@ where Pagination == DialogsRepo.PaginationItem {
196196
try Task.checkCancellation()
197197
try await self?.connectRepo.connect()
198198
}
199-
200-
201-
if self?.stateSubject.value == .syncing(stage: .disconnected) {
202-
try Task.checkCancellation()
203-
try await self?.connectRepo.connect()
204-
}
205199
} catch { prettyLog(error) }
206200

207201
self?.taskConnect = nil

Sources/QuickBloxUIKit/QuickBloxUIKit.swift

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class Sync {
6868
}
6969
}
7070

71-
var syncState: AnyPublisher<SyncState, Never> {
71+
public var syncState: AnyPublisher<SyncState, Never> {
7272
syncData()
7373
return sync!.state
7474
}
@@ -81,33 +81,23 @@ private func syncData() {
8181
}
8282
}
8383

84-
let imageCache = ImageCache.shared
85-
8684
//FIXME: add dialogsView screen
8785
@MainActor @ViewBuilder
88-
public func dialogsView(onExit: (() -> Void)? = nil, onAppear: ((Bool) -> Void)? = nil) -> some View {
86+
public func dialogsView(onExit: (() -> Void)? = nil,
87+
onSelect: @escaping (_ tabIndex: TabIndex) -> Void) -> some View {
8988
DialogsView(dialogsList: DialogsViewModel(dialogsRepo: RepositoriesFabric.dialogs),
90-
content: { dialogsList in
91-
DialogsListView(dialogsList: dialogsList, detailContent: { item, onDismiss in
92-
if item.type == .group {
93-
GroupDialogView(viewModel: DialogViewModel(dialog: item), onDismiss: onDismiss)
94-
} else if item.type == .private {
95-
PrivateDialogView(viewModel: DialogViewModel(dialog: item), onDismiss: onDismiss)
96-
}
97-
},
98-
content: DialogsRowBuilder.defaultRow)
99-
}, detailContent: { item, onDismiss in
89+
detailContent: { item, isInfoPresented in
10090
if item.type == .group {
101-
GroupDialogView(viewModel: DialogViewModel(dialog: item), onDismiss: onDismiss)
91+
GroupDialogView(viewModel: DialogViewModel(dialog: item), isInfoPresented: isInfoPresented)
10292
} else if item.type == .private {
103-
PrivateDialogView(viewModel: DialogViewModel(dialog: item), onDismiss: onDismiss)
93+
PrivateDialogView(viewModel: DialogViewModel(dialog: item), isInfoPresented: isInfoPresented)
10494
}
10595
}, selectTypeContent: { onClose in
10696
DialogTypeView(onClose: onClose)
10797
}, onBack: {
10898
onExit?()
109-
}, onAppear: { appear in
110-
onAppear?(appear)
99+
}, onSelect: { tabIndex in
100+
onSelect(tabIndex)
111101
})
112102
.onAppear {
113103
syncData()

Sources/QuickBloxUIKit/Resources/Assets.xcassets/ThemeColor/HighLight.colorset/Contents.json

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,6 @@
1212
},
1313
"idiom" : "universal"
1414
},
15-
{
16-
"appearances" : [
17-
{
18-
"appearance" : "luminosity",
19-
"value" : "light"
20-
}
21-
],
22-
"color" : {
23-
"color-space" : "srgb",
24-
"components" : {
25-
"alpha" : "1.000",
26-
"blue" : "0xC1",
27-
"green" : "0xFD",
28-
"red" : "0xFF"
29-
}
30-
},
31-
"idiom" : "universal"
32-
},
3315
{
3416
"appearances" : [
3517
{

Sources/QuickBloxUIKit/Resources/en.lproj/Localizable.strings

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"dialog.items.empty" = "There are no dialogs";
1010
"dialog.members.empty" = "You don’t have any users.";
1111
"dialog.messages.empty" = "You don’t have any messages.";
12+
"dialog.info.selectDialog" = "Select a dialog to start communication";
1213
"dialog.type.private" = "Private";
1314
"dialog.type.group" = "Group";
1415
"dialog.type.public" = "Public";
@@ -50,7 +51,7 @@
5051
"alert.actions.remove" = "Remove";
5152
"alert.actions.cancel" = "Cancel";
5253
"alert.actions.ok" = "Ok";
53-
"alert.message.removeUser" = "Are you sure you want to remove ";
54+
"alert.message.removeItem" = "Are you sure you want to remove ";
5455
"alert.message.questionMark" = "?";
5556
"alert.message.errorValidation" = "Error Validation";
5657
"alert.message.addUser" = "Are you sure you want to add ";
@@ -92,6 +93,7 @@
9293
"utils.string.hasLeft" = "has left";
9394
"utils.string.today" = "Today";
9495
"utils.string.yesterday" = "Yesterday";
96+
"utils.string.unknown" = "Unknown";
9597

9698
"utils.string.connecting" = "connecting";
9799
"utils.string.update" = "update";

Sources/QuickBloxUIKit/SwiftUIView/Dialog/AddMembers/AddMembersDialogView.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import QuickBloxData
1313
public struct AddMembersDialogView<ViewModel: AddMembersDialogProtocol>: View {
1414
@State public var settings
1515
= QuickBloxUIKit.settings.addMembersScreen
16-
17-
@Environment(\.dismiss) var dismiss
16+
1817
@Environment(\.isSearching) private var isSearching: Bool
1918

2019
@StateObject public var viewModel: ViewModel
@@ -61,9 +60,7 @@ public struct AddMembersDialogView<ViewModel: AddMembersDialogProtocol>: View {
6160
})
6261
}
6362

64-
.addMembersHeader(onDismiss: {
65-
dismiss()
66-
})
63+
.addMembersHeader()
6764

6865
.disabled(viewModel.isProcessing == true)
6966
.if(viewModel.isProcessing == true) { view in

0 commit comments

Comments
 (0)