Set message extension field
Introduction
ZEGOCLOUD Instant Messaging (ZIM) SDK allows you to add an extension field to a message and send the extension field as additional message information. Message extension fields can be visible to the peer end or visible only to the local end based on the synchronization effects. A message extension field is used to present information such as the translation status and translation content of a message, and the business logic included in the message.
Implementation Steps
- Create a ZIM instance.
- Log in to the ZIM SDK.
- Construct the ZIMMessage object, and fill in the ZIMMessage field in the extendedData object as the message extension field.
- Call the sendMessage interface, pass in the ZIMMessage object, send the message and expand the fields.
Sample code
String toConversationID = "xxxx1";
ZIMTextMessage zimMessage = new ZIMTextMessage();
zimMessage.message = "Message content";
// The extended fields that need to be sent
zimMessage.extendedData = "Message Extension Field";
ZIMMessageSendConfig config = new ZIMMessageSendConfig();
// Set message priority
config.priority = ZIMMessagePriority.LOW;
// Set the conversation type to send
// Send one-on-one chat information
ZIMConversationType type = ZIMConversationType.Peer;
// Send a message
zim.sendMessage(zimMessage, toConversationID, type, config, new ZIMMessageSentCallback() {
@Override
public void onMessageAttached(ZIMMessage zimMessage) {
}
@Override
public void onMessageSent(ZIMMessage zimMessage, ZIMError error) {
// Developers can use this callback to monitor whether the message is sent successfully.
}
});
String toConversationID = "xxxx1";
ZIMTextMessage zimMessage = new ZIMTextMessage();
zimMessage.message = "Message content";
// The extended fields that need to be sent
zimMessage.extendedData = "Message Extension Field";
ZIMMessageSendConfig config = new ZIMMessageSendConfig();
// Set message priority
config.priority = ZIMMessagePriority.LOW;
// Set the conversation type to send
// Send one-on-one chat information
ZIMConversationType type = ZIMConversationType.Peer;
// Send a message
zim.sendMessage(zimMessage, toConversationID, type, config, new ZIMMessageSentCallback() {
@Override
public void onMessageAttached(ZIMMessage zimMessage) {
}
@Override
public void onMessageSent(ZIMMessage zimMessage, ZIMError error) {
// Developers can use this callback to monitor whether the message is sent successfully.
}
});
Sample code
// Send a message
ZIMTextMessage textMessage = ZIMTextMessage(message: "message");
textMessage.extendedData = @"Extended data to be sent"; // Extended data to be sent
ZIMMessageSendConfig sendConfig = ZIMMessageSendConfig();
// Set message priority
sendConfig.priority = ZIMMessagePriority.low;
ZIMMessageSendNotification notification = ZIMMessageSendNotification(onMessageAttached: (message) {
// Callback before sending, developers can get a temporary object here, which is the same object as the zimMessage created by the developer. Developers can use this feature to do some business logic, such as displaying UI in advance, etc.
});
// Set the conversation type and send the message to the corresponding conversation type
ZIMConversationType type = ZIMConversationType.peer;
ZIM.getInstance()!.sendMessage(textMessage, toConversationID, type, sendConfig).then((value) => {
// Developers can use this callback to listen for whether the message was sent successfully.
}).catchError((onError) {
// Developers can catch the exception if the message fails to send.
});
// Send a message
ZIMTextMessage textMessage = ZIMTextMessage(message: "message");
textMessage.extendedData = @"Extended data to be sent"; // Extended data to be sent
ZIMMessageSendConfig sendConfig = ZIMMessageSendConfig();
// Set message priority
sendConfig.priority = ZIMMessagePriority.low;
ZIMMessageSendNotification notification = ZIMMessageSendNotification(onMessageAttached: (message) {
// Callback before sending, developers can get a temporary object here, which is the same object as the zimMessage created by the developer. Developers can use this feature to do some business logic, such as displaying UI in advance, etc.
});
// Set the conversation type and send the message to the corresponding conversation type
ZIMConversationType type = ZIMConversationType.peer;
ZIM.getInstance()!.sendMessage(textMessage, toConversationID, type, sendConfig).then((value) => {
// Developers can use this callback to listen for whether the message was sent successfully.
}).catchError((onError) {
// Developers can catch the exception if the message fails to send.
});
title ="Sample code"
NSString *toConversationID = @"xxxx1";
ZIMTextMessage *textMessage = [[ZIMTextMessage alloc] init];
textMessage.message = @"Message content";
textMessage.extendedData = @"Extended field"; // The extended field that needs to be sent
ZIMMessageSendConfig *config = [[ZIMMessageSendConfig alloc] init];
ZIMMessageSendNotification *notification = [[ZIMMessageSendNotification alloc] init];
notification.onMessageAttached = ^(ZIMMessage * _Nonnull message) {
// The callback before sending, where the client can obtain a temporary object, which belongs to the same object as the zimMessage object created by the developer. The developer can use this feature to do some business logic, such as displaying the UI in advance, etc.
};
// Set the conversation type and select it to send messages to the corresponding conversation type
ZIMConvesationType type = ZIMConversationTypePeer;
// Send a message
[self.zim sendMessage:textMessage toConversationID:toConversationID conversationType:type config:config notification:notification callback:^((ZIMMessage * _Nonnull message, ZIMError * _Nonnull errorInfo)) {
// Developers can use this callback to monitor whether the message is sent successfully.
}];
NSString *toConversationID = @"xxxx1";
ZIMTextMessage *textMessage = [[ZIMTextMessage alloc] init];
textMessage.message = @"Message content";
textMessage.extendedData = @"Extended field"; // The extended field that needs to be sent
ZIMMessageSendConfig *config = [[ZIMMessageSendConfig alloc] init];
ZIMMessageSendNotification *notification = [[ZIMMessageSendNotification alloc] init];
notification.onMessageAttached = ^(ZIMMessage * _Nonnull message) {
// The callback before sending, where the client can obtain a temporary object, which belongs to the same object as the zimMessage object created by the developer. The developer can use this feature to do some business logic, such as displaying the UI in advance, etc.
};
// Set the conversation type and select it to send messages to the corresponding conversation type
ZIMConvesationType type = ZIMConversationTypePeer;
// Send a message
[self.zim sendMessage:textMessage toConversationID:toConversationID conversationType:type config:config notification:notification callback:^((ZIMMessage * _Nonnull message, ZIMError * _Nonnull errorInfo)) {
// Developers can use this callback to monitor whether the message is sent successfully.
}];
Sample code
zim::ZIMMessage* message = nullptr;
zim::ZIMTextMessage text_message;
text_message.message = "message";
// The extended fields that need to be sent
text_message.extendedData = "extendedData";
// Set message priority
zim::ZIMMessageSendConfig config;
config.priority = zim::ZIM_MESSAGE_PRIORITY_LOW;
message = &text_message;
// Set the conversation type
zim::ZIMConversationType type = zim::ZIMConversationType::ZIM_CONVERSATION_TYPE_PEER
auto notification = std::make_shared<zim::ZIMMessageSendNotification>(
[=](const std::shared_ptr<zim::ZIMMessage> &message) { int i = 0; });
zim_->sendMessage(message, "toConversationID", type, config, notification,
[=](const std::shared_ptr<zim::ZIMMessage> &message,
const zim::ZIMError &errorInfo) { int i = 0; });
zim::ZIMMessage* message = nullptr;
zim::ZIMTextMessage text_message;
text_message.message = "message";
// The extended fields that need to be sent
text_message.extendedData = "extendedData";
// Set message priority
zim::ZIMMessageSendConfig config;
config.priority = zim::ZIM_MESSAGE_PRIORITY_LOW;
message = &text_message;
// Set the conversation type
zim::ZIMConversationType type = zim::ZIMConversationType::ZIM_CONVERSATION_TYPE_PEER
auto notification = std::make_shared<zim::ZIMMessageSendNotification>(
[=](const std::shared_ptr<zim::ZIMMessage> &message) { int i = 0; });
zim_->sendMessage(message, "toConversationID", type, config, notification,
[=](const std::shared_ptr<zim::ZIMMessage> &message,
const zim::ZIMError &errorInfo) { int i = 0; });
Sample code
// Configure message extension fields
string toConversationID = "xxxx1";
ZIMTextMessage zimMessage = new ZIMTextMessage();
zimMessage.message = "Message content";
// Extension fields to be sent
zimMessage.extendedData = "Message extension fields";
ZIMMessageSendConfig config = new ZIMMessageSendConfig();
// Set message priority
config.priority = ZIMMessagePriority.Low;
// Set the conversation type for sending
ZIMConversationType type = ZIMConversationType.Peer;
// Send a message
ZIMMessageSendNotification notification = new ZIMMessageSendNotification();
ZIM.GetInstance().SendMessage(zimMessage, toConversationID, type, config, notification,
(ZIMMessage message, ZIMError errorInfo) =>
{
// Callback result of message sending
});
// Configure message extension fields
string toConversationID = "xxxx1";
ZIMTextMessage zimMessage = new ZIMTextMessage();
zimMessage.message = "Message content";
// Extension fields to be sent
zimMessage.extendedData = "Message extension fields";
ZIMMessageSendConfig config = new ZIMMessageSendConfig();
// Set message priority
config.priority = ZIMMessagePriority.Low;
// Set the conversation type for sending
ZIMConversationType type = ZIMConversationType.Peer;
// Send a message
ZIMMessageSendNotification notification = new ZIMMessageSendNotification();
ZIM.GetInstance().SendMessage(zimMessage, toConversationID, type, config, notification,
(ZIMMessage message, ZIMError errorInfo) =>
{
// Callback result of message sending
});
Sample code
// Send single chat `Text` message
const toConversationID = ''; // Other party userID
const conversationType = 0; // conversation type, the value is single chat: 0, room: 1, group: 2
const config: ZIMMessageSendConfig = {
priority: 1, // Set the message priority, the value is low: 1 default, medium: 2, high: 3
};
const messageTextObj: ZIMMessage = { type: 1, message: 'Text message content', extendedData: 'Extended information of the message (optional)' };
const notification: ZIMMessageSendNotification = {
onMessageAttached: function(message) {
// todo: Loading
}
}
zim.sendMessage(messageTextObj, toConversationID, conversationType, config, notification)
.then(function ({ message }) {
// Sent successfully
})
.catch(function (err) {
// Failed to send
});
// Send single chat `Text` message
const toConversationID = ''; // Other party userID
const conversationType = 0; // conversation type, the value is single chat: 0, room: 1, group: 2
const config: ZIMMessageSendConfig = {
priority: 1, // Set the message priority, the value is low: 1 default, medium: 2, high: 3
};
const messageTextObj: ZIMMessage = { type: 1, message: 'Text message content', extendedData: 'Extended information of the message (optional)' };
const notification: ZIMMessageSendNotification = {
onMessageAttached: function(message) {
// todo: Loading
}
}
zim.sendMessage(messageTextObj, toConversationID, conversationType, config, notification)
.then(function ({ message }) {
// Sent successfully
})
.catch(function (err) {
// Failed to send
});
Configure an extension field visible only to the local end
Procedure for sending a message:
- Log in to ZIM SDK, construct a ZIMMessagefield as an extension field visible only to the local end in the ZIMMessage object.
- Call the sendMessage operation and pass in the ZIMMessage object to send the message and the extension field.
Sample code
// 1. Configure the local extension field of a message.
// Specify the conversation ID.
String toConversationID = "xxx1";
// Construct a ZIMMessage object.
ZIMTextMessage zimMessage = new ZIMTextMessage();
zimMessage.message = "Message content";
// Configure the local extension field of a message.
zimTextMessage.localExtendedData = "Local extension field of the message";
ZIMMessageSendConfig config = ZIMMessageSendConfig();
// Configure the priority of the message.
config.priority = ZIMMessagePriority.low;
// Send a private-chat message.
ZIMConversationType type = ZIMConversationType.peer;
// Send a group-chat message.
ZIMConversationType type = ZIMConversationType.group;
// Send a room message.
ZIMConversationType type = ZIMConversationType.room;
// 2. Send the message.
zim.sendMessage(zimMessage, toConversationID, type, config, new ZIMMessageSentCallback() {
@Override
public void onMessageAttached(ZIMMessage zimMessage) {
}
@Override
public void onMessageSent(ZIMMessage zimMessage, ZIMError error) {
// Developers can use this callback to monitor whether the message is sent successfully.
}
});
// 1. Configure the local extension field of a message.
// Specify the conversation ID.
String toConversationID = "xxx1";
// Construct a ZIMMessage object.
ZIMTextMessage zimMessage = new ZIMTextMessage();
zimMessage.message = "Message content";
// Configure the local extension field of a message.
zimTextMessage.localExtendedData = "Local extension field of the message";
ZIMMessageSendConfig config = ZIMMessageSendConfig();
// Configure the priority of the message.
config.priority = ZIMMessagePriority.low;
// Send a private-chat message.
ZIMConversationType type = ZIMConversationType.peer;
// Send a group-chat message.
ZIMConversationType type = ZIMConversationType.group;
// Send a room message.
ZIMConversationType type = ZIMConversationType.room;
// 2. Send the message.
zim.sendMessage(zimMessage, toConversationID, type, config, new ZIMMessageSentCallback() {
@Override
public void onMessageAttached(ZIMMessage zimMessage) {
}
@Override
public void onMessageSent(ZIMMessage zimMessage, ZIMError error) {
// Developers can use this callback to monitor whether the message is sent successfully.
}
});
Sample code
// 1. Configure the local extension field of a message.
// Specify the conversation ID.
String toConversationID = "xxx1";
// Construct a ZIMMessage object.
ZIMTextMessage zimTextMessage = ZIMTextMessage(message: 'message');
// Configure the local extension field of a message.
zimTextMessage.localExtendedData = "Local extension field of the message";
ZIMMessageSendConfig config = ZIMMessageSendConfig();
// Configure the priority of the message.
config.priority = ZIMMessagePriority.low;
// Send a private-chat message.
ZIMConversationType type = ZIMConversationType.peer;
// Send a group-chat message.
ZIMConversationType type = ZIMConversationType.group;
// Send a room message.
ZIMConversationType type = ZIMConversationType.room;
// 2. Send the message.
ZIM.getInstance()!.sendMessage(zimTextMessage, 'toConversationID', type, config).then((value) {
}).catchError((onError){
});
// 1. Configure the local extension field of a message.
// Specify the conversation ID.
String toConversationID = "xxx1";
// Construct a ZIMMessage object.
ZIMTextMessage zimTextMessage = ZIMTextMessage(message: 'message');
// Configure the local extension field of a message.
zimTextMessage.localExtendedData = "Local extension field of the message";
ZIMMessageSendConfig config = ZIMMessageSendConfig();
// Configure the priority of the message.
config.priority = ZIMMessagePriority.low;
// Send a private-chat message.
ZIMConversationType type = ZIMConversationType.peer;
// Send a group-chat message.
ZIMConversationType type = ZIMConversationType.group;
// Send a room message.
ZIMConversationType type = ZIMConversationType.room;
// 2. Send the message.
ZIM.getInstance()!.sendMessage(zimTextMessage, 'toConversationID', type, config).then((value) {
}).catchError((onError){
});
Sample code
// 1. Configure the local extension field of a message.
// Specify the conversation ID.
NSString *toConversationID = @"xxx1";
// Construct a ZIMMessage object.
ZIMTextMessage *zimTextMessage = [[ZIMTextMessage alloc] initWithMessage:@"Message content"];
// Configure the local extension field of a message.zimTextMessage.localExtendedData = @"Local extension field of the message";
ZIMMessageSendConfig *config = [[ZIMMessageSendConfig alloc] init];
// Configure the priority of the message.
config.priority = ZIMMessagePriorityLow;
// Set the type of conversation sent.
// Send a private-chat message.
ZIMConversationType type = ZIMConversationTypePeer;
ZIMMessageSendNotification *notification = [[ZIMMessageSendNotification alloc] init];
notification.onMessageAttached = ^(ZIMMessage *message){
};
[[ZIM getInstance] sendMessage:zimTextMessage toConversationID:toConversationID conversationType:type config:config notification:notification callback:^(ZIMMessage * _Nonnull message, ZIMError * _Nonnull errorInfo) {
// Developers can use this callback to monitor whether the message is sent successfully.
}];
// 1. Configure the local extension field of a message.
// Specify the conversation ID.
NSString *toConversationID = @"xxx1";
// Construct a ZIMMessage object.
ZIMTextMessage *zimTextMessage = [[ZIMTextMessage alloc] initWithMessage:@"Message content"];
// Configure the local extension field of a message.zimTextMessage.localExtendedData = @"Local extension field of the message";
ZIMMessageSendConfig *config = [[ZIMMessageSendConfig alloc] init];
// Configure the priority of the message.
config.priority = ZIMMessagePriorityLow;
// Set the type of conversation sent.
// Send a private-chat message.
ZIMConversationType type = ZIMConversationTypePeer;
ZIMMessageSendNotification *notification = [[ZIMMessageSendNotification alloc] init];
notification.onMessageAttached = ^(ZIMMessage *message){
};
[[ZIM getInstance] sendMessage:zimTextMessage toConversationID:toConversationID conversationType:type config:config notification:notification callback:^(ZIMMessage * _Nonnull message, ZIMError * _Nonnull errorInfo) {
// Developers can use this callback to monitor whether the message is sent successfully.
}];
Sample code
// 1. Configure the local extension field of a message.
// Specify the conversation ID.
std::string conversationID = "conv";
// Construct a ZIMMessage object.
auto zimMessage = std::make_shared<zim::ZIMTextMessage>(message: 'message');
// Configure the local extension field of a message.
zimMessage->localExtendedData = "Local extension field of the message";
auto sendConfig = zim::ZIMMessageSendConfig();
// Configure the priority of the message.
sendConfig.priority = zim::ZIMMessagePriority::ZIM_MESSAGE_PRIORITY_LOW;
//Set the conversation type sent
// Send a private-chat message.
auto conversationType = zim::ZIMConversationType::ZIM_CONVERSATION_TYPE_PEER;
// Send a group-chat message.
// auto conversationType = zim::ZIMConversationType::ZIM_CONVERSATION_TYPE_GROUP;
// Send a room message.
// auto conversationType = zim::ZIMConversationType::ZIM_CONVERSATION_TYPE_ROOM;
// 2. Send the message.
zim_->sendMessage(zimMessage, conversationID, conversationType, sendConfig,
std::make_shared<zim::ZIMMessageSendNotification>(
[=](const std::shared_ptr<zim::ZIMMessage> &message) {
}),
[=](const std::shared_ptr<zim::ZIMMessage> &message,
const zim::ZIMError &errorInfo) {
});
// 1. Configure the local extension field of a message.
// Specify the conversation ID.
std::string conversationID = "conv";
// Construct a ZIMMessage object.
auto zimMessage = std::make_shared<zim::ZIMTextMessage>(message: 'message');
// Configure the local extension field of a message.
zimMessage->localExtendedData = "Local extension field of the message";
auto sendConfig = zim::ZIMMessageSendConfig();
// Configure the priority of the message.
sendConfig.priority = zim::ZIMMessagePriority::ZIM_MESSAGE_PRIORITY_LOW;
//Set the conversation type sent
// Send a private-chat message.
auto conversationType = zim::ZIMConversationType::ZIM_CONVERSATION_TYPE_PEER;
// Send a group-chat message.
// auto conversationType = zim::ZIMConversationType::ZIM_CONVERSATION_TYPE_GROUP;
// Send a room message.
// auto conversationType = zim::ZIMConversationType::ZIM_CONVERSATION_TYPE_ROOM;
// 2. Send the message.
zim_->sendMessage(zimMessage, conversationID, conversationType, sendConfig,
std::make_shared<zim::ZIMMessageSendNotification>(
[=](const std::shared_ptr<zim::ZIMMessage> &message) {
}),
[=](const std::shared_ptr<zim::ZIMMessage> &message,
const zim::ZIMError &errorInfo) {
});
Sample code
// 1. Configure the local extension field of a message.
// Specify the conversation ID.
String toConversationID = "xxx1";
// Construct a ZIMMessage object.
ZIMTextMessage zimMessage = new ZIMTextMessage();
zimMessage.message = "message";
// Configure the local extension field of a message.
zimMessage.localExtendedData = "Local extension field of the message";
ZIMMessageSendConfig config = new ZIMMessageSendConfig();
// Configure the priority of the message.
config.priority = ZIMMessagePriority.Low;
// Set the conversation type sent
// Send a private-chat message.
ZIMConversationType peerType = ZIMConversationType.Peer;
// Send a group-chat message.
ZIMConversationType groupType = ZIMConversationType.Group;
// Send a room message.
ZIMConversationType roomType = ZIMConversationType.Room;
// 2. Send the message.
ZIM.GetInstance().SendMessage(zimMessage, toConversationID, peerType, config, notification, (ZIMMessage message, ZIMError errorInfo) =>
{
// Developers can use this callback to monitor whether the message is sent successfully.
});
// 1. Configure the local extension field of a message.
// Specify the conversation ID.
String toConversationID = "xxx1";
// Construct a ZIMMessage object.
ZIMTextMessage zimMessage = new ZIMTextMessage();
zimMessage.message = "message";
// Configure the local extension field of a message.
zimMessage.localExtendedData = "Local extension field of the message";
ZIMMessageSendConfig config = new ZIMMessageSendConfig();
// Configure the priority of the message.
config.priority = ZIMMessagePriority.Low;
// Set the conversation type sent
// Send a private-chat message.
ZIMConversationType peerType = ZIMConversationType.Peer;
// Send a group-chat message.
ZIMConversationType groupType = ZIMConversationType.Group;
// Send a room message.
ZIMConversationType roomType = ZIMConversationType.Room;
// 2. Send the message.
ZIM.GetInstance().SendMessage(zimMessage, toConversationID, peerType, config, notification, (ZIMMessage message, ZIMError errorInfo) =>
{
// Developers can use this callback to monitor whether the message is sent successfully.
});
Sample code
// Send the single chat `Text` message
const toConversationID = ''; // Other party userID
const conversationType = 0; // conversation type, the value is single chat: 0, room: 1, group: 2
const config: ZIMMessageSendConfig = {
priority: 1, // Set the message priority, the value is low: 1 default, medium: 2, high: 3
};
// 1. Configure the local extension field of a message.
const messageTextObj: ZIMMessage = { type: 1, message: 'Text message content', localExtendedData: 'Local extension information of the message' };
const notification: ZIMMessageSendNotification = {
onMessageAttached: function(message) {
// todo: Loading
}
}
// 2. Send a message
zim.sendMessage(messageTextObj, toConversationID, conversationType, config, notification)
.then(function ({ message }) {
// Sent successfully
})
.catch(function (err) {
// Failed to send
});
// Send the single chat `Text` message
const toConversationID = ''; // Other party userID
const conversationType = 0; // conversation type, the value is single chat: 0, room: 1, group: 2
const config: ZIMMessageSendConfig = {
priority: 1, // Set the message priority, the value is low: 1 default, medium: 2, high: 3
};
// 1. Configure the local extension field of a message.
const messageTextObj: ZIMMessage = { type: 1, message: 'Text message content', localExtendedData: 'Local extension information of the message' };
const notification: ZIMMessageSendNotification = {
onMessageAttached: function(message) {
// todo: Loading
}
}
// 2. Send a message
zim.sendMessage(messageTextObj, toConversationID, conversationType, config, notification)
.then(function ({ message }) {
// Sent successfully
})
.catch(function (err) {
// Failed to send
});
Update the local extension field of a message
For a message that is already received or sent, you can call the updateMessageLocalExtendedData operation to update the local extension field of the message.
The following sample code shows how to update the local extension field of a message that is already received:
Sample code
// After receiving a single chat message, update the local extension field of the message.
zim.setEventHandler(new ZIMEventHandler() {
@Override
public void onPeerMessageReceived(ZIM zim, ArrayList<ZIMMessage> messageList, ZIMMessageReceivedInfo info, String fromUserID) {
for(ZIMMessage message: messageList){
zim.updateMessageLocalExtendedData("Update local extension fields", message, new ZIMMessageLocalExtendedDataUpdatedCallback() {
@Override
public void onMessageExtendedDataUpdated(ZIMMessage message, ZIMError errorInfo) {
// Developers can use this callback to monitor whether the local extended field is updated successfully.
}
});}
}
});
// After receiving a single chat message, update the local extension field of the message.
zim.setEventHandler(new ZIMEventHandler() {
@Override
public void onPeerMessageReceived(ZIM zim, ArrayList<ZIMMessage> messageList, ZIMMessageReceivedInfo info, String fromUserID) {
for(ZIMMessage message: messageList){
zim.updateMessageLocalExtendedData("Update local extension fields", message, new ZIMMessageLocalExtendedDataUpdatedCallback() {
@Override
public void onMessageExtendedDataUpdated(ZIMMessage message, ZIMError errorInfo) {
// Developers can use this callback to monitor whether the local extended field is updated successfully.
}
});}
}
});
Sample code
// Update the local extension field of a private-chat message after you receive the message.
ZIMEventHandler.onPeerMessageReceived = (ZIM zim, List<ZIMMessage> messageList, ZIMMessageReceivedInfo info, String fromUserID){
for(ZIMMessage message in messageList){
ZIM.getInstance()!.updateMessageLocalExtendedData('Update the local extension field.', message).then((value){
// The request was successful.
}).catchError((onError){
// Handle the error based on the corresponding error code table.
});
}
};
// Update the local extension field of a private-chat message after you receive the message.
ZIMEventHandler.onPeerMessageReceived = (ZIM zim, List<ZIMMessage> messageList, ZIMMessageReceivedInfo info, String fromUserID){
for(ZIMMessage message in messageList){
ZIM.getInstance()!.updateMessageLocalExtendedData('Update the local extension field.', message).then((value){
// The request was successful.
}).catchError((onError){
// Handle the error based on the corresponding error code table.
});
}
};
Sample code
// Update the local extension field of a private-chat message after you receive the message.
- (void)zim:(ZIM *)zim peerMessageReceived:(NSArray<ZIMMessage *> *)messageList info:(ZIMMessageReceivedInfo *)info fromUserID:(NSString *)fromUserID {
NSArray *messageBasicList = [ZGZIMManager cnvZIMMessageListToDicList:messageList];
GGLog(@"[GGLog][event][peerMessageReceived],fromUserID:%@,messageList:%@",fromUserID,messageBasicList);
for (ZIMMessage *message in messageList) {
[[ZIM getInstance] updateMessageLocalExtendedData:@"Update local extension fields" message:message callback:^(ZIMMessage * _Nonnull message, ZIMError * _Nonnull errorInfo) {
// Developers can use this callback to monitor whether the local extended field is updated successfully. }];
}
}
// Update the local extension field of a private-chat message after you receive the message.
- (void)zim:(ZIM *)zim peerMessageReceived:(NSArray<ZIMMessage *> *)messageList info:(ZIMMessageReceivedInfo *)info fromUserID:(NSString *)fromUserID {
NSArray *messageBasicList = [ZGZIMManager cnvZIMMessageListToDicList:messageList];
GGLog(@"[GGLog][event][peerMessageReceived],fromUserID:%@,messageList:%@",fromUserID,messageBasicList);
for (ZIMMessage *message in messageList) {
[[ZIM getInstance] updateMessageLocalExtendedData:@"Update local extension fields" message:message callback:^(ZIMMessage * _Nonnull message, ZIMError * _Nonnull errorInfo) {
// Developers can use this callback to monitor whether the local extended field is updated successfully. }];
}
}
Sample code
// Update the local extension field of a private-chat message after you receive the message.
void onPeerMessageReceived(zim::ZIM *zim,
const std::vector<std::shared_ptr<zim::ZIMMessage>> &messageList,
const ZIMMessageReceivedInfo info,
const std::string &fromUserID) override {
for (const auto &message : messageList) {
zim->updateMessageLocalExtendedData("Update the local extension field.", message,
[=](const std::shared_ptr<zim::ZIMMessage> &msg,
const zim::ZIMError &errorInfo) {
// Developers can use this callback to monitor whether the local extension field is updated successfully. });
}
}
// Update the local extension field of a private-chat message after you receive the message.
void onPeerMessageReceived(zim::ZIM *zim,
const std::vector<std::shared_ptr<zim::ZIMMessage>> &messageList,
const ZIMMessageReceivedInfo info,
const std::string &fromUserID) override {
for (const auto &message : messageList) {
zim->updateMessageLocalExtendedData("Update the local extension field.", message,
[=](const std::shared_ptr<zim::ZIMMessage> &msg,
const zim::ZIMError &errorInfo) {
// Developers can use this callback to monitor whether the local extension field is updated successfully. });
}
}
Sample code
ZIM.GetInstance().onReceivePeerMessage += (ZIM zim,
List<ZIMMessage> messageList,
string fromUserID) =>
{
foreach (ZIMMessage message in messageList)
{
ZIM.GetInstance().UpdateMessageLocalExtendedData("Update the local extension field",
message,
(ZIMMessage message, ZIMError errorInfo) =>
{
// Developers can use this callback to monitor whether the local extension field is updated successfully.
});
};
};
ZIM.GetInstance().onReceivePeerMessage += (ZIM zim,
List<ZIMMessage> messageList,
string fromUserID) =>
{
foreach (ZIMMessage message in messageList)
{
ZIM.GetInstance().UpdateMessageLocalExtendedData("Update the local extension field",
message,
(ZIMMessage message, ZIMError errorInfo) =>
{
// Developers can use this callback to monitor whether the local extension field is updated successfully.
});
};
};
The following sample code shows how to update the local extension field of a message that is already received:
Sample code
// Update the local extension field of a private-chat message after you receive the message.
zim.on('peerMessageReceived', function (zim, { messageList, info, fromConversationID }) {
console.log(messageList, fromConversationID);
messageList.forEach((message) => {
zim.updateMessageLocalExtendedData('Update the local extension field', message)
.then(function ({ message }) {
// Operation successful.
})
.catch(function (err) {
// Operation failed.
});
});
});
// Update the local extension field of a private-chat message after you receive the message.
zim.on('peerMessageReceived', function (zim, { messageList, info, fromConversationID }) {
console.log(messageList, fromConversationID);
messageList.forEach((message) => {
zim.updateMessageLocalExtendedData('Update the local extension field', message)
.then(function ({ message }) {
// Operation successful.
})
.catch(function (err) {
// Operation failed.
});
});
});