123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775 |
- //
- // XYIMBaseManager.m
- // Timi
- //
- // Created by 翟玉磊 on 2021/3/25.
- //
- #import "XYIMBaseManager.h"
- #import <RongIMKit/RongIMKit.h>
- #import "XYChatRTMManager.h"
- #import "TMRoomJoinMessage.h"
- #import "TMSysNoticeMessage.h"
- #import "TMCustomMessage.h"
- #import "TMPrivateChatGiftMessage.h"
- #import "TMPrivateChatGameShareMessage.h"
- #import "TMPrivateChatFollowMessage.h"
- // 头条
- #import "XYHeadlineRoomManage.h"
- #pragma mark — 系统消息
- #import "XYVoiceMatchWaitPopupView.h"
- #import "XYVoiceMatchMessageModel.h"
- #import "XYVoiceChatManager.h"
- #import "XYSystemMessageViewController.h"
- #import "XYFriendApplyListViewController.h"
- #import "XYFollowMessageViewController.h"
- #import "XYPeiPlayCommendAlertView.h"
- #import "XYChatRoomDispatchManager.h"
- #import "XYWishGiftCompleteTipView.h"
- #import "XYAnniversaryManager.h"
- #import "XYChatRoomActivityMedalUpTipViewController.h"
- @interface XYIMBaseManager ()<RCIMConnectionStatusDelegate, RCIMReceiveMessageDelegate, RCIMUserInfoDataSource>
- @end
- @implementation XYIMBaseManager
- #pragma mark — Public
- - (void)im_setupAppId:(NSString *)appId {
- [[RCIM sharedRCIM] initWithAppKey:appId];
- [self configSDK];
- }
- - (void)configSDK {
- // 设置 RCIM 的连接状态监听器
- [[RCIM sharedRCIM] setConnectionStatusDelegate:self];
- // 设置 IMlib 的消息接收监听器
- [[RCIM sharedRCIM] setReceiveMessageDelegate:self];
- // 用户信息提供者
- [[RCIM sharedRCIM] setUserInfoDataSource:self];
-
- // 开启合并转发功能
- [[RCIM sharedRCIM] setEnableSendCombineMessage:YES];
- // 支持消息引用功能
- [RCIM sharedRCIM].enableMessageReference = YES;
- // 开启发送输入状态
- [RCIM sharedRCIM].enableTypingStatus = YES;
- // 关闭所有的前台消息提示音
- [RCIM sharedRCIM].disableMessageAlertSound = YES;
- // 设置不输入任何日志
- [RCIMClient sharedRCIMClient].logLevel = RC_Log_Level_None;
-
- // 注册自定义消息
- [[RCIMClient sharedRCIMClient] registerMessageType:TMRoomJoinMessage.class];
- [[RCIMClient sharedRCIMClient] registerMessageType:TMSysNoticeMessage.class];
- [[RCIMClient sharedRCIMClient] registerMessageType:TMCustomMessage.class];
- [[RCIMClient sharedRCIMClient] registerMessageType:TMPrivateChatGiftMessage.class];
- [[RCIMClient sharedRCIMClient] registerMessageType:TMPrivateChatGameShareMessage.class];
- [[RCIMClient sharedRCIMClient] registerMessageType:TMPrivateChatFollowMessage.class];
-
- NSLog(@"融云SDK版本:lib:%@", [[RCIMClient sharedRCIMClient] getSDKVersion]);
- }
- - (void)im_loginWithToken:(NSString *)token complete:(void(^)(BOOL success))block {
- [[RCIMClient sharedRCIMClient] connectWithToken:token dbOpened:^(RCDBErrorCode code) {
- } success:^(NSString *userId) {
- // 登录成功后加入头条聊天室
- [[XYHeadlineRoomManage shareInstance] joinRoom];
- [[XYIMUnReadCountManager sharedInstance] updateAllUnreadCount:nil];
- !block?:block(YES);
- NSLog(@"----------------融云IM连接成功----------------");
-
- } error:^(RCConnectErrorCode errorCode) {// token失效时重新请求业务服务端去融云创建token返回重新登录
- if (errorCode == RC_CONN_TOKEN_INCORRECT) {
- [[XYUserAPIManager new] getRtmTokenSuccessHandler:^(ZYLResponseModel *responseModel) {
-
- [[RCIMClient sharedRCIMClient] connectWithToken:[XYUserInfoManager nowUser].rtmToken dbOpened:^(RCDBErrorCode code) {
- } success:^(NSString *userId) {
- // 登录成功后加入头条聊天室
- [[XYHeadlineRoomManage shareInstance] joinRoom];
- [[XYIMUnReadCountManager sharedInstance] updateAllUnreadCount:nil];
- !block?:block(YES);
- NSLog(@"----------------融云IM连接成功----------------");
- } error:^(RCConnectErrorCode errorCode) {
- !block?:block(NO);
- NSString *msg = [XYIMBaseManager getErrorTextWithCode:errorCode];
- NSLog(@"----------------融云IM连接失败:%@----------------", msg);
- }];
- } failureHandler:^(ZYLNetworkError *error) {
- !block?:block(NO);
- NSLog(@"----------------融云IM连接失败:%@----------------", error.domain);
- }];
-
- }else {// errorCode != RC_CONN_TOKEN_INCORRECT
- !block?:block(NO);
- NSString *msg = [XYIMBaseManager getErrorTextWithCode:errorCode];
- NSLog(@"----------------融云IM连接失败:%@----------------", msg);
- }
-
- }];
- }
- - (void)im_logoutComplete:(void(^)(BOOL success))block {
- [[RCIMClient sharedRCIMClient] logout];
- !block?:block(YES);
- }
- /// 获取单聊会话列表
- - (NSArray *)getConversationList {
- NSArray *convs = [[RCIMClient sharedRCIMClient] getConversationList:@[@(ConversationType_PRIVATE)]];
- NSMutableArray *tempArray = [NSMutableArray array];
- for (RCConversation *conv in convs) {
- if (![BaseMethod isNOTNull:conv.targetId]) {
- continue;
- }
- [tempArray addObject:conv];
- }
- return tempArray;
- }
- /// 删除指定的单聊会话
- - (BOOL)removeConversation:(NSString *)conId {
- return [[RCIMClient sharedRCIMClient] removeConversation:ConversationType_PRIVATE targetId:conId];
- }
- /// 更新im缓存的用户信息
- - (void)refreshUserInfoWithUserId:(NSString *)userId name:(NSString *)name portrait:(NSString *)portrait {
- [[RCIM sharedRCIM] refreshUserInfoCache:[[RCUserInfo alloc] initWithUserId:userId name:StringIsEmpty(name)?@"":name portrait:StringIsEmpty(portrait)?@"":portrait] withUserId:userId];
- }
- /// 清除某个会话中的未读消息数
- - (BOOL)clearMessagesUnreadStatusWithConversationId:(NSString *)convId {
- return [[RCIMClient sharedRCIMClient] clearMessagesUnreadStatus:ConversationType_PRIVATE targetId:convId];
- }
- #pragma mark — RCIMConnectionStatusDelegate
- /*!
- IMKit连接状态的的监听器
- @param status SDK与融云服务器的连接状态
- @discussion 如果您设置了IMKit消息监听之后,当SDK与融云服务器的连接状态发生变化时,会回调此方法。
- */
- - (void)onRCIMConnectionStatusChanged:(RCConnectionStatus)status {
- NSString *statusText = @"";
- switch (status) {
- case ConnectionStatus_UNKNOWN:
- statusText = @"未知状态";
- break;
- case ConnectionStatus_Connected:
- statusText = @"连接成功";
- break;
- case ConnectionStatus_NETWORK_UNAVAILABLE:
- statusText = @"连接过程中,当前设备网络不可用";
- break;
- case ConnectionStatus_KICKED_OFFLINE_BY_OTHER_CLIENT:
- {
- statusText = @"当前用户在其他设备上登录,此设备被踢下线";
- [ApplicationDelegate logoutHandleSuccess:^(BOOL success) {
- }];
- // 防止多次出现
- for (CustomActionAlertController *alVC in ApplicationDelegate.tabbarVC.childViewControllers) {
- if ([alVC isKindOfClass:CustomActionAlertController.class]) {
- [alVC dismiss];
- }
- }
- CustomActionAlertController *alertController = [[CustomActionAlertController alloc] initWithTitle:kLocalizedString(@"下线通知") message:kLocalizedString(@"您的账号被异地登录,是否重新登录!") sure:kLocalizedString(@"重新登录") cancel:kLocalizedString(@"退出登录") selctedBlock:^(NSInteger index, NSString * _Nonnull title) {
- if (index == 0) {
- // 退出
- [ApplicationDelegate createQulickLoginPageVC];
- }
- if (index == 1) {
- // 重新登录
- [ApplicationDelegate createQulickLoginPageVC];
- }
- }];
- [alertController show];
- }
- break;
- case ConnectionStatus_Connecting:
- statusText = @"连接中";
- break;
- case ConnectionStatus_Unconnected:
- statusText = @"连接失败或未连接";
- break;
- case ConnectionStatus_SignOut:
- statusText = @"已注销";
- break;
- case ConnectionStatus_Suspend:
- statusText = @"连接暂时挂起(多是由于网络问题导致),SDK 会在合适时机进行自动重连";
- break;
- case ConnectionStatus_Timeout:
- statusText = @"自动连接超时,SDK 将不会继续连接,用户需要做超时处理,再自行调用 connectWithToken 接口进行连接";
- break;
- case ConnectionStatus_TOKEN_INCORRECT:
- statusText = @"Token无效";
- break;
- case ConnectionStatus_DISCONN_EXCEPTION:
- statusText = @"与服务器的连接已断开,用户被封禁";
- break;
- }
- NSLog(@"融云IM连接状态:%@", statusText);
- }
- - (void)printLog:(RCMessage *)message{
- #ifdef DEBUG
- NSDictionary *object;
- if ([message.content isKindOfClass:TMRoomJoinMessage.class]) {
- TMRoomJoinMessage *commandMessage = (TMRoomJoinMessage *)message.content;
- object = [commandMessage.data jsonValueDecoded];
- NSLog(@"RCIM入口收到的TMRoomJoinMessage数据:%@", object);
- }
-
- if ([message.content isKindOfClass:RCCommandMessage.class]) {
- RCCommandMessage *commandMessage = (RCCommandMessage *)message.content;
- object = [commandMessage.data jsonValueDecoded];
- NSLog(@"RCIM入口收到的RCCommandMessage数据:%@", object);
- }
-
- if ([message.content isKindOfClass:RCTextMessage.class]) {
- RCTextMessage *textMessage = (RCTextMessage *)message.content;
- object = [textMessage.extra jsonValueDecoded];
- NSLog(@"RCIM入口收到的RCTextMessage数据:%@", object);
- }
-
- if ([message.content isKindOfClass:TMSysNoticeMessage.class]) {
- TMSysNoticeMessage *systemMessage = (TMSysNoticeMessage *)message.content;
- object = [systemMessage.notice jsonValueDecoded];
- NSLog(@"RCIM入口收到的TMSysNoticeMessage数据:%@", object);
- }
-
- if ([message.content isKindOfClass:TMCustomMessage.class]) {
- TMCustomMessage *systemMessage = (TMCustomMessage *)message.content;
- NSDictionary *object = [systemMessage.data jsonValueDecoded];
- NSLog(@"RCIM入口收到的TMCustomMessage数据:%@", object);
- }
- #else
- #endif
- }
- #pragma mark — RCIMReceiveMessageDelegate
- /*!
- 接收消息的回调方法
- @param message 当前接收到的消息
- @param left 还剩余的未接收的消息数,left>=0
- @discussion 如果您设置了IMKit消息监听之后,SDK在接收到消息时候会执行此方法(无论App处于前台或者后台)。
- 其中,left为还剩余的、还未接收的消息数量。比如刚上线一口气收到多条消息时,通过此方法,您可以获取到每条消息,left会依次递减直到0。
- 您可以根据left数量来优化您的App体验和性能,比如收到大量消息时等待left为0再刷新UI。
- */
- - (void)onRCIMReceiveMessage:(RCMessage *)message left:(int)left {
-
- [self printLog:message];
-
- if (message.conversationType == ConversationType_PRIVATE) {
-
- if ([NSStringFromClass(message.content.class) hasPrefix:@"RC"] || [message.content isKindOfClass:TMPrivateChatGiftMessage.class] || [message.content isKindOfClass:TMPrivateChatGameShareMessage.class] || [message.content isKindOfClass:TMPrivateChatFollowMessage.class]) {
- // 原生消息、私聊礼物、游戏分享
- dispatch_async(dispatch_get_main_queue(), ^{
- if ([message.content isKindOfClass:RCCommandMessage.class]) {
- // 聊天室消息
- [[XYChatRTMManager sharedInstance] im_onReceived:message left:left];
- }else {
- // 私聊消息
- // 刷新会话列表
- [[NSNotificationCenter defaultCenter] postNotificationName:REFRESH_CONVERSATION_LIST_NOTIFICATION object:nil];
- // 更新未读消息数
- [[XYIMUnReadCountManager sharedInstance] updateMessageUnreadCountWithTabbarBadge:YES];
- if ([message.content isKindOfClass:TMPrivateChatGiftMessage.class]) {
- // 私聊礼物动画
- TMPrivateChatGiftMessage *commandMessage = (TMPrivateChatGiftMessage *)message.content;
- NSDictionary *object = [commandMessage.data jsonValueDecoded];
- [[NSNotificationCenter defaultCenter] postNotificationName:RECEIVED_PRVATE_CHAT_MESSAGE_NOTIFITION object:object];
- }
- }
- });
- }else {
- // 自定义的系统消息
- if ([message.content isKindOfClass:TMCustomMessage.class]) {
- // 自定义消息(系统消息、关注、召集)
- TMCustomMessage *systemMessage = (TMCustomMessage *)message.content;
- NSDictionary *object = [systemMessage.data jsonValueDecoded];
- dispatch_async(dispatch_get_main_queue(), ^{
- [self handleSystemMessageWithMessage:object message:message];
- });
- }
- }
- }else if (message.conversationType == ConversationType_CHATROOM) {
- dispatch_async(dispatch_get_main_queue(), ^{
- // 聊天室消息
- [[XYChatRTMManager sharedInstance] im_onReceived:message left:left];
- });
- }else {
- if ([message.content isKindOfClass:TMSysNoticeMessage.class]) {
- // 系统消息(目前没用)
- TMSysNoticeMessage *systemMessage = (TMSysNoticeMessage *)message.content;
- NSDictionary *object = [systemMessage.notice jsonValueDecoded];
- dispatch_async(dispatch_get_main_queue(), ^{
- [self handleSystemMessageWithMessage:object message:message];
- });
- }
- }
- }
- #pragma mark — RCIMUserInfoDataSource
- /*!
- SDK 的回调,用于向 App 获取用户信息
- @param userId 用户ID
- @param completion 获取用户信息完成之后需要执行的Block [userInfo:该用户ID对应的用户信息]
- @discussion SDK通过此方法获取用户信息并显示,请在completion中返回该用户ID对应的用户信息。
- 在您设置了用户信息提供者之后,SDK在需要显示用户信息的时候,会调用此方法,向您请求用户信息用于显示。
- */
- - (void)getUserInfoWithUserId:(NSString *)userId completion:(void (^)(RCUserInfo *userInfo))completion {
-
- [[XYUserAPIManager new] getImInfoWithUserId:userId successHandler:^(ZYLResponseModel *responseModel) {
- NSDictionary *userDict = responseModel.data;
- if (userDict) {
- NSString *userName = userDict[@"userName"];
- NSString *userAvatar = userDict[@"userAvatar"];
- RCUserInfo *userInfo = [[RCUserInfo alloc] initWithUserId:userId name:userName portrait:userAvatar];
- !completion?:completion(userInfo);
- }else {
- !completion?:completion(nil);
- }
- } failureHandler:^(ZYLNetworkError *error) {
- !completion?:completion(nil);
- }];
- }
- - (void)onReceivedHeadlineMessage:(NSNotification *)notification {
- NSDictionary *object = notification.object;
- if (object) { [self handleSystemMessageWithMessage:object message:nil];}
- }
- #pragma mark — Method
- + (NSString *)getErrorTextWithCode:(NSInteger)errorCode {
- NSString *errorMsg = @"";
- if (errorCode == RC_CONN_TOKEN_INCORRECT) {
- errorMsg = @"Token 无效";
- }else if (errorCode == RC_CONN_ID_REJECT) {
- errorMsg = @"请检查您使用的 AppKey 是否正确";
- }else if (errorCode == RC_CONN_NOT_AUTHRORIZED) {
- errorMsg = @"AppKey 与 Token 不匹配";
- }else if (errorCode == RC_CONN_PACKAGE_NAME_INVALID) {
- errorMsg = @"BundleID 不正确";
- }else if (errorCode == RC_CONN_APP_BLOCKED_OR_DELETED) {
- errorMsg = @"AppKey 被封禁或已删除";
- }else if (errorCode == RC_CONN_USER_BLOCKED) {
- errorMsg = @"用户被封禁";
- }else if (errorCode == RC_DISCONN_KICK) {
- errorMsg = @"用户被踢下线";
- }else if (errorCode == RC_CONN_OTHER_DEVICE_LOGIN) {
- errorMsg = @"用户在其它设备上登录";
- }else if (errorCode == CONCURRENT_LIMIT_ERROR) {
- errorMsg = @"连接超过并发限定值";
- }else if (errorCode == RC_CLIENT_NOT_INIT) {
- errorMsg = @"SDK 没有初始化";
- }else if (errorCode == RC_INVALID_PARAMETER) {
- errorMsg = @"开发者接口调用时传入的参数错误";
- }else if (errorCode == RC_CONNECTION_EXIST) {
- errorMsg = @"Connection 已经存在";
- }else if (errorCode == RC_ENVIRONMENT_ERROR) {
- errorMsg = @"连接环境不正确(融云公有云 SDK 无法连接到私有云环境)";
- }else if (errorCode == RC_CONNECT_TIMEOUT) {
- errorMsg = @"连接超时";
- }else if (errorCode == RC_INVALID_ARGUMENT) {
- errorMsg = @"开发者接口调用时传入的参数错误";
- }else if (errorCode == DATABASE_ERROR) {
- errorMsg = @"数据库错误";
- }
-
- return errorMsg;
- }
- - (void)handleSystemMessageWithMessage:(NSDictionary *)msg message:(RCMessage *)message {
- if (ObjectIsNil(msg)) {
- return;
- }
- NSString *type = msg[@"type"];
- if (StringIsEmpty(type)) {
- type = msg[@"msg"][@"type"];
- }
- if (StringIsEmpty(type)) {
- return;
- }
- if ([type isEqualToString:USER_KICK]) {
- // 用户踢下线
- // 防止多次出现
- for (CustomActionAlertController *alVC in ApplicationDelegate.tabbarVC.childViewControllers) {
- if ([alVC isKindOfClass:CustomActionAlertController.class]) {
- [alVC dismiss];
- }
- }
- // 退出状态
- [ApplicationDelegate logoutHandleSuccess:^(BOOL success) {
-
- }];
- CustomActionAlertController *alertController = [[CustomActionAlertController alloc] initWithTitle:kLocalizedString(@"下线通知") message:msg[@"kickReason"] sure:kLocalizedString(@"确定") cancel:nil selctedBlock:^(NSInteger index, NSString * _Nonnull title) {
-
- [ApplicationDelegate createQulickLoginPageVC];
- }];
- [alertController show];
- }
- if ([type isEqualToString:VOICE_CHAT_MATCH_WAIT]) {
- // 语音速配等待同意
- XYVoiceMatchMessageModel *model = XYVoiceMatchMessageModel.new;
- [model yy_modelSetWithDictionary:msg];
-
- if ([model.userId isEqualToString:[XYUserInfoManager nowUser].userId]) {
- // 自己发起的速配,等待对方处理就行了,自己不需要处理
- return;
- }
- XYVoiceMatchWaitPopupView *waitView = [XYVoiceMatchWaitPopupView sharedInstance];
- [waitView setupVoiceMatchWaitMessage:model];
- [waitView show];
- [waitView setVoiceMatchWaitrejectBlock:^{
- // 拒绝
- [self voiceMatchWaitDecision:0 hisId:model.hisId round:model.round];
- }];
- [waitView setVoiceMatchWaitAgreeBlock:^{
- // 同意
- [self voiceMatchWaitDecision:1 hisId:model.hisId round:model.round];
- }];
- }
- if ([type isEqualToString:VOICE_CHAT_MATCH_FAIL]) {
- // 语音速配失败
- XYVoiceMatchMessageModel *model = XYVoiceMatchMessageModel.new;
- [model yy_modelSetWithDictionary:msg];
-
- if ([model.targetUserId isEqualToString:[XYUserInfoManager nowUser].userId]) {
- // 自己是接收方,速配失败则取消显示的弹窗
- [[XYVoiceMatchWaitPopupView sharedInstance] dismiss];
- return;
- }
- [[NSNotificationCenter defaultCenter] postNotificationName:VOICE_MATCH_NOTIFICATION object:msg];
- }
- if ([type isEqualToString:VOICE_CHAT_MATCH_SUCCESS]) {
- // 语音速配成功
- XYVoiceMatchMessageModel *model = XYVoiceMatchMessageModel.new;
- [model yy_modelSetWithDictionary:msg];
-
- if ([model.targetUserId isEqualToString:[XYUserInfoManager nowUser].userId]) {
- // 自己是接收方,速配失败则取消显示的弹窗
- [[XYVoiceChatManager sharedInstance] pushVoiceChatWithHisId:model.hisId token:model.targetUserToken channelName:model.channelName block:^{
- }];
- }else {
- // 发起方
- [[NSNotificationCenter defaultCenter] postNotificationName:VOICE_MATCH_NOTIFICATION object:msg];
- }
- }
- if ([type isEqualToString:VOICE_CHAT_REJECT]) {
- // 语音速配拒绝
- XYVoiceMatchMessageModel *model = XYVoiceMatchMessageModel.new;
- [model yy_modelSetWithDictionary:msg];
-
- if ([model.targetUserId isEqualToString:[XYUserInfoManager nowUser].userId]) {
- // 自己是接收方,速配失败则取消显示的弹窗
- [[XYVoiceMatchWaitPopupView sharedInstance] dismiss];
- }else {
- // 发起方
- [[NSNotificationCenter defaultCenter] postNotificationName:VOICE_MATCH_NOTIFICATION object:msg];
- }
- }
- if ([type isEqualToString:VOICE_CHAT_START]) {
- // 语音速配开始
- [[NSNotificationCenter defaultCenter] postNotificationName:VOICE_MATCH_NOTIFICATION object:msg];
- }
- if ([type isEqualToString:VOICE_CHAT_STOP]) {
- // 语音速配结束
- [[NSNotificationCenter defaultCenter] postNotificationName:VOICE_MATCH_NOTIFICATION object:msg];
- }
- if ([type isEqualToString:VOICE_CHAT_CANCEL]) {
- // 语音速配取消
- XYVoiceMatchMessageModel *model = XYVoiceMatchMessageModel.new;
- [model yy_modelSetWithDictionary:msg];
-
- if ([model.targetUserId isEqualToString:[XYUserInfoManager nowUser].userId]) {
- // 自己是接收方,速配失败则取消显示的弹窗
- [[XYVoiceMatchWaitPopupView sharedInstance] dismiss];
- }else {
- // 发起方
- [[NSNotificationCenter defaultCenter] postNotificationName:VOICE_MATCH_NOTIFICATION object:msg];
- }
- }
- if ([type isEqualToString:SYSTEM_MSG]) {
- // 系统消息
- Notification *systemNotification = (Notification *)[DataBase getEntityWithName:@"Notification"];
- [systemNotification yy_modelSetWithDictionary:msg];
- systemNotification.user = [DataBase nowUser];
- systemNotification.messageType = SYSTEM_MSG;
- systemNotification.userId = [XYUserInfoManager nowUser].userId;
- systemNotification.msgId = [NSString stringWithFormat:@"%ld", message.messageId];
-
- systemNotification.title = [BaseMethod toString:msg[@"title"]];
- if ([[ApplicationDelegate getCurrentController] isKindOfClass:[XYSystemMessageViewController class]]) {
- systemNotification.readStatus = 0;
- }else {
- systemNotification.readStatus = 1;
- }
- systemNotification.time = [BaseMethod toString:msg[@"timestamp"]];
- systemNotification.content = [BaseMethod toString:msg[@"body"]];
-
- [DataBase commitDataBase];
- // 更新未读消息数量
- [[XYIMUnReadCountManager sharedInstance] updateMessageUnreadCountWithTabbarBadge:YES];
-
- // 通知会话列表更新消息数量
- [NotificationCenter postNotificationName:RECEIVED_SYSTEM_MESSAGE_NOTIFICATION object:nil];
- }
- // if ([type isEqualToString:FRIEND_ADD_REQUEST]) {
- // // 添加好友请求
- // NSString *sendUserId = [BaseMethod toString:msg[@"userId"]];
- // Notification *friendNotification = [DataBase isFriendNotification:sendUserId types:@[FRIEND_ADD_REQUEST]];
- // if (friendNotification) {
- // // 防止重复申请提示
- // return;
- // }
- // friendNotification = (Notification *)[DataBase getEntityWithName:@"Notification"];
- // friendNotification.user = [DataBase nowUser];
- // friendNotification.messageType = FRIEND_ADD_REQUEST;
- // friendNotification.userId = [BaseMethod toString:msg[@"userId"]];
- // friendNotification.userName = [BaseMethod toString:msg[@"userName"]];
- // friendNotification.msgId = [NSString stringWithFormat:@"%ld", message.messageId];;
- // friendNotification.title = @"添加好友";
- //
- // if ([[ApplicationDelegate getCurrentController] isKindOfClass:[XYFriendApplyListViewController class]]) {
- // friendNotification.readStatus = 0;
- // }else {
- // friendNotification.readStatus = 1;
- // }
- // friendNotification.time = [BaseMethod toString:msg[@"timestamp"]];
- // friendNotification.content = [BaseMethod toString:msg[@"content"]];
- //
- // [DataBase commitDataBase];
- // // 更新未读消息数量
- // [[XYIMUnReadCountManager sharedInstance] updateMessageUnreadCountWithTabbarBadge:YES];
- //
- // // 通知会话列表更新消息数量
- // [NotificationCenter postNotificationName:RECEIVED_FRIEND_MESSAGE_NOTIFITION object:nil];
- // }
- // if ([type isEqualToString:FRIEND_ADD_DENY]) {
- // // 拒绝添加好友
- // NSString *sendUserId = [BaseMethod toString:msg[@"userId"]];
- // Notification *friendNotification = [DataBase isFriendNotification:sendUserId types:@[FRIEND_ADD_DENY]];
- // if (friendNotification) {
- // // 防止重复申请提示
- // return;
- // }
- // friendNotification = (Notification *)[DataBase getEntityWithName:@"Notification"];
- // friendNotification.user = [DataBase nowUser];
- // friendNotification.messageType = FRIEND_ADD_DENY;
- // friendNotification.userId = [BaseMethod toString:msg[@"targetId"]];
- // friendNotification.userName = [BaseMethod toString:msg[@"targetName"]];
- // friendNotification.msgId = [NSString stringWithFormat:@"%ld", message.messageId];;
- // friendNotification.title = @"拒绝添加好友";
- //
- // if ([[ApplicationDelegate getCurrentController] isKindOfClass:[XYFriendApplyListViewController class]]) {
- // friendNotification.readStatus = 0;
- // }else {
- // friendNotification.readStatus = 1;
- // }
- // friendNotification.time = [BaseMethod toString:msg[@"timestamp"]];
- // friendNotification.content = [BaseMethod toString:msg[@"content"]];
- //
- // [DataBase commitDataBase];
- // // 更新未读消息数量
- // [[XYIMUnReadCountManager sharedInstance] updateMessageUnreadCountWithTabbarBadge:YES];
- //
- // // 通知会话列表更新消息数量
- // [NotificationCenter postNotificationName:RECEIVED_FRIEND_MESSAGE_NOTIFITION object:nil];
- // }
- // if ([type isEqualToString:FRIEND_ADD_AGREE]) {
- // // 同意添加好友
- // NSString *sendUserId = [BaseMethod toString:msg[@"userId"]];
- // Notification *friendNotification = [DataBase isFriendNotification:sendUserId types:@[FRIEND_ADD_AGREE]];
- // if (friendNotification) {
- // // 防止重复申请提示
- // return;
- // }
- // friendNotification = (Notification *)[DataBase getEntityWithName:@"Notification"];
- // friendNotification.user = [DataBase nowUser];
- // friendNotification.messageType = FRIEND_ADD_AGREE;
- // friendNotification.userId = [BaseMethod toString:msg[@"targetId"]];
- // friendNotification.userName = [BaseMethod toString:msg[@"targetName"]];
- // friendNotification.msgId = [NSString stringWithFormat:@"%ld", message.messageId];;
- // friendNotification.title = @"同意添加好友";
- //
- // if ([[ApplicationDelegate getCurrentController] isKindOfClass:[XYFriendApplyListViewController class]]) {
- // friendNotification.readStatus = 0;
- // }else {
- // friendNotification.readStatus = 1;
- // }
- // friendNotification.time = [BaseMethod toString:msg[@"timestamp"]];
- // friendNotification.content = [BaseMethod toString:msg[@"content"]];
- //
- // [DataBase commitDataBase];
- // // 更新未读消息数量
- // [[XYIMUnReadCountManager sharedInstance] updateMessageUnreadCountWithTabbarBadge:YES];
- //
- // // 通知会话列表更新消息数量
- // [NotificationCenter postNotificationName:RECEIVED_FRIEND_MESSAGE_NOTIFITION object:nil];
- // }
- // if ([type isEqualToString:USER_FOLLOW]) {
- // // 用户关注
- // NSString *sendUserId = [BaseMethod toString:msg[@"userId"]];
- // NSDictionary *userCardVO = msg[@"userCardVO"];
- // Notification *followNotification = [DataBase isFriendNotification:sendUserId types:@[USER_FOLLOW]];
- // if (followNotification == nil) {
- // followNotification = (Notification *)[DataBase getEntityWithName:@"Notification"];
- // }
- // [followNotification yy_modelSetWithDictionary:msg];
- // followNotification.user = [DataBase nowUser];
- // followNotification.messageType = USER_FOLLOW;
- // followNotification.userId = sendUserId;
- // followNotification.userName = userCardVO[@"userName"];
- // followNotification.userAvatar = userCardVO[@"userAvatar"];
- // followNotification.msgId = [NSString stringWithFormat:@"%ld", message.messageId];;
- //
- // followNotification.title = [BaseMethod toString:msg[@"title"]];
- // if ([[ApplicationDelegate getCurrentController] isKindOfClass:[XYFollowMessageViewController class]]) {
- // followNotification.readStatus = 0;
- // }else {
- // followNotification.readStatus = 1;
- // }
- // followNotification.time = [BaseMethod toString:msg[@"timestamp"]];
- // followNotification.content = [NSString stringWithFormat:@"%@ 关注了你", followNotification.userName];
- //
- // [DataBase commitDataBase];
- // // 更新未读消息数量
- // [[XYIMUnReadCountManager sharedInstance] updateMessageUnreadCountWithTabbarBadge:YES];
- //
- // // 通知会话列表更新消息数量
- // [NotificationCenter postNotificationName:RECEIVED_FOLLOW_MESSAGE_NOTIFITION object:nil];
- // }
- if ([type isEqualToString:USER_SCORE_CHANGE] || [type isEqualToString:RTC_SCORE_LEVEL_UP]) {
- //用户积分改变、用户积分升级
- [NotificationCenter postNotificationName:USER_INTEGRAL_CHANGE_NOTIFICATION object:msg];
- }
- if ([type isEqualToString:RTC_CONVENE_FANS_NOTICE]) {
- //召集粉丝
- /*
- [17:12:24] -[XYIMBaseManager handleSystemMessageWithMessage:message:] [第326行] 💕 custom_elem:{
- "isLock" : 0,
- "roomId" : 260698433126400,
- "seatNo" : 0,
- "userId" : 32609354645515,
- "msg" : "我正在桃桃酱房间,快来和我一起玩耍吧!!!",
- "roomType" : 0,
- "type" : "rtc:convene:fans:notice",
- "timestamp" : 1621416543162
- }
- */
-
- XYChatRoomListModel *roomModel = [[XYChatRoomListModel alloc] init];
- roomModel.roomId = msg[@"roomId"];
- roomModel.roomCover = msg[@"roomCover"];
- roomModel.roomName = msg[@"roomName"];
- [[XYPeiPlayCommendAlertView shareInstance] callFans:roomModel];
-
- }
- if ([type isEqualToString:CHAT_AUDIT_FAILED]) {
- //聊天内容审核失败
- /*
- "msgId" : "BQCN-FI23-AKG5-LKOK",
- "timestamp" : 1625206759877,
- "senderId" : 9294409891907,
- "type" : "chat:audit:failed"
- */
- [[NSNotificationCenter defaultCenter] postNotificationName:RECEIVED_PRVATE_CHAT_MESSAGE_NOTIFITION object:msg];
-
- }
- if ([type isEqualToString:RTC_SKILL_ORDER_CHANGE]) {//订单大厅派单数量
- [[XYIMUnReadCountManager sharedInstance] receiveNewDispatchOrderMessage:msg tabbarBadge:YES];
-
- [[NSNotificationCenter defaultCenter] postNotificationName:IM_RECEIVED_DISPATCH_SKILL_ORDER_MESSAGE_NOTIFICATION object:msg];
- }
- if ([type isEqualToString:RTC_SKILL_ORDER_DETAIL]) {//派单详情
- [[XYChatRoomDispatchManager shareInstance] reloadSkillTopAlert:msg];
-
- }
- #pragma mark - 许愿任务完成个人消息
- if ([type isEqualToString:WISH_TASK_COMPETE]) {
- [XYWishGiftCompleteTipView show:msg];
- // 心愿任务状态变更通知
- [[NSNotificationCenter defaultCenter] postNotificationName:WISH_TASK_SWITCH_NOTIFICATION object:nil];
- }
- #pragma mark - 首页挂件
- if ([type isEqualToString:APP_WIDGET_NOTIFY]) {
- [[XYAnniversaryManager sharedInstance] getAnniversaryConfig];
- }
- #pragma mark - 活动勋章升级消息
- if ([type isEqualToString:RTC_ACTIVITY_MEDAL_LEVEL_UP]) {
- NSString *userId = [BaseMethod toString:msg[@"msg"][@"userId"]];
- if ([[XYUserInfoManager nowUser].userId isEqualToString:userId]) {
- // 如果是自己升级则 需要弹窗提示和更新房间用户信息
- [XYChatRoomActivityMedalUpTipViewController showActivityMedalUpLevelWithActivityInfo:msg parentController:[ApplicationDelegate getCurrentController] completeBlock:^{
- }];
- }
- }
- }
- /// 语音速配-同意或拒绝
- /// @param decision decision 是否同意 1同意 0拒绝
- /// @param hisId 匹配记录id
- - (void)voiceMatchWaitDecision:(NSInteger)decision hisId:(NSString *)hisId round:(NSInteger)round {
- [[XYChatAPIManager new] decideVoiceMatchWithHisId:hisId decision:decision round:round successHandler:^(ZYLResponseModel *responseModel) {
- if (decision == 1) {
- // 同意语音
- // [SVProgressHUD showSuccessWithStatus:@"同意语音"];
- }
- [[XYVoiceMatchWaitPopupView sharedInstance] dismiss];
- } failureHandler:^(ZYLNetworkError *error) {
- [[XYVoiceMatchWaitPopupView sharedInstance] dismiss];
- [SVProgressHUD showInfoWithStatus:error.domain];
- }];
- }
- static XYIMBaseManager *_singleInstance = nil;
- + (instancetype)sharedInstance {
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- if (_singleInstance == nil) {
- _singleInstance = [[self alloc]init];
- }
- });
- return _singleInstance;
- }
- + (instancetype)allocWithZone:(struct _NSZone *)zone {
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- _singleInstance = [super allocWithZone:zone];
- });
- return _singleInstance;
- }
- - (id)copyWithZone:(NSZone *)zone {
- return _singleInstance;
- }
- - (id)mutableCopyWithZone:(NSZone *)zone {
- return _singleInstance;
- }
- - (instancetype)init
- {
- self = [super init];
- if (self) {
- [self _addNotification];
- }
- return self;
- }
- - (void)_addNotification {
- /// 接收头条消息通知(目前全平台消息使用的就是此消息)
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onReceivedHeadlineMessage:) name:IM_RECEIVED_HEADLINE_MESSAGE_NOTIFICATION object:nil];
- }
- @end
|