# Editing posts cause notification

**URL:** <https://meta.discourse.org/t/editing-posts-cause-notification/104873>\
**Category:** Support\
**Created:** [December 22, 2018, 12:34am UTC](https://meta.discourse.org/t/editing-posts-cause-notification/104873 "2018-12-22T00:34:51Z")\
**Posts on this page:** 1\
**Showing post:** 25

<div class="post-metadata">

**Author:** ![Grayden\_Shand](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/grayden_shand/32/166586_2.png) [@Grayden\_Shand](https://meta.discourse.org/u/Grayden_Shand)\
**Post date:** [April 23, 2021, 4:33pm UTC](https://meta.discourse.org/t/editing-posts-cause-notification/104873/25 "2021-04-23T16:33:17Z")

</div>

I don’t want to make anything too complex.

I was looking through some of the code for this (thanks @tshenry for the link), and it doesn’t seem like it needs to be that complicated.

The group mentions are currently being triggered [here](https://github.com/discourse/discourse/blob/5bec0e57637ed4351300ad17808b89b585df9568/app/services/post_alerter.rb#L78) (L78-80). [The `expand_group_mentions()` function](https://github.com/discourse/discourse/blob/5bec0e57637ed4351300ad17808b89b585df9568/app/services/post_alerter.rb#L496) is a generator responsible for spitting out the users who should get group mention notifications (while respecting policies like the `SiteSetting.max_users_notified_per_group_mention`).

That seems like a natural place to put this logic.

In the `create_notification` function, [we suppress notifications for anyone who has already received a notification of the same type](https://github.com/discourse/discourse/blob/5bec0e57637ed4351300ad17808b89b585df9568/app/services/post_alerter.rb#L359). This is why editing a post with a group mention triggers a notification for new group members – a notification is actually generated for all users in the group, but it is then suppressed for people who already got the notification.

I’m suggesting something similar, by updating the `expand_group_mentions()` function to also filter out groups that have a record in the `group_mentions` table.

Something like (please excuse my lack of knowledge about ruby syntax)

```plaintext
  def expand_group_mentions(groups, post)
    return unless post.user && groups

    Group.mentionable(post.user, include_public: false).where(id: groups.map(&:id)).each do |group|
      next if group.user_count >= SiteSetting.max_users_notified_per_group_mention

      # Add check for groups already mentioned
      next if GroupMentions().where(group_id: group.id, post_id: post.id).length > 0

      yield group, group.users
    end

  end

```

This does not do anything for the JIT warning though.

Trying to help solve this, let me know if I’m just being annoying… 🙂

---

_[View the full topic](https://meta.discourse.org/t/editing-posts-cause-notification/104873)._
