fetchOwnInfo method

Future<EMUserInfo?> fetchOwnInfo({
  1. int expireTime = 0,
})

~english Gets the current user's attributes from the server.

Param expireTime The time period(seconds) when the user attributes in the cache expire. If the interval between two callers is less than or equal to the value you set in the parameter, user attributes are obtained directly from the local cache; otherwise, they are obtained from the server. For example, if you set this parameter to 120(2 minutes), once this method is called again within 2 minutes, the SDK returns the attributes obtained last time.

Return The user properties that are obtained. See EMUserInfo.

Throws A description of the exception. See EMError. ~end

~chinese 获取当前用户的属性信息。

Param expireTime 获取的用户属性到期时间。如果在到期时间内再次调用该方法,则 SDK 直接返回上次获取到的缓存数据。例如,将该参数设为 120,即 2 分钟,则如果你在 2 分钟内再次调用该方法获取用户属性,SDK 仍将返回上次获取到的属性。否则需从服务器获取。

Return 用户属性。请参见 EMUserInfo

Throws 如果有方法调用的异常会在这里抛出,可以看到具体错误原因。请参见 EMError。 ~end

Implementation

Future<EMUserInfo?> fetchOwnInfo({int expireTime = 0}) async {
  String? currentUser = await EMClient.getInstance.getCurrentUserId();
  if (currentUser != null) {
    try {
      Map<String, EMUserInfo> ret = await fetchUserInfoById(
        [currentUser],
        expireTime: expireTime,
      );
      _effectiveUserInfoMap[ret.values.first.userId] = ret.values.first;
      return ret.values.first;
    } on EMError catch (e) {
      throw e;
    }
  }
  return null;
}