From f1d91643e7925621ea9a4881a02e0eedbcde0398 Mon Sep 17 00:00:00 2001 From: sid597 Date: Wed, 17 Aug 2022 22:03:55 +0530 Subject: [PATCH 1/5] bug fix - don't get notified if someone comments on a block you authored - see no. of messages on inbox icom --- src/cljs/athens/views/comments/core.cljs | 20 ++++++++++++++++--- .../athens/views/notifications/popover.cljs | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/cljs/athens/views/comments/core.cljs b/src/cljs/athens/views/comments/core.cljs index 49ee168a21..013ca597f4 100644 --- a/src/cljs/athens/views/comments/core.cljs +++ b/src/cljs/athens/views/comments/core.cljs @@ -183,6 +183,13 @@ (empty? user-member?) (concat (add-new-member-or-subscriber-to-thread db thread-uid "athens/comment-thread/members" userpage)) (empty? user-subscriber?) (concat (add-new-member-or-subscriber-to-thread db thread-uid "athens/comment-thread/subscribers" userpage))))) +(defn add-block-author-as-member-and-subscriber + [db thread-uid userpage] + (let [user-member? (user-in-thread-as? db "athens/comment-thread/members" thread-uid userpage) + user-subscriber? (user-in-thread-as? db "athens/comment-thread/subscribers" thread-uid userpage)] + (cond-> [] + (empty? user-member?) (concat (add-new-member-or-subscriber-to-thread db thread-uid "athens/comment-thread/members" userpage)) + (empty? user-subscriber?) (concat (add-new-member-or-subscriber-to-thread db thread-uid "athens/comment-thread/subscribers" userpage))))) ;; Notifications @@ -271,7 +278,7 @@ :comment/write-comment ;; There is a sequence for how the operations are to be executed because for some ops, information ;; related to prior op is needed. The sequence is: - ;; - Create a thread if it does not exist with the author as member and subscriber to the thread. + ;; - Create a thread if it does not exist with the block and the comment author as member and subscriber to the thread. ;; - Add comment to the thread. ;; - If the comment contains mentions to users not subscribed to the thread, then add them as subscribers and members. ;; - If this is not the first comment on the thread then add the author of comment as subscriber and member to the thread. @@ -281,7 +288,10 @@ (let [thread-exists? (get-comment-thread-uid @db/dsdb uid) thread-uid (or thread-exists? (common.utils/gen-block-uid)) - + block-author (-> (common-db/get-block-document @db/dsdb [:block/uid uid]) + :block/create + :event/auth + :presence/id) {thread-members-uid :members-prop-uid thread-subs-uid :subscribers-prop-uid new-thread-op :new-thread-op} (when (not thread-exists?) @@ -296,7 +306,10 @@ add-mentions-in-str-as-mem-subs-op (add-mentioned-users-as-member-and-subscriber @db/dsdb thread-members-uid thread-subs-uid comment-string thread-uid thread-exists? author) add-author-as-mem-or-subs (when thread-exists? (add-user-as-member-or-subscriber? @db/dsdb thread-uid (str "[[@" author "]]"))) - + add-block-author-as-sub-and-mem (when (not thread-exists?) + (concat [] + (add-new-member-or-subscriber-to-prop-uid @db/dsdb thread-members-uid (str "[[@" block-author "]]")) + (add-new-member-or-subscriber-to-prop-uid @db/dsdb thread-subs-uid (str "[[@" block-author "]]")))) notification-message (str "**((" uid "))**" "\n" "*[[@" author "]] commented: " comment-string "*") notification-op (create-notification-op-for-comment @db/dsdb uid thread-uid author comment-string notification-message comment-uid) @@ -304,6 +317,7 @@ new-thread-op [comment-op] add-mentions-in-str-as-mem-subs-op + add-block-author-as-sub-and-mem notification-op) comment-notif-op (composite/make-consequence-op {:op/type :comment-notif-op} diff --git a/src/cljs/athens/views/notifications/popover.cljs b/src/cljs/athens/views/notifications/popover.cljs index ea023c057a..dbe7a79c78 100644 --- a/src/cljs/athens/views/notifications/popover.cljs +++ b/src/cljs/athens/views/notifications/popover.cljs @@ -130,7 +130,7 @@ (when (.. e -shiftKey) (rf/dispatch [:right-sidebar/open-item [:node/title user-page-title]]))) :icon (r/as-element [:> BellFillIcon])}] - (when (> 0 num-notifications) + (when (> num-notifications 0) [:> Badge {:position "absolute" :bg "highlight" :color "highlightContrast" From 1484fa7d85db67c6cc2b69a7f097ff839ab934cf Mon Sep 17 00:00:00 2001 From: sid597 Date: Wed, 17 Aug 2022 22:15:00 +0530 Subject: [PATCH 2/5] show comments box when block is closed --- src/cljs/athens/views/blocks/core.cljs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cljs/athens/views/blocks/core.cljs b/src/cljs/athens/views/blocks/core.cljs index 293d82cb72..a8417273f8 100644 --- a/src/cljs/athens/views/blocks/core.cljs +++ b/src/cljs/athens/views/blocks/core.cljs @@ -493,7 +493,6 @@ ;; Show comments when the toggle is on (when (and @show-comments? - open (or @show-textarea? (comments/get-comment-thread-uid @db/dsdb uid))) [inline-comments/inline-comments (comments/get-comments-in-thread @db/dsdb (comments/get-comment-thread-uid @db/dsdb uid)) uid false]) From 54109790f8da7ea405e739bd697de2b387643ac3 Mon Sep 17 00:00:00 2001 From: sid597 Date: Wed, 17 Aug 2022 22:24:07 +0530 Subject: [PATCH 3/5] style and carve fix --- src/cljs/athens/views/comments/core.cljs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/cljs/athens/views/comments/core.cljs b/src/cljs/athens/views/comments/core.cljs index 013ca597f4..21fe111f0f 100644 --- a/src/cljs/athens/views/comments/core.cljs +++ b/src/cljs/athens/views/comments/core.cljs @@ -183,13 +183,6 @@ (empty? user-member?) (concat (add-new-member-or-subscriber-to-thread db thread-uid "athens/comment-thread/members" userpage)) (empty? user-subscriber?) (concat (add-new-member-or-subscriber-to-thread db thread-uid "athens/comment-thread/subscribers" userpage))))) -(defn add-block-author-as-member-and-subscriber - [db thread-uid userpage] - (let [user-member? (user-in-thread-as? db "athens/comment-thread/members" thread-uid userpage) - user-subscriber? (user-in-thread-as? db "athens/comment-thread/subscribers" thread-uid userpage)] - (cond-> [] - (empty? user-member?) (concat (add-new-member-or-subscriber-to-thread db thread-uid "athens/comment-thread/members" userpage)) - (empty? user-subscriber?) (concat (add-new-member-or-subscriber-to-thread db thread-uid "athens/comment-thread/subscribers" userpage))))) ;; Notifications From b3f3c93732d8c9c7b8ba2207c61f90e23171ce67 Mon Sep 17 00:00:00 2001 From: sid597 Date: Thu, 18 Aug 2022 10:20:10 +0530 Subject: [PATCH 4/5] fix: notification for block author and don't double-add user when they comment on their own block --- src/cljs/athens/views/comments/core.cljs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/cljs/athens/views/comments/core.cljs b/src/cljs/athens/views/comments/core.cljs index 21fe111f0f..7051666e8f 100644 --- a/src/cljs/athens/views/comments/core.cljs +++ b/src/cljs/athens/views/comments/core.cljs @@ -299,18 +299,23 @@ add-mentions-in-str-as-mem-subs-op (add-mentioned-users-as-member-and-subscriber @db/dsdb thread-members-uid thread-subs-uid comment-string thread-uid thread-exists? author) add-author-as-mem-or-subs (when thread-exists? (add-user-as-member-or-subscriber? @db/dsdb thread-uid (str "[[@" author "]]"))) - add-block-author-as-sub-and-mem (when (not thread-exists?) - (concat [] - (add-new-member-or-subscriber-to-prop-uid @db/dsdb thread-members-uid (str "[[@" block-author "]]")) - (add-new-member-or-subscriber-to-prop-uid @db/dsdb thread-subs-uid (str "[[@" block-author "]]")))) notification-message (str "**((" uid "))**" "\n" "*[[@" author "]] commented: " comment-string "*") + [add-block-author-as-sub-and-mem + block-author-notification-op] (when (and + (not= author block-author) + (not thread-exists?)) + [(concat [] + (add-new-member-or-subscriber-to-prop-uid @db/dsdb thread-members-uid (str "[[@" block-author "]]")) + (add-new-member-or-subscriber-to-prop-uid @db/dsdb thread-subs-uid (str "[[@" block-author "]]"))) + (create-notification-op-for-users @db/dsdb uid [(str "[[@" block-author "]]")] author notification-message comment-uid "athens/notification/type/comment") ()]) notification-op (create-notification-op-for-comment @db/dsdb uid thread-uid author comment-string notification-message comment-uid) ops (concat add-author-as-mem-or-subs new-thread-op [comment-op] add-mentions-in-str-as-mem-subs-op add-block-author-as-sub-and-mem + block-author-notification-op notification-op) comment-notif-op (composite/make-consequence-op {:op/type :comment-notif-op} From b2402010133cea73ab68a8532608f56eea3ec2d4 Mon Sep 17 00:00:00 2001 From: sid597 Date: Thu, 18 Aug 2022 10:26:51 +0530 Subject: [PATCH 5/5] style fix --- src/cljs/athens/views/comments/core.cljs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cljs/athens/views/comments/core.cljs b/src/cljs/athens/views/comments/core.cljs index 7051666e8f..34a3a61e9c 100644 --- a/src/cljs/athens/views/comments/core.cljs +++ b/src/cljs/athens/views/comments/core.cljs @@ -303,8 +303,8 @@ "*[[@" author "]] commented: " comment-string "*") [add-block-author-as-sub-and-mem block-author-notification-op] (when (and - (not= author block-author) - (not thread-exists?)) + (not= author block-author) + (not thread-exists?)) [(concat [] (add-new-member-or-subscriber-to-prop-uid @db/dsdb thread-members-uid (str "[[@" block-author "]]")) (add-new-member-or-subscriber-to-prop-uid @db/dsdb thread-subs-uid (str "[[@" block-author "]]")))