isGiftMessage static method

bool isGiftMessage(
  1. V2TimMessage message
)

Implementation

static bool isGiftMessage(V2TimMessage message) {
  final bool isCustomMessage =
      message.elemType == MessageElemType.V2TIM_ELEM_TYPE_CUSTOM;
  if (isCustomMessage) {
    final customElem = message.customElem;
    try {
      final Map customData = jsonDecode(customElem?.data ?? "");
      final isIncludeBusinessID = customData.containsKey("businessID");
      final isIncludeData = customData.containsKey("data");
      if (isIncludeBusinessID && isIncludeData) {
        final isLiveKitGiftMessage =
            customData["businessID"] == "flutter_live_kit";
        final Map giftData = customData["data"];
        final isIncludeCmd = giftData.containsKey("cmd");
        final isIncludeCmdInfo = giftData.containsKey("cmdInfo");
        final isMap = giftData['cmdInfo'] is Map;
        return isLiveKitGiftMessage &&
            isIncludeCmd &&
            isIncludeCmdInfo &&
            isMap &&
            (giftData['cmdInfo'] as Map).containsKey('type') &&
            giftData["cmd"] == "send_gift_message";
      }
      return false;
    } catch (error) {
      return false;
    }
  } else {
    return false;
  }
}