addConversationBaseInfoFromGroupAndUseraInfo static method

Future<List<Map<String, dynamic>>> addConversationBaseInfoFromGroupAndUseraInfo(
  1. List<V2TimConversation> convList
)

Implementation

static Future<List<Map<String, dynamic>>> addConversationBaseInfoFromGroupAndUseraInfo(List<V2TimConversation> convList) async {
  List<String> groupids = List<String>.from([]);
  List<String> userids = List<String>.from([]);
  if (convList.isNotEmpty) {
    for (var conv in convList) {
      if (conv.type == ConversationType.V2TIM_C2C) {
        String formatedUserId = conv.conversationID.startsWith("c2c_") ? conv.conversationID.replaceFirst("c2c_", "") : conv.conversationID;
        if (!userInfos.containsKey(formatedUserId)) {
          userids.add(formatedUserId);
        }
      } else if (conv.type == ConversationType.V2TIM_GROUP) {
        String formatedGroupid = conv.conversationID.startsWith("group_") ? conv.conversationID.replaceFirst("group_", "") : conv.conversationID;
        if (!groupsInfos.containsKey(formatedGroupid)) {
          groupids.add(formatedGroupid);
        }
      }
    }
    if (userids.isNotEmpty) {
      V2TimValueCallback<List<V2TimUserFullInfo>> uis = await getUsersInfo(userIDList: userids);
      print("所有用户数据");
      print(uis.toJson());
      if (uis.code == 0 && uis.data != null) {
        if (uis.data!.isNotEmpty) {
          for (var ui in uis.data!) {
            userInfos[ui.userID ?? ""] = ui;
          }
        }
      }
    }
    if (groupids.isNotEmpty) {
      V2TimValueCallback<List<V2TimGroupInfoResult>> gis = await getGroupsInfo(groupIDList: groupids);
      if (gis.code == 0 && gis.data != null) {
        if (gis.data!.isNotEmpty) {
          for (var gi in gis.data!) {
            if (gi.resultCode == 0) {
              groupsInfos[gi.groupInfo!.groupID] = gi.groupInfo ?? V2TimGroupInfo(groupID: "", groupType: "");
            }
          }
        }
      }
    }
  }
  List<Map<String, dynamic>> resConv = List.from([]);
  for (var cv in convList) {
    if (cv.type == ConversationType.V2TIM_C2C) {
      String formatedUserId = cv.conversationID.startsWith("c2c_") ? cv.conversationID.replaceFirst("c2c_", "") : cv.conversationID;
      if (userInfos.containsKey(formatedUserId)) {
        cv.faceUrl = userInfos[formatedUserId]?.faceUrl;
      }
    } else if (cv.type == ConversationType.V2TIM_GROUP) {
      String formatedGroupid = cv.conversationID.startsWith("group_") ? cv.conversationID.replaceFirst("group_", "") : cv.conversationID;
      if (groupsInfos.containsKey(formatedGroupid)) {
        cv.faceUrl = groupsInfos[formatedGroupid]?.faceUrl;
        cv.groupType = groupsInfos[formatedGroupid]?.groupType;
      }
    }
    resConv.add(cv.toJson());
  }
  return resConv;
}