forked from sunflsks/MessageRename
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tweak.x
77 lines (60 loc) · 2.36 KB
/
Tweak.x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <UIKit/UIKit.h>
@interface UIContextMenuConfiguration (Private)
@property (nonatomic, copy) UIContextMenuActionProvider actionProvider;
@end
@interface CKConversation : NSObject
-(NSString *)displayName;
-(void)setDisplayName:(NSString *)arg1;
-(BOOL)isGroupConversation;
@end
@interface CKConversationListCollectionViewController : UICollectionViewController
-(CKConversation*)conversationAtIndexPath:(NSIndexPath*)path;
@end
%hook CKConversationListCollectionViewController
-(UIContextMenuConfiguration*)collectionView:(UICollectionView*)view contextMenuConfigurationForItemAtIndexPath:(NSIndexPath *)indexPath point:(CGPoint)point {
UIContextMenuConfiguration* config = %orig();
CKConversation* conversation = [self conversationAtIndexPath:indexPath];
if ([conversation isGroupConversation]) {
UIContextMenuActionProvider originalBlock = config.actionProvider;
config.actionProvider = ^UIMenu*(NSArray<UIMenuElement*>* actions) {
UIMenu* actionMenu = originalBlock(actions);
NSMutableArray* children = [NSMutableArray arrayWithArray:actionMenu.children];
UIAction* renameAction = [UIAction
actionWithTitle:@"Change Group Name"
image:nil
identifier:nil
handler:^(UIAction* action) {
UIAlertController* alertController = [UIAlertController
alertControllerWithTitle:@"New Group Name"
message:@"Leave blank to remove the name"
preferredStyle:UIAlertControllerStyleAlert
];
[alertController addTextFieldWithConfigurationHandler:nil];
alertController.textFields[0].text = [conversation displayName];
UIAlertAction* cancel = [UIAlertAction
actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:nil
];
UIAlertAction* ok = [UIAlertAction
actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction* alertAction){
UITextField* textField = alertController.textFields[0];
[conversation setDisplayName:textField.text];
[self.collectionView reloadData];
}
];
[alertController addAction:cancel];
[alertController addAction:ok];
alertController.preferredAction = ok;
[self presentViewController:alertController animated:YES completion:nil];
}
];
[children addObjectsFromArray:@[renameAction]];
return [actionMenu menuByReplacingChildren:children];
};
}
return config;
}
%end