Skip to content

Commit

Permalink
Merge branch 'release/0.24.7/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave committed Jan 10, 2023
2 parents b4ec161 + 2c53cec commit ad1d93e
Show file tree
Hide file tree
Showing 53 changed files with 1,438 additions and 739 deletions.
19 changes: 19 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
## Changes in 0.24.7 (2023-01-10)

✨ Features

- Threads: Load the thread list using server-side sorting and pagination ([#6059](https://github.com/vector-im/element-ios/issues/6059))

🙌 Improvements

- Add API to delete user's account data. ([#1651](https://github.com/matrix-org/matrix-ios-sdk/pull/1651))
- Change Sync parser to delete empty account_data events. ([#1656](https://github.com/matrix-org/matrix-ios-sdk/pull/1656))
- CryptoV2: Disable notification decryption ([#1662](https://github.com/matrix-org/matrix-ios-sdk/pull/1662))
- CryptoV2: Verification request and QR listener ([#1663](https://github.com/matrix-org/matrix-ios-sdk/pull/1663))
- Analytics: Do not track cancellation errors ([#1664](https://github.com/matrix-org/matrix-ios-sdk/pull/1664))
- Polls: ensure polls are up to date after they are closed. ([#1672](https://github.com/matrix-org/matrix-ios-sdk/pull/1672))
- Polls: handle decryption errors. ([#1673](https://github.com/matrix-org/matrix-ios-sdk/pull/1673))
- Polls: add support for rendering/replying to poll ended events. ([#1674](https://github.com/matrix-org/matrix-ios-sdk/pull/1674))
- Remove commented device property on MXPushRulesRespose. ([#1677](https://github.com/matrix-org/matrix-ios-sdk/pull/1677))


## Changes in 0.24.6 (2022-12-13)

🙌 Improvements
Expand Down
4 changes: 2 additions & 2 deletions MatrixSDK.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "MatrixSDK"
s.version = "0.24.6"
s.version = "0.24.7"
s.summary = "The iOS SDK to build apps compatible with Matrix (https://www.matrix.org)"

s.description = <<-DESC
Expand Down Expand Up @@ -66,7 +66,7 @@ Pod::Spec.new do |s|

# Experimental / NOT production-ready Rust-based crypto library
s.subspec 'CryptoSDK' do |ss|
ss.dependency 'MatrixSDKCrypto', '0.1.6', :configurations => ["DEBUG"], :inhibit_warnings => true
ss.dependency 'MatrixSDKCrypto', '0.1.7', :configurations => ["DEBUG"], :inhibit_warnings => true
end

end
308 changes: 167 additions & 141 deletions MatrixSDK.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

93 changes: 93 additions & 0 deletions MatrixSDK/Aggregations/MXAggregatedPollsUpdater.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//
// Copyright 2022 The Matrix.org Foundation C.I.C
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

@objcMembers
/// `MXAggregatedPollsUpdater` populates the local database with poll events when some of them may be missing.
/// This can happen for example when a user joins a room with an ongoing poll.
/// In this case `poll.start` and `poll.response` events may be missing causing incorrect rendering of polls on the timeline.
/// This type fetches all the related events of a poll when a `poll.end` event triggers.
public final class MXAggregatedPollsUpdater: NSObject {
private let session: MXSession
private let store: MXStore

public init(session: MXSession, store: MXStore) {
self.session = session
self.store = store
}

public func refreshPoll(after event: MXEvent) {
// the poll refresh is meant to be done at the end of a poll
guard
event.eventType == .pollEnd,
event.relatesTo.relationType == MXEventRelationTypeReference,
let pollStartEventId = event.relatesTo.eventId
else {
return
}

// clients having the poll_started event are supposed to have all the history in between because of the /sync api
guard store.eventExists(withEventId: pollStartEventId, inRoom: event.roomId) == false else {
return
}

session.matrixRestClient.relations(
forEvent: pollStartEventId,
inRoom: event.roomId,
relationType: MXEventRelationTypeReference,
eventType: nil,
from: nil,
direction: MXTimelineDirection.backwards,
limit: nil) { [weak self] response in
switch response {
case .success(let response):
self?.session.store(response: response)
case .failure:
break
}
}
}
}

private extension MXSession {
func store(response: MXAggregationPaginatedResponse) {
// reverse chronological order
let allEvents = response.chunk + response.originalEventArray
storeIfNeeded(events: allEvents)
}

func storeIfNeeded(events: [MXEvent]) {
let eventsToStore = events
.filter { event in
store.eventExists(withEventId: event.eventId, inRoom: event.roomId) == false
}

for event in eventsToStore {
store.storeEvent(forRoom: event.roomId, event: event, direction: .backwards)
}

if eventsToStore.isEmpty == false {
store.commit?()
}
}
}

private extension MXAggregationPaginatedResponse {
var originalEventArray: [MXEvent] {
originalEvent.map { [$0] } ?? []
}
}
5 changes: 5 additions & 0 deletions MatrixSDK/Aggregations/MXAggregations.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ @interface MXAggregations ()
@property (nonatomic) MXAggregatedReactionsUpdater *aggregatedReactionsUpdater;
@property (nonatomic) MXAggregatedEditsUpdater *aggregatedEditsUpdater;
@property (nonatomic) MXAggregatedReferencesUpdater *aggregatedReferencesUpdater;
@property (nonatomic) MXAggregatedPollsUpdater *aggregatedPollsUpdater;

@property (nonatomic, strong, readwrite) MXBeaconAggregations *beaconAggregations;
@property (nonatomic, strong) id<MXBeaconInfoSummaryStoreProtocol> beaconInfoSummaryStore;
Expand Down Expand Up @@ -250,6 +251,8 @@ - (instancetype)initWithMatrixSession:(MXSession *)mxSession
matrixStore:mxSession.store];
self.aggregatedReferencesUpdater = [[MXAggregatedReferencesUpdater alloc] initWithMatrixSession:self.mxSession
matrixStore:mxSession.store];
self.aggregatedPollsUpdater = [[MXAggregatedPollsUpdater alloc] initWithSession:self.mxSession
store:self.mxSession.store];

id<MXBeaconInfoSummaryStoreProtocol> beaconInfoSummaryStore = [[MXBeaconInfoSummaryRealmStore alloc] initWithSession:self.mxSession];

Expand Down Expand Up @@ -312,6 +315,8 @@ - (void)registerListener
[self.beaconAggregations handleBeaconWithEvent:event];
}
break;
case MXEventTypePollEnd:
[self.aggregatedPollsUpdater refreshPollAfter:event];
default:
break;
}
Expand Down
44 changes: 44 additions & 0 deletions MatrixSDK/Background/Crypto/MXDummyBackgroundCrypto.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// Copyright 2022 The Matrix.org Foundation C.I.C
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

#if DEBUG

/// Dummy implementation of background crypto that does nothing and is unable
/// to decrypt notification.
///
/// Note: This is a temporary class to be used with foreground Crypto V2 which
/// is not currently multi-process safe and thus only one process can be
/// decrypting events.
class MXDummyBackgroundCrypto: MXBackgroundCrypto {
enum Error: Swift.Error {
case unableToDecrypt
}

func handleSyncResponse(_ syncResponse: MXSyncResponse) {
}

func canDecryptEvent(_ event: MXEvent) -> Bool {
false
}

func decryptEvent(_ event: MXEvent) throws {
throw Error.unableToDecrypt
}
}

#endif
22 changes: 9 additions & 13 deletions MatrixSDK/Background/MXBackgroundSyncService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,16 @@ public enum MXBackgroundSyncServiceError: Error {
// We can flush any crypto data if our sync response store is empty
let resetBackgroundCryptoStore = syncResponseStoreManager.syncToken() == nil

#if DEBUG
if MXSDKOptions.sharedInstance().enableCryptoV2 {
do {
crypto = try MXBackgroundCryptoV2(credentials: credentials, restClient: restClient)
} catch {
MXLog.failure("[MXBackgroundSyncService] init: Cannot initialize crypto v2", context: error)
crypto = MXLegacyBackgroundCrypto(credentials: credentials, resetBackgroundCryptoStore: resetBackgroundCryptoStore)
crypto = {
#if DEBUG
if MXSDKOptions.sharedInstance().enableCryptoV2 {
// Crypto V2 is currently unable to decrypt notifications due to single-process store,
// so it uses dummy background crypto that does not do anything.
return MXDummyBackgroundCrypto()
}
} else {
crypto = MXLegacyBackgroundCrypto(credentials: credentials, resetBackgroundCryptoStore: resetBackgroundCryptoStore)
}
#else
crypto = MXLegacyBackgroundCrypto(credentials: credentials, resetBackgroundCryptoStore: resetBackgroundCryptoStore)
#endif
#endif
return MXLegacyBackgroundCrypto(credentials: credentials, resetBackgroundCryptoStore: resetBackgroundCryptoStore)
}()

pushRulesManager = MXBackgroundPushRulesManager(withCredentials: credentials)
if let accountData = syncResponseStoreManager.syncResponseStore.accountData {
Expand Down
9 changes: 4 additions & 5 deletions MatrixSDK/ClientInformation/MXClientInformationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class MXClientInformationService: NSObject {
}

guard MXSDKOptions.sharedInstance().enableNewClientInformationFeature else {
return removeDataIfNeeded(on: session)
return deleteDataIfNeeded(on: session)
}

guard let updatedInfo = createClientInformation() else {
Expand All @@ -56,17 +56,16 @@ public class MXClientInformationService: NSObject {
}
}

private func removeDataIfNeeded(on session: MXSession) {
private func deleteDataIfNeeded(on session: MXSession) {
let type = accountDataType(for: session)

guard let currentInfo = session.accountData.accountData(forEventType: type),
!currentInfo.isEmpty else {
guard session.accountData.accountData(forEventType: type) != nil else {
// not exists, no need to do anything
MXLog.debug("[MXClientInformationService] removeDataIfNeeded: no need to remove")
return
}

session.setAccountData([:], forType: type) {
session.deleteAccountData(withType: type) {
MXLog.debug("[MXClientInformationService] removeDataIfNeeded: removed successfully")
} failure: { error in
MXLog.debug("[MXClientInformationService] removeDataIfNeeded: remove failed: \(String(describing: error))")
Expand Down
37 changes: 37 additions & 0 deletions MatrixSDK/Contrib/Swift/MXRestClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,27 @@ public enum MXAccountDataType: Equatable, Hashable {
}
}

/// Represents the threads request include parameter
public enum MXThreadsIncludeParameter: String, RawRepresentable, Equatable, Hashable {
case all
case participated

public init?(rawValue: String) {
switch rawValue {
case kMXThreadsListIncludeAllParameter: self = .all
case kMXThreadsListIncludeParticipatedParameter: self = .participated
default:
return nil
}
}

public var rawValue: String {
switch self {
case .all: return kMXThreadsListIncludeAllParameter
case .participated: return kMXThreadsListIncludeParticipatedParameter
}
}
}



Expand Down Expand Up @@ -1240,6 +1261,22 @@ public extension MXRestClient {
return __roomSummary(with: roomIdOrAlias, via: via, success: currySuccess(completion), failure: curryFailure(completion))
}

/**
List all the threads of a room.

- parameters:
- roomId: the id of the room.
- include: wether the response should include all threads (e.g. `.all`) or only threads participated by the user (e.g. `.participated`)
- from: the token to pass for doing pagination from a previous response.
- completion: A block object called when the operation completes.
- response: Provides the list of root events of the threads and, optionally, the next batch token.

- returns: a `MXHTTPOperation` instance.
*/
@nonobjc @discardableResult func threadsInRoomWithId(_ roomId: String, include: MXThreadsIncludeParameter, from: String?, completion: @escaping (_ response: MXResponse<MXAggregationPaginatedResponse>) -> Void) -> MXHTTPOperation {
return __threadsInRoom(withId: roomId, include: include.rawValue, from: from, success: currySuccess(completion), failure: curryFailure(completion))
};

/**
Upgrade a room to a new version

Expand Down
16 changes: 2 additions & 14 deletions MatrixSDK/Crypto/CryptoMachine/MXCryptoMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,8 @@ extension MXCryptoMachine: MXCryptoVerifying {
content: content
)
}

try await processOutgoingRequests()
}

func handleVerificationConfirmation(_ result: ConfirmVerificationResult) async throws {
Expand Down Expand Up @@ -744,21 +746,7 @@ extension MXCryptoMachine: MXCryptoBackup {

extension MXCryptoMachine: Logger {
func log(logLine: String) {
#if DEBUG
MXLog.debug("[MXCryptoMachine] \(logLine)")
#else
// Filtering out verbose logs for non-debug builds
guard !logLine.starts(with: "DEBUG") else {
return
}
MXLog.debug("[MXCryptoMachine] \(logLine)")
#endif
}

func log(error: String) {
MXLog.error("[MXCryptoMachine] Error", context: [
"error": error
])
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ extension MXEventDecryptionResult {
senderCurve25519Key = event.senderCurve25519Key
claimedEd25519Key = event.claimedEd25519Key
forwardingCurve25519KeyChain = event.forwardingCurve25519Chain
isUntrusted = event.verificationState == VerificationState.untrusted

// `Untrusted` state from rust is currently ignored as it lacks "undecided" option,
// will be changed in a future PR into:
// isUntrusted = event.verificationState == VerificationState.untrusted
isUntrusted = false
}
}

Expand Down
6 changes: 6 additions & 0 deletions MatrixSDK/Crypto/MXCryptoV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,12 @@ private class MXCryptoV2: NSObject, MXCrypto {
// we need to download their keys to be able to proceed with the verification flow
try await self.machine.downloadKeys(users: [userId])
}

do {
try await self.machine.processOutgoingRequests()
} catch {
self.log.error("Error processing requests", context: error)
}
}
}
}
Expand Down
Loading

0 comments on commit ad1d93e

Please sign in to comment.