From 32727cf0ae3f75f2b99388a2d67b301d57f51ff6 Mon Sep 17 00:00:00 2001 From: cage Date: Sat, 30 May 2020 11:53:17 +0200 Subject: [PATCH] - [breaking changes] changed table for attachments; - fixed bug that prevented statuses missing attachments when the status was reblogged. --- src/db.lisp | 85 ++++++++++++++++++++++-------------------- src/thread-window.lisp | 12 +++--- 2 files changed, 51 insertions(+), 46 deletions(-) diff --git a/src/db.lisp b/src/db.lisp index 6bd0aed..3c69c56 100644 --- a/src/db.lisp +++ b/src/db.lisp @@ -237,7 +237,8 @@ +make-close+))) (defun make-attachment () - (query-low-level (strcat (prepare-table +table-attachment+) + (query-low-level (strcat (prepare-table +table-attachment+ :autogenerated-id-p nil) + " id TEXT NOT NULL," ;; one of swconf:*allowed-attachment-type* " type TEXT NOT NULL," " url TEXT NOT NULL," @@ -253,8 +254,7 @@ " bitrate TEXT," " description TEXT," " blurhash TEXT," - " \"status-id\" TEXT," - " UNIQUE(id) ON CONFLICT FAIL" + " \"status-id\" TEXT" +make-close+))) (defun make-conversation () @@ -431,7 +431,6 @@ (create-table-index +table-status+ '(:folder :timeline :status-id)) (create-table-index +table-account+ '(:id :acct)) (create-table-index +table-followed-user+ '(:user-id)) - (create-table-index +table-attachment+ '(:id)) (create-table-index +table-subscribed-tag+ '(:id)) (create-table-index +table-ignored-status+ '(:folder :timeline :status-id)) (create-table-index +table-pagination-status+ '(:folder :timeline :status-id)) @@ -726,43 +725,47 @@ than (swconf:config-purge-history-days-offset) days in the past" (description tooter:description) (blurhash tooter:blurhash)) object (assert status-id) - (with-no-row-id (+table-attachment+ id) - (let* ((actual-attachment-type (prepare-for-db kind)) - (original-file-metadata (metadata-original metadata)) - (width (prepare-for-db (metadata-width original-file-metadata))) - (height (prepare-for-db (metadata-height original-file-metadata))) - (frame-rate (prepare-for-db (metadata-frame-rate original-file-metadata))) - (duration (prepare-for-db (metadata-duration original-file-metadata))) - (bitrate (prepare-for-db (metadata-bitrate original-file-metadata))) - (insert-query (make-insert +table-attachment+ - (:id - :type - :url - :preview-url - :remote-url - :text-url - :width - :height - :frame-rate - :duration - :bitrate - :description - :blurhash - :status-id) - (id - actual-attachment-type - url - preview-url - remote-url - text-url - width - height - frame-rate - duration - bitrate - description - blurhash - status-id)))) + (let* ((actual-attachment-type (prepare-for-db kind)) + (original-file-metadata (metadata-original metadata)) + (width (prepare-for-db (metadata-width original-file-metadata))) + (height (prepare-for-db (metadata-height original-file-metadata))) + (frame-rate (prepare-for-db (metadata-frame-rate original-file-metadata))) + (duration (prepare-for-db (metadata-duration original-file-metadata))) + (bitrate (prepare-for-db (metadata-bitrate original-file-metadata))) + (insert-query (make-insert +table-attachment+ + (:id + :type + :url + :preview-url + :remote-url + :text-url + :width + :height + :frame-rate + :duration + :bitrate + :description + :blurhash + :status-id) + (id + actual-attachment-type + url + preview-url + remote-url + text-url + width + height + frame-rate + duration + bitrate + description + blurhash + status-id))) + (attachment-exists-p (fetch-single (select :* + (from +table-attachment+) + (where (:and (:= :status-id status-id) + (:= :id id))))))) + (when (not attachment-exists-p) (query insert-query))))) (defmacro insert-or-update (table keys values) diff --git a/src/thread-window.lisp b/src/thread-window.lisp index a97e916..70675cf 100644 --- a/src/thread-window.lisp +++ b/src/thread-window.lisp @@ -780,14 +780,16 @@ db:renumber-timeline-message-index." (refresh-event (make-instance 'program-events:refresh-conversations-window-event))) (multiple-value-bind (reblogged-status-body reblogged-status-attachments) (reblogged-data fields) - (let ((actual-body (if (string= body reblogged-status-body) - body - (strcat body reblogged-status-body)))) + (let ((actual-body (if (string= body reblogged-status-body) + body + (strcat body reblogged-status-body))) + (actual-attachments (if (string= attachments reblogged-status-attachments) + attachments + (strcat reblogged-status-attachments attachments)))) (setf (message-window:source-text *message-window*) (strcat header actual-body - reblogged-status-attachments - attachments)) + actual-attachments)) (db:mark-status-red-p timeline-type timeline-folder status-id) (resync-rows-db object :redraw t) (program-events:push-event refresh-event)