Skip to content

Commit

Permalink
Fixed ==> 修复 Alfred 在 v2.3.17 版本多次输入空格偶尔闪退的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
TKkk committed Aug 19, 2018
1 parent da04d2c commit bf0d186
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ FOUNDATION_EXPORT const unsigned char WeChatPluginVersionString[];
@property(retain, nonatomic) NSString *m_nsHeadHDImgUrl;
@property(retain, nonatomic) NSString *m_nsHeadHDMd5;
@property(retain, nonatomic) NSString *m_nsAliasName;
@property(nonatomic) BOOL m_isShowRedDot;
@property(nonatomic) BOOL m_isShowRedDot;
- (BOOL)isBrandContact;
- (BOOL)isSelf;
- (id)getGroupDisplayName;
Expand Down Expand Up @@ -404,3 +404,10 @@ FOUNDATION_EXPORT const unsigned char WeChatPluginVersionString[];
- (void)emoticonDownloadFailed:(EmoticonMsgInfo *)arg1;
- (void)emoticonDownloadFinished:(EmoticonMsgInfo *)arg1;
@end

@interface MMChatMangerSearchReportMgr : NSObject
@property(retain, nonatomic) NSMutableArray *brandContactSearchResults;
@property(retain, nonatomic) NSMutableArray *chatLogSearchResults;
@property(retain, nonatomic) NSMutableArray *contactSearchResults;
@property(retain, nonatomic) NSMutableArray *groupContactSearchResults;
@end
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ FOUNDATION_EXPORT const unsigned char WeChatPluginVersionString[];
@property(retain, nonatomic) NSString *m_nsHeadHDImgUrl;
@property(retain, nonatomic) NSString *m_nsHeadHDMd5;
@property(retain, nonatomic) NSString *m_nsAliasName;
@property(nonatomic) BOOL m_isShowRedDot;
@property(nonatomic) BOOL m_isShowRedDot;
- (BOOL)isBrandContact;
- (BOOL)isSelf;
- (id)getGroupDisplayName;
Expand Down Expand Up @@ -404,3 +404,10 @@ FOUNDATION_EXPORT const unsigned char WeChatPluginVersionString[];
- (void)emoticonDownloadFailed:(EmoticonMsgInfo *)arg1;
- (void)emoticonDownloadFinished:(EmoticonMsgInfo *)arg1;
@end

@interface MMChatMangerSearchReportMgr : NSObject
@property(retain, nonatomic) NSMutableArray *brandContactSearchResults;
@property(retain, nonatomic) NSMutableArray *chatLogSearchResults;
@property(retain, nonatomic) NSMutableArray *contactSearchResults;
@property(retain, nonatomic) NSMutableArray *groupContactSearchResults;
@end
Binary file modified Other/Products/Debug/WeChatPlugin.framework/Versions/A/WeChatPlugin
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ FOUNDATION_EXPORT const unsigned char WeChatPluginVersionString[];
@property(retain, nonatomic) NSString *m_nsHeadHDImgUrl;
@property(retain, nonatomic) NSString *m_nsHeadHDMd5;
@property(retain, nonatomic) NSString *m_nsAliasName;
@property(nonatomic) BOOL m_isShowRedDot;
@property(nonatomic) BOOL m_isShowRedDot;
- (BOOL)isBrandContact;
- (BOOL)isSelf;
- (id)getGroupDisplayName;
Expand Down Expand Up @@ -404,3 +404,10 @@ FOUNDATION_EXPORT const unsigned char WeChatPluginVersionString[];
- (void)emoticonDownloadFailed:(EmoticonMsgInfo *)arg1;
- (void)emoticonDownloadFinished:(EmoticonMsgInfo *)arg1;
@end

@interface MMChatMangerSearchReportMgr : NSObject
@property(retain, nonatomic) NSMutableArray *brandContactSearchResults;
@property(retain, nonatomic) NSMutableArray *chatLogSearchResults;
@property(retain, nonatomic) NSMutableArray *contactSearchResults;
@property(retain, nonatomic) NSMutableArray *groupContactSearchResults;
@end
Binary file not shown.
Binary file modified Other/Products/Debug/WeChatPlugin.framework/WeChatPlugin
Binary file not shown.
2 changes: 1 addition & 1 deletion WeChatPlugin.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,4 @@
<Bucket
type = "0"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.ExceptionBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
scope = "0"
stopOnStyle = "0">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
84 changes: 50 additions & 34 deletions WeChatPlugin/Sources/Managers/TKWebServerManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ - (void)addHandleForSearchUser {
NSString *keyword = request.query ? request.query[@"keyword"] ? request.query[@"keyword"] : @"" : @"";
__block NSMutableArray *sessionList = [NSMutableArray array];

// 返回最近聊天列表
// 返回最近聊天列表
if ([keyword isEqualToString:@""]) {
MMSessionMgr *sessionMgr = [[objc_getClass("MMServiceCenter") defaultCenter] getService:objc_getClass("MMSessionMgr")];
NSMutableArray <MMSessionInfo *> *arrSession = sessionMgr.m_arrSession;
Expand All @@ -87,9 +87,9 @@ - (void)addHandleForSearchUser {
return [GCDWebServerDataResponse responseWithJSONObject:sessionList];
}

// 返回搜索结果
// 返回搜索结果
__block BOOL hasResult = NO;

MMContactSearchLogic *logic = weakSelf.searchLogic;
[logic doSearchWithKeyword:keyword searchScene:31 resultIsShownBlock:nil completion:^ {
if ([logic respondsToSelector:@selector(reloadSearchResultDataWithKeyword:completionBlock:)]) {
Expand All @@ -103,21 +103,22 @@ - (void)addHandleForSearchUser {
}
}];

while (!(hasResult && logic.isContactSearched && logic.isGroupContactSearched)) {};

[logic.contactResults enumerateObjectsUsingBlock:^(MMSearchResultItem * _Nonnull contact, NSUInteger idx, BOOL * _Nonnull stop) {
if ([contact.result isKindOfClass:objc_getClass("MMComplexContactSearchResult")]) {
[sessionList addObject:[weakSelf dictFromContactSearchResult:(MMComplexContactSearchResult *)contact.result]];
} else if([contact.result isKindOfClass:objc_getClass("MMComplexGroupContactSearchResult")]) {
[sessionList addObject:[weakSelf dictFromGroupSearchResult:(MMComplexGroupContactSearchResult *)contact.result]];
while (!(hasResult && logic.isContactSearched && logic.isGroupContactSearched && logic.isBrandContactSearched)) {};

MMChatMangerSearchReportMgr *reportMgr = [[objc_getClass("MMServiceCenter") defaultCenter] getService:objc_getClass("MMChatMangerSearchReportMgr")];

[reportMgr.contactSearchResults enumerateObjectsUsingBlock:^(id contact, NSUInteger idx, BOOL * _Nonnull stop) {
if ([contact isKindOfClass:objc_getClass("MMComplexContactSearchResult")]) {
[sessionList addObject:[weakSelf dictFromContactSearchResult:(MMComplexContactSearchResult *)contact]];
} else if([contact isKindOfClass:objc_getClass("MMComplexGroupContactSearchResult")]) {
[sessionList addObject:[weakSelf dictFromGroupSearchResult:(MMComplexGroupContactSearchResult *)contact]];
}

}];
[logic.groupResults enumerateObjectsUsingBlock:^(MMSearchResultItem * _Nonnull group, NSUInteger idx, BOOL * _Nonnull stop) {
[sessionList addObject:[weakSelf dictFromGroupSearchResult:(MMComplexGroupContactSearchResult *)group.result]];
[reportMgr.groupContactSearchResults enumerateObjectsUsingBlock:^(MMComplexGroupContactSearchResult *group, NSUInteger idx, BOOL * _Nonnull stop) {
[sessionList addObject:[weakSelf dictFromGroupSearchResult:group]];
}];
[logic.oaResults enumerateObjectsUsingBlock:^(MMSearchResultItem * _Nonnull contact, NSUInteger idx, BOOL * _Nonnull stop) {
[sessionList addObject:[weakSelf dictFromContactSearchResult:(MMComplexContactSearchResult *)contact.result]];
[reportMgr.brandContactSearchResults enumerateObjectsUsingBlock:^(MMComplexContactSearchResult *contact, NSUInteger idx, BOOL * _Nonnull stop) {
[sessionList addObject:[weakSelf dictFromContactSearchResult:contact]];
}];

[logic clearAllResults];
Expand All @@ -131,7 +132,7 @@ - (void)addHandleForSearchUserChatLog {
[self.webServer addHandlerForMethod:@"GET" path:@"/wechat-plugin/chatlog" requestClass:[GCDWebServerRequest class] processBlock:^GCDWebServerResponse * _Nullable(__kindof GCDWebServerRequest * _Nonnull request) {
NSString *userId = request.query ? request.query[@"userId"] ? request.query[@"userId"] : nil : nil;
NSInteger count = request.query ? request.query[@"count"] ? [request.query[@"count"] integerValue] : 30 : 30;

if (userId) {
NSMutableArray *chatLogList = [NSMutableArray array];

Expand Down Expand Up @@ -226,18 +227,30 @@ - (void)addHandleForSendMsg {
}

- (NSDictionary *)dictFromGroupSearchResult:(MMComplexGroupContactSearchResult *)result {
if (![result isKindOfClass:objc_getClass("MMComplexGroupContactSearchResult")]) {
return [self dictWithErrorMsg:result.className];
}
WCContactData *groupContact = result.groupContact;
if (!groupContact) {
return [self dictWithErrorMsg:@"搜索群组有误"];
}
__block NSString *subTitle = @"";
NSMutableArray *subTitleArray = [NSMutableArray array];
if (result.searchType == 2) {
[result.groupMembersResult.membersSearchReults enumerateObjectsUsingBlock:^(MMComplexContactSearchResult * _Nonnull contact, NSUInteger idx, BOOL * _Nonnull stop) {
NSString *matchStr =[self matchWithContactResult:contact];
subTitle = [NSString stringWithFormat:@"%@%@(%@)", TKLocalizedString(@"assistant.search.member"), contact.contact.m_nsNickName, matchStr];
NSString *contactName;
if(contact.contact.m_nsRemark && ![contact.contact.m_nsRemark isEqualToString:@""]) {
contactName = contact.contact.m_nsRemark;
} else {
contactName = contact.contact.m_nsNickName;
}
[subTitleArray addObject:[NSString stringWithFormat:@"%@(%@)", contactName, matchStr]];
}];
}

NSString *subTitle = @"";
if (subTitleArray.count > 0) {
subTitle = [NSString stringWithFormat:@"%@: %@",TKLocalizedString(@"assistant.search.member"),[subTitleArray componentsJoinedByString:@", "]];
}
NSString *imgPath = [self cacheAvatarPathFromHeadImgUrl:groupContact.m_nsHeadImgUrl];
NSString *wechatId = [groupContact getContactDisplayUsrName];

Expand Down Expand Up @@ -282,6 +295,9 @@ - (NSString *)matchWithContactResult:(MMComplexContactSearchResult *)result {
}

- (NSDictionary *)dictFromContactSearchResult:(MMComplexContactSearchResult *)result {
if (![result isKindOfClass:objc_getClass("MMComplexContactSearchResult")]) {
return [self dictWithErrorMsg:result.className];
}
WCContactData *contact = result.contact;
if (!contact) {
return [self dictWithErrorMsg:@"搜索用户有误"];
Expand Down Expand Up @@ -312,7 +328,7 @@ - (NSDictionary *)dictFromSessionInfo:(MMSessionInfo *)sessionInfo {

WCContactData *contact = sessionInfo.m_packedInfo.m_contact;
MessageData *msgData = sessionInfo.m_packedInfo.m_msgData;

NSString *title = [self getUserNameWithContactData:contact showOriginName:YES];
NSString *msgContent = [[TKMessageManager shareManager] getMessageContentWithData:msgData];
NSString *imgPath = [self cacheAvatarPathFromHeadImgUrl:contact.m_nsHeadImgUrl];
Expand Down Expand Up @@ -345,7 +361,7 @@ - (NSDictionary *)dictFromMessageData:(MessageData *)msgData {
MMSessionMgr *sessionMgr = [[objc_getClass("MMServiceCenter") defaultCenter] getService:objc_getClass("MMSessionMgr")];
WCContactData *msgContact = [sessionMgr getContact:msgData.fromUsrName];
NSString *title = [[TKMessageManager shareManager] getMessageContentWithData:msgData];

NSString *url;
long long voiceMessSvrId = 0;
if (msgData.messageType == 1) {
Expand All @@ -372,22 +388,22 @@ - (NSDictionary *)dictFromMessageData:(MessageData *)msgData {
[imgMgr downloadImageWithMessage:msgData];
}
} else if (msgData.isCustomEmojiMsg || msgData.isEmojiAppMsg) {
// 以下注释取的是表情包服务器的地址,这会有一个问题,alfred 无法播放远程 gif 图片
// NSDictionary *msgDict = [self dictWithMessageContent:msgData.msgContent];
// if (msgDict[@"msg"] && msgDict[@"msg"][@"emoji"] && msgDict[@"msg"][@"emoji"][@"cdnurl"]) {
// url = msgDict[@"msg"][@"emoji"][@"cdnurl"];
// } else {
if ([[TKCacheManager shareManager] fileExistsWithName:msgData.m_nsEmoticonMD5]) {
url = [[TKCacheManager shareManager] filePathWithName:msgData.m_nsEmoticonMD5];
} else {
url = [[TKCacheManager shareManager] cacheEmotionMessage:msgData];
}
// }
// 以下注释取的是表情包服务器的地址,这会有一个问题,alfred 无法播放远程 gif 图片
// NSDictionary *msgDict = [self dictWithMessageContent:msgData.msgContent];
// if (msgDict[@"msg"] && msgDict[@"msg"][@"emoji"] && msgDict[@"msg"][@"emoji"][@"cdnurl"]) {
// url = msgDict[@"msg"][@"emoji"][@"cdnurl"];
// } else {
if ([[TKCacheManager shareManager] fileExistsWithName:msgData.m_nsEmoticonMD5]) {
url = [[TKCacheManager shareManager] filePathWithName:msgData.m_nsEmoticonMD5];
} else {
url = [[TKCacheManager shareManager] cacheEmotionMessage:msgData];
}
// }

} else if(msgData.isVoiceMsg) {
voiceMessSvrId = msgData.mesSvrID;
if (msgData.msgVoiceText.length > 0) {
title = [title stringByAppendingString:msgData.msgVoiceText];
title = [title stringByAppendingString:msgData.msgVoiceText];
}
if (msgData.IsUnPlayed) {
title = [NSString stringWithFormat:@"%@%@",TKLocalizedString(@"assistant.search.message.unread"),title];
Expand Down Expand Up @@ -418,7 +434,7 @@ - (NSDictionary *)dictFromMessageData:(MessageData *)msgData {
}

- (NSDictionary *)dictWithMessageContent:(NSString *)msg {

NSError *error;
// 转换群聊的 msg
NSString *msgContent = [msg substringFromIndex:[msg rangeOfString:@"<msg"].location];
Expand Down
9 changes: 8 additions & 1 deletion WeChatPlugin/WeChatPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ FOUNDATION_EXPORT const unsigned char WeChatPluginVersionString[];
@property(retain, nonatomic) NSString *m_nsHeadHDImgUrl;
@property(retain, nonatomic) NSString *m_nsHeadHDMd5;
@property(retain, nonatomic) NSString *m_nsAliasName;
@property(nonatomic) BOOL m_isShowRedDot;
@property(nonatomic) BOOL m_isShowRedDot;
- (BOOL)isBrandContact;
- (BOOL)isSelf;
- (id)getGroupDisplayName;
Expand Down Expand Up @@ -404,3 +404,10 @@ FOUNDATION_EXPORT const unsigned char WeChatPluginVersionString[];
- (void)emoticonDownloadFailed:(EmoticonMsgInfo *)arg1;
- (void)emoticonDownloadFinished:(EmoticonMsgInfo *)arg1;
@end

@interface MMChatMangerSearchReportMgr : NSObject
@property(retain, nonatomic) NSMutableArray *brandContactSearchResults;
@property(retain, nonatomic) NSMutableArray *chatLogSearchResults;
@property(retain, nonatomic) NSMutableArray *contactSearchResults;
@property(retain, nonatomic) NSMutableArray *groupContactSearchResults;
@end

0 comments on commit bf0d186

Please sign in to comment.