Forward messages
Function overview
ZIM SDK supports two forms of message forwarding:
- Forwarding merged messages.
- Forwarding messages one by one.
Forwarding Merged Messages
- Only ZIM SDK version 2.14.0 and above supports sending and receiving merged messages.
- If the SDK version of the receiving end is between [2.0.0, 2.14.0), the receiving end can receive merged messages, but the message type will be displayed as unknown and the message content cannot be obtained. To obtain this message, please upgrade the SDK to version 2.14.0 or above.
- If the SDK version of the receiving end is version 1.x.x, it cannot receive merged messages.
Send merged messages
The steps to send merged messages are as follows:
- Construct the merged message body using the ZIMCombineMessage object. The parameters include:
Parameter | Type | Required | Description |
---|---|---|---|
title | NSString * | Yes | The title of the merged message, with a default maximum length of 20 bytes. If you need to configure it, please contact ZEGOCLOUD technical support. |
summary | NSString * | Yes | The summary of the merged message, with a default maximum length of 100 bytes. If you need to configure it, please contact ZEGOCLOUD technical support. |
messageList | ArrayList< ZIMMessage > | Yes | The original message list to be merged and forwarded. It does not support merging and forwarding messages of signaling, barrage, recall, and system types, and does not support merging and forwarding unsuccessful messages. |
ZIM SDK supports including other merged messages in a merged message.
- Call the sendMessage interface to send the merged message. For more information about this operation, see Send & Receive messages - Send messages.
The following is an example code for a user to send a merged message in a one-on-one conversation:
// Send a merged message in a one-on-one chat session
ZIMConversationType type = ZIMConversationTypePeer; // Conversation type, values: one-on-one: 0, room: 1, group: 2
ZIMMessageSendConfig *config = [[ZIMMessageSendConfig alloc] init];
// The original message list to be merged and forwarded, can be obtained from the message history
NSMutableArray<ZIMMessage *> *messageList = [NSMutableArray array];
[messageList addObject:message1];
[messageList addObject:message2];
ZIMCombineMessage *combineMessage = [[ZIMCombineMessage alloc] initWithTitle:@"Title" summary:@"Summary" messages:messageList];
[zim sendMessage:combineMessage conversationId:@"conv_id" type:type config:config callback:^(ZIMMessage *zimMessage, ZIMError *error) {
if (error) {
// Developers can use this callback to listen for whether the message was sent successfully.
}
}];
Receive merged messages
The callback interface for receiving merged messages is the same as the callback interface for receiving normal messages. Please refer to Send & Receive messages - Receive messages for the specific interface.
The receive message callback only returns the title, summary, and merge ID of the merged message. If you need to know the content of the merged message, please refer to View Merged Message Details.
The following is an example code for a user to receive merged messages in a one-on-one conversation:
// Send a merged message in a one-on-one chat session
ZIMConversationType type = ZIMConversationTypePeer; // Conversation type, values: one-on-one: 0, room: 1, group: 2
ZIMMessageSendConfig *config = [[ZIMMessageSendConfig alloc] init];
// The original message list to be merged and forwarded, can be obtained from the message history
NSMutableArray<ZIMMessage *> *messageList = [NSMutableArray array];
[messageList addObject:message1];
[messageList addObject:message2];
ZIMCombineMessage *combineMessage = [[ZIMCombineMessage alloc] initWithTitle:@"Title" summary:@"Summary" messages:messageList];
[zim sendMessage:combineMessage conversationId:@"conv_id" type:type config:config callback:^(ZIMMessage *zimMessage, ZIMError *error) {
if (error) {
// Developers can use this callback to listen for whether the message was sent successfully.
}
}];
View merged message details
Operations on a combined message, for example, listening, adding, and historical message pulling, return only the title, summary, and ID of the combined message. To view sub-messages contained in the combined message, call the queryCombineMessageDetail operation.
The result is returned in the ZIMCombineMessageDetailQueriedCallback callback.
- (void)queryCombineMessageDetailByMessage:(ZIMCombineMessage *)message
callback:(ZIMCombineMessageDetailQueriedCallback)callback
Parameter | Type | Required | Description |
---|---|---|---|
message | ZIMCombineMessage | Yes | Merged message. |
[zim queryCombineMessageDetailByMessage:combineMessage callback:^(ZIMCombineMessage * _Nonnull message, ZIMError * _Nonnull errorInfo) {
// View the merged message, the specific sub-messages are in the messageList of the message in the callback.
}];
If one of the sub-messages is a combined message, you need to call the queryCombineMessageDetail operation to obtain the sub-messages of the combined message. If there are multiple nested combined messages, you need to call this operation multiple times accordingly.
Forward messages one by one
Forwarding messages one by one is essentially sending messages that have been successfully sent as parameters to other conversations. It uses the same interface as sending normal messages. Developers can refer to Send & Receive messages - Send messages for details of this interface.