Calculate message storage size

pull/153/head
M66B 6 years ago
parent dbe27f6e9e
commit 717881a4b8

@ -1457,9 +1457,38 @@ class Core {
} catch (Throwable ex) {
Log.e(ex);
}
updateMessageSize(context, message.id);
}
}
private static void updateMessageSize(Context context, long id) {
DB db = DB.getInstance(context);
EntityMessage message = db.message().getMessage(id);
if (message == null || !message.content)
return;
int size = (int) message.getFile(context).length();
if (size == 0)
return;
List<EntityAttachment> attachments = db.attachment().getAttachments(message.id);
for (EntityAttachment attachment : attachments) {
if (!attachment.available)
return;
long asize = attachment.getFile(context).length();
if (asize == 0)
return;
size += asize;
}
Log.i("Setting message=" + id + " size=" + message.size + "/" + size);
db.message().setMessageSize(message.id, size);
}
static void notifyMessages(Context context, List<TupleMessageEx> messages) {
Log.i("Notify messages=" + messages.size());

@ -324,6 +324,9 @@ public interface DaoMessage {
@Query("UPDATE message SET content = :content, preview = :preview, warning = :warning WHERE id = :id")
int setMessageContent(long id, boolean content, String preview, String warning);
@Query("UPDATE message SET size = :size WHERE id = :id")
int setMessageSize(long id, Integer size);
@Query("UPDATE message SET headers = :headers WHERE id = :id")
int setMessageHeaders(long id, String headers);

Loading…
Cancel
Save