Index: flag.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag/Attic/flag.module,v
retrieving revision 1.11.2.72.2.23
diff -u -r1.11.2.72.2.23 flag.module
--- flag.module	29 Oct 2009 05:06:11 -0000	1.11.2.72.2.23
+++ flag.module	2 Nov 2009 06:13:36 -0000
@@ -531,6 +531,32 @@
 }
 
 /**
+ * Implementation of hook_activity_info().
+ */
+function flag_activity_info() {
+  $info = new stdClass();
+  $info->api = 2;
+  $info->name = 'flag';
+  // The order of objects here matters. If a user is both the author and the
+  // flagging user, the flagging user message takes precedence.
+  $info->objects = array('node author' => 'node', 'flagging user' => 'account', 'comment author' => 'comment');
+  $info->hooks = array('flag' => array('flag', 'unflag'));
+
+  // Figure out the activity access control realms and the types.
+  $flags = flag_get_flags();
+  foreach ($flags as $fid => $flag) {
+    $info->realms["flag_" . $flag->fid] = $flag->title;
+    // Currently, flagging a user cannot be recorded.
+    if ($flag->content_type != 'user') {
+      $info->type_options[$flag->fid] = $flag->title;
+    }
+  }
+  $info->object_type = 'flag';
+  $info->path = drupal_get_path('module', 'flag') . '/includes';
+  return $info;
+}
+
+/**
  * Menu callback for (un)flagging a node.
  *
  * Used both for the regular callback as well as the JS version.
@@ -654,9 +680,14 @@
  */
 function flag_flag($action, $flag, $content_id, $account) {
   if (module_exists('trigger')) {
-    $flag_action = $flag->get_flag_action($content_id);
-    $flag_action->action = $action;
-    $context = (array)$flag_action;
+    $context['hook'] = 'flag';
+    $context['account'] = $account;
+    $context['flag'] = $flag;
+    $context['op'] = $action;
+
+    // We add to the $context all the objects we know about:
+    $context = array_merge($flag->get_relevant_action_objects($content_id), $context);
+
     // Generic "all flags" actions.
     foreach (_trigger_get_hook_aids($action, $action) as $aid => $action_info) {
       // The 'if ($aid)' is a safeguard against http://drupal.org/node/271460#comment-886564
Index: includes/flag.activity.inc
===================================================================
RCS file: includes/flag.activity.inc
diff -N includes/flag.activity.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ includes/flag.activity.inc	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,66 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Provides Flag integration with Activity2.
+ * @see http://drupal.org/project/activity
+ */
+
+/**
+ * Implementation of hook_activity_grants().
+ */
+function flag_activity_grants($activity) {
+  $flags = flag_get_flags();
+  $realms = array();
+  // Assign all those flags for nodes.
+  foreach ($flags as $fid => $flag) {
+    // This will also work for comments as those activity records have nids.
+    if ($activity->nid && $flag->content_type == 'node') {
+      $realms['flag_' . $flag->fid] = array($activity->nid);
+    }
+    elseif ($flag->content_type == 'user') {
+      $realms['flag_' . $flag->fid] = array($activity->uid);
+    }
+  }
+  return $realms;
+}
+
+/**
+ * Implementation of hook_activity_access_grants().
+ */
+function flag_activity_access_grants($account) {
+  // Get all the user and node flags.
+  $user_flags = flag_get_user_flags('user', NULL, $account->uid);
+  $node_flags = flag_get_user_flags('node', NULL, $account->uid);
+
+  $flag_grants = array();
+  if (!empty($node_flags)) {
+    foreach ($node_flags as $flagged_objects) {
+      foreach ($flagged_objects as $nid => $flagged) {
+        // Tell activity to grant user $account access to those flagged with
+        // $fid that are $nid.
+        $flag_grants['flag_' . $flagged->fid][] = $nid;
+      }
+    }
+  }
+
+  if (!empty($user_flags)) {
+    foreach ($user_flags as $flagged_objects) {
+      foreach ($flagged_objects as $uid => $flagged) {
+        // Tell Activity to grant user $account access to those flagged with
+        // $fid that are $uid.
+        $flag_grants['flag_' . $flagged->fid][] = $uid;
+      }
+    }
+  }
+
+  return $flag_grants;
+}
+
+/**
+ * Implementation of hook_activity_type_check().
+ */
+function flag_activity_type_check($token_objects, $types) {
+  return (in_array($token_objects['flag']->fid, $types));
+}
