Skip to content

Commit

Permalink
Add new action to block subscription requests, fixes #1320
Browse files Browse the repository at this point in the history
  • Loading branch information
tmolitor-stud-tu committed Jan 4, 2025
1 parent c8e488f commit c8f504b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Monal/Classes/ContactRequestsMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ struct ContactRequestsMenuEntry: View {
//see https://www.hackingwithswift.com/forums/swiftui/tap-button-in-hstack-activates-all-button-actions-ios-14-swiftui-2/2952
.buttonStyle(BorderlessButtonStyle())

Button {
// deny request
MLXMPPManager.sharedInstance().remove(contact)
MLXMPPManager.sharedInstance().block(true, contact:contact)
} label: {
Image(systemName: "xmark.circle")
.foregroundStyle(Color.red)
}
//see https://www.hackingwithswift.com/forums/swiftui/tap-button-in-hstack-activates-all-button-actions-ios-14-swiftui-2/2952
.buttonStyle(BorderlessButtonStyle())

Button {
// deny request
MLXMPPManager.sharedInstance().remove(contact)
Expand Down
14 changes: 13 additions & 1 deletion Monal/Classes/MonalAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,12 @@ -(BOOL) application:(UIApplication*) application didFinishLaunchingWithOptions:(
actionWithIdentifier:@"DENY_SUBSCRIPTION_ACTION"
title:NSLocalizedString(@"Deny new contact", @"")
options:UNNotificationActionOptionNone
icon:[UNNotificationActionIcon iconWithSystemImageName:@"person.crop.circle.badge.minus"]
];
UNNotificationAction* blockSubscriptionAction = [UNNotificationAction
actionWithIdentifier:@"BLOCK_SUBSCRIPTION_ACTION"
title:NSLocalizedString(@"Block new contact", @"")
options:UNNotificationActionOptionNone
icon:[UNNotificationActionIcon iconWithSystemImageName:@"person.crop.circle.badge.xmark"]
];

Expand All @@ -467,7 +473,7 @@ -(BOOL) application:(UIApplication*) application didFinishLaunchingWithOptions:(
];
UNNotificationCategory* subscriptionCategory = [UNNotificationCategory
categoryWithIdentifier:@"subscription"
actions:@[approveSubscriptionAction, denySubscriptionAction]
actions:@[approveSubscriptionAction, denySubscriptionAction, blockSubscriptionAction]
intentIdentifiers:@[]
options:UNNotificationCategoryOptionCustomDismissAction
];
Expand Down Expand Up @@ -998,6 +1004,12 @@ -(void) userNotificationCenter:(UNUserNotificationCenter*) center didReceiveNoti
DDLogInfo(@"DENY_SUBSCRIPTION_ACTION triggered...");
[[MLXMPPManager sharedInstance] removeContact:fromContact];
}
else if([response.actionIdentifier isEqualToString:@"BLOCK_SUBSCRIPTION_ACTION"])
{
DDLogInfo(@"BLOCK_SUBSCRIPTION_ACTION triggered...");
[[MLXMPPManager sharedInstance] removeContact:fromContact];
[[MLXMPPManager sharedInstance] block:YES contact:fromContact];
}
else if([response.actionIdentifier isEqualToString:@"com.apple.UNNotificationDefaultActionIdentifier"]) //open chat of this contact
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
while(self.activeChats == nil)
Expand Down

0 comments on commit c8f504b

Please sign in to comment.