I feel like I am probably missing something in how to get all the pieces working together, but I can't get the digests to send. I've got:
Message 7.x-1.9
Message notify 7.x-2.5
Message subscribe 7.x-1.0-rc1+8-dev
Message digest 7.x-1.0-beta4
Message subscribe email frequency 7.x-1.0

I've enabled the subscribe_node and email_node flags and limited them to certain content types. I then edited the "comment insert" message type email template and the immediate notification of comments works fine. With digest and subscribe email frequency enabled, I see the field on the edit account page, but changing the values doesn't prevent the immediate notification from going out. As mentioned on the project page, I don't have a default message notifier set in the message subscribe settings.

Not sure if it is related, but I had a rule to redirect to the user page after update (from the user edit page) and it stopped working when I was trying to configure digests. When I made message_subscribe_email_freq a required field (but without a default value), the redirect rule works again. But I'm still getting immediate notifications rather than digests.

Any help would be very appreciated!

Comments

anemirovsky’s picture

Hopefully I can help you troubleshoot. There's one piece of info I think is missing. There should be some code either in one of the message example modules or in a custom modules that runs the message_subscribe_send_message() function. For example, if you enable the message_notify_example module, you'll see that it will use that function if the message_subscribe module is enabled. However, the example module is flawed because before it does that, it runs message_notify_send_message(), which will immediately send the message via email and also remove it from the queue for sending in the digest.

So, what's the code look like for your site that's actually sending the messages?

wmfinnegan’s picture

Thanks so much for guidance!
I've adapted the message notify example module - commenting out the function you mention as a flaw:
//message_notify_send_message($message, $options);
if (module_exists('message_subscribe')) {
// If Message-subscribe exists, let this example module use it.
message_subscribe_send_message('comment', $comment, $message, array('email' => $options));
}
Now the message subscribe email frequency settings seems to work (no notification on never, immediate on immediate). Just now tested the message digest, so I guess I'll find out in 24 hours...

adanielyan’s picture

Hi anemirovsky, thank you for the hint. However I don't understand how message_notify_send_message() and message_subscribe_send_message() should work together. In the example module we have this code:

 message_notify_send_message($message, $options);
  if (module_exists('message_subscribe')) {
    // If Message-subscribe exists, let this example module use it.
    message_subscribe_send_message('comment', $comment, $message, array('email' => $options));
  }

So if what you are saying is true and message_notify_send_message() sends an email and then removes the message from queue, the message_subscribe_send_message() function should not be able to send the email anymore. However I'm pretty sure I receive the email sent by message_subscribe_send_message() function, because the email I receive is formatted according to the options I provided to this function (which are different from options provided to message_notify_send_message() function).

That said, I am still not sure how to use these two functions together.

wmfinnegan’s picture

So, I'm not quite there on the daily digest. At the time of my comment above, I'd created 3 comments on a subscribed node and a little after midnight a message went out entitled "[Site Name] Message Digest" and it was empty except for a series of "---" dividers. Looks like two dividers, so it seems to have registered that there are three messages, but it isn't passing the message content.

In Structure/Message Types/Comment Insert/Manage Display, the fields for Daily Digest are: "Message text 0 partial" and "Message text 1 partial" which are the same as what is used for the subject and body for the immediate notifications. I do not have much experience with the message stack other than getting the immediate email notifications to send out on comments on a node, so I'm not sure exactly how to troubleshoot this, but am really hoping I can get these digests working...

adanielyan’s picture

Do you have any idea where this "---" divider is coming from? I receive daily digest emails with proper content but the formatting is way screwed. I wonder where I can change the way the messages are put together.

anemirovsky’s picture

@wmfinnegan, those two partial text fields refer to the Message Text field, which is configured by editing your message type. Make sure that there is content in that field. For example, the first instance of the field in my configuration has:

[message:field-comment-ref:author] commented on [message:field-comment-ref:node:title]

and the second instance has:

Hello [message:field-comment-ref:node:author],

<a href="[message:field-comment-ref:author:url]">[message:field-comment-ref:author:name]</a> has commented on your post <a href="[message:field-comment-ref:node:url]">[message:field-comment-ref:node:title]</a>.

Cheers,
Message notify example robot

If that doesn't work, I would create an issue in the Message Digest module issue queue, as this module only handles setting the frequency of the message digest through the administrative user interface, but doesn't handle formatting the message.

@adanielyan, same with your issue. This module doesn't handle generating the content of the digest email, so you're better served creating an issue in the Message Digest module issue queue.

adanielyan’s picture

@anemirovsky, thank you for responding!

In fact I have my digest email with the right content. However I would like to change the way messages are stacked together. Right now the messages are divided by "----" string and they don't even start from a new line. So I wanted to change the way the messages are put together. If you know how to manipulate that I will appreciate any help. I understand that this might be not the right place to ask this question though. Will post in Message Digest issue queue too.

anemirovsky’s picture

Status: Active » Fixed

Wish I could help there. I haven't actually touched the guts of the message_digest module as the formatting worked fine for my use-case. Hope you get help in the Message Digest issue queue!

I'm going to mark this issue as fixed.

Status: Fixed » Closed (fixed)

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

willowdigit’s picture

Just posted an issue comment at https://drupal.org/node/2225937#comment-8877927

But I believe the issue really belong here, and seeing that it is already here, here goes. I believe the logic in message_subscribe_email_frequency_message_subscribe_get_subscribers_alter() to be faulty.

Having followed the module's instructions, I removed all default notifiers. But then $uids[$row->entity_id]['notifiers'] has no value, and it is not set to anything at all.

I replaced that function with this:

function message_subscribe_email_frequency_message_subscribe_get_subscribers_alter(&$uids, $values) {
  if (empty($uids)) {
    // Nobody is subscribed to the content.
    return;
  }
  // Get the frequency setting for any users subscribed to the content.
  // We don't use the Field API to get these values as we want to get the
  // settings for all the users with a single query.
  $query = "
    SELECT
      entity_id, message_subscribe_email_freq_value
    FROM
      {field_data_message_subscribe_email_freq}
    WHERE
      deleted != 1
    AND
      entity_id IN (:entity_ids)
  ";
  $result = db_query($query, array(':entity_ids' => array_keys($uids)))->fetchAll();
  foreach ($result as $row) {
    // Add notifier based on frequency selected by user.
    $frequency = $row->message_subscribe_email_freq_value;
    if (isset($frequency) && $frequency != MESSAGE_SUBSCRIBE_EMAIL_FREQUENCY_NEVER) {
      $uids[$row->entity_id]['notifiers'][$frequency] = $frequency;
    }
  }
}
anemirovsky’s picture

Thanks for submitting this. This hook that I've implemented comes from the message_subscribe module, which also integrates with the message_notify module, which is the module that handles actually sending the email. It allows a user to subscribe to something and choose whether they would like to receive an email or not. However, the user can be subscribed to something and choose not to receive an email. In that case, they should not be notified via the digest, since they've chosen not to receive email notifications.

Looking at your code, the issue I see is that it doesn't take into account whether the user selected to receive an email notification for an item they're subscribed to. Because of that, it will send the notification via the digest, even though they've selected not to receive an email notification. That's what that extra code in my module is attempting to do. It first checks that the user has even selected to receive an email for a subscription item before it then decides to modify the frequency setting.

Happy to help continue troubleshooting, but I don't think this is the correct solution.

bsarchive’s picture

@WillowDigit's code works for me too. If a user has said they're happy to receive a weekly digest email, why would you want them to say they're happy to be communicated with by email as well? If a user unchecks the email box but then selects to receive a weekly digest email, what should they expect to receive?

I'd suggest the email option isn't necessary.

bsarchive’s picture

Status: Closed (fixed) » Active
anemirovsky’s picture

Status: Active » Closed (fixed)

Thanks for your comment. I think you have a valid use-case that you're describing, but the issue is that this module is not meant to prescribe a specific workflow. It only exposes existing options for the weekly and daily digests implemented in the message_subscribe_email module and implements a hook from the message_subscribe module to alter the notifier configured for any messages triggered by that module.

The message_subscribe module does offer users the ability to subscribe to a piece of content but choose not to be notified by email when that content is updated. This might happen if the site has implemented a notification block that aggregates all the notifications for the user on their profile page. In that case, they may want to have that notification block updated when a piece of content updates but they may not want to get emailed every time the content is updated.

This module is not meant to override that email setting, it is only intended to determine the frequency the user is notified via email if they have selected to be notified by email for a particular piece of content they are subscribed to. Because of that, we don't want to force emailing a message if the user has selected that they don't want to receive email notifications for a specific piece of content.

You're welcome to use the code from @WillowDigit in a custom module, but I don't want to add it to this module as that's not the intended purpose of this module.