Skip to content

Commit

Permalink
Update SDK to 1.0.102-alpha (#1408)
Browse files Browse the repository at this point in the history
* Update SDK to 1.0.102-alpha

* Log error

* Notification Improvements API part 1 (#1410)

* changes

* WIP

* progress

* updated test

* removed unused

* code improvement

* Process diffs as batches provided by the SDK.

---------

Co-authored-by: Mauro <34335419+Velin92@users.noreply.github.com>
Co-authored-by: Doug <douglase@element.io>
  • Loading branch information
3 people authored Jul 27, 2023
1 parent 188d41e commit 1529b5b
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 160 deletions.
52 changes: 25 additions & 27 deletions ElementX.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/matrix-org/matrix-rust-components-swift",
"state" : {
"revision" : "ac6472d2f05128f05345e657e41267dbc0f06f7c",
"version" : "1.0.101-alpha"
"revision" : "fdef408540bf71be867bb59454562f21dcdd64da",
"version" : "1.0.102-alpha"
}
},
{
Expand Down
10 changes: 7 additions & 3 deletions ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -378,17 +378,21 @@ class SDKClientMock: SDKClientProtocol {
}
//MARK: - `notificationClient`

public var notificationClientThrowableError: Error?
public var notificationClientCallsCount = 0
public var notificationClientCalled: Bool {
return notificationClientCallsCount > 0
}
public var notificationClientReturnValue: NotificationClientBuilder!
public var notificationClientClosure: (() -> NotificationClientBuilder)?
public var notificationClientClosure: (() throws -> NotificationClientBuilder)?

public func `notificationClient`() -> NotificationClientBuilder {
public func `notificationClient`() throws -> NotificationClientBuilder {
if let error = notificationClientThrowableError {
throw error
}
notificationClientCallsCount += 1
if let notificationClientClosure = notificationClientClosure {
return notificationClientClosure()
return try notificationClientClosure()
} else {
return notificationClientReturnValue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ import UserNotifications
import MatrixRustSDK

protocol NotificationItemProxyProtocol {
var event: TimelineEventProxyProtocol { get }
var event: NotificationEvent? { get }

var eventID: String { get }

var senderID: String { get }

var roomID: String { get }

Expand All @@ -46,16 +50,21 @@ protocol NotificationItemProxyProtocol {

extension NotificationItemProxyProtocol {
var isEncrypted: Bool {
switch event.type {
case .messageLike(let content):
switch content {
case .roomEncrypted:
return true
switch event {
case .none, .invite:
return false
case .timeline(let event):
switch try? event.eventType() {
case .messageLike(let content):
switch content {
case .roomEncrypted:
return true
default:
return false
}
default:
return false
}
default:
return false
}
}

Expand All @@ -66,17 +75,22 @@ extension NotificationItemProxyProtocol {

struct NotificationItemProxy: NotificationItemProxyProtocol {
let notificationItem: NotificationItem
let eventID: String
let receiverID: String
let roomID: String

var event: TimelineEventProxyProtocol {
TimelineEventProxy(timelineEvent: notificationItem.event)
var event: NotificationEvent? {
notificationItem.event
}

var senderDisplayName: String? {
notificationItem.senderInfo.displayName
}

var senderID: String {
notificationItem.senderInfo.userId
}

var roomDisplayName: String {
notificationItem.roomInfo.displayName
}
Expand All @@ -94,7 +108,7 @@ struct NotificationItemProxy: NotificationItemProxyProtocol {
}

var isNoisy: Bool {
notificationItem.isNoisy
notificationItem.isNoisy ?? false
}

var senderAvatarMediaSource: MediaSourceProxy? {
Expand All @@ -117,14 +131,16 @@ struct NotificationItemProxy: NotificationItemProxyProtocol {
struct EmptyNotificationItemProxy: NotificationItemProxyProtocol {
let eventID: String

var event: TimelineEventProxyProtocol {
MockTimelineEventProxy(eventID: eventID)
var event: NotificationEvent? {
nil
}

let roomID: String

let receiverID: String

var senderID: String { "" }

var senderDisplayName: String? { nil }

var senderAvatarURL: String? { nil }
Expand Down Expand Up @@ -155,7 +171,7 @@ extension NotificationItemProxyProtocol {
let notification = UNMutableNotificationContent()
notification.receiverID = receiverID
notification.roomID = roomID
notification.eventID = event.eventID
notification.eventID = eventID
notification.sound = isNoisy ? UNNotificationSound(named: UNNotificationSoundName(rawValue: "message.caf")) : nil
// So that the UI groups notification that are received for the same room but also for the same user
notification.threadIdentifier = "\(receiverID)\(roomID)"
Expand All @@ -167,20 +183,25 @@ extension NotificationItemProxyProtocol {
(!isDM && roomAvatarMediaSource != nil) {
return true
}
switch event.type {
case .state, .none:
switch event {
case .invite, .none:
return false
case let .messageLike(content):
switch content {
case let .roomMessage(messageType):
switch messageType {
case .image, .video, .audio:
return true
case .timeline(let event):
switch try? event.eventType() {
case .state, .none:
return false
case let .messageLike(content):
switch content {
case let .roomMessage(messageType):
switch messageType {
case .image, .video, .audio:
return true
default:
return false
}
default:
return false
}
default:
return false
}
}
}
Expand All @@ -201,45 +222,28 @@ extension NotificationItemProxyProtocol {
/// - mediaProvider: Media provider to process also media. May be passed nil to ignore media operations.
/// - Returns: A notification content object if the notification should be displayed. Otherwise nil.
func process(mediaProvider: MediaProviderProtocol?) async throws -> UNMutableNotificationContent {
if self is EmptyNotificationItemProxy {
switch event {
case .none:
return processEmpty()
} else {
switch event.type {
case .none:
return processEmpty()
case let .state(content):
return try await processStateEvent(content: content, mediaProvider: mediaProvider)
case .invite:
return try await processInvited(mediaProvider: mediaProvider)
case .timeline(let event):
switch try? event.eventType() {
case let .messageLike(content):
switch content {
case .roomMessage(messageType: let messageType):
return try await processRoomMessage(messageType: messageType, mediaProvider: mediaProvider)
default:
return processEmpty()
}
}
}
}

// MARK: - Private

private func processStateEvent(content: StateEventContent, mediaProvider: MediaProviderProtocol?) async throws -> UNMutableNotificationContent {
switch content {
case let .roomMemberContent(userId, membershipState):
switch membershipState {
case .invite:
if userId == receiverID {
return try await processInvited(mediaProvider: mediaProvider)
} else {
return processEmpty()
}
default:
return processEmpty()
}
default:
return processEmpty()
}
}

// MARK: - Private

private func processInvited(mediaProvider: MediaProviderProtocol?) async throws -> UNMutableNotificationContent {
var notification = baseMutableContent

Expand All @@ -253,7 +257,7 @@ extension NotificationItemProxyProtocol {
}

notification = try await notification.addSenderIcon(using: mediaProvider,
senderID: event.senderID,
senderID: senderID,
senderName: senderDisplayName ?? roomDisplayName,
icon: icon)
notification.body = body
Expand Down Expand Up @@ -299,7 +303,7 @@ extension NotificationItemProxyProtocol {
notification.categoryIdentifier = NotificationConstants.Category.message

notification = try await notification.addSenderIcon(using: mediaProvider,
senderID: event.senderID,
senderID: senderID,
senderName: senderDisplayName ?? roomDisplayName,
icon: icon)
return notification
Expand Down
6 changes: 5 additions & 1 deletion ElementX/Sources/Services/Room/RoomProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,11 @@ class RoomProxy: RoomProxyProtocol {
/// This should become automatic on the RustSDK side at some point
private func fetchMembers() async {
await Task.dispatch(on: .global()) {
self.room.fetchMembers()
do {
_ = try self.room.fetchMembers()
} catch {
MXLog.error("Failed fetching members: \(error)")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ struct RoomEventStringBuilder {
member: sender.id,
memberIsYou: isOutgoing)
.map(AttributedString.init)
case .poll, .pollEnd:
return nil
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
private let stateSubject = CurrentValueSubject<RoomSummaryProviderState, Never>(.notLoaded)
private let countSubject = CurrentValueSubject<UInt, Never>(0)

private let diffPublisher = PassthroughSubject<RoomListEntriesUpdate, Never>()
private let diffsPublisher = PassthroughSubject<[RoomListEntriesUpdate], Never>()

var roomListPublisher: CurrentValuePublisher<[RoomSummary], Never> {
roomListSubject.asCurrentValuePublisher()
Expand All @@ -59,8 +59,8 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
self.eventStringBuilder = eventStringBuilder
self.name = name

diffPublisher
.collect(.byTime(serialDispatchQueue, 0.025))
diffsPublisher
.receive(on: serialDispatchQueue)
.sink { [weak self] in self?.updateRoomsWithDiffs($0) }
.store(in: &cancellables)
}
Expand All @@ -73,10 +73,10 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
self.roomList = roomList

do {
let listUpdatesSubscriptionResult = try roomList.entries(listener: RoomListEntriesListenerProxy { [weak self] update in
let listUpdatesSubscriptionResult = try roomList.entries(listener: RoomListEntriesListenerProxy { [weak self] updates in
guard let self else { return }
MXLog.verbose("\(name): Received list update")
diffPublisher.send(update)
diffsPublisher.send(updates)
})

listUpdatesTaskHandle = listUpdatesSubscriptionResult.entriesStream
Expand Down Expand Up @@ -324,13 +324,13 @@ extension MatrixRustSDK.RoomListEntry {
}

private class RoomListEntriesListenerProxy: RoomListEntriesListener {
private let onUpdateClosure: (RoomListEntriesUpdate) -> Void
private let onUpdateClosure: ([RoomListEntriesUpdate]) -> Void

init(_ onUpdateClosure: @escaping (RoomListEntriesUpdate) -> Void) {
init(_ onUpdateClosure: @escaping ([RoomListEntriesUpdate]) -> Void) {
self.onUpdateClosure = onUpdateClosure
}

func onUpdate(roomEntriesUpdate: RoomListEntriesUpdate) {
func onUpdate(roomEntriesUpdate: [RoomListEntriesUpdate]) {
onUpdateClosure(roomEntriesUpdate)
}
}
Expand Down
59 changes: 0 additions & 59 deletions ElementX/Sources/Services/Timeline/TimelineEventProxy.swift

This file was deleted.

Loading

0 comments on commit 1529b5b

Please sign in to comment.