fetchPrevious method
Future<List<BaseMessage> >
fetchPrevious({
- required dynamic onSuccess(
- List<
BaseMessage> message
- List<
- required dynamic onError(
- CometChatException excep
Returns a list of BaseMessage object fetched after putting the filters.
Implementation
Future<List<BaseMessage>> fetchPrevious(
{required Function(List<BaseMessage> message)? onSuccess,
required Function(CometChatException excep)? onError}) async {
try {
int? updateAfterLong;
int? timestampLong;
if (this.updatedAfter != null) {
updateAfterLong = this.updatedAfter!.millisecondsSinceEpoch ~/ 1000;
}
if (this.timestamp != null) {
timestampLong = this.timestamp!.millisecondsSinceEpoch ~/ 1000;
}
final result = await channel.invokeMethod('fetchPreviousMessages', {
'uid': this.uid,
'guid': this.guid,
'searchTerm': this.searchKeyword,
'messageId': this.messageId,
'limit': this.limit,
'timestamp': timestampLong,
'unread': this.unread,
'hideblockedUsers': this.hideMessagesFromBlockedUsers,
'updateAfter': updateAfterLong,
'updatesOnly': this.updatesOnly,
'categories': this.categories,
'types': this.types,
'parentMessageId': this.parentMessageId,
'hideReplies': this.hideReplies,
'hideDeletedMessages': this.hideDeleted,
'withTags': this.withTags,
'tags': this.tags,
'key': this.key,
'myMentionsOnly': this._myMentionsOnly ?? false,
'mentionsWithTagInfo': this._mentionsWithTagInfo ?? false,
'mentionsWithBlockedInfo': this._mentionsWithBlockedInfo ?? false,
'interactionGoalCompletedOnly': this.interactionGoalCompletedOnly
});
final List<BaseMessage> res = [];
if (result != null) {
key = result["key"];
debugPrint("key in SDK $key");
if (result["list"] != null) {
for (var _obj in result["list"]) {
try {
res.add(BaseMessage.fromMap(_obj));
} catch (e) {
if (onError != null) {
onError(CometChatException(ErrorCode.errorUnhandledException,
e.toString(), e.toString()));
}
return [];
}
}
}
}
if (onSuccess != null) onSuccess(res);
return res;
} on PlatformException catch (platformException) {
if (onError != null) {
onError(CometChatException(platformException.code,
platformException.details, platformException.message));
}
} catch (e) {
debugPrint("Error: ${e.toString()}");
if (onError != null) {
onError(CometChatException(
ErrorCode.errorUnhandledException, e.toString(), e.toString()));
}
}
return [];
}