<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[BuddyPress] [1810] trunk/bp-friends.php: Fixes #982</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd>1810</dd>
<dt>Author</dt> <dd>apeatling</dd>
<dt>Date</dt> <dd>2009-09-07 19:25:59 +0000 (Mon, 07 Sep 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fixes #982</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpfriendsphp">trunk/bp-friends.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpfriendsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-friends.php (1809 => 1810)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-friends.php        2009-09-07 18:46:37 UTC (rev 1809)
+++ trunk/bp-friends.php        2009-09-07 19:25:59 UTC (rev 1810)
</span><span class="lines">@@ -43,7 +43,6 @@
</span><span class="cx">         $bp-&gt;friends-&gt;id = 'friends';
</span><span class="cx">                 
</span><span class="cx">         $bp-&gt;friends-&gt;table_name = $wpdb-&gt;base_prefix . 'bp_friends';
</span><del>-        $bp-&gt;friends-&gt;format_activity_function = 'friends_format_activity';
</del><span class="cx">         $bp-&gt;friends-&gt;format_notification_function = 'friends_format_notifications';
</span><span class="cx">         $bp-&gt;friends-&gt;slug = BP_FRIENDS_SLUG;
</span><span class="cx">         
</span><span class="lines">@@ -270,58 +269,37 @@
</span><span class="cx">  * notifications for the user and for this specific component.
</span><span class="cx">  */
</span><span class="cx"> 
</span><del>-function friends_record_activity( $args ) {
-        if ( function_exists('bp_activity_record') ) {
-                extract( (array)$args );
-                bp_activity_record( $item_id, $component_name, $component_action, $is_private, $secondary_item_id, $user_id, $secondary_user_id );
-        }
</del><ins>+function friends_record_activity( $args = '' ) {
+        global $bp;
+        
+        if ( !function_exists( 'bp_activity_add' ) )
+                return false;
+
+        $defaults = array(
+                'user_id' =&gt; $bp-&gt;loggedin_user-&gt;id,
+                'content' =&gt; false,
+                'primary_link' =&gt; false,
+                'component_name' =&gt; $bp-&gt;friends-&gt;id,
+                'component_action' =&gt; false,
+                'item_id' =&gt; false,
+                'secondary_item_id' =&gt; false,
+                'recorded_time' =&gt; time(),
+                'hide_sitewide' =&gt; false
+        );
+
+        $r = wp_parse_args( $args, $defaults );
+        extract( $r, EXTR_SKIP );        
+
+        return bp_activity_add( array( 'user_id' =&gt; $user_id, 'content' =&gt; $content, 'primary_link' =&gt; $primary_link, 'component_name' =&gt; $component_name, 'component_action' =&gt; $component_action, 'item_id' =&gt; $item_id, 'secondary_item_id' =&gt; $secondary_item_id, 'recorded_time' =&gt; $recorded_time, 'hide_sitewide' =&gt; $hide_sitewide ) );
</ins><span class="cx"> }
</span><del>-add_action( 'friends_friendship_accepted', 'friends_record_activity' );
</del><span class="cx"> 
</span><span class="cx"> function friends_delete_activity( $args ) {
</span><del>-        if ( function_exists('bp_activity_delete') ) {
</del><ins>+        if ( function_exists('bp_activity_delete_by_item_id') ) {
</ins><span class="cx">                 extract( (array)$args );
</span><del>-                bp_activity_delete( $item_id, $component_name, $component_action, $user_id, $secondary_item_id );
</del><ins>+                bp_activity_delete_by_item_id( array( 'item_id' =&gt; $item_id, 'component_name' =&gt; $bp-&gt;friends-&gt;id, 'component_action' =&gt; $component_action, 'user_id' =&gt; $user_id, 'secondary_item_id' =&gt; $secondary_item_id ) );
</ins><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-function friends_format_activity( $item_id, $user_id, $action, $secondary_item_id = false, $for_secondary_user = false ) {
-        global $bp;
-        
-        switch( $action ) {
-                case 'friendship_created':
-                        $friendship = new BP_Friends_Friendship( $item_id, false, false );
-
-                        if ( !$friendship-&gt;initiator_user_id || !$friendship-&gt;friend_user_id )
-                                return false;
-                        
-                        if ( $for_secondary_user ) {
-                                
-                                $user_1 = bp_core_get_userlink( $friendship-&gt;initiator_user_id );
-                                $user_2 = bp_core_get_userlink($friendship-&gt;friend_user_id, false, false, true);
-                                
-                                return array( 
-                                        'primary_link' =&gt; bp_core_get_userlink( $friendship-&gt;friend_user_id, false, true ),
-                                        'content' =&gt; apply_filters( 'bp_friends_friendship_accepted_activity', sprintf( __( '%s and %s are now friends', 'buddypress' ), $user_1, $user_2 ) . ' &lt;span class=&quot;time-since&quot;&gt;%s&lt;/span&gt;', $user_1, $user_2 )
-                                );                                
-                        } else {
-                                
-                                $user_1 = bp_core_get_userlink( $friendship-&gt;friend_user_id );
-                                $user_2 = bp_core_get_userlink($friendship-&gt;initiator_user_id);
-                                
-                                return array( 
-                                        'primary_link' =&gt; bp_core_get_userlink( $friendship-&gt;friend_user_id, false, true ),
-                                        'content' =&gt; apply_filters( 'bp_friends_friendship_accepted_activity', sprintf( __( '%s and %s are now friends', 'buddypress' ), bp_core_get_userlink( $friendship-&gt;friend_user_id ), bp_core_get_userlink($friendship-&gt;initiator_user_id) ) . ' &lt;span class=&quot;time-since&quot;&gt;%s&lt;/span&gt;', $user_1, $user_2 )
-                                );                        
-                        }
-                break;
-        }
-        
-        do_action( 'friends_format_activity', $action, $item_id, $user_id, $action, $secondary_item_id, $for_secondary_user );
-        
-        return false;
-}
-
</del><span class="cx"> function friends_register_activity_actions() {
</span><span class="cx">         global $bp;
</span><span class="cx">         
</span><span class="lines">@@ -618,8 +596,8 @@
</span><span class="cx">         $friendship_id = BP_Friends_Friendship::get_friendship_id( $initiator_userid, $friend_userid );
</span><span class="cx">         $friendship = new BP_Friends_Friendship( $friendship_id );
</span><span class="cx">         
</span><del>-        // Remove the activity stream items
-        friends_delete_activity( array( 'item_id' =&gt; $friendship_id, 'component_name' =&gt; $bp-&gt;friends-&gt;slug, 'component_action' =&gt; 'friendship_accepted', 'user_id' =&gt; $bp-&gt;displayed_user-&gt;id ) );
</del><ins>+        // Remove the activity stream item for the user who canceled the friendship
+        friends_delete_activity( array( 'item_id' =&gt; $friendship_id, 'component_action' =&gt; 'friendship_accepted', 'user_id' =&gt; $bp-&gt;displayed_user-&gt;id ) );
</ins><span class="cx">         
</span><span class="cx">         do_action( 'friends_friendship_deleted', $friendship_id, $initiator_userid, $friend_userid );
</span><span class="cx">         
</span><span class="lines">@@ -640,16 +618,38 @@
</span><span class="cx">         if ( !$friendship-&gt;is_confirmed &amp;&amp; BP_Friends_Friendship::accept( $friendship_id ) ) {
</span><span class="cx">                 friends_update_friend_totals( $friendship-&gt;initiator_user_id, $friendship-&gt;friend_user_id );
</span><span class="cx">                 
</span><del>-                // Remove the friend request notice
</del><ins>+                /* Remove the friend request notice */
</ins><span class="cx">                 bp_core_delete_notifications_for_user_by_item_id( $friendship-&gt;friend_user_id, $friendship-&gt;initiator_user_id, 'friends', 'friendship_request' );        
</span><span class="cx">                 
</span><del>-                // Add a friend accepted notice for the initiating user
</del><ins>+                /* Add a friend accepted notice for the initiating user */
</ins><span class="cx">                 bp_core_add_notification( $friendship-&gt;friend_user_id, $friendship-&gt;initiator_user_id, 'friends', 'friendship_accepted' );
</span><span class="cx">                 
</span><del>-                // Record in activity streams
-                friends_record_activity( array( 'item_id' =&gt; $friendship_id, 'component_name' =&gt; $bp-&gt;friends-&gt;slug, 'component_action' =&gt; 'friendship_created', 'is_private' =&gt; 0, 'user_id' =&gt; $friendship-&gt;initiator_user_id, 'secondary_user_id' =&gt; $friendship-&gt;friend_user_id ) );
</del><ins>+                $initiator_link = bp_core_get_userlink( $friendship-&gt;initiator_user_id );
+                $friend_link = bp_core_get_userlink( $friendship-&gt;friend_user_id );
</ins><span class="cx">                 
</span><del>-                // Send the email notification
</del><ins>+                $primary_link = apply_filters( 'bp_friends_friendship_accepted_primary_link', bp_core_get_userlink( $friendship-&gt;initiator_user_id ), &amp;$friendship );
+                $activity_content = apply_filters( 'bp_friends_friendship_accepted_activity', sprintf( __( '%s and %s are now friends', 'buddypress' ), $initiator_link, $friend_link ), &amp;$friendship );
+                        
+                /* Record in activity streams for the initiator */
+                friends_record_activity( array( 
+                        'user_id' =&gt; $friendship-&gt;initiator_user_id,
+                        'component_action' =&gt; 'friendship_created',
+                        'content' =&gt; $activity_content,
+                        'primary_link' =&gt; $primary_link,
+                        'item_id' =&gt; $friendship_id
+                ) );
+                
+                /* Record in activity streams for the friend */
+                friends_record_activity( array( 
+                        'user_id' =&gt; $friendship-&gt;friend_user_id,
+                        'component_action' =&gt; 'friendship_created',
+                        'content' =&gt; $activity_content,
+                        'primary_link' =&gt; $primary_link,
+                        'item_id' =&gt; $friendship_id,
+                        'hide_sitewide' =&gt; true /* We've already got the first entry site wide */
+                ) );
+                
+                /* Send the email notification */
</ins><span class="cx">                 require_once( BP_PLUGIN_DIR . '/bp-friends/bp-friends-notifications.php' );
</span><span class="cx">                 friends_notification_accepted_request( $friendship-&gt;id, $friendship-&gt;initiator_user_id, $friendship-&gt;friend_user_id );
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>