|
@@ -2,30 +2,139 @@
|
|
|
// KSTXC2CChatViewController.m
|
|
|
// KulexiuForTeacher
|
|
|
//
|
|
|
-// Created by 王智 on 2023/8/10.
|
|
|
+// Created by 王智 on 2023/8/23.
|
|
|
//
|
|
|
|
|
|
#import "KSTXC2CChatViewController.h"
|
|
|
+#import "TUIBaseChatViewController+ProtectedAPI.h"
|
|
|
+#import "TUIChatConfig.h"
|
|
|
+#import "TUICloudCustomDataTypeCenter.h"
|
|
|
+#import "TUILinkCellData.h"
|
|
|
+#import "TUIMessageController.h"
|
|
|
+#import "TUIMessageDataProvider.h"
|
|
|
+
|
|
|
+#define kC2CTypingTime 30.0
|
|
|
|
|
|
@interface KSTXC2CChatViewController ()
|
|
|
|
|
|
+// 如果满足了一次sendTypingBaseCondation 则当前会话未退出前都使用 sendTypingBaseCondationInVC
|
|
|
+// If one sendTypingBaseCondation is satisfied, sendTypingBaseCondationInVC is used until the current session exits
|
|
|
+
|
|
|
+@property(nonatomic, assign) BOOL sendTypingBaseCondationInVC;
|
|
|
+
|
|
|
+
|
|
|
@end
|
|
|
|
|
|
@implementation KSTXC2CChatViewController
|
|
|
|
|
|
+- (void)dealloc {
|
|
|
+ self.sendTypingBaseCondationInVC = NO;
|
|
|
+}
|
|
|
- (void)viewDidLoad {
|
|
|
[super viewDidLoad];
|
|
|
// Do any additional setup after loading the view.
|
|
|
+ self.sendTypingBaseCondationInVC = NO;
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark - Override Methods
|
|
|
+- (NSString *)forwardTitleWithMyName:(NSString *)nameStr {
|
|
|
+ return [NSString stringWithFormat:TIMCommonLocalizableString(TUIKitRelayChatHistoryForSomebodyFormat), self.conversationData.title, nameStr];
|
|
|
}
|
|
|
|
|
|
-/*
|
|
|
-#pragma mark - Navigation
|
|
|
+- (void)inputController:(TUIInputController *)inputController didSelectMoreCell:(TUIInputMoreCell *)cell {
|
|
|
+ [super inputController:inputController didSelectMoreCell:cell];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)inputControllerBeginTyping:(TUIInputController *)inputController {
|
|
|
+ [super inputControllerBeginTyping:inputController];
|
|
|
|
|
|
-// In a storyboard-based application, you will often want to do a little preparation before navigation
|
|
|
-- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
|
|
- // Get the new view controller using [segue destinationViewController].
|
|
|
- // Pass the selected object to the new view controller.
|
|
|
+ [self sendTypingMsgByStatus:YES];
|
|
|
}
|
|
|
-*/
|
|
|
|
|
|
+- (void)inputControllerEndTyping:(TUIInputController *)inputController {
|
|
|
+ [super inputControllerEndTyping:inputController];
|
|
|
+
|
|
|
+ [self sendTypingMsgByStatus:NO];
|
|
|
+}
|
|
|
+
|
|
|
+- (BOOL)sendTypingBaseCondation {
|
|
|
+ if (self.sendTypingBaseCondationInVC) {
|
|
|
+ return YES;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ([self.messageController isKindOfClass:TUIMessageController.class]) {
|
|
|
+ TUIMessageController *vc = (TUIMessageController *)self.messageController;
|
|
|
+ NSDictionary *messageFeatureDic = (id)[vc.C2CIncomingLastMsg parseCloudCustomData:messageFeature];
|
|
|
+
|
|
|
+ if (messageFeatureDic && [messageFeatureDic isKindOfClass:[NSDictionary class]] && [messageFeatureDic.allKeys containsObject:@"needTyping"] &&
|
|
|
+ [messageFeatureDic.allKeys containsObject:@"version"]) {
|
|
|
+ BOOL needTyping = NO;
|
|
|
+
|
|
|
+ BOOL versionControl = NO;
|
|
|
+
|
|
|
+ BOOL timeControl = NO;
|
|
|
+
|
|
|
+ if ([messageFeatureDic[@"needTyping"] intValue] == 1) {
|
|
|
+ needTyping = YES;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ([messageFeatureDic[@"version"] intValue] == 1) {
|
|
|
+ versionControl = YES;
|
|
|
+ }
|
|
|
+
|
|
|
+ CFTimeInterval current = [NSDate.new timeIntervalSince1970];
|
|
|
+ long currentTimeFloor = floor(current);
|
|
|
+ long otherSideTimeFloor = floor([vc.C2CIncomingLastMsg.timestamp timeIntervalSince1970]);
|
|
|
+ long interval = currentTimeFloor - otherSideTimeFloor;
|
|
|
+ if (interval <= kC2CTypingTime) {
|
|
|
+ timeControl = YES;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (needTyping && versionControl && timeControl) {
|
|
|
+ self.sendTypingBaseCondationInVC = YES;
|
|
|
+ return YES;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return NO;
|
|
|
+}
|
|
|
+- (void)sendTypingMsgByStatus:(BOOL)editing {
|
|
|
+ // switch control
|
|
|
+ if (![TUIChatConfig defaultConfig].enableTypingStatus) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (![self sendTypingBaseCondation]) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ NSError *error = nil;
|
|
|
+ NSDictionary *param = @{
|
|
|
+ BussinessID : BussinessID_Typing,
|
|
|
+ @"typingStatus" : editing ? @1 : @0,
|
|
|
+ @"version" : @1,
|
|
|
+ @"userAction" : @14,
|
|
|
+ @"actionParam" : editing ? @"EIMAMSG_InputStatus_Ing" : @"EIMAMSG_InputStatus_End",
|
|
|
+ };
|
|
|
+ NSData *data = [NSJSONSerialization dataWithJSONObject:param options:0 error:&error];
|
|
|
+
|
|
|
+ V2TIMMessage *msg = [TUIMessageDataProvider getCustomMessageWithJsonData:data];
|
|
|
+ TUISendMessageAppendParams *appendParams = [[TUISendMessageAppendParams alloc] init];
|
|
|
+ appendParams.isSendPushInfo = NO;
|
|
|
+ appendParams.isOnlineUserOnly = YES;
|
|
|
+ appendParams.priority = V2TIM_PRIORITY_DEFAULT;
|
|
|
+
|
|
|
+ [TUIMessageDataProvider sendMessage:msg
|
|
|
+ toConversation:self.conversationData
|
|
|
+ appendParams:appendParams
|
|
|
+ Progress:^(uint32_t progress) {
|
|
|
+
|
|
|
+ }
|
|
|
+ SuccBlock:^{
|
|
|
+ NSLog(@"success");
|
|
|
+ }
|
|
|
+ FailBlock:^(int code, NSString *desc) {
|
|
|
+ NSLog(@"Fail");
|
|
|
+ }];
|
|
|
+}
|
|
|
@end
|