mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-27 19:56:57 +02:00
Add presence offline mode setting
This commit is contained in:
@@ -715,6 +715,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
||||
|
||||
// Instantiate new session
|
||||
mxSession = [[MXSession alloc] initWithMatrixRestClient:mxRestClient];
|
||||
mxSession.preferredSyncPresence = self.preferredSyncPresence;
|
||||
|
||||
// Check whether an antivirus url is defined.
|
||||
if (_antivirusServerURL)
|
||||
@@ -1007,7 +1008,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
||||
|
||||
// Update user presence
|
||||
MXWeakify(self);
|
||||
[self setUserPresence:MXPresenceUnavailable andStatusMessage:nil completion:^{
|
||||
[self setUserPresence:MXPresenceOffline andStatusMessage:nil completion:^{
|
||||
MXStrongifyAndReturnIfNil(self);
|
||||
[self cancelPauseBackgroundTask];
|
||||
}];
|
||||
@@ -1045,8 +1046,10 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
||||
case MXSessionStatePauseRequested:
|
||||
{
|
||||
// Resume SDK and update user presence
|
||||
MXWeakify(self);
|
||||
[mxSession resume:^{
|
||||
[self setUserPresence:MXPresenceOnline andStatusMessage:nil completion:nil];
|
||||
MXStrongifyAndReturnIfNil(self);
|
||||
[self setUserPresence:self.preferredSyncPresence andStatusMessage:nil completion:nil];
|
||||
|
||||
[self refreshAPNSPusher];
|
||||
[self refreshPushKitPusher];
|
||||
@@ -1513,7 +1516,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
||||
|
||||
MXLogDebug(@"[MXKAccount] %@: The session is ready. Matrix SDK session has been started in %0.fms.", self.mxCredentials.userId, [[NSDate date] timeIntervalSinceDate:self->openSessionStartDate] * 1000);
|
||||
|
||||
[self setUserPresence:MXPresenceOnline andStatusMessage:nil completion:nil];
|
||||
[self setUserPresence:self.preferredSyncPresence andStatusMessage:nil completion:nil];
|
||||
|
||||
} failure:^(NSError *error) {
|
||||
MXStrongifyAndReturnIfNil(self);
|
||||
@@ -2159,4 +2162,17 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Presence
|
||||
|
||||
- (void)setPreferredSyncPresence:(MXPresence)preferredSyncPresence
|
||||
{
|
||||
[super setPreferredSyncPresence:preferredSyncPresence];
|
||||
|
||||
if (self.mxSession)
|
||||
{
|
||||
self.mxSession.preferredSyncPresence = preferredSyncPresence;
|
||||
[self setUserPresence:preferredSyncPresence andStatusMessage:nil completion:nil];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
@protected BOOL _isSoftLogout;
|
||||
@protected BOOL _hasPusherForPushNotifications;
|
||||
@protected BOOL _hasPusherForPushKitNotifications;
|
||||
@protected MXPresence _preferredSyncPresence;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,6 +90,12 @@
|
||||
*/
|
||||
@property (nonatomic, readonly) BOOL hasPusherForPushKitNotifications;
|
||||
|
||||
/**
|
||||
The account's preferred Presence status to share while the application is in foreground.
|
||||
Defaults to MXPresenceOnline.
|
||||
*/
|
||||
@property (nonatomic) MXPresence preferredSyncPresence;
|
||||
|
||||
|
||||
/**
|
||||
Enable In-App notifications based on Remote notifications rules.
|
||||
|
||||
@@ -80,6 +80,15 @@
|
||||
|
||||
_warnedAboutEncryption = [coder decodeBoolForKey:@"warnedAboutEncryption"];
|
||||
|
||||
if ([coder decodeIntForKey:@"preferredSyncPresence"])
|
||||
{
|
||||
_preferredSyncPresence = [coder decodeInt64ForKey:@"preferredSyncPresence"];
|
||||
}
|
||||
else
|
||||
{
|
||||
_preferredSyncPresence = MXPresenceOnline;
|
||||
}
|
||||
|
||||
_others = [coder decodeObjectForKey:@"others"];
|
||||
}
|
||||
|
||||
@@ -143,6 +152,8 @@
|
||||
|
||||
[coder encodeBool:_warnedAboutEncryption forKey:@"warnedAboutEncryption"];
|
||||
|
||||
[coder encodeInt64:_preferredSyncPresence forKey:@"preferredSyncPresence"];
|
||||
|
||||
[coder encodeObject:_others forKey:@"others"];
|
||||
}
|
||||
|
||||
|
||||
@@ -62,6 +62,7 @@ typedef NS_ENUM(NSUInteger, SECTION_TAG)
|
||||
SECTION_TAG_IGNORED_USERS,
|
||||
SECTION_TAG_INTEGRATIONS,
|
||||
SECTION_TAG_USER_INTERFACE,
|
||||
SECTION_TAG_PRESENCE,
|
||||
SECTION_TAG_ADVANCED,
|
||||
SECTION_TAG_ABOUT,
|
||||
SECTION_TAG_LABS,
|
||||
@@ -137,6 +138,11 @@ typedef NS_ENUM(NSUInteger, IDENTITY_SERVER)
|
||||
IDENTITY_SERVER_INDEX
|
||||
};
|
||||
|
||||
typedef NS_ENUM(NSUInteger, PRESENCE)
|
||||
{
|
||||
PRESENCE_OFFLINE_MODE = 0,
|
||||
};
|
||||
|
||||
typedef NS_ENUM(NSUInteger, ADVANCED)
|
||||
{
|
||||
ADVANCED_SHOW_NSFW_ROOMS_INDEX = 0,
|
||||
@@ -520,6 +526,16 @@ TableViewSectionsDelegate>
|
||||
|
||||
[tmpSections addObject: sectionUserInterface];
|
||||
|
||||
if(BuildSettings.presenceSettingsAllowConfiguration)
|
||||
{
|
||||
Section *sectionPresence = [Section sectionWithTag:SECTION_TAG_PRESENCE];
|
||||
[sectionPresence addRowWithTag:PRESENCE_OFFLINE_MODE];
|
||||
sectionPresence.headerTitle = VectorL10n.settingsPresence;
|
||||
sectionPresence.footerTitle = VectorL10n.settingsPresenceOfflineModeDescription;
|
||||
|
||||
[tmpSections addObject:sectionPresence];
|
||||
}
|
||||
|
||||
Section *sectionAdvanced = [Section sectionWithTag:SECTION_TAG_ADVANCED];
|
||||
sectionAdvanced.headerTitle = [VectorL10n settingsAdvanced];
|
||||
|
||||
@@ -2287,6 +2303,24 @@ TableViewSectionsDelegate>
|
||||
cell.selectionStyle = UITableViewCellSelectionStyleDefault;
|
||||
}
|
||||
}
|
||||
else if (section == SECTION_TAG_PRESENCE)
|
||||
{
|
||||
if (row == PRESENCE_OFFLINE_MODE)
|
||||
{
|
||||
MXKTableViewCellWithLabelAndSwitch* labelAndSwitchCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath];
|
||||
|
||||
labelAndSwitchCell.mxkLabel.text = VectorL10n.settingsPresenceOfflineMode;
|
||||
|
||||
MXKAccount *account = MXKAccountManager.sharedManager.accounts.firstObject;
|
||||
|
||||
labelAndSwitchCell.mxkSwitch.on = account.preferredSyncPresence == MXPresenceOffline;
|
||||
labelAndSwitchCell.mxkSwitch.onTintColor = ThemeService.shared.theme.tintColor;
|
||||
labelAndSwitchCell.mxkSwitch.enabled = YES;
|
||||
[labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(togglePresenceOfflineMode:) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
cell = labelAndSwitchCell;
|
||||
}
|
||||
}
|
||||
else if (section == SECTION_TAG_ADVANCED)
|
||||
{
|
||||
if (row == ADVANCED_SHOW_NSFW_ROOMS_INDEX)
|
||||
@@ -3907,6 +3941,19 @@ TableViewSectionsDelegate>
|
||||
self.deactivateAccountViewController = deactivateAccountViewController;
|
||||
}
|
||||
|
||||
- (void)togglePresenceOfflineMode:(UISwitch *)sender
|
||||
{
|
||||
MXKAccount *account = MXKAccountManager.sharedManager.accounts.firstObject;
|
||||
if (sender.isOn)
|
||||
{
|
||||
account.preferredSyncPresence = MXPresenceOffline;
|
||||
}
|
||||
else
|
||||
{
|
||||
account.preferredSyncPresence = MXPresenceOnline;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)toggleNSFWPublicRoomsFiltering:(UISwitch *)sender
|
||||
{
|
||||
RiotSettings.shared.showNSFWPublicRooms = sender.isOn;
|
||||
|
||||
Reference in New Issue
Block a user