Index: flag.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag/Attic/flag.module,v
retrieving revision 1.11.2.72.2.10
diff -u -p -r1.11.2.72.2.10 flag.module
--- flag.module	14 Sep 2009 23:59:25 -0000	1.11.2.72.2.10
+++ flag.module	18 Sep 2009 17:23:06 -0000
@@ -578,10 +578,16 @@ function flag($action, $flag_name, $cont
 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;
-    $aids = _trigger_get_hook_aids($action, $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);
+    
+    // get the $aids
+    $aids = _trigger_get_hook_aids('flag', $action);
     foreach ($aids as $aid => $action_info) {
       // The 'if ($aid)' is a safeguard against http://drupal.org/node/271460#comment-886564
       if ($aid) {
@@ -1250,3 +1256,30 @@ function flag_get_token($nid) {
 function flag_check_token($token, $seed) {
   return drupal_get_token($seed) == $token;
 }
+
+/**
+ * Implementation of hook_activity_info().
+ */
+function flag_activity_info() {
+  $info = new stdClass();
+  $info->api = 2;
+  $info->name = 'flag';
+  // Ironically, order matters. If im both the author and the Flagger
+  // I want the Flagger message
+  $info->objects = array('Node Author' => 'node', 'Flagger' => '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;
+}
\ No newline at end of file
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	18 Sep 2009 17:23:06 -0000
@@ -0,0 +1,64 @@
+<?php
+// $Id: $
+/**
+ * @file:
+ * provides Activity2 Integration. 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();
+  // apparently flag module doesn't return an array().
+  if (!empty($node_flags)) {
+    foreach ($node_flags as $flagged_objects) {
+      foreach ($flagged_objects as $nid => $flagged) {
+        // tell activity we 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 we 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));
+}
\ No newline at end of file
