- Android
- iOS
- JavaScript
- Flutter
- ReactNative
Create a MergeMessage, then send it using the sendMessage API.
MergeMessage Structure
| Name | Type | Description | Version |
|---|---|---|---|
| title | String | Title of the merged message | 1.0.0 |
| conversation | Conversation | Conversation identifier. All merged messages must come from the same conversation. | 1.0.0 |
| messageIdList | List | List of merged message IDs. It cannot exceed 100 items. | 1.0.0 |
| previewList | List | List of merged messages previewed in the message bubble. It cannot exceed 10 items. | 1.0.0 |
Code Example
// conversation containing the messages to merge
Conversation srcConversation = new Conversation(Conversation.ConversationType.PRIVATE, "userid1");
List<String> messageIdList = new ArrayList<>();
messageIdList.add("messageId1");
messageIdList.add("messageId2");
messageIdList.add("messageId3");
List<MergeMessagePreviewUnit> previewList = new ArrayList<>();
for (int i = 0; i < 3; i++) {
MergeMessagePreviewUnit unit = new MergeMessagePreviewUnit();
unit.setPreviewContent("previewContent" + i);
UserInfo userInfo = new UserInfo();
userInfo.setUserId("userId" + i);
userInfo.setUserName("userName" + i);
unit.setSender(userInfo);
previewList.add(unit);
}
MergeMessage merge = new MergeMessage("title", srcConversation, messageIdList, previewList);
// target conversation to forward to
Conversation dstConversation = new Conversation(Conversation.ConversationType.GROUP, "groupid1");
Message m = JIM.getInstance().getMessageManager().sendMessage(merge, dstConversation, new IMessageManager.ISendMessageCallback() {
@Override
public void onSuccess(Message message) {
}
@Override
public void onError(Message message, int errorCode) {
}
});
Get Merged Message List
/**
* get the list of merged messages
* @param containerMsgId merged-message ID
* @param callback result callback
*/
void getMergedMessageList(String containerMsgId,
IGetMessagesCallback callback);
Create a JMergeMessage, then send it using the sendMessage API.
JMergeMessage Structure
| Name | Type | Description | Version |
|---|---|---|---|
| title | NSString | Title of the merged message | 1.0.0 |
| conversation | JConversation | Conversation identifier. All merged messages must come from the same conversation. | 1.0.0 |
| messageIdList | NSArray <NSString *> | List of merged message IDs. It cannot exceed 100 items. | 1.0.0 |
| previewList | NSArray <JMergeMessagePreviewUnit *> | List of merged messages previewed in the message bubble. It cannot exceed 10 items. | 1.0.0 |
Code Example
NSArray *messageIdList = @[@"messageId1", @"messageId2", @"messageId3", @"messageId4"];
NSMutableArray *previewList = [NSMutableArray array];
for (int i = 0; i < 4; i++) {
JMergeMessagePreviewUnit *unit = [[JMergeMessagePreviewUnit alloc] init];
unit.previewContent = [NSString stringWithFormat:@"previewContent%d", i];
JUserInfo *userInfo = [[JUserInfo alloc] init];
userInfo.userId = [NSString stringWithFormat:@"userId%d", i];
userInfo.userName = [NSString stringWithFormat:@"name%d", i];
userInfo.portrait = @"portait";
unit.sender = userInfo;
[previewList addObject:unit];
}
// conversation containing the messages to merge
JConversation *srcConversation = [[JConversation alloc] initWithConversationType:JConversationTypePrivate conversationId:@"userid1"];
JMergeMessage *merge = [[JMergeMessage alloc] initWithTitle:@"title"
conversation:srcConversation
MessageIdList:messageIdList
previewList:previewList];
// target conversation to forward to
JConversation *dstConversation = [[JConversation alloc] initWithConversationType:JConversationTypeGroup conversationId:@"groupid1"];
[JIM.shared.messageManager sendMessage:merge
inConversation:dstConversation
success:^(JMessage *message) {
} error:^(JErrorCode errorCode, JMessage *message) {
}];
Get Merged Message List
/// get the list of merged messages
/// - Parameters:
/// - messageId: merged-message ID
/// - successBlock: success callback
/// - errorBlock: failure callback
- (void)getMergedMessageList:(NSString *)messageId
success:(void (^)(NSArray<JMessage *> *mergedMessages))successBlock
error:(void (^)(JErrorCode code))errorBlock;
messages Parameters
| Name | Type | Required | Default | Description | Version |
|---|---|---|---|---|---|
| message | Object | Yes | Message object | 1.0.0 | |
| message.conversationType | Number | Yes | Conversation type | 1.0.0 | |
| message.conversationId | String | Yes | Conversation ID. For PRIVATE conversations, it is the recipient userId; for GROUP conversations, it is the group ID. | 1.0.0 | |
| message.messages | Array | Yes | List of messages to merge and forward. See the example below for the format. | 1.0.0 | |
| message.previewList | Array | Yes | Custom message-content summary. The array format only needs to be agreed upon across clients. | 1.0.0 | |
| message.title | String | Yes | Title of the forwarded message | 1.0.0 | |
| lifeTime | Number | No | 0 | Message destruction duration. It must be greater than 0, in ms; for example, 60 seconds is 1 * 60 * 1000. | 1.9.0 |
| lifeTimeAfterRead | Number | No | 0 | Read-once message duration. It must be greater than 0, in ms; for example, 60 seconds is 1 * 60 * 1000. | 1.9.0 |
callbacks Parameters
| Name | Type | Required | Default | Description | Version |
|---|---|---|---|---|---|
| callbacks | Object | No | Callback object | 1.0.0 | |
| callbacks.onbefore | Function | No | Pre-send callback. When invoked, it returns the temporary message identifier tid, which can be used to render the message. After a successful send, the backend updates the message state by tid. | 1.0.0 |
Success Callback
| Name | Type | Description | Version |
|---|---|---|---|
| message | Object | After sending succeeds, returns a message object with messageId and sentTime. See Message for the message structure. | 1.0.0 |
Failure Callback
| Name | Type | Description | Version |
|---|---|---|---|
| result | Object | When sending fails, returns an object containing tid and error. Check error.msg directly or see [status codes].(../../../status_code/web) | 1.0.0 |
Code Example
let { ConversationType } = jetim;
let params = {
conversationType: ConversationType.PRIVATE,
conversationId: 'userid02',
// message is a message object retrieved from message history or received by a message listener
messageIdList: [message],
previewList: [
{ content: 'Hello Chat', sender: { name: 'Xiaoke', other: 'custom extension shared across platforms' } }
],
title: 'Chat history between Xiao J and Xiao G'
};
let callbacks = {
onbefore: (message) => {
// render on the page and use message.tid as the unique identifier
}
};
jetim.sendMergeMessage(params, callbacks).then((msg) => {
console.log('send merge message successfully', msg);
}, (result) => {
let { error, tid } = result;
// Use tid to update the failed-message state. On Web, failed messages are stored only in SDK memory and are unavailable after a refresh
console.log(tid, error);
});
Create a MergeMessage, then send it using the sendMergeMessage API.
MergeMessage Structure
| Name | Type | Description | Version |
|---|---|---|---|
| title | String | Title of the merged message | 1.0.0 |
| conversation | Conversation | Conversation identifier. All merged messages must come from the same conversation. | 1.0.0 |
| messageIdList | string[] | List of merged message IDs. It cannot exceed 100 items. | 1.0.0 |
| previewList | string[] | List of merged messages previewed in the message bubble. It cannot exceed 10 items. | 1.0.0 |
Code Example
import JuggleIM from 'juggleim-rnsdk';
// conversation containing the messages to merge
const srcConversation = {
type: 1,
id: 'userId1'
};
const messageIdList = ['messageId1', 'messageId2', 'messageId3'];
const previewList = [
{
previewContent: 'previewContent0',
sender: {
userId: 'userId0',
userName: 'userName0'
}
},
{
previewContent: 'previewContent1',
sender: {
userId: 'userId1',
userName: 'userName1'
}
}
];
const mergeMessage = {
title: 'title',
conversation: srcConversation,
messageIdList: messageIdList,
previewList: previewList
};
// target conversation to forward to
const dstConversation = {
type: 2,
id: 'groupId1'
};
const callback = (message: any, errorCode: number) => {
if (errorCode === 0) {
console.log('sendMergeMessage success, messageId is ' + message.messageId);
} else {
console.log('sendMergeMessage error, errorCode is ' + errorCode.toString());
}
};
JuggleIM.sendMergeMessage(mergeMessage, dstConversation, callback).then((message) => {
console.log('after send, clientMsgNo is ' + message.clientMsgNo);
});
Get Merged Message List
const mergedMessages = await JuggleIM.getMergedMessageList('messageId');
MergeMessage Structure
| Name | Type | Description | Version |
|---|---|---|---|
| title | String | Title of the merged message | 0.6.3 |
| conversation | Conversation | Conversation identifier. All merged messages must come from the same conversation. | 0.6.3 |
| messageIdList | List | List of merged message IDs. It cannot exceed 100 items. | 0.6.3 |
| previewList | List | List of merged messages previewed in the message bubble. It cannot exceed 10 items. | 0.6.3 |
Code Example
// conversation whose messages will be merged (source conversation)
Conversation srcConversation = Conversation(ConversationType.group, 'groupId1');
// messages is the list selected in the source conversation
List<Message> messages = [];
List<MergeMessagePreviewUnit> previewList = [];
List<String> messageIdList = [];
String title = 'Chat history for xxx';
for (Message message in messages) {
messageIdList.add(message.messageId);
// Assume all messages are text. Image messages are typically represented as [Image]
previewList.add(MergeMessagePreviewUnit(message.content.content, message.sender));
}
MergeMessage mergeMessage = MergeMessage.create(title, srcConversation, messageIdList, previewList);
// target conversation to forward to
Conversation dstConversation = Conversation(ConversationType.private, 'userId1');
DataCallback<Message> callback = (m, errorCode) {
if (errorCode == 0) {
print("sendMessage success, messageId is " + m.messageId);
} else {
print('sendMessage error, errorCode is ' + errorCode.toString() + ', clientMsgNo is ' + m.clientMsgNo!.toString());
}
};
Message message = await JuggleIm.instance.sendMessage(mergeMessage, dstConversation, callback);
Get Merged Message List
Result<List<Message>> result = await JuggleIm.instance.getMergedMessageList('messageId');