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
startTimestamp
andendTimestamp
.- if you want a more precise interval, provide with
startMessageID
andendMessageID
. - if
startClosed
istrue
, that means the query result will contain the Message whose Message.sentTimestamp isstartTimestamp
and Message.id isstartMessageID
.endClosed
has the same effect onendTimestamp
andendMessageID
. - if the count of messages in the interval is more than
limit
, the the query result will be a list of message that length islimit
from start-endpoint.
- if you want a more precise interval, provide with
- you can query message by vector with one endpoint and
direction
.- If provide
startTimestamp
orstartTimestamp
withstartMessageID
, means provide the start-endpoint of the query vector. - If provide
endTimestamp
orendTimestamp
withendMessageID
, means provide end-endpoint of the query vector.
- If provide
- you can query message only with
direction
.- If
direction
is MessageQueryDirection.newToOld, means query from current timestamp to oldest timestamp. - If
direction
is 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;
}