Add the ability to send messages to multiple users

Created on 2 February 2023, almost 2 years ago
Updated 15 August 2023, over 1 year ago

Problem/Motivation

When trying to send a message to multiple users, the message will send only to one user.

Steps to reproduce

- Install the Privatemsg module and enable it.
- Try to send a message to multiple users.

Proposed resolution

Fix the issue by converting the "To" field to a text field with a custom autocomplete controller.

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇯🇴Jordan Qusai Taha Amman

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

Merge Requests

Comments & Activities

  • Issue created by @Qusai Taha
  • Issue was unassigned.
  • Status changed to Needs review almost 2 years ago
  • 🇨🇿Czech Republic viperror

    If I applied this patch #2, i ve got message warning: 1 line adds whitespace errors. When I tried go to write new message url, I have this error: Symfony\Component\Routing\Exception\RouteNotFoundException: Route "privatemsg.participants_searchautocomplete" does not exist. in Drupal\Core\Routing\RouteProvider->getRouteByName() (line 206 of core\lib\Drupal\Core\Routing\RouteProvider.php).

  • 🇻🇳Vietnam tra.duong

    @viperror The patch add routing, you need to clear the cache to recognize new route.

    @Qusai Taha, your patch contains error.
    in src/Form/CreateThreadForm.php i/src/Form/CreateThreadForm.php

    ...
    +    // Split search users.
    +    $recipients = explode(", ", $form_state->getValue('to')); <-- CHECK
    +    $recipients_id = [];
    

    Note: User's input, better split by comma, not followed by any space.

    +        ->condition('name', $recipient, "="); <-- CHECK
    

    Note: very dangerous
    1. SQL injection may happen here.
    2. Because this is user's input, a trim() on $recipient is good.

    +        $recipient_id = $query->execute()->fetchCol(); <-- CHECK
    +
    +        if (empty($recipient_id)) {
    

    Note: Query produce array/boolean

    +          $this->messenger()->addError($this->t('There a user name is not valid, please make sure to enter a valid user name.')); <-- CHECK
    +        }
    

    Note:
    -> the error message is not correct.
    -> Consider log errors and send message once the check name is done,
    -> Showing which name is error is awesome here too.

    +        else {
    +          $recipients_id[] = $recipient_id; <-- CHECK
    +        }
    ...
    

    Note: here produce multiple dimension array
    It will let this piece of code error

    +    if (!empty($recipients_id)) {
    +      if (count($recipients_id) > 1) {
    +        foreach($recipients_id as $recipient_id) { 
    +          $thread_id = $this->privateMsgService->createThread($author_id, $subject, $body_value, $format, $recipient_id); <-- CHECK
    +        }
    

    Note: $recipient_id is array, not int

  • Status changed to Needs work over 1 year ago
  • ivnish Kazakhstan

    New major version release is coming soon (with drupal entities). This issue already fixed there.

  • Status changed to Fixed over 1 year ago
  • ivnish Kazakhstan

    Fixed in the 2.0.x branch

  • When someone adds you to a multi-user conversation, how do you leave that message thread? What should you do if you don't want to disable the private message completely but want to leave this thread?
    Since you cannot leave, you continue to receive all the message notifications that you do not want.

  • ivnish Kazakhstan

    There is no this functionality now. But thanks for the idea!

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024