Index: flag.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag/Attic/flag.module,v
retrieving revision 1.11.2.68
diff -u -p -r1.11.2.68 flag.module
--- flag.module	14 Mar 2009 06:13:54 -0000	1.11.2.68
+++ flag.module	18 Jun 2009 17:42:24 -0000
@@ -1513,3 +1548,29 @@ 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, flaggin a user cannot be recorded
+    if ($flag->content_type != 'user') {
+      $info->type_options[$flag->fid] = $flag->title;
+    }
+  }
+  $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 Jun 2009 17:42:24 -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);
+    }
+    else if ($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));
+}