Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically retry decryptions in the active room when the app becomes active again just in case the NSE received keys we're not aware of #3628

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions ElementX/Sources/Mocks/Generated/GeneratedMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14076,44 +14076,44 @@ class TimelineProxyMock: TimelineProxyProtocol {
}
//MARK: - retryDecryption

var retryDecryptionForUnderlyingCallsCount = 0
var retryDecryptionForCallsCount: Int {
var retryDecryptionSessionIDsUnderlyingCallsCount = 0
var retryDecryptionSessionIDsCallsCount: Int {
get {
if Thread.isMainThread {
return retryDecryptionForUnderlyingCallsCount
return retryDecryptionSessionIDsUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = retryDecryptionForUnderlyingCallsCount
returnValue = retryDecryptionSessionIDsUnderlyingCallsCount
}

return returnValue!
}
}
set {
if Thread.isMainThread {
retryDecryptionForUnderlyingCallsCount = newValue
retryDecryptionSessionIDsUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
retryDecryptionForUnderlyingCallsCount = newValue
retryDecryptionSessionIDsUnderlyingCallsCount = newValue
}
}
}
}
var retryDecryptionForCalled: Bool {
return retryDecryptionForCallsCount > 0
var retryDecryptionSessionIDsCalled: Bool {
return retryDecryptionSessionIDsCallsCount > 0
}
var retryDecryptionForReceivedSessionID: String?
var retryDecryptionForReceivedInvocations: [String] = []
var retryDecryptionForClosure: ((String) async -> Void)?
var retryDecryptionSessionIDsReceivedSessionIDs: [String]?
var retryDecryptionSessionIDsReceivedInvocations: [[String]?] = []
var retryDecryptionSessionIDsClosure: (([String]?) async -> Void)?

func retryDecryption(for sessionID: String) async {
retryDecryptionForCallsCount += 1
retryDecryptionForReceivedSessionID = sessionID
func retryDecryption(sessionIDs: [String]?) async {
retryDecryptionSessionIDsCallsCount += 1
retryDecryptionSessionIDsReceivedSessionIDs = sessionIDs
DispatchQueue.main.async {
self.retryDecryptionForReceivedInvocations.append(sessionID)
self.retryDecryptionSessionIDsReceivedInvocations.append(sessionIDs)
}
await retryDecryptionForClosure?(sessionID)
await retryDecryptionSessionIDsClosure?(sessionIDs)
}
//MARK: - paginateBackwards

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
.throttle(for: .milliseconds(100), scheduler: DispatchQueue.main, latest: true)
.weakAssign(to: \.state.unseenKnockRequests, on: self)
.store(in: &cancellables)

NotificationCenter.default.publisher(for: UIApplication.didBecomeActiveNotification)
.sink { [weak self] _ in
Task {
await self?.roomProxy.timeline.retryDecryption()
}
}
.store(in: &cancellables)
stefanceriu marked this conversation as resolved.
Show resolved Hide resolved
}

private func processIdentityStatusChanges(_ changes: [IdentityStatusChange]) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class TimelineInteractionHandler {
MXLog.info("Showing debug info for \(eventTimelineItem.id)")
actionsSubject.send(.showDebugInfo(debugInfo))
case .retryDecryption(let sessionID):
Task { await timelineController.retryDecryption(for: sessionID) }
Task { await timelineController.retryDecryption(sessionIDs: [sessionID]) }
stefanceriu marked this conversation as resolved.
Show resolved Hide resolved
case .report:
actionsSubject.send(.displayReportContent(itemID: itemID, senderID: eventTimelineItem.sender.id))
case .react:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class MockRoomTimelineController: RoomTimelineControllerProtocol {
nil
}

func retryDecryption(for sessionID: String) async { }
func retryDecryption(sessionIDs: [String]?) async { }

func eventTimestamp(for itemID: TimelineItemIdentifier) -> Date? {
timelineItemsTimestamp[itemID] ?? .now
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
return nil
}

func retryDecryption(for sessionID: String) async {
await activeTimeline.retryDecryption(for: sessionID)
func retryDecryption(sessionIDs: [String]?) async {
await activeTimeline.retryDecryption(sessionIDs: sessionIDs)
}

// MARK: - Private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protocol RoomTimelineControllerProtocol {

func sendHandle(for itemID: TimelineItemIdentifier) -> SendHandleProxy?

func retryDecryption(for sessionID: String) async
func retryDecryption(sessionIDs: [String]?) async
stefanceriu marked this conversation as resolved.
Show resolved Hide resolved

func eventTimestamp(for itemID: TimelineItemIdentifier) -> Date?
}
10 changes: 6 additions & 4 deletions ElementX/Sources/Services/Timeline/TimelineProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,14 @@ final class TimelineProxy: TimelineProxyProtocol {
}
}

func retryDecryption(for sessionID: String) async {
MXLog.info("Retrying decryption for sessionID: \(sessionID)")
func retryDecryption(sessionIDs: [String]?) async {
let sessionIDs = sessionIDs ?? []

MXLog.info("Retrying decryption for sessionIDs: \(sessionIDs)")

await Task.dispatch(on: .global()) { [weak self] in
self?.timeline.retryDecryption(sessionIds: [sessionID])
MXLog.info("Finished retrying decryption for sessionID: \(sessionID)")
self?.timeline.retryDecryption(sessionIds: sessionIDs)
MXLog.info("Finished retrying decryption for sessionID: \(sessionIDs)")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protocol TimelineProxyProtocol {

func messageEventContent(for timelineItemID: TimelineItemIdentifier) async -> RoomMessageEventContentWithoutRelation?

func retryDecryption(for sessionID: String) async
func retryDecryption(sessionIDs: [String]?) async

func paginateBackwards(requestSize: UInt16) async -> Result<Void, TimelineProxyError>
func paginateForwards(requestSize: UInt16) async -> Result<Void, TimelineProxyError>
Expand Down Expand Up @@ -113,3 +113,9 @@ protocol TimelineProxyProtocol {
html: String?,
intentionalMentions: Mentions) -> RoomMessageEventContentWithoutRelation
}

extension TimelineProxyProtocol {
func retryDecryption() async {
await retryDecryption(sessionIDs: nil)
}
}
Loading