queryMessage method
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
startTimestampandendTimestamp.- if you want a more precise interval, provide with
startMessageIDandendMessageID. - if
startClosedistrue, that means the query result will contain the Message whose Message.sentTimestamp isstartTimestampand Message.id isstartMessageID.endClosedhas the same effect onendTimestampandendMessageID. - if the count of messages in the interval is more than
limit, the the query result will be a list of message that length islimitfrom start-endpoint.
- if you want a more precise interval, provide with
- you can query message by vector with one endpoint and
direction.- If provide
startTimestamporstartTimestampwithstartMessageID, means provide the start-endpoint of the query vector. - If provide
endTimestamporendTimestampwithendMessageID, means provide end-endpoint of the query vector.
- If provide
- you can query message only with
direction.- If
directionis MessageQueryDirection.newToOld, means query from current timestamp to oldest timestamp. - If
directionis MessageQueryDirection.oldToNew, means query from oldest timestamp to current timestamp.
- If
- you can query message with
type, it will filter Message except the specifiedtype.
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;
}