{"action":"created","comment":{"url":"https://api.github.com/repos/easemob/easeui_ios/pulls/comments/55471073","id":55471073,"diff_hunk":"@@ -0,0 +1,272 @@\n+//\n+//  EaseMessageHelper+InputState.m\n+//  EaseUI\n+//\n+//  Created by WYZ on 16/2/16.\n+//  Copyright © 2016年 easemob. All rights reserved.\n+//\n+\n+#import \"EaseMessageHelper+InputState.h\"\n+#import <objc/runtime.h>\n+\n+/** @brief 待发送输入状态的CMD消息action */\n+#define KEM_INPUTSTATE_CMDACTION                   @\"em_inputState_cmdAction\"\n+/** @brief 输入状态cmd扩展字段,对应的value值为待撤销消息id */\n+#define KEM_INPUTSTATE_STATE        @\"em_inputState_state\"\n+/** @brief 校验输入状态cmd发送时间间隔 */\n+#define KEM_INPUTSTATE_TIMEINTERVAL  5\n+/** @brief 输入状态cmd接收方聊天页面title */\n+#define KEM_INPUTSTATE_TITLE  @\"对方正在输入...\"\n+\n+static char inputStateValidKey;\n+static char inputStateTimerKey;\n+static char inputStateRunLoopKey;\n+static char inputStateLatestTimestampKey;\n+\n+@interface EaseMessageHelper()\n+\n+@property (nonatomic, strong) NSNumber *isValid;  //对应为BOOL\n+\n+@property (nonatomic, strong) NSTimer *timer;\n+\n+@property (nonatomic, strong) NSRunLoop *runLoop;\n+\n+@property (nonatomic, strong) NSNumber *latestTimestamp;//发送方使用，用于cmd消息发送时间间隔\n+\n+@end\n+\n+@implementation EaseMessageHelper (InputState)\n+\n+#pragma mark - getter\n+\n+- (NSNumber *)isValid\n+{\n+    return objc_getAssociatedObject(self, &inputStateValidKey);\n+}\n+\n+- (NSTimer *)timer\n+{\n+    return objc_getAssociatedObject(self, &inputStateTimerKey);\n+}\n+\n+- (NSRunLoop *)runLoop\n+{\n+    return objc_getAssociatedObject(self, &inputStateRunLoopKey);\n+}\n+\n+- (NSNumber *)latestTimestamp\n+{\n+    return objc_getAssociatedObject(self, &inputStateLatestTimestampKey);\n+}\n+\n+#pragma mark - setter\n+\n+- (void)setIsValid:(NSNumber *)isValid\n+{\n+    objc_setAssociatedObject(self, &inputStateValidKey, isValid, OBJC_ASSOCIATION_RETAIN_NONATOMIC);\n+}\n+\n+- (void)setTimer:(NSTimer *)timer\n+{\n+    objc_setAssociatedObject(self, &inputStateTimerKey, timer, OBJC_ASSOCIATION_RETAIN_NONATOMIC);\n+}\n+\n+- (void)setRunLoop:(NSRunLoop *)runLoop\n+{\n+    objc_setAssociatedObject(self, &inputStateRunLoopKey, runLoop, OBJC_ASSOCIATION_RETAIN_NONATOMIC);\n+}\n+\n+- (void)setLatestTimestamp:(NSNumber *)latestTimestamp\n+{\n+    objc_setAssociatedObject(self, &inputStateLatestTimestampKey, latestTimestamp, OBJC_ASSOCIATION_RETAIN_NONATOMIC);\n+}\n+\n+#pragma mark - public\n+\n+/**\n+ * 验证cmd消息是否含有输入状态提示功能\n+ *\n+ * @param model 待验证消息\n+ * @return 判断结果, YES代表消息含有输入状态提示功能\n+ */\n++ (BOOL)isInputCMDMessage:(EMMessage *)message\n+{\n+    if (![EaseMessageHelper inputStateIsValid]) {\n+        return NO;\n+    }\n+    if (!message.body || ![message.body isKindOfClass:[EMCmdMessageBody class]]) {\n+        return NO;\n+    }\n+    EMCmdMessageBody *body = (EMCmdMessageBody *)message.body;\n+    return [body.action isEqualToString:KEM_INPUTSTATE_CMDACTION];\n+}\n+\n+/**\n+ * 重置输入状态cmd消息的发送时间(前提会话为单聊)\n+ *\n+ * @param conversationType 会话类型\n+ */\n++ (void)resetInputStateCmdMessageSendTime:(EMConversationType)conversationType\n+{\n+    if (conversationType == EMConversationTypeChat &&\n+        [EaseMessageHelper inputStateIsValid]) {\n+        [[EaseMessageHelper sharedInstance] setLatestTimestamp:nil];\n+    }\n+}\n+\n+//验证消息发送方，输入状态cmd是否符合发送规律，符合则发送cmd，不符合跳出\n++ (void)canSendInputCmdMsgToChatter:(NSString *)chatter status:(BOOL)isInput\n+{\n+    //输入提示未开启，或 未连接，不发送\n+    if (![EaseMessageHelper inputStateIsValid] ||\n+        ![[EMClient sharedClient] isConnected])\n+    {\n+        return;\n+    }\n+    BOOL isCanSend = NO;\n+    NSNumber *latestTimestamp = [EaseMessageHelper sharedInstance].latestTimestamp;\n+    if (isInput)\n+    {\n+        NSDate *currentDate = [NSDate date];\n+        long long currentTimestamp = (long long)[currentDate timeIntervalSince1970];\n+        \n+        if (!latestTimestamp ||\n+            currentTimestamp - latestTimestamp.longLongValue >= KEM_INPUTSTATE_TIMEINTERVAL)\n+        {\n+            latestTimestamp = [NSNumber numberWithLongLong:currentTimestamp];\n+            isCanSend = YES;\n+        }\n+    }\n+    else {\n+        latestTimestamp = nil;\n+        isCanSend = YES;\n+    }\n+    if (isCanSend)\n+    {\n+        //可以发送cmd消息\n+        [EaseMessageHelper sendInputStateCmdMessage:chatter status:isInput];\n+        [[EaseMessageHelper sharedInstance] setLatestTimestamp:latestTimestamp];\n+    }\n+}\n+\n+/**\n+ * 处理接收的输入状态cmd消息\n+ *\n+ * @param cmdMessage 待处理cmd消息\n+ */\n+- (NSString *)handleReceiveInputStateCmdMessage:(EMMessage *)cmdMessage\n+{\n+    NSString *conversationTitle = nil;\n+    if (![EaseMessageHelper isInputCMDMessage:cmdMessage])\n+    {\n+        return conversationTitle;\n+    }\n+    if ([cmdMessage.ext[KEM_INPUTSTATE_STATE] boolValue])\n+    {\n+        conversationTitle = KEM_INPUTSTATE_TITLE;\n+    }\n+    return conversationTitle;\n+}\n+\n+//接收者开启runloop计时\n+- (void)startRunLoopByReceiver","path":"EaseUI/EaseUI/EMUIKit/Helper/EaseMessageHelper+InputState.m","position":172,"original_position":172,"commit_id":"e3f7303eb48865fae4f7ea4023cff5eefcea5c35","original_commit_id":"e3f7303eb48865fae4f7ea4023cff5eefcea5c35","user":{"login":"Neil-Cao","id":9793953,"avatar_url":"https://avatars.githubusercontent.com/u/9793953?v=3","gravatar_id":"","url":"https://api.github.com/users/Neil-Cao","html_url":"https://github.com/Neil-Cao","followers_url":"https://api.github.com/users/Neil-Cao/followers","following_url":"https://api.github.com/users/Neil-Cao/following{/other_user}","gists_url":"https://api.github.com/users/Neil-Cao/gists{/gist_id}","starred_url":"https://api.github.com/users/Neil-Cao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Neil-Cao/subscriptions","organizations_url":"https://api.github.com/users/Neil-Cao/orgs","repos_url":"https://api.github.com/users/Neil-Cao/repos","events_url":"https://api.github.com/users/Neil-Cao/events{/privacy}","received_events_url":"https://api.github.com/users/Neil-Cao/received_events","type":"User","site_admin":false},"body":"对于一个会话来说，双方都是接收者，所以没有必要强调方法中没有必要强调接收者","created_at":"2016-03-09T04:34:43Z","updated_at":"2016-03-09T04:34:43Z","html_url":"https://github.com/easemob/easeui_ios/pull/14#discussion_r55471073","pull_request_url":"https://api.github.com/repos/easemob/easeui_ios/pulls/14","_links":{"self":{"href":"https://api.github.com/repos/easemob/easeui_ios/pulls/comments/55471073"},"html":{"href":"https://github.com/easemob/easeui_ios/pull/14#discussion_r55471073"},"pull_request":{"href":"https://api.github.com/repos/easemob/easeui_ios/pulls/14"}}},"pull_request":{"url":"https://api.github.com/repos/easemob/easeui_ios/pulls/14","id":61902185,"html_url":"https://github.com/easemob/easeui_ios/pull/14","diff_url":"https://github.com/easemob/easeui_ios/pull/14.diff","patch_url":"https://github.com/easemob/easeui_ios/pull/14.patch","issue_url":"https://api.github.com/repos/easemob/easeui_ios/issues/14","number":14,"state":"open","locked":false,"title":"v3.x revoke message、burn after read、group @、inputState","user":{"login":"wyuzhang","id":16917238,"avatar_url":"https://avatars.githubusercontent.com/u/16917238?v=3","gravatar_id":"","url":"https://api.github.com/users/wyuzhang","html_url":"https://github.com/wyuzhang","followers_url":"https://api.github.com/users/wyuzhang/followers","following_url":"https://api.github.com/users/wyuzhang/following{/other_user}","gists_url":"https://api.github.com/users/wyuzhang/gists{/gist_id}","starred_url":"https://api.github.com/users/wyuzhang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wyuzhang/subscriptions","organizations_url":"https://api.github.com/users/wyuzhang/orgs","repos_url":"https://api.github.com/users/wyuzhang/repos","events_url":"https://api.github.com/users/wyuzhang/events{/privacy}","received_events_url":"https://api.github.com/users/wyuzhang/received_events","type":"User","site_admin":false},"body":"v3.x revoke message、burn after read、group @、inputState","created_at":"2016-03-07T11:03:12Z","updated_at":"2016-03-09T04:34:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5aa29f215eaadb5fba14320b2e3067596de510b9","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/easemob/easeui_ios/pulls/14/commits","review_comments_url":"https://api.github.com/repos/easemob/easeui_ios/pulls/14/comments","review_comment_url":"https://api.github.com/repos/easemob/easeui_ios/pulls/comments{/number}","comments_url":"https://api.github.com/repos/easemob/easeui_ios/issues/14/comments","statuses_url":"https://api.github.com/repos/easemob/easeui_ios/statuses/e3f7303eb48865fae4f7ea4023cff5eefcea5c35","head":{"label":"wyuzhang:new_dev","ref":"new_dev","sha":"e3f7303eb48865fae4f7ea4023cff5eefcea5c35","user":{"login":"wyuzhang","id":16917238,"avatar_url":"https://avatars.githubusercontent.com/u/16917238?v=3","gravatar_id":"","url":"https://api.github.com/users/wyuzhang","html_url":"https://github.com/wyuzhang","followers_url":"https://api.github.com/users/wyuzhang/followers","following_url":"https://api.github.com/users/wyuzhang/following{/other_user}","gists_url":"https://api.github.com/users/wyuzhang/gists{/gist_id}","starred_url":"https://api.github.com/users/wyuzhang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wyuzhang/subscriptions","organizations_url":"https://api.github.com/users/wyuzhang/orgs","repos_url":"https://api.github.com/users/wyuzhang/repos","events_url":"https://api.github.com/users/wyuzhang/events{/privacy}","received_events_url":"https://api.github.com/users/wyuzhang/received_events","type":"User","site_admin":false},"repo":{"id":51728024,"name":"easeui_ios","full_name":"wyuzhang/easeui_ios","owner":{"login":"wyuzhang","id":16917238,"avatar_url":"https://avatars.githubusercontent.com/u/16917238?v=3","gravatar_id":"","url":"https://api.github.com/users/wyuzhang","html_url":"https://github.com/wyuzhang","followers_url":"https://api.github.com/users/wyuzhang/followers","following_url":"https://api.github.com/users/wyuzhang/following{/other_user}","gists_url":"https://api.github.com/users/wyuzhang/gists{/gist_id}","starred_url":"https://api.github.com/users/wyuzhang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wyuzhang/subscriptions","organizations_url":"https://api.github.com/users/wyuzhang/orgs","repos_url":"https://api.github.com/users/wyuzhang/repos","events_url":"https://api.github.com/users/wyuzhang/events{/privacy}","received_events_url":"https://api.github.com/users/wyuzhang/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/wyuzhang/easeui_ios","description":"","fork":true,"url":"https://api.github.com/repos/wyuzhang/easeui_ios","forks_url":"https://api.github.com/repos/wyuzhang/easeui_ios/forks","keys_url":"https://api.github.com/repos/wyuzhang/easeui_ios/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wyuzhang/easeui_ios/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wyuzhang/easeui_ios/teams","hooks_url":"https://api.github.com/repos/wyuzhang/easeui_ios/hooks","issue_events_url":"https://api.github.com/repos/wyuzhang/easeui_ios/issues/events{/number}","events_url":"https://api.github.com/repos/wyuzhang/easeui_ios/events","assignees_url":"https://api.github.com/repos/wyuzhang/easeui_ios/assignees{/user}","branches_url":"https://api.github.com/repos/wyuzhang/easeui_ios/branches{/branch}","tags_url":"https://api.github.com/repos/wyuzhang/easeui_ios/tags","blobs_url":"https://api.github.com/repos/wyuzhang/easeui_ios/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wyuzhang/easeui_ios/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wyuzhang/easeui_ios/git/refs{/sha}","trees_url":"https://api.github.com/repos/wyuzhang/easeui_ios/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wyuzhang/easeui_ios/statuses/{sha}","languages_url":"https://api.github.com/repos/wyuzhang/easeui_ios/languages","stargazers_url":"https://api.github.com/repos/wyuzhang/easeui_ios/stargazers","contributors_url":"https://api.github.com/repos/wyuzhang/easeui_ios/contributors","subscribers_url":"https://api.github.com/repos/wyuzhang/easeui_ios/subscribers","subscription_url":"https://api.github.com/repos/wyuzhang/easeui_ios/subscription","commits_url":"https://api.github.com/repos/wyuzhang/easeui_ios/commits{/sha}","git_commits_url":"https://api.github.com/repos/wyuzhang/easeui_ios/git/commits{/sha}","comments_url":"https://api.github.com/repos/wyuzhang/easeui_ios/comments{/number}","issue_comment_url":"https://api.github.com/repos/wyuzhang/easeui_ios/issues/comments{/number}","contents_url":"https://api.github.com/repos/wyuzhang/easeui_ios/contents/{+path}","compare_url":"https://api.github.com/repos/wyuzhang/easeui_ios/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wyuzhang/easeui_ios/merges","archive_url":"https://api.github.com/repos/wyuzhang/easeui_ios/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wyuzhang/easeui_ios/downloads","issues_url":"https://api.github.com/repos/wyuzhang/easeui_ios/issues{/number}","pulls_url":"https://api.github.com/repos/wyuzhang/easeui_ios/pulls{/number}","milestones_url":"https://api.github.com/repos/wyuzhang/easeui_ios/milestones{/number}","notifications_url":"https://api.github.com/repos/wyuzhang/easeui_ios/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wyuzhang/easeui_ios/labels{/name}","releases_url":"https://api.github.com/repos/wyuzhang/easeui_ios/releases{/id}","deployments_url":"https://api.github.com/repos/wyuzhang/easeui_ios/deployments","created_at":"2016-02-15T03:21:03Z","updated_at":"2016-02-15T03:21:04Z","pushed_at":"2016-03-07T10:30:53Z","git_url":"git://github.com/wyuzhang/easeui_ios.git","ssh_url":"git@github.com:wyuzhang/easeui_ios.git","clone_url":"https://github.com/wyuzhang/easeui_ios.git","svn_url":"https://github.com/wyuzhang/easeui_ios","homepage":null,"size":3692,"stargazers_count":0,"watchers_count":0,"language":"Objective-C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"easemob:new_dev","ref":"new_dev","sha":"57e63983320f1838b1af4f67f08798038549de96","user":{"login":"easemob","id":2704962,"avatar_url":"https://avatars.githubusercontent.com/u/2704962?v=3","gravatar_id":"","url":"https://api.github.com/users/easemob","html_url":"https://github.com/easemob","followers_url":"https://api.github.com/users/easemob/followers","following_url":"https://api.github.com/users/easemob/following{/other_user}","gists_url":"https://api.github.com/users/easemob/gists{/gist_id}","starred_url":"https://api.github.com/users/easemob/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/easemob/subscriptions","organizations_url":"https://api.github.com/users/easemob/orgs","repos_url":"https://api.github.com/users/easemob/repos","events_url":"https://api.github.com/users/easemob/events{/privacy}","received_events_url":"https://api.github.com/users/easemob/received_events","type":"Organization","site_admin":false},"repo":{"id":42239230,"name":"easeui_ios","full_name":"easemob/easeui_ios","owner":{"login":"easemob","id":2704962,"avatar_url":"https://avatars.githubusercontent.com/u/2704962?v=3","gravatar_id":"","url":"https://api.github.com/users/easemob","html_url":"https://github.com/easemob","followers_url":"https://api.github.com/users/easemob/followers","following_url":"https://api.github.com/users/easemob/following{/other_user}","gists_url":"https://api.github.com/users/easemob/gists{/gist_id}","starred_url":"https://api.github.com/users/easemob/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/easemob/subscriptions","organizations_url":"https://api.github.com/users/easemob/orgs","repos_url":"https://api.github.com/users/easemob/repos","events_url":"https://api.github.com/users/easemob/events{/privacy}","received_events_url":"https://api.github.com/users/easemob/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/easemob/easeui_ios","description":"","fork":false,"url":"https://api.github.com/repos/easemob/easeui_ios","forks_url":"https://api.github.com/repos/easemob/easeui_ios/forks","keys_url":"https://api.github.com/repos/easemob/easeui_ios/keys{/key_id}","collaborators_url":"https://api.github.com/repos/easemob/easeui_ios/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/easemob/easeui_ios/teams","hooks_url":"https://api.github.com/repos/easemob/easeui_ios/hooks","issue_events_url":"https://api.github.com/repos/easemob/easeui_ios/issues/events{/number}","events_url":"https://api.github.com/repos/easemob/easeui_ios/events","assignees_url":"https://api.github.com/repos/easemob/easeui_ios/assignees{/user}","branches_url":"https://api.github.com/repos/easemob/easeui_ios/branches{/branch}","tags_url":"https://api.github.com/repos/easemob/easeui_ios/tags","blobs_url":"https://api.github.com/repos/easemob/easeui_ios/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/easemob/easeui_ios/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/easemob/easeui_ios/git/refs{/sha}","trees_url":"https://api.github.com/repos/easemob/easeui_ios/git/trees{/sha}","statuses_url":"https://api.github.com/repos/easemob/easeui_ios/statuses/{sha}","languages_url":"https://api.github.com/repos/easemob/easeui_ios/languages","stargazers_url":"https://api.github.com/repos/easemob/easeui_ios/stargazers","contributors_url":"https://api.github.com/repos/easemob/easeui_ios/contributors","subscribers_url":"https://api.github.com/repos/easemob/easeui_ios/subscribers","subscription_url":"https://api.github.com/repos/easemob/easeui_ios/subscription","commits_url":"https://api.github.com/repos/easemob/easeui_ios/commits{/sha}","git_commits_url":"https://api.github.com/repos/easemob/easeui_ios/git/commits{/sha}","comments_url":"https://api.github.com/repos/easemob/easeui_ios/comments{/number}","issue_comment_url":"https://api.github.com/repos/easemob/easeui_ios/issues/comments{/number}","contents_url":"https://api.github.com/repos/easemob/easeui_ios/contents/{+path}","compare_url":"https://api.github.com/repos/easemob/easeui_ios/compare/{base}...{head}","merges_url":"https://api.github.com/repos/easemob/easeui_ios/merges","archive_url":"https://api.github.com/repos/easemob/easeui_ios/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/easemob/easeui_ios/downloads","issues_url":"https://api.github.com/repos/easemob/easeui_ios/issues{/number}","pulls_url":"https://api.github.com/repos/easemob/easeui_ios/pulls{/number}","milestones_url":"https://api.github.com/repos/easemob/easeui_ios/milestones{/number}","notifications_url":"https://api.github.com/repos/easemob/easeui_ios/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/easemob/easeui_ios/labels{/name}","releases_url":"https://api.github.com/repos/easemob/easeui_ios/releases{/id}","deployments_url":"https://api.github.com/repos/easemob/easeui_ios/deployments","created_at":"2015-09-10T10:58:13Z","updated_at":"2016-02-26T02:15:09Z","pushed_at":"2016-03-07T11:03:12Z","git_url":"git://github.com/easemob/easeui_ios.git","ssh_url":"git@github.com:easemob/easeui_ios.git","clone_url":"https://github.com/easemob/easeui_ios.git","svn_url":"https://github.com/easemob/easeui_ios","homepage":null,"size":7267,"stargazers_count":12,"watchers_count":12,"language":"Objective-C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":11,"mirror_url":null,"open_issues_count":7,"forks":11,"open_issues":7,"watchers":12,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/easemob/easeui_ios/pulls/14"},"html":{"href":"https://github.com/easemob/easeui_ios/pull/14"},"issue":{"href":"https://api.github.com/repos/easemob/easeui_ios/issues/14"},"comments":{"href":"https://api.github.com/repos/easemob/easeui_ios/issues/14/comments"},"review_comments":{"href":"https://api.github.com/repos/easemob/easeui_ios/pulls/14/comments"},"review_comment":{"href":"https://api.github.com/repos/easemob/easeui_ios/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/easemob/easeui_ios/pulls/14/commits"},"statuses":{"href":"https://api.github.com/repos/easemob/easeui_ios/statuses/e3f7303eb48865fae4f7ea4023cff5eefcea5c35"}}}}