<!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" />
<title>[BuddyPress][8479] trunk/src/bp-messages: Improved inline documentation in bp-messages.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { 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 #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#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>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://buddypress.trac.wordpress.org/changeset/8479">8479</a></dd>
<dt>Author</dt> <dd>boonebgorges</dd>
<dt>Date</dt> <dd>2014-06-07 18:57:23 +0000 (Sat, 07 Jun 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Improved inline documentation in bp-messages.

See <a href="http://buddypress.trac.wordpress.org/ticket/5022">#5022</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcbpmessagesbpmessagesactionsphp">trunk/src/bp-messages/bp-messages-actions.php</a></li>
<li><a href="#trunksrcbpmessagesbpmessagescachephp">trunk/src/bp-messages/bp-messages-cache.php</a></li>
<li><a href="#trunksrcbpmessagesbpmessagesclassesphp">trunk/src/bp-messages/bp-messages-classes.php</a></li>
<li><a href="#trunksrcbpmessagesbpmessagescssjsphp">trunk/src/bp-messages/bp-messages-cssjs.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcbpmessagesbpmessagesactionsphp"></a>
<div class="modfile"><h4>Modified: trunk/src/bp-messages/bp-messages-actions.php (8478 => 8479)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/bp-messages/bp-messages-actions.php    2014-06-07 18:00:43 UTC (rev 8478)
+++ trunk/src/bp-messages/bp-messages-actions.php       2014-06-07 18:57:23 UTC (rev 8479)
</span><span class="lines">@@ -3,9 +3,9 @@
</span><span class="cx"> /**
</span><span class="cx">  * BuddyPress Messages Actions
</span><span class="cx">  *
</span><del>- * Action functions are exactly the same as screen functions, however they do not
- * have a template screen associated with them. Usually they will send the user
- * back to the default screen after execution.
</del><ins>+ * Action functions are exactly the same as screen functions, however they do
+ * not have a template screen associated with them. Usually they will send the
+ * user back to the default screen after execution.
</ins><span class="cx">  *
</span><span class="cx">  * @package BuddyPress
</span><span class="cx">  * @subpackage MessagesActions
</span><span class="lines">@@ -14,6 +14,9 @@
</span><span class="cx"> // Exit if accessed directly
</span><span class="cx"> if ( !defined( 'ABSPATH' ) ) exit;
</span><span class="cx"> 
</span><ins>+/**
+ * Process a request to view a single message thread.
+ */
</ins><span class="cx"> function messages_action_conversation() {
</span><span class="cx"> 
</span><span class="cx">  if ( !bp_is_messages_component() || !bp_is_current_action( 'view' ) )
</span><span class="lines">@@ -47,6 +50,11 @@
</span><span class="cx"> }
</span><span class="cx"> add_action( 'bp_actions', 'messages_action_conversation' );
</span><span class="cx"> 
</span><ins>+/**
+ * Process a request to delete a message.
+ *
+ * @return bool False on failure.
+ */
</ins><span class="cx"> function messages_action_delete_message() {
</span><span class="cx"> 
</span><span class="cx">  if ( !bp_is_messages_component() || bp_is_current_action( 'notices' ) || !bp_is_action_variable( 'delete', 0 ) )
</span><span class="lines">@@ -71,6 +79,11 @@
</span><span class="cx"> }
</span><span class="cx"> add_action( 'bp_actions', 'messages_action_delete_message' );
</span><span class="cx"> 
</span><ins>+/**
+ * Process a request to bulk delete messages.
+ *
+ * @return bool False on failure.
+ */
</ins><span class="cx"> function messages_action_bulk_delete() {
</span><span class="cx"> 
</span><span class="cx">  if ( !bp_is_messages_component() || !bp_is_action_variable( 'bulk-delete', 0 ) )
</span></span></pre></div>
<a id="trunksrcbpmessagesbpmessagescachephp"></a>
<div class="modfile"><h4>Modified: trunk/src/bp-messages/bp-messages-cache.php (8478 => 8479)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/bp-messages/bp-messages-cache.php      2014-06-07 18:00:43 UTC (rev 8478)
+++ trunk/src/bp-messages/bp-messages-cache.php 2014-06-07 18:57:23 UTC (rev 8479)
</span><span class="lines">@@ -7,7 +7,6 @@
</span><span class="cx">  * actions throughout BuddyPress.
</span><span class="cx">  *
</span><span class="cx">  * @package BuddyPress
</span><del>- * @subpackage SettingsLoader
</del><span class="cx">  */
</span><span class="cx"> 
</span><span class="cx"> // Exit if accessed directly
</span><span class="lines">@@ -24,7 +23,7 @@
</span><span class="cx"> add_action( 'messages_screen_inbox',   'bp_core_clear_cache' );
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * Clears unread count cache for each recipient after a message is sent.
</del><ins>+ * Clear unread count cache for each recipient after a message is sent.
</ins><span class="cx">  *
</span><span class="cx">  * @since BuddyPress (2.0.0)
</span><span class="cx">  *
</span><span class="lines">@@ -38,7 +37,7 @@
</span><span class="cx"> add_action( 'messages_message_after_save', 'bp_messages_clear_unread_count_cache_on_message_save' );
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * Clears unread count cache for the logged-in user after a message is deleted.
</del><ins>+ * Clear unread count cache for the logged-in user after a message is deleted.
</ins><span class="cx">  *
</span><span class="cx">  * @since BuddyPress (2.0.0)
</span><span class="cx">  *
</span><span class="lines">@@ -51,8 +50,8 @@
</span><span class="cx"> add_action( 'messages_before_delete_thread', 'bp_messages_clear_unread_count_cache_on_message_delete' );
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * Invalidates cache for notices.
- * 
</del><ins>+ * Invalidate cache for notices.
+ *
</ins><span class="cx">  * Currently, invalidates active notice cache.
</span><span class="cx">  *
</span><span class="cx">  * @since BuddyPress (2.0.0)
</span><span class="lines">@@ -61,4 +60,4 @@
</span><span class="cx">  wp_cache_delete( 'active_notice', 'bp_messages' );
</span><span class="cx"> }
</span><span class="cx"> add_action( 'messages_notice_after_save',    'bp_notices_clear_cache' );
</span><del>-add_action( 'messages_notice_before_delete', 'bp_notices_clear_cache' );
</del><span class="cx">\ No newline at end of file
</span><ins>+add_action( 'messages_notice_before_delete', 'bp_notices_clear_cache' );
</ins></span></pre></div>
<a id="trunksrcbpmessagesbpmessagesclassesphp"></a>
<div class="modfile"><h4>Modified: trunk/src/bp-messages/bp-messages-classes.php (8478 => 8479)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/bp-messages/bp-messages-classes.php    2014-06-07 18:00:43 UTC (rev 8478)
+++ trunk/src/bp-messages/bp-messages-classes.php       2014-06-07 18:57:23 UTC (rev 8479)
</span><span class="lines">@@ -520,16 +520,64 @@
</span><span class="cx">  }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+/**
+ * Single message class.
+ */
</ins><span class="cx"> class BP_Messages_Message {
</span><ins>+       /**
+        * ID of the message.
+        *
+        * @var int
+        */
</ins><span class="cx">   public $id;
</span><ins>+
+       /**
+        * ID of the message thread.
+        *
+        * @var int
+        */
</ins><span class="cx">   public $thread_id;
</span><ins>+
+       /**
+        * ID of the sender.
+        *
+        * @var int
+        */
</ins><span class="cx">   public $sender_id;
</span><ins>+
+       /**
+        * Subject line of the message.
+        *
+        * @var string
+        */
</ins><span class="cx">   public $subject;
</span><ins>+
+       /**
+        * Content of the message.
+        *
+        * @var string
+        */
</ins><span class="cx">   public $message;
</span><ins>+
+       /**
+        * Date the message was sent.
+        *
+        * @var string
+        */
</ins><span class="cx">   public $date_sent;
</span><span class="cx"> 
</span><ins>+       /**
+        * Message recipients.
+        *
+        * @var bool|array
+        */
</ins><span class="cx">   public $recipients = false;
</span><span class="cx"> 
</span><ins>+       /**
+        * Constructor.
+        *
+        * @param int $id Optional. ID of the message.
+        */
</ins><span class="cx">   public function __construct( $id = null ) {
</span><span class="cx">          $this->date_sent = bp_core_current_time();
</span><span class="cx">          $this->sender_id = bp_loggedin_user_id();
</span><span class="lines">@@ -539,6 +587,11 @@
</span><span class="cx">          }
</span><span class="cx">  }
</span><span class="cx"> 
</span><ins>+       /**
+        * Set up data related to a specific message object.
+        *
+        * @param int $id ID of the message.
+        */
</ins><span class="cx">   public function populate( $id ) {
</span><span class="cx">          global $wpdb, $bp;
</span><span class="cx"> 
</span><span class="lines">@@ -552,6 +605,12 @@
</span><span class="cx">          }
</span><span class="cx">  }
</span><span class="cx"> 
</span><ins>+       /**
+        * Send a message.
+        *
+        * @return int|bool ID of the newly created message on success, false
+        *         on failure.
+        */
</ins><span class="cx">   public function send() {
</span><span class="cx">          global $wpdb, $bp;
</span><span class="cx"> 
</span><span class="lines">@@ -605,13 +664,24 @@
</span><span class="cx">          return $this->id;
</span><span class="cx">  }
</span><span class="cx"> 
</span><ins>+       /**
+        * Get a list of recipients for a message.
+        *
+        * @return array
+        */
</ins><span class="cx">   public function get_recipients() {
</span><span class="cx">          global $bp, $wpdb;
</span><span class="cx">          return $wpdb->get_results( $wpdb->prepare( "SELECT user_id FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d", $this->thread_id ) );
</span><span class="cx">  }
</span><span class="cx"> 
</span><del>-       /** Static Functions ******************************************************/
</del><ins>+        /** Static Functions **************************************************/
</ins><span class="cx"> 
</span><ins>+       /**
+        * Get list of recipient IDs from their usernames.
+        *
+        * @param array $recipient_usernames Usernames of recipients.
+        * @return array
+        */
</ins><span class="cx">   public static function get_recipient_ids( $recipient_usernames ) {
</span><span class="cx">          if ( !$recipient_usernames )
</span><span class="cx">                  return false;
</span><span class="lines">@@ -627,16 +697,36 @@
</span><span class="cx">          return $recipient_ids;
</span><span class="cx">  }
</span><span class="cx"> 
</span><ins>+       /**
+        * Get the ID of the message last sent by the logged-in user for a given thread.
+        *
+        * @param int $thread_id ID of the thread.
+        * @return int|null ID of the message if found, otherwise null.
+        */
</ins><span class="cx">   public static function get_last_sent_for_user( $thread_id ) {
</span><span class="cx">          global $wpdb, $bp;
</span><span class="cx">          return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE sender_id = %d AND thread_id = %d ORDER BY date_sent DESC LIMIT 1", bp_loggedin_user_id(), $thread_id ) );
</span><span class="cx">  }
</span><span class="cx"> 
</span><ins>+       /**
+        * Check whether a user is the sender of a message.
+        *
+        * @param int $user_id ID of the user.
+        * @param int $message_id ID of the message.
+        * @return int|null Returns the ID of the message if the user is the
+        *         sender, otherwise null.
+        */
</ins><span class="cx">   public static function is_user_sender( $user_id, $message_id ) {
</span><span class="cx">          global $wpdb, $bp;
</span><span class="cx">          return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE sender_id = %d AND id = %d", $user_id, $message_id ) );
</span><span class="cx">  }
</span><span class="cx"> 
</span><ins>+       /**
+        * Get the ID of the sender of a message.
+        *
+        * @param int $message_id ID of the message.
+        * @return int|null The ID of the sender if found, otherwise null.
+        */
</ins><span class="cx">   public static function get_message_sender( $message_id ) {
</span><span class="cx">          global $wpdb, $bp;
</span><span class="cx">          return $wpdb->get_var( $wpdb->prepare( "SELECT sender_id FROM {$bp->messages->table_name_messages} WHERE id = %d", $message_id ) );
</span></span></pre></div>
<a id="trunksrcbpmessagesbpmessagescssjsphp"></a>
<div class="modfile"><h4>Modified: trunk/src/bp-messages/bp-messages-cssjs.php (8478 => 8479)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/bp-messages/bp-messages-cssjs.php      2014-06-07 18:00:43 UTC (rev 8478)
+++ trunk/src/bp-messages/bp-messages-cssjs.php 2014-06-07 18:57:23 UTC (rev 8479)
</span><span class="lines">@@ -3,8 +3,6 @@
</span><span class="cx"> /**
</span><span class="cx">  * BuddyPress Messages CSS and JS
</span><span class="cx">  *
</span><del>- * Apply WordPress defined filters to private messages
- *
</del><span class="cx">  * @package BuddyPress
</span><span class="cx">  * @subpackage MessagesScripts
</span><span class="cx">  */
</span><span class="lines">@@ -12,6 +10,9 @@
</span><span class="cx"> // Exit if accessed directly
</span><span class="cx"> if ( !defined( 'ABSPATH' ) ) exit;
</span><span class="cx"> 
</span><ins>+/**
+ * Enqueue the JS for messages autocomplete.
+ */
</ins><span class="cx"> function messages_add_autocomplete_js() {
</span><span class="cx"> 
</span><span class="cx">  // Include the autocomplete JS for composing a message.
</span><span class="lines">@@ -28,6 +29,11 @@
</span><span class="cx"> }
</span><span class="cx"> add_action( 'bp_actions', 'messages_add_autocomplete_js' );
</span><span class="cx"> 
</span><ins>+/**
+ * Enqueue the CSS for messages autocomplete.
+ *
+ * @todo Why do we call wp_print_styles()?
+ */
</ins><span class="cx"> function messages_add_autocomplete_css() {
</span><span class="cx"> 
</span><span class="cx">  if ( bp_is_messages_component() && bp_is_current_action( 'compose' ) ) {
</span><span class="lines">@@ -39,6 +45,11 @@
</span><span class="cx"> }
</span><span class="cx"> add_action( 'wp_head', 'messages_add_autocomplete_css' );
</span><span class="cx"> 
</span><ins>+/**
+ * Print inline JS for initializing the messages autocomplete.
+ *
+ * @todo Why is this here and not in a properly enqueued file?
+ */
</ins><span class="cx"> function messages_autocomplete_init_jsblock() {
</span><span class="cx"> ?>
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>