It seems there isn't a default rule for user relationships out of the box, here's a basic one I've created which others might find useful:

{ "rules_log_activity_when_user_relationship_is_made" : {
    "LABEL" : "Log activity when user relationship is made",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "heartbeat_rules", "user_relationships_rules" ],
    "ON" : [ "user_relationships_approve" ],
    "DO" : [
      { "heartbeat_activity_heartbeat_become_friends" : {
          "nid" : "0",
          "uid" : "[requester:uid]",
          "nid_target" : "0",
          "uid_target" : "[requestee:uid]",
          "message_id" : { "value" : { "heartbeat_become_friends" : "heartbeat_become_friends" } },
          "!username" : "[requester:link]",
          "!user2" : "[requestee:link]"
        }
      }
    ]
  }
}

Would this be useful to include in the default rules? Maybe this rule could be included but set to disabled by default (this issue may be relevant when thinking about this: http://drupal.org/node/1471566 )? I'll create a patch if others agree.

Comments

hedley’s picture

Here's another rule I've created. The one above saves one activity status in the database (User A is now friends with User B), the one below saves two (User A is now friends with User B + User B is now friends with User A) saving two activity statuses allows each to be associated with a different UID, for my purposes I'm using views to display heartbeat activity and this method works well.

{ "rules_log_activity_when_user_relationship_is_made" : {
    "LABEL" : "Log activity when user relationship is made",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "heartbeat_rules", "user_relationships_rules" ],
    "ON" : [ "user_relationships_approve" ],
    "DO" : [
      { "heartbeat_activity_heartbeat_become_friends" : {
          "nid" : "0",
          "uid" : "[requester:uid]",
          "message_id" : { "value" : { "heartbeat_become_friends" : "heartbeat_become_friends" } },
          "!username" : "[requester:link]",
          "!user2" : "[requestee:link]"
        }
      },
      { "heartbeat_activity_heartbeat_become_friends" : {
          "nid" : "0",
          "uid" : "[requestee:uid]",
          "message_id" : { "value" : { "heartbeat_become_friends" : "heartbeat_become_friends" } },
          "!username" : "[requestee:link]",
          "!user2" : "[requester:link]"
        }
      }
    ]
  }
}
dieppon’s picture

Hi,

I have a simple mutual relationship call "friend" and would like to show the users that 2 specific users has become friends, which rule should I add?

Thanks

hedley’s picture

The first rule I posted should be sufficient but they will both do the job in different ways. Logging one status update (the first method) will cause comments posted on the status on either users stream to be visible on both, logging two status updates (the second method) will keep comments separate.

Stalski’s picture

Status: Active » Needs work

This is certainly something that can go into the defaults of heartbeat, it was for drupal6. On the time of writing the biggest part, rules integration was not yet done if I recollect correctly.

I'll test the code and push it to git ;) Thx.

Stalski’s picture

Status: Needs work » Needs review

Added to git. Can somebody test this out to make sure?

Stalski’s picture

Status: Needs review » Fixed

Reopen if this is not working.

Status: Fixed » Closed (fixed)

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