Pin/Unpin Logic (#3084)

This commit is contained in:
Mauro
2024-07-26 20:41:00 +02:00
committed by GitHub
parent 5a4d21ab7a
commit 0da2d4917b
24 changed files with 659 additions and 69 deletions
@@ -100,6 +100,10 @@ class MockRoomTimelineController: RoomTimelineControllerProtocol {
func redact(_ itemID: TimelineItemIdentifier) async { }
func pin(eventID: String) async { }
func unpin(eventID: String) async { }
func messageEventContent(for itemID: TimelineItemIdentifier) -> RoomMessageEventContentWithoutRelation? {
.init(noPointer: .init())
}
@@ -237,6 +237,36 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
}
}
func pin(eventID: String) async {
MXLog.info("Pinning event \(eventID) in \(roomID)")
switch await activeTimeline.pin(eventID: eventID) {
case .success(let value):
if value {
MXLog.info("Finished pinning event \(eventID)")
} else {
MXLog.error("Failed pinning event \(eventID) because is already pinned")
}
case .failure(let error):
MXLog.error("Failed pinning event \(eventID) with error: \(error)")
}
}
func unpin(eventID: String) async {
MXLog.info("Unpinning event \(eventID) in \(roomID)")
switch await activeTimeline.unpin(eventID: eventID) {
case .success(let value):
if value {
MXLog.info("Finished unpinning event \(eventID)")
} else {
MXLog.error("Failed unpinning event \(eventID) because is not pinned")
}
case .failure(let error):
MXLog.error("Failed unpinning event \(eventID) with error: \(error)")
}
}
func messageEventContent(for timelineItemID: TimelineItemIdentifier) async -> RoomMessageEventContentWithoutRelation? {
await activeTimeline.messageEventContent(for: timelineItemID)
}
@@ -68,6 +68,10 @@ protocol RoomTimelineControllerProtocol {
func redact(_ itemID: TimelineItemIdentifier) async
func pin(eventID: String) async
func unpin(eventID: String) async
func messageEventContent(for itemID: TimelineItemIdentifier) async -> RoomMessageEventContentWithoutRelation?
func debugInfo(for itemID: TimelineItemIdentifier) -> TimelineItemDebugInfo
@@ -202,6 +202,24 @@ final class TimelineProxy: TimelineProxyProtocol {
}
}
func pin(eventID: String) async -> Result<Bool, TimelineProxyError> {
do {
return try await .success(timeline.pinEvent(eventId: eventID))
} catch {
MXLog.error("Failed to pin the event \(eventID) with error: \(error)")
return .failure(.sdkError(error))
}
}
func unpin(eventID: String) async -> Result<Bool, TimelineProxyError> {
do {
return try await .success(timeline.unpinEvent(eventId: eventID))
} catch {
MXLog.error("Failed to unpin the event \(eventID) with error: \(error)")
return .failure(.sdkError(error))
}
}
// MARK: - Sending
func sendAudio(url: URL,
@@ -46,6 +46,10 @@ protocol TimelineProxyProtocol {
func redact(_ timelineItemID: TimelineItemIdentifier,
reason: String?) async -> Result<Void, TimelineProxyError>
func pin(eventID: String) async -> Result<Bool, TimelineProxyError>
func unpin(eventID: String) async -> Result<Bool, TimelineProxyError>
// MARK: - Sending
func sendAudio(url: URL,