Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark comments as read #32775

Merged
merged 2 commits into from
May 19, 2023
Merged

Mark comments as read #32775

merged 2 commits into from
May 19, 2023

Conversation

Pytal
Copy link
Member

@Pytal Pytal commented Jun 9, 2022

Fix #23877

Calls the existing DAV comments read handler

public function propPatch(PropPatch $propPatch) {
$propPatch->handle(self::PROPERTY_NAME_READ_MARKER, [$this, 'setReadMarker']);
}

Run the following SQL query to observe updates to the database

select *
from oc_comments_read_markers
order by marker_datetime

@Pytal Pytal added this to the Nextcloud 25 milestone Jun 9, 2022
@Pytal Pytal self-assigned this Jun 9, 2022
@Pytal Pytal force-pushed the fix/23877/unread-comments branch 2 times, most recently from 2e26c68 to 6824eda Compare June 10, 2022 23:33
@Pytal Pytal requested review from artonge, skjnldsv, a team and szaimen and removed request for a team June 10, 2022 23:36
@Pytal Pytal added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Jun 10, 2022
@Pytal Pytal marked this pull request as ready for review June 10, 2022 23:37
@Pytal Pytal added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Jun 10, 2022
@Pytal Pytal marked this pull request as draft June 10, 2022 23:59
@Pytal Pytal force-pushed the fix/23877/unread-comments branch from 6824eda to b963f7b Compare June 27, 2022 23:03
@Pytal Pytal added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Jun 27, 2022
@Pytal Pytal marked this pull request as ready for review June 27, 2022 23:31
Copy link
Member

@skjnldsv skjnldsv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be much more than just the comments as read?
Why can't we just watch the Comments component and handle read on scroll/focus or something? I am not super fond of this API change for comments only? Or maybe there are other usages this æctive handler might have on other tabs?

@Pytal
Copy link
Member Author

Pytal commented Jun 28, 2022

The active handler, essentially the focus handler, seemed appropriate and would fit alongside the existing mount, update, and destroy handler API, although it may not be worth it if it's only used in comments

There are two ways then

  1. Add the active handler to the sidebar tab API which could also be used by other tabs
  2. Add https://github.com/Akryum/vue-observe-visibility as a dependency and do something like
diff --git a/apps/comments/src/services/CommentsInstance.js b/apps/comments/src/services/CommentsInstance.js
index f5263f35c3..4a9c90d220 100644
--- a/apps/comments/src/services/CommentsInstance.js
+++ b/apps/comments/src/services/CommentsInstance.js
@@ -24,6 +24,7 @@ import { getLoggerBuilder } from '@nextcloud/logger'
 import { translate as t, translatePlural as n } from '@nextcloud/l10n'
 import CommentsApp from '../views/Comments'
 import Vue from 'vue'
+import VueObserveVisibility from 'vue-observe-visibility'
 
 const logger = getLoggerBuilder()
        .setApp('comments')
@@ -61,6 +62,8 @@ export default class CommentInstance {
                        },
                })
 
+               Vue.use(VueObserveVisibility)
+
                // Init Comments component
                const View = Vue.extend(CommentsApp)
                return new View(options)
diff --git a/apps/comments/src/views/Comments.vue b/apps/comments/src/views/Comments.vue
index fbe81d23b9..65e77c8f54 100644
--- a/apps/comments/src/views/Comments.vue
+++ b/apps/comments/src/views/Comments.vue
@@ -21,7 +21,9 @@
   -->
 
 <template>
-       <div class="comments" :class="{ 'icon-loading': isFirstLoading }">
+       <div class="comments"
+               :class="{ 'icon-loading': isFirstLoading }"
+               v-observe-visibility="onVisibilityChange">
                <!-- Editor -->
                <Comment v-bind="editorData"
                        :auto-complete="autoComplete"
@@ -127,6 +129,17 @@ export default {
        },
 
        methods: {
+               async onVisibilityChange(isVisible) {
+                       if (isVisible) {
+                               try {
+                                       await markCommentsAsRead(this.commentsType, this.ressourceId, new Date())
+                                       emit('comments:comments:read', { ressourceId: this.ressourceId })
+                               } catch (e) {
+                                       showError(e.message || t('comments', 'Error marking comments as read'))
+                               }
+                       }
+               },
+
                /**
                 * Update current ressourceId and fetch new data
                 *

What do you think @skjnldsv?

@Pytal
Copy link
Member Author

Pytal commented Jul 4, 2022

What do you think about the active vs. observability approaches above @artonge?

@skjnldsv
Copy link
Member

skjnldsv commented Jul 5, 2022

Sorry, I forgot t reply.
My concerns is aboutover-engineering this.

Do we actually require to check for focus?
Can't we just assume that the activeTab being set to true means the tab is displayed and the comment read?

@artonge
Copy link
Contributor

artonge commented Jul 5, 2022

What do you think about the active vs. observability approaches above @ artonge?

I don't know, what is Talk doing to check if a message is read? Maybe we can reuse the logic? In any case I would choose what makes a consistent feeling.
For me, it is more a UX question than an engineering one.

@Pytal
Copy link
Member Author

Pytal commented Jul 5, 2022

Do we actually require to check for focus? Can't we just assume that the activeTab being set to true means the tab is displayed and the comment read?

The active handler is handling the "activeTab being set to true", if there is somewhere else in the code to handle "activeTab being set to true" cleanly without the API addition I cannot grep it currently and so I am open to any suggestions @skjnldsv

The hacky way without the API addition would be to watch activeTab in https://github.com/nextcloud/server/blob/8b23c1c6772afdd4a1709bdb85cf3b88c5b5a6a5/apps/files/src/views/Sidebar.vue and call markCommentsAsRead() if activeTab === 'comments' which is outside the scoped sidebar tab API system and therefore not a viable solution

I don't know, what is Talk doing to check if a message is read? Maybe we can reuse the logic? In any case I would choose what makes a consistent feeling.
For me, it is more a UX question than an engineering one.

Talk is invoking it on scroll, see https://github.com/nextcloud/spreed/blob/d9b7a3f53bb40fadc0295a52b4e0f52605e179f5/src/components/MessagesList/MessagesList.vue#L421-L424 -> https://github.com/nextcloud/spreed/blob/d9b7a3f53bb40fadc0295a52b4e0f52605e179f5/src/components/MessagesList/MessagesList.vue#L694-L757, which would only add complexity compared to the boolean check of marking comments as read on active

The implementation of the active handler and other higher up changes in the current state of the PR was driven by responsiveness requirements for UX so that the unread comments icon disappears when comments are read instead of having to reload the page

@skjnldsv skjnldsv mentioned this pull request Aug 12, 2022
@marcelklehr
Copy link
Member

Hello everyone,

I was assigned maintainer of the comments app recently.

@Pytal I think going forward with the visbilty observer is the best option!

@Pytal Pytal force-pushed the fix/23877/unread-comments branch from b963f7b to ccfb772 Compare May 2, 2023 01:59
@Pytal Pytal requested review from skjnldsv and marcelklehr May 2, 2023 02:00
@Pytal Pytal force-pushed the fix/23877/unread-comments branch from ccfb772 to 78742b5 Compare May 3, 2023 01:43
@Pytal

This comment was marked as outdated.

@Pytal Pytal force-pushed the fix/23877/unread-comments branch from 78742b5 to 006538b Compare May 3, 2023 01:51
@Pytal
Copy link
Member Author

Pytal commented May 3, 2023

/compile amend /

@nextcloud-command nextcloud-command force-pushed the fix/23877/unread-comments branch 2 times, most recently from e115125 to c1679df Compare May 3, 2023 02:01
This was referenced May 3, 2023
@blizzz blizzz mentioned this pull request May 17, 2023
@marcelklehr
Copy link
Member

/rebase

@marcelklehr marcelklehr force-pushed the fix/23877/unread-comments branch from c1679df to 554c508 Compare May 19, 2023 09:27
@marcelklehr
Copy link
Member

/compile

Signed-off-by: Christopher Ng <[email protected]>
Signed-off-by: nextcloud-command <[email protected]>
@marcelklehr marcelklehr force-pushed the fix/23877/unread-comments branch from 88cab51 to 94af306 Compare May 19, 2023 10:02
@marcelklehr
Copy link
Member

/compile

Signed-off-by: nextcloud-command <[email protected]>
Copy link
Contributor

@miaulalala miaulalala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM didn't test but PROPPATCH looks fine

@marcelklehr marcelklehr merged commit b3e8e0c into master May 19, 2023
@marcelklehr marcelklehr deleted the fix/23877/unread-comments branch May 19, 2023 12:39
@blizzz blizzz modified the milestones: Nextcloud 27, Nextcloud 28 May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Comments are not marked as read
8 participants