queryMessage method

Future<List<Message>> queryMessage({
  1. int? startTimestamp,
  2. String? startMessageID,
  3. bool? startClosed,
  4. int? endTimestamp,
  5. String? endMessageID,
  6. bool? endClosed,
  7. MessageQueryDirection? direction,
  8. int? limit = 20,
  9. int? type,
})

To query the history of the Message which has been sent.

startTimestamp's default is null, unit is millisecond. startMessageID's default is null. startClosed's default is false. endTimestamp's default is null, unit is millisecond. endMessageID's default is null. endClosed's default is false. direction's default is MessageQueryDirection.newToOld. limit's default is 20, should not more than 100. type's default is null.

  • you can query message in the specified timestamp interval with startTimestamp and endTimestamp.
    • if you want a more precise interval, provide with startMessageID and endMessageID.
    • if startClosed is true, that means the query result will contain the Message whose Message.sentTimestamp is startTimestamp and Message.id is startMessageID. endClosed has the same effect on endTimestamp and endMessageID.
    • if the count of messages in the interval is more than limit, the the query result will be a list of message that length is limit from start-endpoint.
  • you can query message by vector with one endpoint and direction.
    • If provide startTimestamp or startTimestamp with startMessageID, means provide the start-endpoint of the query vector.
    • If provide endTimestamp or endTimestamp with endMessageID, means provide end-endpoint of the query vector.
  • you can query message only with direction.
  • you can query message with type, it will filter Message except the specified type.

Returns a list of Message, the order is from old to new.

Implementation

Future<List<Message>> queryMessage({
  int? startTimestamp,
  String? startMessageID,
  bool? startClosed,
  int? endTimestamp,
  String? endMessageID,
  bool? endClosed,
  MessageQueryDirection? direction,
  int? limit = 20,
  int? type,
}) async {
  var start = {};
  if (startTimestamp != null) {
    start['timestamp'] = startTimestamp;
  }
  if (startMessageID != null) {
    start['id'] = startMessageID;
  }
  if (startClosed != null) {
    start['close'] = startClosed;
  }
  var end = {};
  if (endTimestamp != null) {
    end['timestamp'] = endTimestamp;
  }
  if (endMessageID != null) {
    end['id'] = endMessageID;
  }
  if (endClosed != null) {
    end['close'] = endClosed;
  }
  var args = <dynamic, dynamic>{
    'clientId': client.id,
    'conversationId': id,
  };
  if (start.isNotEmpty) {
    args['start'] = start;
  }
  if (end.isNotEmpty) {
    args['end'] = end;
  }
  if (direction != null) {
    args['direction'] = direction.index + 1;
  }
  if (limit != null) {
    if (limit < 1 || limit > 100) {
      throw ArgumentError(
        'limit should in [1...100].',
      );
    }
    args['limit'] = limit;
  }
  if (type != null) {
    args['type'] = type;
  }
  final List rawDatas = await call(
    method: 'queryMessage',
    arguments: args,
  );
  List<Message> messages = [];
  for (var item in rawDatas) {
    messages.add(
      Message._instanceFrom(
        item,
      ),
    );
  }
  return messages;
}