Skip to content

Commit

Permalink
Update ==> Alfred 完善搜索匹配展示 && 群消息显示发送用户头像
Browse files Browse the repository at this point in the history
  • Loading branch information
TKkk committed Aug 25, 2018
1 parent bf0d186 commit b7d8152
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ FOUNDATION_EXPORT const unsigned char WeChatPluginVersionString[];
NSMutableDictionary *m_dictGroupContacts;
}
- (id)GetAllGroups;
- (id)GetGroupMemberContact:(id)arg1;
@end

@interface WCContactData : NSObject
Expand Down Expand Up @@ -143,6 +144,7 @@ FOUNDATION_EXPORT const unsigned char WeChatPluginVersionString[];
- (BOOL)isChatRoomMessage;
- (NSString *)groupChatSenderDisplayName;
- (id)getRealMessageContent;
- (id)getChatRoomUsrName;
- (BOOL)isSendFromSelf;
- (BOOL)isCustomEmojiMsg;
- (BOOL)isImgMsg;
Expand Down Expand Up @@ -291,6 +293,7 @@ FOUNDATION_EXPORT const unsigned char WeChatPluginVersionString[];

@interface MMAvatarService : NSObject
- (NSString *)avatarCachePath;
- (void)avatarImageWithContact:(id)arg1 completion:(void (^)(NSImage *image))arg2;
@end

@interface NSString (MD5)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
framework module WeChatPlugin {
umbrella header "WeChatPlugin.h"

export *
module * { export * }
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ FOUNDATION_EXPORT const unsigned char WeChatPluginVersionString[];
NSMutableDictionary *m_dictGroupContacts;
}
- (id)GetAllGroups;
- (id)GetGroupMemberContact:(id)arg1;
@end

@interface WCContactData : NSObject
Expand Down Expand Up @@ -143,6 +144,7 @@ FOUNDATION_EXPORT const unsigned char WeChatPluginVersionString[];
- (BOOL)isChatRoomMessage;
- (NSString *)groupChatSenderDisplayName;
- (id)getRealMessageContent;
- (id)getChatRoomUsrName;
- (BOOL)isSendFromSelf;
- (BOOL)isCustomEmojiMsg;
- (BOOL)isImgMsg;
Expand Down Expand Up @@ -291,6 +293,7 @@ FOUNDATION_EXPORT const unsigned char WeChatPluginVersionString[];

@interface MMAvatarService : NSObject
- (NSString *)avatarCachePath;
- (void)avatarImageWithContact:(id)arg1 completion:(void (^)(NSImage *image))arg2;
@end

@interface NSString (MD5)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
framework module WeChatPlugin {
umbrella header "WeChatPlugin.h"

export *
module * { export * }
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ FOUNDATION_EXPORT const unsigned char WeChatPluginVersionString[];
NSMutableDictionary *m_dictGroupContacts;
}
- (id)GetAllGroups;
- (id)GetGroupMemberContact:(id)arg1;
@end

@interface WCContactData : NSObject
Expand Down Expand Up @@ -143,6 +144,7 @@ FOUNDATION_EXPORT const unsigned char WeChatPluginVersionString[];
- (BOOL)isChatRoomMessage;
- (NSString *)groupChatSenderDisplayName;
- (id)getRealMessageContent;
- (id)getChatRoomUsrName;
- (BOOL)isSendFromSelf;
- (BOOL)isCustomEmojiMsg;
- (BOOL)isImgMsg;
Expand Down Expand Up @@ -291,6 +293,7 @@ FOUNDATION_EXPORT const unsigned char WeChatPluginVersionString[];

@interface MMAvatarService : NSObject
- (NSString *)avatarCachePath;
- (void)avatarImageWithContact:(id)arg1 completion:(void (^)(NSImage *image))arg2;
@end

@interface NSString (MD5)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
framework module WeChatPlugin {
umbrella header "WeChatPlugin.h"

export *
module * { export * }
}
Binary file not shown.
Binary file modified Other/Products/Debug/WeChatPlugin.framework/WeChatPlugin
Binary file not shown.
8 changes: 7 additions & 1 deletion Other/Uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ then
rm "$app_executable_path"
rm -rf "$framework_path"
mv "$app_executable_backup_path" "$app_executable_path"
echo "\n\t卸载成功"

if [ -f "$app_executable_backup_path" ]
echo "卸载失败,请到 /Applications/WeChat.app/Contents/MacOS 路径,删除 WeChatPlugin.framework、WeChat 两个文件文件,并将 WeChat_backup 重命名为 WeChat"
then
echo "\n\t卸载成功"
fi

else
echo "\n\t未发现微信小助手"
fi
12 changes: 6 additions & 6 deletions WeChatPlugin/Sources/Config/TKWeChatPluginConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
@property (nonatomic, assign) BOOL autoLoginEnable; /**< 是否自动登录 */
@property (nonatomic, assign) BOOL onTop; /**< 是否要置顶微信 */
@property (nonatomic, assign) BOOL multipleSelectionEnable; /**< 是否要进行多选 */
@property (nonatomic, assign) BOOL forbidCheckVersion; /**< 禁止检测版本 */
@property (nonatomic, copy) NSMutableArray *autoReplyModels; /**< 自动回复的数组 */
@property (nonatomic, copy) NSMutableArray *remoteControlModels; /**< 远程控制的数组 */
@property (nonatomic, copy) NSMutableArray *ignoreSessionModels; /**< 聊天置底的数组 */
@property (nonatomic, copy) NSMutableArray *selectSessions; /**< 已经选中的会话 */
@property (nonatomic, copy) NSMutableSet *revokeMsgSet; /**< 撤回的消息集合 */
@property (nonatomic, assign) BOOL forbidCheckVersion; /**< 禁止检测版本 */
@property (nonatomic, strong) NSMutableArray *autoReplyModels; /**< 自动回复的数组 */
@property (nonatomic, strong) NSMutableArray *remoteControlModels; /**< 远程控制的数组 */
@property (nonatomic, strong) NSMutableArray *ignoreSessionModels; /**< 聊天置底的数组 */
@property (nonatomic, strong) NSMutableArray *selectSessions; /**< 已经选中的会话 */
@property (nonatomic, strong) NSMutableSet *revokeMsgSet; /**< 撤回的消息集合 */
@property (nonatomic, copy) NSString *currentUserName; /**< 当前用户的id */
@property (nonatomic, copy, readonly) NSDictionary *localInfoPlist;
@property (nonatomic, copy, readonly) NSDictionary *romoteInfoPlist;
Expand Down
37 changes: 27 additions & 10 deletions WeChatPlugin/Sources/Managers/TKAssistantMenuManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@ - (void)initAssistantMenuItems {
target:self
keyEquivalent:@"t"
state:[[TKWeChatPluginConfig sharedConfig] preventRevokeEnable]];
// 防撤回自己
NSMenuItem *preventSelfRevokeItem = [NSMenuItem menuItemWithTitle:TKLocalizedString(@"assistant.menu.revokeSelf")
action:@selector(onPreventSelfRevoke:)
target:self
keyEquivalent:@""
state:[[TKWeChatPluginConfig sharedConfig] preventSelfRevokeEnable]];

NSMenu *subPreventMenu = [[NSMenu alloc] initWithTitle:TKLocalizedString(@"assistant.menu.revoke")];
[subPreventMenu addItems:@[preventSelfRevokeItem]];
preventRevokeItem.submenu = subPreventMenu;
if ([[TKWeChatPluginConfig sharedConfig] preventRevokeEnable]) {
// 防撤回自己
NSMenuItem *preventSelfRevokeItem = [NSMenuItem menuItemWithTitle:TKLocalizedString(@"assistant.menu.revokeSelf")
action:@selector(onPreventSelfRevoke:)
target:self
keyEquivalent:@""
state:[[TKWeChatPluginConfig sharedConfig] preventSelfRevokeEnable]];

NSMenu *subPreventMenu = [[NSMenu alloc] initWithTitle:TKLocalizedString(@"assistant.menu.revoke")];
[subPreventMenu addItems:@[preventSelfRevokeItem]];
preventRevokeItem.submenu = subPreventMenu;
}

// 自动回复
NSMenuItem *autoReplyItem = [NSMenuItem menuItemWithTitle:TKLocalizedString(@"assistant.menu.autoReply")
Expand Down Expand Up @@ -164,6 +166,21 @@ - (void)changePluginMenuItemWithIndex:(NSInteger)index state:(NSControlStateValu
- (void)onPreventRevoke:(NSMenuItem *)item {
item.state = !item.state;
[[TKWeChatPluginConfig sharedConfig] setPreventRevokeEnable:item.state];
if (item.state) {
// 防撤回自己
NSMenuItem *preventSelfRevokeItem = [NSMenuItem menuItemWithTitle:TKLocalizedString(@"assistant.menu.revokeSelf")
action:@selector(onPreventSelfRevoke:)
target:self
keyEquivalent:@""
state:[[TKWeChatPluginConfig sharedConfig] preventSelfRevokeEnable]];

NSMenu *subPreventMenu = [[NSMenu alloc] initWithTitle:TKLocalizedString(@"assistant.menu.revoke")];
[subPreventMenu addItems:@[preventSelfRevokeItem]];
item.submenu = subPreventMenu;
} else {
item.submenu = nil;
}

}

/**
Expand Down
1 change: 1 addition & 0 deletions WeChatPlugin/Sources/Managers/TKCacheManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
- (BOOL)fileExistsWithName:(NSString *)fileName;
- (NSString *)filePathWithName:(NSString *)fileName;
- (NSString *)cacheEmotionMessage:(MessageData *)emotionMsg;
- (NSString *)cacheAvatarWithContact:(WCContactData *)contact;

@end
28 changes: 28 additions & 0 deletions WeChatPlugin/Sources/Managers/TKCacheManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ @interface TKCacheManager () <EmoticonDownloadMgrExt>

@property (nonatomic, copy) NSString *cacheDirectory;
@property (nonatomic, strong) NSMutableSet *emotionSet;
@property (nonatomic, strong) NSMutableSet *avatarSet;
@end

@implementation TKCacheManager
Expand Down Expand Up @@ -42,6 +43,7 @@ - (instancetype)init
}

self.emotionSet = [NSMutableSet set];
self.avatarSet = [NSMutableSet set];
}
return self;
}
Expand Down Expand Up @@ -113,4 +115,30 @@ - (void)emoticonDownloadFinished:(EmoticonMsgInfo *)msgInfo {
}];
}

- (NSString *)cacheAvatarWithContact:(WCContactData *)contact {
NSString *headImgUrl = contact.m_nsHeadImgUrl;
if (headImgUrl.length == 0) return @"";

NSString *imgPath = @"";
if ([headImgUrl respondsToSelector:@selector(md5String)]) {
NSString *imgMd5Str = [headImgUrl performSelector:@selector(md5String)];
MMAvatarService *avatarService = [[objc_getClass("MMServiceCenter") defaultCenter] getService:objc_getClass("MMAvatarService")];

if ([avatarService avatarCachePath] && imgMd5Str) {
imgPath = [NSString stringWithFormat:@"%@%@",[avatarService avatarCachePath], imgMd5Str];
NSFileManager *fileMgr = [NSFileManager defaultManager];
if (![fileMgr fileExistsAtPath:imgPath] && ![self.avatarSet containsObject:imgPath]) {
[self.avatarSet addObject:imgPath];
[avatarService avatarImageWithContact:contact completion:^(NSImage *image) {
NSData *imageData = [image TIFFRepresentation];
[imageData writeToFile:imgPath atomically:YES];
[self.avatarSet removeObject:imgPath];
}];
}

}
}
return imgPath ?: @"";

}
@end
44 changes: 22 additions & 22 deletions WeChatPlugin/Sources/Managers/TKWebServerManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ - (void)addHandleForSearchUserChatLog {
WCContactData *toUserContact = [sessionMgr getContact:userId];
NSString *wechatId = [toUserContact getContactDisplayUsrName];
NSString *title = [weakSelf getUserNameWithContactData:toUserContact showOriginName:YES];
NSString *imgPath = [weakSelf cacheAvatarPathFromHeadImgUrl:toUserContact.m_nsHeadImgUrl];
NSString *imgPath = [[TKCacheManager shareManager] cacheAvatarWithContact:toUserContact];
NSDictionary *toUserContactDict = @{@"title": [NSString stringWithFormat:@"To: %@", title],
@"subTitle": chatLogList.count > 0 ? TKLocalizedString(@"assistant.search.chatlog") : @"",
@"icon": imgPath ?: @"",
Expand Down Expand Up @@ -241,17 +241,23 @@ - (NSDictionary *)dictFromGroupSearchResult:(MMComplexGroupContactSearchResult *
NSString *contactName;
if(contact.contact.m_nsRemark && ![contact.contact.m_nsRemark isEqualToString:@""]) {
contactName = contact.contact.m_nsRemark;
if (contact.fieldType != 1) {
contactName = [NSString stringWithFormat:@"%@(%@)", contactName, matchStr];
}
} else {
contactName = contact.contact.m_nsNickName;
if (contact.fieldType != 3) {
contactName = [NSString stringWithFormat:@"%@(%@)", contactName, matchStr];
}
}
[subTitleArray addObject:[NSString stringWithFormat:@"%@(%@)", contactName, matchStr]];
[subTitleArray addObject:contactName];
}];
}
NSString *subTitle = @"";
if (subTitleArray.count > 0) {
subTitle = [NSString stringWithFormat:@"%@: %@",TKLocalizedString(@"assistant.search.member"),[subTitleArray componentsJoinedByString:@", "]];
subTitle = [NSString stringWithFormat:@"%@%@",TKLocalizedString(@"assistant.search.member"),[subTitleArray componentsJoinedByString:@", "]];
}
NSString *imgPath = [self cacheAvatarPathFromHeadImgUrl:groupContact.m_nsHeadImgUrl];
NSString *imgPath = [[TKCacheManager shareManager] cacheAvatarWithContact:groupContact];
NSString *wechatId = [groupContact getContactDisplayUsrName];

return @{@"title": [NSString stringWithFormat:@"%@%@", TKLocalizedString(@"assistant.search.group"), groupContact.getGroupDisplayName],
Expand Down Expand Up @@ -311,7 +317,7 @@ - (NSDictionary *)dictFromContactSearchResult:(MMComplexContactSearchResult *)re
}

NSString *subTitle =[self matchWithContactResult:result];
NSString *imgPath = [self cacheAvatarPathFromHeadImgUrl:contact.m_nsHeadImgUrl];
NSString *imgPath = [[TKCacheManager shareManager] cacheAvatarWithContact:contact];

NSString *wechatId = [contact getContactDisplayUsrName];
return @{@"title": title,
Expand All @@ -331,7 +337,7 @@ - (NSDictionary *)dictFromSessionInfo:(MMSessionInfo *)sessionInfo {

NSString *title = [self getUserNameWithContactData:contact showOriginName:YES];
NSString *msgContent = [[TKMessageManager shareManager] getMessageContentWithData:msgData];
NSString *imgPath = [self cacheAvatarPathFromHeadImgUrl:contact.m_nsHeadImgUrl];
NSString *imgPath = [[TKCacheManager shareManager] cacheAvatarWithContact:contact];

NSString *wechatId = [contact getContactDisplayUsrName];
return @{@"title": title,
Expand Down Expand Up @@ -419,7 +425,16 @@ - (NSDictionary *)dictFromMessageData:(MessageData *)msgData {
}

NSString *subTitle = [self getDateStringWithTimeStr:msgData.msgCreateTime];
NSString *imgPath = [self cacheAvatarPathFromHeadImgUrl:msgContact.m_nsHeadImgUrl];

NSString *imgPath;
if ([msgContact isGroupChat]) {
GroupStorage *contactStorage = [[objc_getClass("MMServiceCenter") defaultCenter] getService:objc_getClass("GroupStorage")];
WCContactData *fromContact = [contactStorage GetGroupMemberContact:[msgData getChatRoomUsrName]];
imgPath = [[TKCacheManager shareManager] cacheAvatarWithContact:fromContact];
} else {
imgPath = [[TKCacheManager shareManager] cacheAvatarWithContact:msgContact];
}

if (!msgContact.isGroupChat) {
subTitle = [NSString stringWithFormat:@"from: %@ %@",[self getUserNameWithContactData:msgContact showOriginName:NO], subTitle];
}
Expand Down Expand Up @@ -462,21 +477,6 @@ - (NSString *)getDateStringWithTimeStr:(NSTimeInterval)time{
return @"";
}

// 获取本地图片缓存路径
- (NSString *)cacheAvatarPathFromHeadImgUrl:(NSString *)imgUrl {
if (imgUrl.length == 0) return @"";

NSString *imgPath = @"";
if ([imgUrl respondsToSelector:@selector(md5String)]) {
NSString *imgMd5Str = [imgUrl performSelector:@selector(md5String)];
MMAvatarService *avatarService = [[objc_getClass("MMServiceCenter") defaultCenter] getService:objc_getClass("MMAvatarService")];
if ([avatarService avatarCachePath] && imgMd5Str) {
imgPath = [NSString stringWithFormat:@"%@%@",[avatarService avatarCachePath], imgMd5Str];
}
}
return imgPath ?: @"";
}

- (NSString *)getUserNameWithContactData:(WCContactData *)contact showOriginName:(BOOL)showOriginName {
if (!contact) return @"";

Expand Down
3 changes: 3 additions & 0 deletions WeChatPlugin/WeChatPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ FOUNDATION_EXPORT const unsigned char WeChatPluginVersionString[];
NSMutableDictionary *m_dictGroupContacts;
}
- (id)GetAllGroups;
- (id)GetGroupMemberContact:(id)arg1;
@end

@interface WCContactData : NSObject
Expand Down Expand Up @@ -143,6 +144,7 @@ FOUNDATION_EXPORT const unsigned char WeChatPluginVersionString[];
- (BOOL)isChatRoomMessage;
- (NSString *)groupChatSenderDisplayName;
- (id)getRealMessageContent;
- (id)getChatRoomUsrName;
- (BOOL)isSendFromSelf;
- (BOOL)isCustomEmojiMsg;
- (BOOL)isImgMsg;
Expand Down Expand Up @@ -291,6 +293,7 @@ FOUNDATION_EXPORT const unsigned char WeChatPluginVersionString[];

@interface MMAvatarService : NSObject
- (NSString *)avatarCachePath;
- (void)avatarImageWithContact:(id)arg1 completion:(void (^)(NSImage *image))arg2;
@end

@interface NSString (MD5)
Expand Down

0 comments on commit b7d8152

Please sign in to comment.