subscribe method

Future<List<ChatPresence>> subscribe({
  1. required List<String> members,
  2. required int expiry,
})

~english Subscribes to a user's presence states. If the subscription succeeds, the subscriber will receive the callback when the user's presence state changes.

Param members The list of IDs of users whose presence states you want to subscribe to.

Param expiry The expiration time of the presence subscription.

Return Which contains IDs of users whose presence states you have subscribed to.

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

~chinese 订阅指定用户的在线状态。

Param members 要订阅在线状态的用户 ID 数组。

Param expiry 订阅时长,单位为秒。最长不超过 2,592,000 (30×24×3600) 秒,即 30 天。

Return 返回被订阅用户的当前状态。

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

Implementation

Future<List<ChatPresence>> subscribe({
  required List<String> members,
  required int expiry,
}) async {
  Map req = {'members': members, "expiry": expiry};
  Map result =
      await _channel.invokeMethod(ChatMethodKeys.presenceSubscribe, req);
  try {
    ChatError.hasErrorFromResult(result);
    List<ChatPresence> list = [];
    result[ChatMethodKeys.presenceSubscribe]?.forEach((element) {
      list.add(ChatPresence.fromJson(element));
    });
    return list;
  } on ChatError catch (e) {
    throw e;
  }
}