createCustomMessage
(Android/iOS & Mac/Windows) API, where data
stores the polling title and options. And store the user ID of the voter and selected option(s) in the key
and value
of the message extension, respectively. With the selected options of users, we can calculate the polling percentage real time.createCustomMessage
API, where data
stores the title of the group notice, and then store the user ID and the corresponding info in the key
and value
of the message extension, respectively.createCustomMessage
API, where data
stores the title and options of the survey, and then store the user ID and the corresponding info in the key
and value
of the message extension, respectively.setMessageExtensions
(Android / iOS & Mac / Windows) API to set the message extension. If an extension already exists, modify its value
info. Otherwise, add new ones.setMessageExtensions
API are detailed as follows:Attribute | Definition | Description |
message | Message object | Three message conditions to meet: The message is sent successfully. The message is not a message of a community/audio-video group. |
extensions | Extensions | Modify the `value` info of an existing extension, or add new extensions. |
key
and value
of an extension can contain up to 100 B and 1 KB, respectively. You can set up to 20 extensions each time and 300 extensions for a message.List<V2TIMMessageExtension> extensionList = new ArrayList<>();V2TIMMessageExtension extension1 = new V2TIMMessageExtension();extension1.setExtensionKey("key1");extension1.setExtensionValue("value1");extensionList.add(extension1);V2TIMMessageExtension extension2 = new V2TIMMessageExtension();extension2.setExtensionKey("key2");extension2.setExtensionValue("value2");extensionList.add(extension2);V2TIMManager.getMessageManager().setMessageExtensions(lastMsg, extensionList, new V2TIMValueCallback<List<V2TIMMessageExtensionResult>>() {@Overridepublic void onSuccess(List<V2TIMMessageExtensionResult> v2TIMMessageExtensionResults) {// Set message extensions successfully}@Overridepublic void onError(int code, String desc) {// Failed to set message extensions}});
NSMutableArray *extensionList = [NSMutableArray array];V2TIMMessageExtension *extension1 = [[V2TIMMessageExtension alloc] init];extension1.extensionKey = @"key1";extension1.extensionValue = @"value1";[extensionList addObject:extension1];V2TIMMessageExtension *extension2 = [[V2TIMMessageExtension alloc] init];extension2.extensionKey = @"key2";extension2.extensionValue = @"value2";[extensionList addObject:extension2];[[V2TIMManager sharedInstance] setMessageExtensions:message extensions:extensionList succ:^(NSArray<V2TIMMessageExtensionResult *> *extensionResultList) {// Set message extensions successfully} fail:^(int code, NSString *desc) {// Failed to set message extensions}];
class ValueCallback final : public V2TIMValueCallback<T> {public:using SuccessCallback = std::function<void(const T &)>;using ErrorCallback = std::function<void(int, const V2TIMString &)>;ValueCallback() = default;~ValueCallback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess(const T &value) override {if (success_callback_) {success_callback_(value);}}void OnError(int error_code, const V2TIMString &error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;};V2TIMMessageExtensionVector extensionList;V2TIMMessageExtension extension1;extension1.extensionKey = "key1";extension1.extensionValue = "value1";extensionList.PushBack(extension1);V2TIMMessageExtension extension2;extension2.extensionKey = "key2";extension2.extensionValue = "value2";extensionList.PushBack(extension2);auto *callback = new ValueCallback<V2TIMMessageExtensionResultVector>{};callback->SetCallback([=](const V2TIMMessageExtensionResultVector &extensionResultList) {// Set message extensions successfullydelete callback;},[=](int error_code, const V2TIMString &error_message) {// Failed to set message extensionsdelete callback;});V2TIMManager::GetInstance()->GetMessageManager()->SetMessageExtensions(message, extensionList, callback);
V2TIMManager.getMessageManager().getMessageExtensions(lastMsg, new V2TIMValueCallback<List<V2TIMMessageExtension>>() {@Overridepublic void onSuccess(List<V2TIMMessageExtension> extensions) {// Got message extensions successfully}@Overridepublic void onError(int code, String desc) {// Failed to get message extensions}});
[[V2TIMManager sharedInstance] getMessageExtensions:message succ:^(NSArray<V2TIMMessageExtension *> *extensionList) {// Got message extensions successfully} fail:^(int code, NSString *desc) {// Failed to get message extensions}];
class ValueCallback final : public V2TIMValueCallback<T> {public:using SuccessCallback = std::function<void(const T &)>;using ErrorCallback = std::function<void(int, const V2TIMString &)>;ValueCallback() = default;~ValueCallback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess(const T &value) override {if (success_callback_) {success_callback_(value);}}void OnError(int error_code, const V2TIMString &error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;};auto *callback = new ValueCallback<V2TIMMessageExtensionVector>{};callback->SetCallback([=](const V2TIMMessageExtensionVector &extensionList) {// Got message extensions successfullydelete callback;},[=](int error_code, const V2TIMString &error_message) {// Failed to get message extensionsdelete callback;});V2TIMManager::GetInstance()->GetMessageManager()->GetMessageExtensions(message, callback);
deleteMessageExtensions
(Android/iOS & Mac/Windows) to delete message extensions. If the value of the keys
field is set to null
/nil
, all message extensions will be cleared.List<String> keyList = new ArrayList<>();keyList.add("key1");keyList.add("key2");V2TIMManager.getMessageManager().deleteMessageExtensions(lastMsg, keyList, new V2TIMValueCallback<List<V2TIMMessageExtensionResult>>() {@Overridepublic void onSuccess(List<V2TIMMessageExtensionResult> v2TIMMessageExtensionResults) {// Deleted message extensions successfully}@Overridepublic void onError(int code, String desc) {// Failed to delete message extensions}});
[[V2TIMManager sharedInstance] deleteMessageExtensions:message keys:@[@"key1",@"key2"] succ:^(NSArray<V2TIMMessageExtensionResult *> *extensionResultList){// Deleted message extensions successfully} fail:^(int code, NSString *desc) {// Failed to delete message extensions}];
class ValueCallback final : public V2TIMValueCallback<T> {public:using SuccessCallback = std::function<void(const T &)>;using ErrorCallback = std::function<void(int, const V2TIMString &)>;ValueCallback() = default;~ValueCallback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess(const T &value) override {if (success_callback_) {success_callback_(value);}}void OnError(int error_code, const V2TIMString &error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;};V2TIMStringVector keys;keys.PushBack("key1");keys.PushBack("key2");auto *callback = new ValueCallback<V2TIMMessageExtensionResultVector>{};callback->SetCallback([=](const V2TIMMessageExtensionResultVector &extensionResultList) {// Deleted message extensions successfullydelete callback;},[=](int error_code, const V2TIMString &error_message) {// Failed to delete message extensionsdelete callback;});V2TIMManager::GetInstance()->GetMessageManager()->DeleteMessageExtensions(message, keys, callback);
addAdvancedMsgListener
, you will receive the onRecvMessageExtensionsChanged
(Android/iOS & Mac/Windows) callback when message extensions are added or updated, and the onRecvMessageExtensionsDeleted
(Android/iOS & Mac/Windows) callback when message extensions are deleted.V2TIMManager.getMessageManager().addAdvancedMsgListener(new V2TIMAdvancedMsgListener() {@Overridepublic void onRecvMessageExtensionsChanged(String msgID, List<V2TIMMessageExtension> extensions) {// Received a notification of message extension change}@Overridepublic void onRecvMessageExtensionsDeleted(String msgID, List<String> extensionKeys) {// Received a notification of message extension deletion}});
[[V2TIMManager sharedInstance] addAdvancedMsgListener:self];- (void)onRecvMessageExtensionsChanged:(NSString *)msgID extensions:(NSArray<V2TIMMessageExtension *> *)extensions {// Received a notification of message extension change}- (void)onRecvMessageExtensionsDeleted:(NSString *)msgID extensionKeys:(NSArray<NSString *> *)extensionKeys {// Received a notification of message extension deletion}
class AdvancedMsgListener final : public V2TIMAdvancedMsgListener {public:void OnRecvMessageExtensionsChanged(const V2TIMString &msgID,const V2TIMMessageExtensionVector &extensions) override {// Received a notification of message extension change}void OnRecvMessageExtensionsDeleted(const V2TIMString &msgID,const V2TIMStringVector &extensionKeys) override {// Received a notification of message extension deletion}// Other members …};// Add an event listener for advanced messages. Keep `advancedMsgListener` valid before it is removed to ensure event callbacks are received.AdvancedMsgListener advancedMsgListener;V2TIMManager::GetInstance()->GetMessageManager()->AddAdvancedMsgListener(&advancedMsgListener);
Was this page helpful?