addAdvancedMsgListener

Introduction

Add an advanced message listener, which can be used to listen for all the receiving messages.

The related callback functions can be defined in V2TimAdvancedMsgListener.

Invoking this method will add an additional new listener to the array of listeners.

It is suggested to register an advanced message listener, just after logging, to ensure all the messages can be received.

Receiving a Text Message

Receiving a Custom Message

Receiving a Rich Media Message

Receiving a Message Containing Multiple Elements

Parameter details

Parameter name Parameter type Required Platform Description
listener V2TimAdvancedMsgListener yes All The specific message listener.

Returned template

void

Return value details

This function has no return value

Code example

    V2TimAdvancedMsgListener listener = V2TimAdvancedMsgListener(
      onRecvC2CReadReceipt: (List<V2TimMessageReceipt> receiptList) {
      },
      onRecvMessageModified: (V2TimMessage message) {
      },
      onRecvMessageReadReceipts: (List<V2TimMessageReceipt> receiptList) {
        receiptList.forEach((element) {
          element.groupID; 
          element.msgID; 
          element.readCount; 
          element.unreadCount; 
          element.userID; 
        });
      },
      onRecvMessageRevoked: (String messageid) {
      },
      onRecvNewMessage: (V2TimMessage message) async {
        if (message.elemType == MessageElemType.V2TIM_ELEM_TYPE_TEXT) {
          message.textElem?.text;
        }
        if (message.elemType == MessageElemType.V2TIM_ELEM_TYPE_CUSTOM) {
          message.customElem?.data;
          message.customElem?.desc;
          message.customElem?.extension;
        }
        if (message.elemType == MessageElemType.V2TIM_ELEM_TYPE_IMAGE) {
          message.imageElem
              ?.path; 
          message.imageElem?.imageList?.forEach((element) {
            element?.height;
            element?.localUrl;
            element?.size;
            element?.type; 
            element?.url;
            element?.uuid;
            element?.width;
          });
        }
        if (message.elemType == MessageElemType.V2TIM_ELEM_TYPE_VIDEO) {
          message.videoElem?.UUID;
          message.videoElem?.duration;
          message.videoElem?.localSnapshotUrl;
          message.videoElem?.localVideoUrl;
          message.videoElem?.snapshotHeight;
          message.videoElem?.snapshotPath;
          // ...
        }
        if (message.elemType == MessageElemType.V2TIM_ELEM_TYPE_SOUND) {
          message.soundElem?.UUID;
          message.soundElem?.dataSize;
          message.soundElem?.duration;
          message.soundElem?.localUrl;
          message.soundElem?.url;
          // ...
        }
        if (message.elemType == MessageElemType.V2TIM_ELEM_TYPE_FILE) {
          message.fileElem?.UUID;
          message.fileElem?.fileName;
          message.fileElem?.fileSize;
          message.fileElem?.localUrl;
          message.fileElem?.path;
          message.fileElem?.url;
        }
        if (message.elemType == MessageElemType.V2TIM_ELEM_TYPE_LOCATION) {
          message.locationElem?.desc;
          message.locationElem?.latitude;
          message.locationElem?.longitude;
        }
        if (message.elemType == MessageElemType.V2TIM_ELEM_TYPE_FACE) {
          message.faceElem?.data;
          message.faceElem?.index;
        }
        if (message.elemType == MessageElemType.V2TIM_ELEM_TYPE_GROUP_TIPS) {
          message.groupTipsElem?.groupID; 
          message.groupTipsElem?.type; 
          message.groupTipsElem?.opMember; 
          message.groupTipsElem?.memberList; 
          message.groupTipsElem?.groupChangeInfoList; 
          message.groupTipsElem?.memberChangeInfoList; 
          message.groupTipsElem?.memberCount; 
        }
        if (message.elemType == MessageElemType.V2TIM_ELEM_TYPE_MERGER) {
          message.mergerElem?.abstractList;
          message.mergerElem?.isLayersOverLimit;
          message.mergerElem?.title;
          V2TimValueCallback<List<V2TimMessage>> download =
              await TencentImSDKPlugin.v2TIMManager
                  .getMessageManager()
                  .downloadMergerMessage(
                    msgID: message.msgID!,
                  );
          if (download.code == 0) {
            List<V2TimMessage>? messageList = download.data;
          }
        }
        if (message.textElem?.nextElem != null) {
        }
      },
      onSendMessageProgress: (V2TimMessage message, int progress) {
      },
    );
    TencentImSDKPlugin.v2TIMManager
        .getMessageManager()
        .addAdvancedMsgListener(listener: listener);

results matching ""

    No results matching ""