Skip to:
Content

BuddyPress.org

Opened 11 years ago

Closed 7 years ago

#5395 closed enhancement (maybelater)

Notify everyone that comments on an activity update of new comments

Reported by: terraling's profile terraling Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Activity Keywords: 2nd-opinion, trac-tidy-2018
Cc:

Description

On my site I don't have nested BuddyPress comments in the activity stream and it threw up an issue that I've resolved and thought I'd share here in case it is useful.

Jack posts a status update.
Jill comments on Jack's update (Jack gets an email notice)
John chimes in and comments on Jack's update (Jack gets an email notice, Jill doesn't)
Jack comments to both of them with a reply to his own update (no-one gets an email notice)

That's how people are familiar with commenting on status updates from FB.

If Jack responds individually to each with the nested comments, John and Jill are unaware of the other's ongoing conversations with Jack, although they might expect to be kept in the loop.

I'm not doing anything fancy with notifications, but have reworked bp_activity_new_comment_notification so that everyone in a conversation thread (apart from the person posting the comment) gets an email notice.

It now looks something like this:

function my_activity_new_comment_notification( $comment_id, $params ) {
	global $wpdb;
	// Set some default parameters
	$activity_id = 0;
	$parent_id   = 0;

	extract( $params );

	$conversation_ids = $wpdb->get_results( "
		SELECT DISTINCT user_id
		FROM wp_bp_activity
		WHERE item_id = " . $activity_id . "
		AND user_id != " . $user_id	); // list of user_ids of anyone involved in the conversation except current commenter

	$poster_name   = bp_core_get_user_displayname( $user_id );
	$thread_link   = bp_activity_get_permalink( $activity_id );
	$poster_name = stripslashes( $poster_name );
	$content = bp_activity_filter_kses( stripslashes($content) );

	if ( !empty($conversation_ids) ) { //to rule out someone talking to themselves
		foreach ($conversation_ids as $conversation_id) {
			// Set up and send the message
			$ud      = bp_core_get_core_userdata( $conversation_id->user_id );
			$to      = $ud->user_email;
			$subject = bp_get_email_subject( array( 'text' => sprintf( __( '%s replied to one of your updates', 'buddypress' ), $poster_name ) ) );
			$message = sprintf( __(
	'%1$s replied to one of your updates:

	"%2$s"

	To view your original update and all comments, log in and visit: %3$s

	---------------------
	', 'buddypress' ), $poster_name, $content, $thread_link );

			/* Send the message */
			wp_mail( $to, $subject, $message );
			do_action( 'bp_activity_sent_reply_to_update_email', $original_activity->user_id, $subject, $message, $comment_id, $commenter_id, $params );
		}
	}
}

I'll have to re-work in notification settings etc., but it's a start.

Attachments (1)

5395.patch (12.6 KB) - added by boonebgorges 11 years ago.

Download all attachments as: .zip

Change History (12)

#1 @terraling
11 years ago

I'll just toss in here that I had to tweak the messages so that they say something like:

"Jack commented on their update",
"Jill commented on Jack's update", or
"John commented on your update".

Code then looks like:

function my_activity_new_comment_notification( $comment_id, $params ) {
	global $wpdb;
	// Set some default parameters
	$activity_id = 0;
	$parent_id   = 0;
	extract( $params );

	$conversation_ids = $wpdb->get_results( "
		SELECT DISTINCT user_id
		FROM wp_bp_activity
		WHERE item_id = " . $activity_id . "
		AND user_id != " . $user_id	); // list of user_ids of anyone involved in the conversation except current commenter

	$original_activity = new BP_Activity_Activity( $activity_id );
	$op = $original_activity->user_id;
	$op_name = bp_core_get_user_displayname( $op );

	$poster_name   = bp_core_get_user_displayname( $user_id );
	$thread_link   = bp_activity_get_permalink( $activity_id );
	$poster_name = stripslashes( $poster_name );
	$content = bp_activity_filter_kses( stripslashes($content) );

	if ( $op == $user_id ) { // is it the OP commenting on their own update?
		$notice = sprintf( __( "%s commented on their update", "buddypress" ), $poster_name );
	} else {
		$notice = sprintf( __( "%s commented on %s's update", "buddypress" ), $poster_name, $op_name );
	}
	if ( !empty($conversation_ids) ) { //to rule out someone talking to themselves
		foreach ($conversation_ids as $conversation_id) {
			// Set up and send the message
			$ud      = bp_core_get_core_userdata( $conversation_id->user_id );
			$to      = $ud->user_email;
			if ( $conversation_id == $op ) {
				$notice = sprintf( __( "%s commented on your update", "buddypress" ), $poster_name );
			}
			$subject = bp_get_email_subject( array( 'text' => $notice ) );
			$message = $notice . ":\r\n\r\n" . sprintf( __(
'"%1$s"

To view the original update and all comments visit: %2$s
', 'buddypress' ), $content, $thread_link );

			/* Send the message */
			wp_mail( $to, $subject, $message );
			do_action( 'bp_activity_sent_reply_to_update_email', $original_activity->user_id, $subject, $message, $comment_id, $commenter_id, $params );
		}
	}
}

#2 @boonebgorges
11 years ago

  • Component changed from Core to Activity
  • Keywords 2nd-opinion added

This is a pretty cool idea.

I worked up a more usable patch. I haven't really tested it much, so ymmv. But it shows the general strategy I'd take. See 5395.patch.

  • created a separate function bp_activity_get_thread_participants() to get the participants. I was able to do this without introducing new SQL queries.
  • Adjust the logic in the existing bp_activity_new_comment_notification() for complete backpat.

There are a couple aspects I'm unsure about, or need more work.

  1. I'm using the single 'notification_activity_new_reply' setting for all notification types. We might want something more fine-grained, in which case we'd need another setting section.
  2. This is going to result in lots more email for people in some cases. We might want per-thread muting. Muted topics could be stored in usermeta. We'd then need to have UI to show whether you're subscribed/not subscribed to a given thread. This gets complicated fast (see buddypress-group-email-subscription)
  3. In some cases, this could result in sending lots of emails, if threads are very long. Not sure how big a problem this is in general. But this'd be the first place in BP (to my knowledge) where we attempt to send an email to more than a person or two at a time.

Feedback welcome.

@boonebgorges
11 years ago

#3 @terraling
11 years ago

With WP comments where a number of people are responding to a blog post, say, the comment threads may be discreet and cross-notifications are not necessarily required.

But, for me, at least, the BP activity stream is more like commenting on facebook status updates, where all commenters may expect to be in the loop. Maybe not always, and the FB solution is to allow users to opt-out of notifications on a per-thread basis (i.e. it's not in the settings, it's a discreet button somewhere alongside the original status update).

The easiest way to offer an opt-out without complex UI would be to simply add a link in the email notification itself ("To unsubscribe to comments in this thread click here").

On my own site when it goes live soon I'll just have to see how people respond, and add fine-grained controls if it seems necessary -- unless it's already added to core ;-)

#4 @boonebgorges
11 years ago

Marked #5430 as duplicate.

#5 @DJPaul
11 years ago

JJJ discovered in a previous bbPress commit than BCC'ing a bunch of people to a related message is a much better idea than sending an individual email to each person -- it puts one email through your email queue, instead of 'n'.

As Boone says, this is an interesting idea; I'm hesitant to punt it to FR at this stage because it has a recent-ish patch attached and has been reviewed. Putting it into 2.1 so we can revisit how we might do this and milestone it accordingly.

#6 @DJPaul
11 years ago

  • Milestone changed from Awaiting Review to 2.1

#7 @DJPaul
10 years ago

  • Milestone changed from 2.1 to 2.2

#8 @DJPaul
10 years ago

  • Milestone changed from 2.2 to 2.3

#9 @DJPaul
10 years ago

  • Milestone changed from 2.3 to Future Release

#10 @DJPaul
7 years ago

  • Keywords trac-tidy-2018 added

We're closing this ticket because it has not received any contribution or comments for at least two years. We have decided that it is better to close tickets that are good ideas, which have not gotten (or are unlikely to get) contributions, rather than keep things open indefinitely. This will help us share a more realistic roadmap for BuddyPress with you.

Everyone very much appreciates the time and effort that you spent sharing your idea with us. On behalf of the entire BuddyPress team, thank you.

If you feel strongly that this enhancement should still be added to BuddyPress, and you are able to contribute effort towards it, we encourage you to re-open the ticket, or start a discussion about it in our Slack channel. Please consider that time has proven that good ideas without contributions do not get built.

For more information, see https://bpdevel.wordpress.com/2018/01/21/our-awaiting-contributions-milestone-contains/
or find us on Slack, in the #buddypress channel: https://make.wordpress.org/chat/

#11 @DJPaul
7 years ago

  • Milestone Awaiting Contributions deleted
  • Resolution set to maybelater
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.