Skip to content

Commit

Permalink
Bump SDK version and fix breaking changes. (#610)
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave authored Feb 22, 2023
1 parent 246879f commit 2399088
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/matrix-org/matrix-rust-components-swift",
"state" : {
"revision" : "986c400f8d4d0f9d467370f98d70b6b742e90e18",
"version" : "1.0.38-alpha"
"revision" : "cceadb7fb59518e642010901b8f0cd87946221f3",
"version" : "1.0.40-alpha"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion ElementX/Sources/Services/Room/MockRoomProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct MockRoomProxy: RoomProxyProtocol {

func startLiveEventListener() { }

func addTimelineListener(listener: TimelineListener) -> Result<Void, RoomProxyError> {
func addTimelineListener(listener: TimelineListener) -> Result<[TimelineItem], RoomProxyError> {
.failure(.failedAddingTimelineListener)
}

Expand Down
8 changes: 4 additions & 4 deletions ElementX/Sources/Services/Room/RoomProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,16 @@ class RoomProxy: RoomProxyProtocol {
}
}

func addTimelineListener(listener: TimelineListener) -> Result<Void, RoomProxyError> {
func addTimelineListener(listener: TimelineListener) -> Result<[TimelineItem], RoomProxyError> {
let settings = RoomSubscription(requiredState: [RequiredState(key: "m.room.topic", value: ""),
RequiredState(key: "m.room.canonical_alias", value: "")],
timelineLimit: nil)
if let token = slidingSyncRoom.subscribeAndAddTimelineListener(listener: listener, settings: settings) {
timelineObservationToken = token
if let result = try? slidingSyncRoom.subscribeAndAddTimelineListener(listener: listener, settings: settings) {
timelineObservationToken = result.taskHandle
Task {
await fetchMembers()
}
return .success(())
return .success(result.items)
} else {
return .failure(.failedAddingTimelineListener)
}
Expand Down
2 changes: 1 addition & 1 deletion ElementX/Sources/Services/Room/RoomProxyProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protocol RoomProxyProtocol {

func loadDisplayNameForUserId(_ userId: String) async -> Result<String?, RoomProxyError>

func addTimelineListener(listener: TimelineListener) -> Result<Void, RoomProxyError>
func addTimelineListener(listener: TimelineListener) -> Result<[TimelineItem], RoomProxyError>

func paginateBackwards(requestSize: UInt, untilNumberOfItems: UInt) async -> Result<Void, RoomProxyError>

Expand Down
95 changes: 46 additions & 49 deletions ElementX/Sources/Services/Timeline/RoomTimelineProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ class RoomTimelineProvider: RoomTimelineProviderProtocol {
.store(in: &cancellables)

switch await roomProxy.addTimelineListener(listener: roomTimelineListener) {
case .success(let items):
itemProxies = items.map(TimelineItemProxy.init)
case .failure:
let roomID = await roomProxy.id
MXLog.error("Failed adding timeline listener on room with identifier: \(roomID)")
default:
break
}
}
}
Expand Down Expand Up @@ -87,79 +87,76 @@ class RoomTimelineProvider: RoomTimelineProviderProtocol {

MXLog.verbose("Finished applying diff")
}

// swiftlint:disable:next cyclomatic_complexity function_body_length
private func buildDiff(from diff: TimelineDiff, on itemProxies: [TimelineItemProxy]) -> CollectionDifference<TimelineItemProxy>? {
var changes = [CollectionDifference<TimelineItemProxy>.Change]()

switch diff.change() {
case .push:
guard let item = diff.push() else {
fatalError()
}
case .pushFront:
guard let item = diff.pushFront() else { fatalError() }

MXLog.verbose("Push Front")
let itemProxy = TimelineItemProxy(item: item)
changes.append(.insert(offset: 0, element: itemProxy, associatedWith: nil))
case .pushBack:
guard let item = diff.pushBack() else { fatalError() }

MXLog.verbose("Push")
MXLog.verbose("Push Back")
let itemProxy = TimelineItemProxy(item: item)
changes.append(.insert(offset: Int(itemProxies.count), element: itemProxy, associatedWith: nil))
case .updateAt:
guard let update = diff.updateAt() else {
fatalError()
}
case .insert:
guard let update = diff.insert() else { fatalError() }

MXLog.verbose("Update \(update.index), current total count: \(itemProxies.count)")
MXLog.verbose("Insert at \(update.index), current total count: \(itemProxies.count)")
let itemProxy = TimelineItemProxy(item: update.item)
changes.append(.remove(offset: Int(update.index), element: itemProxy, associatedWith: nil))
changes.append(.insert(offset: Int(update.index), element: itemProxy, associatedWith: nil))
case .insertAt:
guard let update = diff.insertAt() else {
fatalError()
case .append:
guard let items = diff.append() else { fatalError() }

MXLog.verbose("Append new items with count: \(items.count), to current total count: \(itemProxies.count)")
for (index, item) in items.enumerated() {
changes.append(.insert(offset: Int(itemProxies.count) + index, element: TimelineItemProxy(item: item), associatedWith: nil))
}
case .set:
guard let update = diff.set() else { fatalError() }

MXLog.verbose("Insert at \(update.index), current total count: \(itemProxies.count)")
MXLog.verbose("Update \(update.index), current total count: \(itemProxies.count)")
let itemProxy = TimelineItemProxy(item: update.item)
changes.append(.remove(offset: Int(update.index), element: itemProxy, associatedWith: nil))
changes.append(.insert(offset: Int(update.index), element: itemProxy, associatedWith: nil))
case .move:
guard let update = diff.move() else {
fatalError()
}

MXLog.verbose("Move from: \(update.oldIndex) to: \(update.newIndex), current total count: \(itemProxies.count)")
let itemProxy = itemProxies[Int(update.oldIndex)]
changes.append(.remove(offset: Int(update.oldIndex), element: itemProxy, associatedWith: nil))
changes.append(.insert(offset: Int(update.newIndex), element: itemProxy, associatedWith: nil))
case .removeAt:
guard let index = diff.removeAt() else {
fatalError()
}
case .popFront:
MXLog.verbose("Pop Front, current total count: \(itemProxies.count)")
guard let itemProxy = itemProxies.first else { fatalError() }

MXLog.verbose("Remove from: \(index), current total count: \(itemProxies.count)")
changes.append(.remove(offset: 0, element: itemProxy, associatedWith: nil))
case .popBack:
MXLog.verbose("Pop Back, current total count: \(itemProxies.count)")
guard let itemProxy = itemProxies.last else { fatalError() }

changes.append(.remove(offset: itemProxies.count - 1, element: itemProxy, associatedWith: nil))
case .remove:
guard let index = diff.remove() else { fatalError() }

MXLog.verbose("Remove item at: \(index), current total count: \(itemProxies.count)")
let itemProxy = itemProxies[Int(index)]
changes.append(.remove(offset: Int(index), element: itemProxy, associatedWith: nil))
case .replace:
guard let items = diff.replace() else {
fatalError()
}

MXLog.verbose("Replace all items with new count: \(items.count), current total count: \(itemProxies.count)")
case .clear:
MXLog.verbose("Clear all items, current total count: \(itemProxies.count)")
for (index, itemProxy) in itemProxies.enumerated() {
changes.append(.remove(offset: index, element: itemProxy, associatedWith: nil))
}
case .reset:
guard let items = diff.reset() else { fatalError() }

for (index, item) in items.enumerated() {
changes.append(.insert(offset: index, element: TimelineItemProxy(item: item), associatedWith: nil))
}
case .clear:
MXLog.verbose("Clear all items, current total count: \(itemProxies.count)")
MXLog.verbose("Replace all items with new count: \(items.count), current total count: \(itemProxies.count)")
for (index, itemProxy) in itemProxies.enumerated() {
changes.append(.remove(offset: index, element: itemProxy, associatedWith: nil))
}
case .pop:
MXLog.verbose("Pop, current total count: \(itemProxies.count)")
guard let itemProxy = itemProxies.last else {
fatalError()
}

changes.append(.remove(offset: itemProxies.count - 1, element: itemProxy, associatedWith: nil))
for (index, timelineItem) in items.enumerated() {
changes.append(.insert(offset: index, element: TimelineItemProxy(item: timelineItem), associatedWith: nil))
}
}

return CollectionDifference(changes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
case .emote(content: let content):
let message = MessageTimelineItem(item: eventItemProxy.item, content: content)
return buildEmoteTimelineItemFromMessage(eventItemProxy, message, isOutgoing, groupState)
case .audio:
#warning("Audio timeline items not currently supported")
return nil
case .none:
return buildFallbackTimelineItem(eventItemProxy, isOutgoing, groupState)
}
Expand Down
3 changes: 3 additions & 0 deletions NSE/Sources/Other/NotificationItemProxy+NSE.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ extension NotificationItemProxy {
senderId: senderId,
roomId: roomId,
mediaProvider: mediaProvider)
case .audio:
#warning("Audio timeline items not currently supported")
return nil
case .video(content: let content):
return try await processVideo(content: content,
senderId: senderId,
Expand Down
2 changes: 1 addition & 1 deletion project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ include:
packages:
MatrixRustSDK:
url: https://github.com/matrix-org/matrix-rust-components-swift
exactVersion: 1.0.38-alpha
exactVersion: 1.0.40-alpha
# path: ../matrix-rust-sdk
DesignKit:
path: DesignKit
Expand Down

0 comments on commit 2399088

Please sign in to comment.