smpl shortarray

This commit is contained in:
Christien Rioux 2023-08-07 08:07:51 -04:00
parent c59828df90
commit e68cbb26eb
7 changed files with 80 additions and 24 deletions

View file

@ -205,3 +205,36 @@ Future<IList<proto.Message>?> getLocalConversationMessages({
return out;
});
}
Future<IList<proto.Message>?> getRemoteConversationMessages({
required ActiveAccountInfo activeAccountInfo,
required TypedKey remoteConversationKey,
required TypedKey remoteIdentityPublicKey,
}) async {
final conversation = await readRemoteConversation(
activeAccountInfo: activeAccountInfo,
remoteConversationKey: remoteConversationKey,
remoteIdentityPublicKey: remoteIdentityPublicKey);
if (conversation == null) {
return null;
}
final messagesOwned =
proto.OwnedDHTRecordPointerProto.fromProto(conversation.messages);
final crypto = await getConversationCrypto(
activeAccountInfo: activeAccountInfo,
remoteIdentityPublicKey: remoteIdentityPublicKey);
return (await DHTShortArray.openOwned(messagesOwned,
parent: localConversationOwned.recordKey, crypto: crypto))
.scope((messages) async {
var out = IList<proto.Message>();
for (var i = 0; i < messages.length; i++) {
final msg = await messages.getItemProtobuf(proto.Message.fromBuffer, i);
if (msg == null) {
throw Exception('Failed to get message');
}
out = out.add(msg);
}
return out;
});
}