Skip to:
Content

BuddyPress.org

Opened 7 years ago

Closed 6 years ago

#5327 closed defect (bug) (fixed)

bp_get_the_thread_recipients() is not displaying correctly

Reported by: colabsadmin Owned by: boonebgorges
Milestone: 2.2 Priority: normal
Severity: normal Version: 1.9.1
Component: Messages Keywords: needs-patch good-first-bug
Cc:

Description

When there are 5 or more participants of a message, the bp_get_the_thread_recipients() will include "you" in the recipient count. Either reduce the amount of recipients by 1 or possibly change the wording from recipient to participants and remove "and you".

Example. The following will displayed when there are 4 recipients plus "you" (so total of 5 people on the thread.)

“Conversation between 5 Recipients and you”
instead of
“Conversation between 4 Recipients and you”

Attachments (1)

5327.patch (6.6 KB) - added by joshshashaty 6 years ago.

Download all attachments as: .zip

Change History (11)

#1 @boonebgorges
7 years ago

  • Component changed from Core to Messaging
  • Milestone changed from Awaiting Review to 2.0

Ha, I never noticed this. Good find.

We could also say something like "Conversation between 5 recipients, including you".

Let's do one or the other for 2.0.

#2 @henry.wright
7 years ago

Hi boonebgorges

How about "5 participants in this conversation". I'm thinking an explicit reference to 'you' being in the convo isn't needed because if you can see the conversation then you'll know you're in it.

Alternatively, I built something a while ago for this which outputs the avatars of all of the participants in the thread if the number of members participating is less than 6. If more than 6 then it's just a line of text (pretty much what is in BP core now) to save space on the page.

function bp_the_thread_participant_avatars() {
    global $thread_template;
    
    $recipient_links = array();

    if ( count( $thread_template->thread->recipients ) >= 6 )
        return apply_filters( 'bp_the_thread_participant_avatars', sprintf( __( '%d participants', 'buddypress' ), count($thread_template->thread->recipients) ) );

    foreach( (array) $thread_template->thread->recipients as $recipient ) {
        
        $participant_name = bp_core_get_user_displayname( $recipient->user_id );
        $participant_username = bp_core_get_username( $recipient->user_id );
		
        if ( ! empty( $participant_username ) ) {
		
            $recipient_link = '<a href="/' . $participant_username .'/" title="' . $participant_name .'">' . bp_core_fetch_avatar( array( 'item_id' => $recipient->user_id, 'width' => 30, 'height' => 30, 'class' => 'avatar', 'title' => $participant_name, 'alt' => $participant_name ) ) . '</a>';
            $recipient_links[] = $recipient_link;
        }
    }
    return apply_filters( 'bp_the_thread_participant_avatars', implode( '', $recipient_links ) );
		
}

#3 @henry.wright
7 years ago

Looking at that - $recipient_link might need to be modified slightly as I was using root profiles when I wrote it :)

#4 @boonebgorges
7 years ago

  • Keywords needs-patch added
  • Milestone changed from 2.0 to 2.1

#5 @DJPaul
6 years ago

  • Keywords good-first-bug added

To fix this, I suggest the following:

  • Remove the < 5 handling from bp_get_the_thread_recipients().
  • Re-add that code around the second call to bp_get_the_thread_recipients() in bp-templates/bp-legacy/buddypress/members/single/messages/single.php.
    • Adjust the code you're adding to fix the localisation bug with the "%d Recipients" string; it should be using %s and number_format_i18n().
    • "Recipients" probably should be lower-cased.

I suggest moving the < 5 checks into the template because this feels like something a theme would want to control, rather than have to handle a hardcoded limit in BuddyPress core.

#6 @DJPaul
6 years ago

  • Milestone changed from 2.1 to 2.2

@joshshashaty
6 years ago

#7 @joshshashaty
6 years ago

Took @DJPaul suggestion and put the count logic in the template so people can have control over that number, also allowed them to modify the text in either situation where we want to list users with links or just the number of people in the message. Created new functions to support this, bp_get_thread_recipients_count(), bp_the_thread_recipients_list(), bp_get_thread_recipients_list() ... we left the old function (bp_get_the_thread_recipients) in case anyone is using the single.php template in their theme and modified it to use our new functions.

Props to @Clean-Cole for all the help on this patch (my first patch). Suggestions/thoughts welcome.

#8 @henry.wright
6 years ago

Hi joshshashaty

Just a thought on the recipient count conditional logic: 10 is quite a large number (displaying 9 recipient names on screen might take up a bit of space). Perhaps you could make the value filterable? For example:

$number = apply_filters( 'tag-blah', $number );

if ( $number <= bp_get_thread_recipients_count() ) :
...

#9 @joshshashaty
6 years ago

Ah, the patch should apply it using 5 as the number to check, should show that in my last commit in that patch... sorry about that! I was using 10 just to test. Putting that count check in the template will give people the ability to override it and use their own number in their own themes/child-themes if they want to, though.

#10 @boonebgorges
6 years ago

  • Owner set to boonebgorges
  • Resolution set to fixed
  • Status changed from new to closed

In 9095:

Rework the building of the recipient list on single messages.

  • Deprecate bp_get_the_thread_recipients().
  • Move the recipient count logic into the members/single/messages/single.php template.
  • Introduce bp_get_thread_recipients_count() and bp_get_thread_recipients_list() to separate the logic of the deprecated function.

Props joshshashaty, Clean-Cole.
Fixes #5327.

Note: See TracTickets for help on using tickets.