Index: flag_friend.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag_friend/flag_friend.module,v
retrieving revision 1.3.4.30
diff -u -p -r1.3.4.30 flag_friend.module
--- flag_friend.module	9 Jun 2009 19:15:13 -0000	1.3.4.30
+++ flag_friend.module	12 Jun 2009 10:21:39 -0000
@@ -289,7 +289,7 @@ function flag_friend_form_flag_confirm_a
     $action = $form['action']['#value'];
     $flag = flag_get_flag('friend');
     $content_id = $form['content_id']['#value'];
-    $token = $_REQUEST['token'];
+    $token = isset($_REQUEST['token']) ? $_REQUEST['token'] : '';
 
     switch ($action) {
       case 'flag':
@@ -337,6 +337,8 @@ function flag_friend_message_form($actio
  * Form to confirm an unfriend flagging.
  */
 function flag_friend_unfriend_form($action, $flag, $content_id, $token) {
+  global $user;
+
   $form['current'] = array('#type' => 'value', '#value' => func_get_args());
 
   $status = flag_friend_determine_friend_status($flag, $user->uid, $content_id);
@@ -374,14 +376,10 @@ function flag_friend_form_submit($form, 
   $token = $form_state['values']['current'][3];
   $status = flag_friend_determine_friend_status($flag, $user->uid, $content_id, TRUE);
   
-  if ($form_state['values']['flag_friend_message']) {
+  if (isset($form_state['values']['flag_friend_message'])) {
     $flag->friend_message = $form_state['values']['flag_friend_message'];
-    // check the status before trying to record.
-    // we do this because the flag is removed in hook_flag if this status is
-    // true there, which results in an error when trying to save the message
-    // because we have no fcid with which to save. so just email it and do not
-    // record.
-    if ($status !== FLAG_FRIEND_BOTH) {
+    // Record message only if user pending request.
+    if ($status === FLAG_FRIEND_PENDING) {
       flag_friend_message($action, $flag, $content_id, $user->uid);
     }
     flag_friend_message_email($status, $flag, $content_id, $user);
@@ -390,6 +388,10 @@ function flag_friend_form_submit($form, 
   elseif ($status === FLAG_FRIEND_FLAGGED || $status === FLAG_FRIEND_APPROVAL) {
     flag_friend_unfriend($action, $flag, $content_id, $user, $status);
   }
+  elseif ($status === FLAG_FRIEND_PENDING) {
+    // Clean message when user cancel own request.
+    flag_friend_message($action, $flag, $content_id, $user->uid);
+  }
 }
 
 /**
@@ -521,7 +523,7 @@ function theme_flag_friend_message_email
       Thanks,
 
       The !site Team', array(
-        '!firstname' => $sender->firstname ? $sender->firstname : $sender->name,
+        '!firstname' => isset($sender->firstname) ? $sender->firstname : $sender->name,
         '!site' => variable_get('site_name', ''),
         '!message' => $flag->friend_message ? t('Message:'). $flag->friend_message : '',
         '!link' => url('user/'. $sender->uid, array('absolute' => TRUE)),
@@ -540,7 +542,7 @@ function theme_flag_friend_message_email
 
       Thanks,
       The !site Team', array(
-        '!firstname' => $sender->firstname ? $sender->firstname : $sender->name,
+        '!firstname' => isset($sender->firstname) ? $sender->firstname : $sender->name,
         '!site' => variable_get('site_name', ''),
         '!message' => $flag->friend_message ? t('Message:'). $flag->friend_message : '',
         '!link' => url('user/'. $recipient->uid .'/friends', array('absolute' => TRUE)),
