Since it's only a few lines of code we should add a rules event for new comments. This way we can easily inform the user who carried out the activity as well as all people that commented it by email. Just like facebook. Are there any plans to do that or should I just go ahead and attach a patch? I don't know when I will have time for this but probably in the next few days.

Comments

Stalski’s picture

Nice feature request drake,

I will implement this soon. Adding it to the TODO list, and is very easy indeed. If you have a patch earlier, please do post it here. I will buy you a beer then.

DrakeRemory’s picture

A beer sounds great! Maybe I'll find the time to do this next week.

Stalski’s picture

Assigned: Unassigned » Stalski
Status: Active » Needs review

Hey,

I implemented this and committed http://drupal.org/cvs?commit=331384 it.
It would be great if you let me know if it works for you, even if it works ;) So i have some input on other use cases. I tested it by adding a custom message to the screen, using my new added tokens for the comment.

Note! As there are two kinds of comments - normal on the message itself or on the node if one is there - the tokens are constructed the same way. If a node is known, the comment body is a normal node comment body and if not, the comment is the heartbeat_comment message.

regards,

Stalski

DrakeRemory’s picture

Thanks Stalski,

I'll check it out and report back.

gilcpd’s picture

Hey Stalski and DrakeRemory,

Going on the same request (maybe that's what you have just done) how about adding an rule option to post 2 different messages for the Target of the action and one for the Acting user.

Example:

I'm logging the comments on the profile ( content profile module ) and on the Rules I have 2 actions:

1 log activity for single user (profile being commented):
!commentauthor: !commentbody
-----------------------------------------------

2 log activity for single user (comment author):
!commentauthor commented on !target's profile.
-----------------------------------------------

The problem is that I have to provide User and Target on the Heartbeat logging rule, therefore both messages are shown on both profiles when:
message 1 should show only for the profile being commented stream
and
message 2 on the comment author stream.

what you guys think? :)

Gill

Stalski’s picture

Status: Needs review » Fixed

That's another use case and maybe worth another issue. However, what you are doing rather custom. Logging two messages is possible but in the display we need a parameter to block the messages.
Proposition: do your two loggings . Implement the hook_heartbeat_messages_alter and loop through the messages. Decide what you will show and what not. Mabye something like:
When it's the X stream (parameters HeartbeatAccess object) and when a message id = "adding_heartbeat_comment" and the variables have a key that is the "profile page" variable : dont / do show it.
This can work great for you. There is an example on the demosite of that hook. (no conditions but you can figure it out for your use case specific)

regards,

Stalski

Stalski’s picture

Status: Fixed » Closed (fixed)
DrakeRemory’s picture

Status: Closed (fixed) » Needs work

Hi Stalski,

now you can only add actions for the user that commented a heartbeat message and to the user that carried out the activity. It would be nice if could also add actions for all users that commented the heartbeat message. For example to send notification emails to them like facebook does. So we need another event that is invoked for all these users.

Stalski’s picture

yeah , it would be great. Some extra calculation is then needed ofcourse.
in the event we will have the uaid of the message and we need to query the users in heartbeat_comments that reacted on this uaid.

I am just not sure if this needs to be done in heartbeat or if it can be done just as easily custom. Creating a rules event is in fact very easy to implement. But i will think about it. If you have the time, feel free to write that events hook with the callback for it.
You can use the same data object as used in the other event, heartbeat already provides.

DrakeRemory’s picture

Since I want to use this as an easy way of notifying people when somebody else replied to the same heartbeat message it would be nice to have a page that shows only one heartbeat message by a given id. Something like heartbeat/view/%uaid. This should catch the translated heartbeat message with attachments.

Stalski’s picture

Good point, thought of that as well.
will make that too

Stalski’s picture

Status: Needs work » Needs review

This is implementated and the urls are heartbeat/message/uaid
I am thinking of a way to use those urls in another way. Currently the people are not aware of the existence of these urls.

Stalski’s picture

TODO:
create custom example on how to have a rules action that notifies all involved users for an activity message.

Stalski’s picture

Status: Needs review » Fixed

Now heartbeat/message/%uaid url is available as well in the time info (as facebook does). It works for mails as well i already checked

jaochoo’s picture

Is there a way to control how and where the single message is displayed? E.g. a user shout is displayed on the user profile page, a group message is displayed on the group homepage, etc.

Stalski’s picture

You can alter it in code. Since heartbeat is overridable in every place, class extensions and theming functions, you could override the theme('heartbeat_time_ago') function to set it normal, and override the global layout with the hook_heartbeat_theme_alter function.
Information here: http://heartbeat.menhireffect.be/code/hookheartbeatthemealter

jaochoo’s picture

Is there also a hook for this, i.e. everytime a comment (either node comment or Heartbeat) is made I can execute a custom action? I would like to push a message on top of the stream when there was a new message, i.e. (pseudo code):

On (new comment) { UPDATE heartbeat_activity SET date=now WHERE message_id=...}

jaochoo’s picture

May I ask you guys how do you notify all related users about a new comment and similar? I installed the Messaging and Notifcations modules because I thought they might have a nice Rules integration but they don't provide it. Do you just use the normal Drupal action for sending an email? Are translated emails possible with that?

Stalski’s picture

i think there is a mail action in rules by default no??

jaochoo’s picture

i think there is a mail action in rules by default no??

Yes, that's what I meant. However, I was looking for feedback from others, maybe they have a better approach. For example, the mail action in Rules does not support multilingual mails (i.e. our Thai employees will get their "Someone posted on your wall" notification on English rather than on Thai). Furthermore, I thought there might be a notification method which integrates with Rules and adds a checkbox to the users settings where he can select whether he wants or does not want to get that specific notification.

Stalski, in the latest version of Heartbeat, is the "notify all relevant users/commenters of a Heartbeat message" implemented already?

Stalski’s picture

Status: Fixed » Closed (fixed)

They mails are translatable! they go through the translation system t function of drupal, so they can be translated in the "translate search UI".

If that would not be enough, you could call php code and do a function call there to a custom drupal_mail function ...

Notify ... is custom stuff. Heartbeat only provides the means to do it by providing the events ... . The rest is up to you, I cannot write your site :)

regards

Stalski

jaochoo’s picture

Notify ... is custom stuff. Heartbeat only provides the means to do it by providing the events ... . The rest is up to you

I understand that. My question was (same what others asked before):
a) Does Heartbeat now provide a Rules event is triggered whenever a comment (to a Heartbeat message or the node itself) is made and providing all users/email addresses which already replied to that message? In 4.6 I can only use "User who made the comment" as recipient.
b) Is there a Rules action which sends an email to more than one recipient?

I.e. I am asking for: Hearbeat providing the event and all relevant recipients; Rules providing the action to send an email to multiple recipients.

Stalski’s picture

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

I added a second event that is invoked for all users that previously commented a heartbeat message.

In heartbeat 6.x-4.9:

After Line 349 in heartbeat_comments.module:

  rules_invoke_event('heartbeat_comment_post', $user, $saved, $author);

paste

    // For actions on related users
    $reactions = heartbeat_get_message_reactions($uaid);
    $related_users = array();
    foreach ($reactions as $reaction) {
      /* Prevent invoking this event for the user whose hearbeat message was reacted on, the auhtor of
         the comment and for invoking it twice for the same user */
      if ($reaction->uid != $user->uid && $reaction->uid != $author->uid && !in_array($reaction->uid, $related_users)) {
        rules_invoke_event('heartbeat_related_comment_post', $user, $saved, $author, user_load(array('uid' => $reaction->uid)));
        $related_users[] = $reaction->uid;
      }
    }

After Line 24 in heartbeat_comment.rules.inc paste

    'heartbeat_related_comment_post_' => array(
      'label' => t('User\'s related heartbeat message was commented'),
      'module' => 'heartbeat_comments',
      'arguments' => array(
        'user' => array('type' => 'user', 'label' => t('User who reacts on the acivity.')),
        'heartbeat_comment' => array('type' => 'heartbeat_comment', 'label' => t('Comment that has been posted.')),
        'author' => array('type' => 'user', 'label' => t('User who is the original author of the activity.')),
        'related_user' => array('type' => 'user', 'lebel' => t('User that is related to the heartbeat message.')),
      ),
      'redirect' => TRUE,
    ),

We could also provide a token for a link to the single message that can easily be used in notification mails.

Stalski’s picture

I altered it a little but works fine. Thanks,

It will be available in next snapshot.

Stalski’s picture

Status: Active » Fixed

committed

Status: Fixed » Closed (fixed)

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

martin.l’s picture

Status: Closed (fixed) » Active

Hello,

this does not work.

I have the following configuration:
- latest dev-snapshot as of 10.February 2011
- Configured a rule on event "User's related heartbeat message was commented"
- as an action to the rule "Send a mail to an arbitrary mail adress"
- As a recipient I added the token: [related_user:mail] + my private emailadress

When the corresponding event should be triggered => nothing happens, not even the mail to my private emailadress is sent.

Stalski’s picture

Status: Active » Closed (fixed)

This is a whole other issue than described and fixed here.
You can open a new issue if you want. You can also provide more explanation on what really happens. If you post the message template export and the rule export, i could try to reproduce it.
I must say that i am not very on top of D6 as of the month to come. So It would be easier to provide a patch for this in that new issue.

So your first step should be to open a new issue with the problem you have, explained in detail