OnRecvNewMessageCallback

Introduction

The callback of receiving a new message event.

Returned template

OnRecvNewMessageCallback = void Function(
V2TimMessage message
)

Return value details

name type description
message V2TimMessage The new message received.

Code example

    V2TimAdvancedMsgListener listener = V2TimAdvancedMsgListener(
      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) {
        }
      },
    );
    TencentImSDKPlugin.v2TIMManager
        .getMessageManager()
        .addAdvancedMsgListener(listener: listener);

results matching ""

    No results matching ""