IM 即时通讯
圈组消息扩展
更新时间: 2022/12/09 19:41:23
本文已废弃,请前往会话消息回复(Thread)和圈组快捷评论查看更新的文档。
功能概述
圈组消息扩展提供消息相关扩展功能(v9.1.0),包括 会话消息回复、消息快捷评论 等。所有功能包含在 NIMQChatMessageExtendManager 协议中。
圈组的会话消息回复和消息快捷评论均属于增值功能,需先在云信控制台开通后才能使用。
会话消息回复
消息回复可以对目标消息进行回复,形成父、子消息的逻辑结构,一条消息可以有0或者一条父消息;父消息可以有0或者n条子消息;消息的父消息通过threadRefer获取,该消息回复的消息通过replyRefer等获取;
消息回复
消息回复有两个接口,分为同步和异步,但返回的调用结果都是示当前这个函数调用完成,需要后续的回调才能判断消息是否已经发送至服务器
- 接口原型
/**
* 回复消息
*
* @param message 新生成的消息
* @param target 被回复的消息
* @param error 错误 如果在准备发送消息阶段发生错误,这个error会被填充相应的信息
*
* @return 是否调用成功,这里返回的 result 只是表示当前这个函数调用是否成功,需要后续的回调才能够判断消息是否已经发送至服务器
*/
- (BOOL)reply:(NIMQChatMessage *)message
to:(NIMQChatMessage *)target
error:(NSError * __nullable *)error;
/**
* 异步回复消息
*
* @param message 新生成的消息
* @param target 被回复的消息
* @param completion 发送完成后的回调,这里的回调完成只表示当前这个函数调用完成,需要后续的回调才能判断消息是否已经发送至服务器
*/
- (void)reply:(NIMQChatMessage *)message
to:(NIMQChatMessage *)target
completion:(__nullable NIMQChatHandler)completion;
- 示例代码
id<NIMQChatMessageManager> qchatMessageManager = [[NIMSDK sharedSDK] qchatMessageManager];
NIMQChatMessage *replyMessage = [[NIMQChatMessage alloc] init];
replyMessage.text = @"回复文本消息的内容";
//targetMsg--- 被回复的消息是由服务端返回或者缓存中取到的消息
//同步方法
NSError *error = nil;
BOOL result = [qchatMessageManager reply:replyMessage
to:targetMsg
error:&error];
//异步方法
[qchatMessageManager reply:replyMessage to:targetMsg completion: ^(NSError *error){
//your code
}];
从服务端查询引用的消息
查询引用消息可查询几种引用类型,包括回复的,thread根消息,以及两者都包含的。
/**
* 消息引用类型
*/
typedef NS_ENUM(NSInteger, NIMQChatMessageReferType) {
/**
* 回复的
* @discussion
*/
NIMQChatMessageReferTypeReply = 1,
/**
* Thread (根消息)
* @discussion
*/
NIMQChatMessageReferTypeThread = 2,
/**
* 所有 (回复的+根消息)
* @discussion
*/
NIMQChatMessageReferTypeAll = 3,
};
- 接口原型
/**
* 从服务端查询引用的消息
*
* @param message 消息
* @param type 引用类型
* @param completion 结果回调
*/
- (void)getReferMessages:(NIMQChatMessage *)message
type:(NIMQChatMessageReferType)type
completion:(nullable NIMQChatGetMessageHistoryHandler)completion;
- 示例代码
//此处消息来源可以是服务端查询到的,或者收到的,或者缓存的等
NIMQChatMessage *message = ***;
[[NIMSDK sharedSDK].qchatMessageManager getReferMessages: message type: NIMQChatMessageReferTypeReply completion:^(NSError * error, NIMQChatGetMessageHistoryResult * result){
// your code
}];
从服务端查询Thread的所有消息
此接口可以查询一条链路上的所有消息,比如D回复了C,C回复了B,B回复了A,那么可以查询到A,B,C,D四条消息。当然参数中有其他选项让你选择性的获取,包括时间节点和要排除的消息id等。
- 接口原型
/**
* 从服务端查询Thread的所有消息
*
* @param param 传入参数
* @param completion 结果回调
*/
- (void)getThreadMessages:(NIMQChatGetThreadMessagesParam *)param
completion:(nullable NIMQChatGetThreadMessagesHandler)completion;
- 示例代码
NIMQChatGetThreadMessagesParam *param = [NIMQChatGetThreadMessagesParam new];
param.message = msg; //某条用来定位查询的源消息
param.fromTime = 0;
param.toTime = @(0);
param.limit = 5;
[[NIMSDK sharedSDK].qchatMessageManager getThreadMessages:param completion:^(NSError * error, NIMQChatGetThreadMessagesResult * result){
// your code
}];
批量查询消息的meta信息
此接口为批量接口,通过消息查询此消息的被回复数和最后一条回复消息的时间戳。如果此消息为非thread根消息,将不会返回任何信息。故此接口的回调结果是个字典结构,每条消息id对应相应的询到的信息。
- 接口原型
/**
* 批量从服务端查询消息Thread的meta信息
*
* @param param 传入参数,消息数组
* @param completion 结果回调
*/
- (void)batchGetMessageThreadInfo:(NSArray <NIMQChatMessage *> *)param
completion:(nullable NIMQChatBatchGetMessageThreadInfoHandler)completion;
- 示例代码
NSArray *msgArr = @[msg1, msg2];
[[NIMSDK sharedSDK].qchatMessageManager batchGetMessageThreadInfo:msgArr completion:^(NSError * error, NSDictionary <NSString *, NIMQChatMessageThreadInfo *> * result){
// your code
}];
消息快捷评论
消息快评功能和IM中的快捷评论是类似的, 都是通过一个int值来指示消息内容,开发者可通过这个值自由扩展。
添加快捷评论
给一条消息添加快捷评论,只需要传入需要评论的消息和评论的type值就行。每个用户对一条消息的一种评论只能添加一次,比如对A消息发了评论1,那再次发1将被覆盖不会累加。
- 接口原型
/**
* 发送快捷评论
*
* @param type 评论类型
* @param message 被评论消息
* @param completion 完成回调
*/
- (void)addQuickCommentType:(int64_t)type
toMessage:(NIMQChatMessage *)message
completion:(NIMQChatHandler _Nullable)completion;
- 示例代码
//服务端获得或本地缓存的消息
NIMQChatMessage *msg = ***;
[[NIMSDK sharedSDK].qchatMessageManager addQuickCommentType:6 toMessage:msg completion:^(NSError * error){
// your code
}];
删除快捷评论
- 接口原型
/**
* 从服务端删除一条评论
*
* @param type 评论类型
* @param message 被评论消息
* @param completion 完成回调
*/
- (void)deleteQuickCommentType:(int64_t)type
toMessage:(NIMQChatMessage *)message
completion:(NIMQChatHandler _Nullable)completion;
- 示例代码
//服务端获得或本地缓存的消息
NIMQChatMessage *msg = ***;
[[NIMSDK sharedSDK].qchatMessageManager deleteQuickCommentType:6 toMessage:msg completion:^(NSError * error){
// your code
}];
批量获取快捷评论
- 接口原型
/**
* 批量获取快捷评论
*
* @param param 参数,(目标消息的serverId, 一次最多10条)
* @param completion 完成回调
*/
- (void)fetchQuickComments:(NIMQChatFetchQuickCommentsByMsgIdsParam *)param
completion:(NIMQChatFetchQuickCommentsByMsgIdsHandler)completion;
- 示例代码
//服务端获得或本地缓存的消息
NSArray *msgArr = @[msg1, msg2];
[[NIMSDK sharedSDK].qchatMessageManager fetchQuickComments:msgArr completion:^(NSError * error, NIMQChatFetchQuickCommentsByMsgIdsResult * result){
// your code
}];
此文档是否对你有帮助?
有帮助
我要吐槽