Warn unknown devices: the dialog is a one time change to check unknown devices.

If the user presses cancel or ok, devices will be no more unknown
This commit is contained in:
manuroe
2017-02-15 11:36:22 +01:00
parent fd86929f5e
commit 79e21f6d75
2 changed files with 23 additions and 30 deletions
+23 -23
View File
@@ -3121,12 +3121,28 @@
[event.roomId isEqualToString:self.roomDataSource.roomId]
&& [event.sentError.domain isEqualToString:MXEncryptingErrorDomain]
&& event.sentError.code == MXEncryptingErrorUnknownDeviceCode
&& !currentAlert) // Show the alert once in case of resending several events
&& !unknownDevices) // Show the alert once in case of resending several events
{
__weak __typeof(self) weakSelf = self;
[self dismissTemporarySubViews];
// List all unknown devices
unknownDevices = [[MXUsersDevicesMap alloc] init];
NSArray<MXEvent*> *outgoingMsgs = self.roomDataSource.room.outgoingMessages;
for (MXEvent *event in outgoingMsgs)
{
if (event.sentState == MXEventSentStateFailed
&& [event.sentError.domain isEqualToString:MXEncryptingErrorDomain]
&& event.sentError.code == MXEncryptingErrorUnknownDeviceCode)
{
MXUsersDevicesMap<MXDeviceInfo*> *eventUnknownDevices = event.sentError.userInfo[MXEncryptingErrorUnknownDeviceDevicesKey];
[unknownDevices addEntriesFromMap:eventUnknownDevices];
}
}
currentAlert = [[MXKAlert alloc] initWithTitle:[NSBundle mxk_localizedStringForKey:@"unknown_devices_alert_title"]
message:[NSBundle mxk_localizedStringForKey:@"unknown_devices_alert"]
style:MXKAlertStyleAlert];
@@ -3134,13 +3150,18 @@
currentAlert.cancelButtonIndex = [currentAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) {
typeof(self) self = weakSelf;
self->currentAlert = nil;
// Acknowledge the existence of all devices
[self.mainSession.crypto setDevicesKnown:self->unknownDevices complete:^{
self->unknownDevices = nil;
}];
}];
[currentAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"unknown_devices_verify"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) {
typeof(self) self = weakSelf;
self->currentAlert = nil;
[self showUnknownDevices];
[self performSegueWithIdentifier:@"showUnknownDevices" sender:self];
}];
currentAlert.mxkAccessibilityIdentifier = @"RoomVCUnknownDevicesAlert";
@@ -3148,27 +3169,6 @@
}
}
- (void)showUnknownDevices
{
// List all unknown devices
unknownDevices = [[MXUsersDevicesMap alloc] init];
NSArray<MXEvent*> *outgoingMsgs = self.roomDataSource.room.outgoingMessages;
for (MXEvent *event in outgoingMsgs)
{
if (event.sentState == MXEventSentStateFailed
&& [event.sentError.domain isEqualToString:MXEncryptingErrorDomain]
&& event.sentError.code == MXEncryptingErrorUnknownDeviceCode)
{
MXUsersDevicesMap<MXDeviceInfo*> *eventUnknownDevices = event.sentError.userInfo[MXEncryptingErrorUnknownDeviceDevicesKey];
[unknownDevices addEntriesFromMap:eventUnknownDevices];
}
}
[self performSegueWithIdentifier:@"showUnknownDevices" sender:self];
}
- (void)resendAllUnsentMessages
{
// List unsent event ids