FriendsOfFlarum / follow-tags

Follow tags and be notified of new discussions and replies
MIT License
10 stars 11 forks source link

[Feature Request] Ability to notify new replies even if the last post wasn't read #32

Open oscarotero opened 3 years ago

oscarotero commented 3 years ago

As I can see in this code: https://github.com/FriendsOfFlarum/follow-tags/blob/master/src/Jobs/SendNotificationWhenReplyIsPosted.php#L67 the email notification is sent only to users who view the last post of the discussion, right?

There are many users who read the replies in the email notification, so they don't enter in the forum and stop receiving more updates of the discussion. I'd love to have an option in the plugin to change this behavior and send the emails to all subscribed users, no matter if they read the last post.

xmarcux commented 1 year ago

I have made a hackish solution for notification mails even if user has not read the post. User will receive mails for all replies on post even if post is not read if "Lurk" has been chosen for the tag. I include a patch file if somebody else is interested: obsess.txt

To run the patch file:

What is changed is the sql that searches for users in file: SendNotificationWhenReplyIsPosted.php on line: 62-74 The replacement sql is:

        $notify = User::select('users.*')
            ->where('users.id', '!=', $this->post->user_id)
            ->join('tag_user', 'tag_user.user_id', '=', 'users.id')
            ->whereIn('tag_user.tag_id', $tagIds->all())
            ->whereIn('tag_user.subscription', ['lurk'])
            ->get()
            ->reject(function (User $user) use ($tags) {
                return $tags->map->stateFor($user)->map->subscription->contains('ignore')
                    || !$this->post->isVisibleTo($user);
            });

It starts on this line: https://github.com/FriendsOfFlarum/follow-tags/blob/master/src/Jobs/SendNotificationWhenReplyIsPosted.php#L62

As I am not a php developer I will not be able create a full change for this feature and add a merge request. Hope this could be useful to somebody else.