Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi.
Current push_notifications_privatemsg_message_insert is incomplete, because if role is selected for a private message, there are no recipients to send push notification.
This code fix this function: (Sorry, I cannot create a patch file).
File: push_notification.module
Function: push_notifications_privatemsg_message_insert($message)
New function:
<?php
/**
* Implements hook_privatemsg_message_insert.
*/
function push_notifications_privatemsg_message_insert( $message ) {
if ( variable_get( 'push_notifications_privatemsg_integration', 0 ) ) {
// Compose the payload. If the body is empty, just use the subject line.
// Otherwise, combine subject and body.
$payload = (empty($message->body)) ? $message->subject : $message->subject . ' ' . $message->body;
$payload = 'From ' . $message->author->name . ': ' . $payload;
// Compose an array of recipients.
$recipients = array();
foreach ( $message->recipients as $recipient ) {
if ( $recipient->type == "role" && $recipient->name != 'authenticated user' ) {
$sql = 'SELECT uid FROM {users_roles} WHERE rid = :rid';
$q = db_query( $sql, array( ':rid' => $recipient->rid ) );
// $uids = array();
// while ($row = db_fetch_array($q)) {
foreach ( $q as $row ) {
// $uids[] = $row['uid'];
$recipients[] = $row->uid;
}
}
elseif ( $recipient->type == "role" && $recipient->name == 'authenticated user' ) {
$q = db_select( 'users', 'u' )
->fields( 'u' )
->execute()
->fetchAssoc();
foreach ( $q as $row ) {
$recipients[] = $row->uid;
}
}
else
$recipients[] = $recipient->uid;
}
push_notifications_send_message( $recipients, $payload );
}
}
?>
I cannot send my actual file, because I did many other changes.
Regards.
Byron H.
http://silencesoft.pw
pd. Thanks if somebody can create a patch with this code.
Comments
Comment #1
Anonymous (not verified) CreditAttribution: Anonymous commentedI'm just about to test this on a project. I'll create a patch shortly.
Best, Paul
Comment #2
Anonymous (not verified) CreditAttribution: Anonymous commentedI have cleaned up the code and modified the code to consistently use the latest database abstraction layer.
Will test soon.
Comment #3
Anonymous (not verified) CreditAttribution: Anonymous commentedThe above works great. I'll create a patch ..
Comment #4
jbarwick CreditAttribution: jbarwick commentedI noticed that paul said he would create a patch 7 months ago.
The latest dev release says 11 months ago.
So, I assume the patch is not in the dev branch.
OK, so the question is, do we apply the above subroutine to the prod branch or the dev branch?
Comment #5
jbarwick CreditAttribution: jbarwick commentedBy the way, I just applied to prod branch and it worked great.
Should we be using dev branch? anyone know?
Comment #6
silenceway CreditAttribution: silenceway commentedHello.
My code works on dev and stable. But I'm using dev at this time.
Paul code must works on both two.
:)
pd. Thanks Paul for update.
Byron H.
http://silencesoft.pw
Comment #8
haagendazs CreditAttribution: haagendazs commentedJust pushed the patch from #2 to the dev branch. Thanks for the patch!