Activities are not assigned to a destination

Created on 28 January 2021, almost 4 years ago
Updated 11 July 2024, 4 months ago

Problem/Motivation

We have configured the create_post_group message template to create an activity on group stream (destination stream_group) when post is created. But activity is not displayed on the stream when post is created.
I've checked - post is created, activity is created, but it's not displayed. Reason - field_activity_recipient_group is empty for this activity.
I've checked some other messages with the same destination type, but related to other entities - it's the same - entity and activity are created, but recipient group field is empty.

After some investiagtions it turned out that $recipients variable in activity_creator_message_insert() is corrupted. So there is a code (line 96 of activity_creator.module):

$recipients = $plugin->getRecipients($data, $data['last_uid'], 0);

and recipients looks like this:

array(
  0 => array(
    'target_type' => 'group',
    'target_id' => 876,
  ),
).

But below there is the following code (line 115 of activity_creator.module):

$activity_creator_data['recipient'] = $recipients[$recipients_key];

This code is looking for $recipients[876] but... this item does not exist.

Steps to reproduce

Create post (or other entity) that should be displayed on group stream.
I guess other destinations like stream_profile, stream_explore, stream_home may be affected as well.

Proposed resolution

I've found 2 ways to fix this bug:
1. Add these lines to activity_creator_message_insert() (at line 100 of activity_creator.module):

// Let's use entity id as array key.
$recipients = array_combine(array_column($recipients, 'target_id'), $recipients);

2. Update GroupActivityContext->getRecipients() (see line 42 of GroupActivityContext.php):

// Replace '$recipients[]' with '$recipients[$gid]'.
$recipients[$gid] = [
  'target_type' => 'group',
  'target_id' => $gid,
];

What solution is more preferable?
Is it possible to fix it in the next release?

🐛 Bug report
Status

Needs review

Version

13.0

Component

Code (back-end)

Created by

🇷🇺Russia i-grou

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024