Merge pull request #2692 from vector-im/giomfo/revoke_3pid_invite

Room members: third-party invites can now be revoked
This commit is contained in:
giomfo
2019-09-04 18:00:23 +02:00
committed by GitHub
3 changed files with 92 additions and 66 deletions
+1
View File
@@ -5,6 +5,7 @@ Improvements:
* Prompt to accept integration manager policies on use (#2600).
* Widgets: Whitelist [MSC1961](https://github.com/matrix-org/matrix-doc/pull/1961) widget urls
* i18n: Enable Polish (pl).
* Room members: third-party invites can now be revoked
Changes in 0.9.2 (2019-08-08)
===============================================
+1 -1
View File
@@ -212,7 +212,7 @@
"room_participants_leave_prompt_msg" = "Are you sure you want to leave the room?";
"room_participants_remove_prompt_title" = "Confirmation";
"room_participants_remove_prompt_msg" = "Are you sure you want to remove %@ from this chat?";
"room_participants_remove_third_party_invite_msg" = "Remove third-party invite is not supported yet until the api exists";
"room_participants_remove_third_party_invite_prompt_msg" = "Are you sure you want to revoke this invite?";
"room_participants_invite_prompt_title" = "Confirmation";
"room_participants_invite_prompt_msg" = "Are you sure you want to invite %@ to this chat?";
"room_participants_filter_room_members" = "Filter room members";
@@ -798,7 +798,9 @@
- (void)addRoomThirdPartyInviteToParticipants:(MXRoomThirdPartyInvite*)roomThirdPartyInvite roomState:(MXRoomState*)roomState
{
// If the homeserver has converted the 3pid invite into a room member, do no show it
if (![roomState memberWithThirdPartyInviteToken:roomThirdPartyInvite.token])
// If the invite has been revoked (null display name), do not show it too.
if (![roomState memberWithThirdPartyInviteToken:roomThirdPartyInvite.token]
&& roomThirdPartyInvite.displayname)
{
Contact *contact = [[Contact alloc] initMatrixContactWithDisplayName:roomThirdPartyInvite.displayname andMatrixID:nil];
contact.isThirdPartyInvite = YES;
@@ -1373,8 +1375,6 @@
if (section == participantsSection || section == invitedSection)
{
__weak typeof(self) weakSelf = self;
if (currentAlert)
{
[currentAlert dismissViewControllerAnimated:NO completion:nil];
@@ -1384,6 +1384,7 @@
if (section == participantsSection && userParticipant && (0 == row) && !currentSearchText.length)
{
// Leave ?
MXWeakify(self);
currentAlert = [UIAlertController alertControllerWithTitle:NSLocalizedStringFromTable(@"room_participants_leave_prompt_title", @"Vector", nil)
message:NSLocalizedStringFromTable(@"room_participants_leave_prompt_msg", @"Vector", nil)
preferredStyle:UIAlertControllerStyleAlert];
@@ -1392,11 +1393,8 @@
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action) {
if (weakSelf)
{
typeof(self) self = weakSelf;
self->currentAlert = nil;
}
MXStrongifyAndReturnIfNil(self);
self->currentAlert = nil;
}]];
@@ -1404,25 +1402,25 @@
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
if (weakSelf)
{
typeof(self) self = weakSelf;
self->currentAlert = nil;
MXStrongifyAndReturnIfNil(self);
self->currentAlert = nil;
[self addPendingActionMask];
MXWeakify(self);
[self.mxRoom leave:^{
[self addPendingActionMask];
[self.mxRoom leave:^{
[self withdrawViewControllerAnimated:YES completion:nil];
} failure:^(NSError *error) {
[self removePendingActionMask];
NSLog(@"[RoomParticipantsVC] Leave room %@ failed", self.mxRoom.roomId);
// Alert user
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
}
MXStrongifyAndReturnIfNil(self);
[self withdrawViewControllerAnimated:YES completion:nil];
} failure:^(NSError *error) {
MXStrongifyAndReturnIfNil(self);
[self removePendingActionMask];
NSLog(@"[RoomParticipantsVC] Leave room %@ failed", self.mxRoom.roomId);
// Alert user
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
}]];
@@ -1464,6 +1462,7 @@
if (row < participants.count)
{
Contact *contact = participants[row];
MXWeakify(self);
if (contact.mxMember)
{
@@ -1479,11 +1478,8 @@
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action) {
if (weakSelf)
{
typeof(self) self = weakSelf;
self->currentAlert = nil;
}
MXStrongifyAndReturnIfNil(self);
self->currentAlert = nil;
}]];
@@ -1491,51 +1487,80 @@
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
if (weakSelf)
{
typeof(self) self = weakSelf;
self->currentAlert = nil;
[self addPendingActionMask];
[self.mxRoom kickUser:memberUserId
reason:nil
success:^{
[self removePendingActionMask];
[participants removeObjectAtIndex:row];
// Refresh display
[self.tableView reloadData];
} failure:^(NSError *error) {
[self removePendingActionMask];
NSLog(@"[RoomParticipantsVC] Kick %@ failed", memberUserId);
// Alert user
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
}
MXStrongifyAndReturnIfNil(self);
self->currentAlert = nil;
[self addPendingActionMask];
MXWeakify(self);
[self.mxRoom kickUser:memberUserId
reason:nil
success:^{
MXStrongifyAndReturnIfNil(self);
[self removePendingActionMask];
[participants removeObjectAtIndex:row];
// Refresh display
[self.tableView reloadData];
} failure:^(NSError *error) {
MXStrongifyAndReturnIfNil(self);
[self removePendingActionMask];
NSLog(@"[RoomParticipantsVC] Kick %@ failed", memberUserId);
// Alert user
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
}]];
}
else
else if (contact.mxThirdPartyInvite)
{
// This is a third-party invite, it could not be removed until the api exists
// This is a third-party invite
currentAlert = [UIAlertController alertControllerWithTitle:nil
message:NSLocalizedStringFromTable(@"room_participants_remove_third_party_invite_msg", @"Vector", nil)
message:NSLocalizedStringFromTable(@"room_participants_remove_third_party_invite_prompt_msg", @"Vector", nil)
preferredStyle:UIAlertControllerStyleAlert];
[currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"]
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action) {
if (weakSelf)
{
typeof(self) self = weakSelf;
self->currentAlert = nil;
}
MXStrongifyAndReturnIfNil(self);
self->currentAlert = nil;
}]];
[currentAlert addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"remove", @"Vector", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
MXStrongifyAndReturnIfNil(self);
self->currentAlert = nil;
[self addPendingActionMask];
MXWeakify(self);
[self.mxRoom sendStateEventOfType:kMXEventTypeStringRoomThirdPartyInvite
content:@{} stateKey:contact.mxThirdPartyInvite.token success:^(NSString *eventId) {
MXStrongifyAndReturnIfNil(self);
[self removePendingActionMask];
[participants removeObjectAtIndex:row];
// Refresh display
[self.tableView reloadData];
} failure:^(NSError *error) {
MXStrongifyAndReturnIfNil(self);
[self removePendingActionMask];
NSLog(@"[RoomParticipantsVC] Revoke 3pid invite failed");
// Alert user
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
}]];
}