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

Rename MXSessionSyncProgress #1686

Merged
merged 2 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
60 changes: 30 additions & 30 deletions MatrixSDK.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions MatrixSDK/MXSDKOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,12 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) BOOL enableNewClientInformationFeature;

/**
Enable the calculating of progress during sync, incl counting the number
Enable the calculating of progress during session startup, incl counting the number
of attempts to sync with the server and percentage of response data processed.

@remark NO by default
*/
@property (nonatomic) BOOL enableSyncProgress;
@property (nonatomic) BOOL enableStartupProgress;

@end

Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK/MXSDKOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ - (instancetype)init

_enableSymmetricBackup = NO;
_enableNewClientInformationFeature = NO;
_enableSyncProgress = NO;
_enableStartupProgress = NO;
}

return self;
Expand Down
6 changes: 3 additions & 3 deletions MatrixSDK/MXSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ FOUNDATION_EXPORT NSString *const kMXSessionNoRoomTag;
@class MXCapabilities;
@class MXEventStreamService;
@class MXLocationService;
@class MXSessionSyncProgress;
@class MXSessionStartupProgress;

#pragma mark - MXSession
/**
Expand Down Expand Up @@ -434,9 +434,9 @@ FOUNDATION_EXPORT NSString *const kMXSessionNoRoomTag;
@property (nonatomic, readonly) BOOL syncWithLazyLoadOfRoomMembers;

/**
Handler that can compute the overal progress of sync and report it to a delegate
Handler that can compute the overal progress of session startup and report it to a delegate
*/
@property (nonatomic, readonly) MXSessionSyncProgress *syncProgress;
@property (nonatomic, readonly) MXSessionStartupProgress *startupProgress;

/**
The profile of the current user.
Expand Down
30 changes: 15 additions & 15 deletions MatrixSDK/MXSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ Queue of requested direct room change operations ([MXSession setRoom:directWithU

@property (nonatomic, readwrite) MXClientInformationService *clientInformationService;

@property (nonatomic, strong) MXSessionSyncProgress *syncProgress;
@property (nonatomic, strong) MXSessionStartupProgress *startupProgress;

@end

Expand Down Expand Up @@ -312,9 +312,9 @@ - (id)initWithMatrixRestClient:(MXRestClient*)mxRestClient
_homeserverCapabilitiesService = [[MXHomeserverCapabilitiesService alloc] initWithSession: self];
[_homeserverCapabilitiesService updateWithCompletion:nil];

if (MXSDKOptions.sharedInstance.enableSyncProgress)
if (MXSDKOptions.sharedInstance.enableStartupProgress)
{
_syncProgress = [[MXSessionSyncProgress alloc] init];
_startupProgress = [[MXSessionStartupProgress alloc] init];
}

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onDidDecryptEvent:) name:kMXEventDidDecryptNotification object:nil];
Expand Down Expand Up @@ -585,10 +585,10 @@ - (void)handleSyncResponse:(MXSyncResponse *)syncResponse
void(^dispatch_group_leave_with_progress)(dispatch_group_t) = ^(dispatch_group_t dispatchGroup) {
dispatch_group_leave(dispatchGroup);

if (MXSDKOptions.sharedInstance.enableSyncProgress && progress)
if (MXSDKOptions.sharedInstance.enableStartupProgress && progress)
{
completedRooms += 1;
progress([self syncProgressForCompleted:completedRooms total:totalRooms]);
progress([self startupProgressForCompleted:completedRooms total:totalRooms]);
}
};

Expand Down Expand Up @@ -1277,7 +1277,7 @@ - (void)close

// Clean any cached initial sync response
[self.initialSyncResponseCache deleteData];
self.syncProgress = nil;
self.startupProgress = nil;

// Flush the store
[self.storeService closeStores];
Expand Down Expand Up @@ -1451,9 +1451,9 @@ - (void)serverSyncWithServerTimeout:(NSUInteger)serverTimeout
clientTimeout:(NSUInteger)clientTimeout
setPresence:(NSString*)setPresence
{
if (MXSDKOptions.sharedInstance.enableSyncProgress)
if (MXSDKOptions.sharedInstance.enableStartupProgress)
{
[self.syncProgress incrementSyncAttempt];
[self.startupProgress incrementSyncAttempt];
}

dispatch_group_t initialSyncDispatchGroup = dispatch_group_create();
Expand Down Expand Up @@ -1556,9 +1556,9 @@ - (void)serverSyncWithServerTimeout:(NSUInteger)serverTimeout

[self handleSyncResponse:syncResponse
progress:^(CGFloat progress) {
if (MXSDKOptions.sharedInstance.enableSyncProgress)
if (MXSDKOptions.sharedInstance.enableStartupProgress)
{
[self.syncProgress updateProcessingProgress:progress forPhase:MXSessionSyncProcessingPhaseSyncResponse];
[self.startupProgress updateProcessingProgress:progress forPhase:MXSessionProcessingResponsePhaseSyncResponse];
}
}
completion:^{
Expand All @@ -1571,9 +1571,9 @@ - (void)serverSyncWithServerTimeout:(NSUInteger)serverTimeout
[self fixRoomsSummariesLastMessageWithMaxServerPaginationCount:MXRoomSummaryPaginationChunkSize
force:YES
progress:^(CGFloat progress) {
if (MXSDKOptions.sharedInstance.enableSyncProgress)
if (MXSDKOptions.sharedInstance.enableStartupProgress)
{
[self.syncProgress updateProcessingProgress:progress forPhase:MXSessionSyncProcessingPhaseRoomSummaries];
[self.startupProgress updateProcessingProgress:progress forPhase:MXSessionProcessingResponsePhaseRoomSummaries];
}
}
completion:^{
Expand Down Expand Up @@ -2266,7 +2266,7 @@ - (void)handleOutdatedSyncResponse:(MXSyncResponse *)syncResponse
[self handleCryptoSyncResponse:syncResponse onComplete:completion];
}

- (CGFloat)syncProgressForCompleted:(NSInteger)completed total:(NSInteger)total
- (CGFloat)startupProgressForCompleted:(NSInteger)completed total:(NSInteger)total
{
return total > 0 ? (CGFloat)completed/(CGFloat)total : 0;
}
Expand Down Expand Up @@ -3368,10 +3368,10 @@ - (void)fixRoomsSummariesLastMessageWithMaxServerPaginationCount:(NSUInteger)max
__block NSInteger completedRooms = 0;
void(^dispatch_group_leave_with_progress)(dispatch_group_t) = ^(dispatch_group_t dispatchGroup) {
dispatch_group_leave(dispatchGroup);
if (MXSDKOptions.sharedInstance.enableSyncProgress && progress)
if (MXSDKOptions.sharedInstance.enableStartupProgress && progress)
{
completedRooms += 1;
progress([self syncProgressForCompleted:completedRooms total:self.rooms.count]);
progress([self startupProgressForCompleted:completedRooms total:self.rooms.count]);
}
};

Expand Down
98 changes: 98 additions & 0 deletions MatrixSDK/MXSessionStartupProgress.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
//
// 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

/// Different stages of starting up a session that may complete
/// in non-trivial amount of time. These stages can be observed
/// and used to update the user interface during session loading.
public enum MXSessionStartupStage {

/// Migrating data to a new store version
case migratingData(progress: Double)

/// Syncing with the server as Nth attempt
case serverSyncing(attempt: Int)

/// Processing server response
case processingResponse(progress: Double)

var isSyncing: Bool {
guard case .serverSyncing = self else {
return false
}
return true
}
}

/// Delegate that recieves stage updates
public protocol MXSessionStartupProgressDelegate: AnyObject {
func sessionDidUpdateStartupStage(_ stage: MXSessionStartupStage)
}

/// Distinct phases of the `processingResponse` stage that report
/// their own local progress separately and complete in a given order
@objc public enum MXSessionProcessingResponsePhase: Int, CaseIterable {

/// Processing the response from the server
case syncResponse

/// Updating room summaries
case roomSummaries
}

/// `MXSessionStartupProgress` tracks individual stages and per-stage progress
/// during a session startup, where the application may be blocking user interactions.
@objc public class MXSessionStartupProgress: NSObject {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change of functionality from MXSessionSyncProgress, only renaming

private var syncAttempts = 0
private var stage: MXSessionStartupStage? {
didSet {
if let state = stage {
delegate?.sessionDidUpdateStartupStage(state)
}
}
}

public weak var delegate: MXSessionStartupProgressDelegate? {
didSet {
if let state = stage {
delegate?.sessionDidUpdateStartupStage(state)
}
}
}

/// Increment the total number of sync attempts during the `serverSyncing` stage
@objc public func incrementSyncAttempt() {
guard stage == nil || stage?.isSyncing == true else {
return
}

syncAttempts += 1
stage = .serverSyncing(attempt: syncAttempts)
}

/// Update the local progress of a specific phase within `processingResponse`
///
/// The overal progress will be computed and reported automatically
@objc public func updateProcessingProgress(_ progress: Double, forPhase phase: MXSessionProcessingResponsePhase) {
let totalPhases = Double(MXSessionProcessingResponsePhase.allCases.count)
let currentPhaseProgress = progress / totalPhases
let previousPhasesProgress = Double(phase.rawValue) / totalPhases
let totalProgress = previousPhasesProgress + currentPhaseProgress

stage = .processingResponse(progress: totalProgress)
}
}
93 changes: 0 additions & 93 deletions MatrixSDK/MXSessionSyncProgress.swift

This file was deleted.

Loading