1.listen AsyncOnAddMsg event
%hook CMessageMgr
- (void)AsyncOnAddMsg:(NSString *)msg MsgWrap:(CMessageWrap *)wrap {
WXSettingsInstance.username = msg;
WXSettingsInstance.content = [wrap m_nsContent];
[[NSNotificationCenter defaultCenter] postNotificationName:@"CBWeChatNewMessageNotification" object:nil];
}
%end
2.add new msg button in office docs' webView
%hook MMWebViewController
-(void)viewDidLoad {
%orig;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cb_didReceiveNewMessage) name:@"CBWeChatNewMessageNotification" object:nil];
}
%new
- (void)cb_didReceiveNewMessage {
NSString *username = WXSettingsInstance.username;
NSString *content = WXSettingsInstance.content;
NSLog(@"%@",username);
NSLog(@"%@",content);
CContactMgr *contactMgr = [[objc_getClass("MMServiceCenter") defaultCenter] getService:[objc_getClass("CContactMgr") class]];
CContact *contact = [contactMgr getContactByName:username];
dispatch_async(dispatch_get_main_queue(), ^{
NSString *text = [NSString stringWithFormat:@" %@: %@ ", contact.m_nsNickName, content];
NSLog(@"%@",text);
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 64, 414, 30);
button.alpha = 0.7;
button.backgroundColor = [UIColor blackColor];
[button setTitle:text forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
button.titleLabel.font = [UIFont systemFontOfSize:12];
[button addTarget:self action:@selector(backToMsgContentViewController:) forControlEvents:UIControlEventTouchUpInside];
[[self view] addSubview:button];
});
}
%new
- (void)backToMsgContentViewController:(UIButton *)button {
[button removeFromSuperview];
// back to webview
NSArray *webViewViewControllers = [[objc_getClass("CAppViewControllerManager") getCurrentNavigationController] viewControllers];
WXSettingsInstance.webViewViewControllers = webViewViewControllers;
// back rootViewController
UINavigationController *navVC = [objc_getClass("CAppViewControllerManager") getCurrentNavigationController];
[navVC popToRootViewControllerAnimated:NO];
NSString *username = WXSettingsInstance.username;
CContactMgr *contactMgr = [[objc_getClass("MMServiceCenter") defaultCenter] getService:[objc_getClass("CContactMgr") class]];
CContact *contact = [contactMgr getContactByName:username];
MMMsgLogicManager *logicMgr = [[objc_getClass("MMServiceCenter") defaultCenter] getService:[objc_getClass("MMMsgLogicManager") class]];
[logicMgr PushOtherBaseMsgControllerByContact:contact navigationController:navVC animated:YES];
}
%end
3.add back button in chatview
%hook BaseMsgContentViewController
-(void)viewDidLoad {
%orig;
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(414-50, 74, 40, 30);
button.alpha = 0.7;
button.layer.masksToBounds = YES;
button.layer.cornerRadius = 15;
button.backgroundColor = [UIColor blackColor];
[button setTitle:@"back" forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
button.titleLabel.font = [UIFont systemFontOfSize:12];
[button addTarget:self action:@selector(backToWebViewController) forControlEvents:UIControlEventTouchUpInside];
[[self view] addSubview:button];
}
%new
- (void)backToWebViewController {
NSArray *webViewViewControllers = WXSettingsInstance.webViewViewControllers;
if (webViewViewControllers) {
[[objc_getClass("CAppViewControllerManager") getCurrentNavigationController] setViewControllers:webViewViewControllers animated:YES];
}
}
%end