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

[Comment] Mention @discussion or @group to represent all members of the thread or group #10934

Open
wants to merge 87 commits into
base: master
Choose a base branch
from

Conversation

jerinkc
Copy link

@jerinkc jerinkc commented Jul 3, 2024

Mentioning @discussion in the comment will notify all members of the discussion.
Mentioning @group in the comment will notify all members of the group.

Closes #8148

jerinkc added 21 commits July 3, 2024 16:43
… changes related to mentioning thread with the help of discussion
…us changes of adding collections as a member to group
Remove forbidden name validation for username
comment_spec update
Name change: COLLECTIONS -> MENTIONABLE_COLLECTIONS
@jerinkc jerinkc changed the title Mention @thread or @group to represent all members of the thread or group [WIP] Mention @thread or @group to represent all members of the thread or group Jul 3, 2024
@robguthrie
Copy link
Member

Hi @jerinkc - it's really wonderful to see you've made a PR to start on this feature. Thank you. I've not seen a loomio feature PR in years.

With the greatest respect, I don't think it's going in the right direction currently - I can understand why, this is a super challenging feature to add, not only is the existing mentioning code complex because we support both markdown and html comment formats, it has some legacy behavior support included in it too.

Some tips I can offer:

  • have a look at app/services/announcement_service.rb we have the key words that reference group and discussion_group (thread) in there for when you invite people to a discussion thread.
  • have a look at app/models/concerns/has_mentions.rb and make a new file app/models/concerns/has_audience_mentions.rb copying the style in has_mentions but looking for 'group' and 'discussion_group' rather than usernames.
  • Then create a clone of app/models/concerns/events/notify/mentions.rb called .../notify/audiences.rb which looks for mentioned_audiences and sends app/models/events/comment_announced.rb (also a new file)

Does that make any sense? You're free to explore the approach however you like, but this is how I recommend you look at it

@jerinkc
Copy link
Author

jerinkc commented Jul 5, 2024

Hey @robguthrie ,

Thank you for your quick review and insightful comment on the current approach. I genuinely appreciate your feedback!

I’ll take the suggested changes into account and try to implement them.

@jerinkc
Copy link
Author

jerinkc commented Jul 7, 2024

Hey @robguthrie,

Thank you once again for the tips! The approach is perfectly clear to me. I want to get your opinion on a couple of additional points:

  • In your previous comment, you mentioned ‘discussion_group’ instead of ‘thread.’ Should I use the term ‘discussion_group’ instead of ‘thread’ throughout the implementation?

  • Regarding the current approach, I’ve used two users to represent the audience in the database. I find this helpful when listing users for mentions in the UI. If this approach is acceptable, I plan to use these users to store notifications for audiences.

@robguthrie
Copy link
Member

robguthrie commented Jul 7, 2024

Hi @jerinkc

  • On the server side we tend to use the term discussion rather than thread. discussion_group or discussion would be best.
  • I don't think you should continue with the approach of pushing this through a fake user account. It would be better to list "audiences" with users when mentioning, then with the separate has_audience_mentions concerns you detect the use of the discussion or group token. The has_mentions concern will just ignore this.

I suggest you ignore the frontend stuff for now. Write some tests that create a comment with a <span data-mention-id="group"> in them, then use that to build the has_audience_mention concern, which creates it's own notification type. It will share a similar pattern to has_mentions but be parallel to it, and the has_mentions probably won't need to change.

@jerinkc
Copy link
Author

jerinkc commented Jul 30, 2024

Hey @robguthrie,

I have added more changes along with the internationalization feature.

Also, should I work with the UI part here or would you prefer it in another PR?

@robguthrie
Copy link
Member

You can put the UI stuff in here too, please.

Sorry there was a misunderstanding about how to handle translation. The code/server side should just be english in all cases - it will be surprisingly simple to translate just the visible text with the existing translation library in the UI only.

@jerinkc
Copy link
Author

jerinkc commented Jul 31, 2024

@robguthrie

I understand you want to apply translation only to the visible part of the UI. Which is for the UI code it should be something like,

<p>Hey, 
    <span class=\"mention\"
        data-mention-id=\"discussion\"
         label=\"discussion\">
         @diskussion
    </span></p>

So the server will recognize when a discussion is mentioned.

If internationalization applies to the markdown format, how will it detect that the incoming message has mentioned audiences without the current configuration? I think we should retain the current translating functionality(including back_translate method) and only apply it to the markdown format. What do you think?

@robguthrie
Copy link
Member

Oh Yeah. That's right, it will be necessary for markdown formatted content. Thanks for thinking of that.

@jerinkc
Copy link
Author

jerinkc commented Aug 22, 2024

@robguthrie Take a look whenever you get a chance. Thanks!

@robguthrie
Copy link
Member

Sorry I've taken so long to review this. Will run and test it tomorrow.
Can you tell me - do you think this is finished? Do you think there is any more work to do, and have you had the opportunity to deploy it and test it with users?

@jerinkc
Copy link
Author

jerinkc commented Sep 6, 2024

Hey,

It is done if it applies only to comments. I’ve tested it locally with multiple users, and everything is working smoothly.

Note: Translations for other languages are not included.

Here’s a quick demo: Video Link

@@ -714,6 +718,7 @@ en:
user_added_to_group: "%{actor} added you to the group: %{title}"
user_mentioned: "%{actor} mentioned you in: %{title}"
user_reminded: "%{actor} is reminding you to vote in: %{title}"
comment_announced: "%{actor} mentioned you in: %{title}"
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this should be more specific. What do you think about having two messages:
"%{actor} notified everyone in the group" and
"%{actor} notified everyone in the thread"

@robguthrie
Copy link
Member

Ok, I've given this a test run. It looks really promising! Well done.

image

I notice that you need to type @discussion to mention everyone in the thread.. The Loomio term is "thread" so I think it would make sense to use that as the keyword.

Also when I check the "Notified" button I see this:
image
Which is from notifying the group.. but there are no entries for notifying the thread. I'm not sure why that is.

I'll look more closely at it and get back to you

@jerinkc
Copy link
Author

jerinkc commented Sep 12, 2024

I missed the notification part during implementation, it has been added in the latest commits. Also, the UI now uses @thread instead of @discussion.

Screenshot 2024-09-10 at 11 28 22 PM Screenshot 2024-09-11 at 1 28 49 PM Screenshot 2024-09-10 at 11 28 41 PM

@robguthrie
Copy link
Member

Wow. It's really coming together now. There are two last things that need some attention..

Permissions.

Frontend:
Can you ensure that @thread and @group mention suggestions only show when the user is permitted to notify?
We need to call AbilityService.canNotifyGroup and AbilityService.canAnnounceDiscussion before adding the mention options to the list and presenting them to the user.

https://github.com/loomio/loomio/blob/master/vue/src/shared/services/ability_service.js#L135C3-L135C24

Backend:

To be secure we also need to authorize this on the back end. You can see an example of this here:

https://github.com/loomio/loomio/blob/master/app/extras/user_inviter.rb#L72

So you can call user.ability.authorize! :announce, discussion and user.ability.authorize! :announce, group on the back end to ensure the client is allowed to notify.

Education:
It would be good to explain what these options do, as people will see them and not know.. I wonder if we can put a subtitle in the suggestions list "Notify everyone in the group" under the @group, for example.

@jerinkc
Copy link
Author

jerinkc commented Oct 13, 2024

Hey, I have made the necessary changes. Also, I used user.ability.authorize! :notify, group instead of user.ability.authorize! :announce, group. Let me know if it works.

Screenshot 2024-10-13 at 12 58 25 PM Screenshot 2024-10-13 at 12 42 20 PM

@robguthrie
Copy link
Member

robguthrie commented Oct 13, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide a @all alias shorthand for notifying everyone about a reply
2 participants