use of org.whispersystems.signalservice.internal.storage.protos.StorageItem in project Signal-Android by WhisperSystems.
the class SignalServiceAccountManager method readStorageRecords.
public List<SignalStorageRecord> readStorageRecords(StorageKey storageKey, List<StorageId> storageKeys) throws IOException, InvalidKeyException {
if (storageKeys.isEmpty()) {
return Collections.emptyList();
}
List<SignalStorageRecord> result = new ArrayList<>();
Map<ByteString, Integer> typeMap = new HashMap<>();
List<ReadOperation> readOperations = new LinkedList<>();
ReadOperation.Builder currentOperation = ReadOperation.newBuilder();
for (StorageId key : storageKeys) {
typeMap.put(ByteString.copyFrom(key.getRaw()), key.getType());
if (currentOperation.getReadKeyCount() >= STORAGE_READ_MAX_ITEMS) {
Log.i(TAG, "Going over max read items. Starting a new read operation.");
readOperations.add(currentOperation.build());
currentOperation = ReadOperation.newBuilder();
}
if (StorageId.isKnownType(key.getType())) {
currentOperation.addReadKey(ByteString.copyFrom(key.getRaw()));
} else {
result.add(SignalStorageRecord.forUnknown(key));
}
}
if (currentOperation.getReadKeyCount() > 0) {
readOperations.add(currentOperation.build());
}
Log.i(TAG, "Reading " + storageKeys.size() + " items split over " + readOperations.size() + " page(s).");
String authToken = this.pushServiceSocket.getStorageAuth();
for (ReadOperation readOperation : readOperations) {
StorageItems items = this.pushServiceSocket.readStorageItems(authToken, readOperation);
for (StorageItem item : items.getItemsList()) {
Integer type = typeMap.get(item.getKey());
if (type != null) {
result.add(SignalStorageModels.remoteToLocalStorageRecord(item, type, storageKey));
} else {
Log.w(TAG, "No type found! Skipping.");
}
}
}
return result;
}
use of org.whispersystems.signalservice.internal.storage.protos.StorageItem in project Signal-Android by signalapp.
the class SignalServiceAccountManager method readStorageRecords.
public List<SignalStorageRecord> readStorageRecords(StorageKey storageKey, List<StorageId> storageKeys) throws IOException, InvalidKeyException {
if (storageKeys.isEmpty()) {
return Collections.emptyList();
}
List<SignalStorageRecord> result = new ArrayList<>();
Map<ByteString, Integer> typeMap = new HashMap<>();
List<ReadOperation> readOperations = new LinkedList<>();
ReadOperation.Builder currentOperation = ReadOperation.newBuilder();
for (StorageId key : storageKeys) {
typeMap.put(ByteString.copyFrom(key.getRaw()), key.getType());
if (currentOperation.getReadKeyCount() >= STORAGE_READ_MAX_ITEMS) {
Log.i(TAG, "Going over max read items. Starting a new read operation.");
readOperations.add(currentOperation.build());
currentOperation = ReadOperation.newBuilder();
}
if (StorageId.isKnownType(key.getType())) {
currentOperation.addReadKey(ByteString.copyFrom(key.getRaw()));
} else {
result.add(SignalStorageRecord.forUnknown(key));
}
}
if (currentOperation.getReadKeyCount() > 0) {
readOperations.add(currentOperation.build());
}
Log.i(TAG, "Reading " + storageKeys.size() + " items split over " + readOperations.size() + " page(s).");
String authToken = this.pushServiceSocket.getStorageAuth();
for (ReadOperation readOperation : readOperations) {
StorageItems items = this.pushServiceSocket.readStorageItems(authToken, readOperation);
for (StorageItem item : items.getItemsList()) {
Integer type = typeMap.get(item.getKey());
if (type != null) {
result.add(SignalStorageModels.remoteToLocalStorageRecord(item, type, storageKey));
} else {
Log.w(TAG, "No type found! Skipping.");
}
}
}
return result;
}
Aggregations