Changeset 462 for trunk/bp-messages/bp-messages-classes.php
- Timestamp:
- 10/30/2008 12:18:36 AM (17 years ago)
- File:
-
- 1 edited
-
trunk/bp-messages/bp-messages-classes.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-messages/bp-messages-classes.php
r391 r462 284 284 285 285 var $thread_id; 286 var $recipients ;286 var $recipients = false; 287 287 288 288 function bp_messages_message( $id = null ) { … … 318 318 319 319 // First insert the message into the messages table 320 $sql = $wpdb->prepare( "INSERT INTO " . $bp['messages']['table_name_messages'] . " ( sender_id, subject, message, date_sent, message_order, sender_is_group ) VALUES ( %d, %s, %s, FROM_UNIXTIME(%d), %d, %d )", $userdata->ID, $this->subject, $this->message, $this->date_sent, $this->message_order, $this->sender_is_group ); 321 322 if ( $wpdb->query($sql) === false ) 323 return false; 324 320 if ( !$wpdb->query( $wpdb->prepare( "INSERT INTO " . $bp['messages']['table_name_messages'] . " ( sender_id, subject, message, date_sent, message_order, sender_is_group ) VALUES ( %d, %s, %s, FROM_UNIXTIME(%d), %d, %d )", $userdata->ID, $this->subject, $this->message, $this->date_sent, $this->message_order, $this->sender_is_group ) ) ) 321 return false; 322 325 323 // Next, if thread_id is set, we are adding to an existing thread, if not, start a new one. 326 324 if ( $this->thread_id ) { … … 331 329 $message_ids = serialize($message_ids); 332 330 331 // We need this so we can return the new message ID. 332 $message_id = $wpdb->insert_id; 333 333 334 // Update the sender ids for the thread 334 335 $sender_ids = unserialize($the_ids->sender_ids); … … 345 346 346 347 // Find the recipients and update the unread counts for each 347 $recipients = $wpdb->get_results( $wpdb->prepare( "SELECT user_id FROM " . $bp['messages']['table_name_recipients'] . " WHERE thread_id = %d", $this->thread_id ) ); 348 349 for ( $i = 0; $i < count($recipients); $i++ ) { 350 if ( $recipients[$i]->user_id != $userdata->ID ) 351 $wpdb->query( $wpdb->prepare( "UPDATE " . $bp['messages']['table_name_recipients'] . " SET unread_count = unread_count + 1, sender_only = 0 WHERE thread_id = %d AND user_id = %d", $this->thread_id, $recipients[$i]->user_id ) ); 348 if ( !$this->recipients ) 349 $this->recipients = $this->get_recipients(); 350 351 for ( $i = 0; $i < count($this->recipients); $i++ ) { 352 if ( $this->recipients[$i]->user_id != $userdata->ID ) 353 $wpdb->query( $wpdb->prepare( "UPDATE " . $bp['messages']['table_name_recipients'] . " SET unread_count = unread_count + 1, sender_only = 0 WHERE thread_id = %d AND user_id = %d", $this->thread_id, $this->recipients[$i]->user_id ) ); 352 354 } 353 355 } else { … … 374 376 } 375 377 } 376 update_usermeta( $userdata->ID, 'last_activity', date( 'Y-m-d H:i:s' ) ); 378 379 $this->id = $message_id; 377 380 378 381 return true; 382 } 383 384 function get_recipients() { 385 global $bp, $wpdb; 386 387 return $wpdb->get_results( $wpdb->prepare( "SELECT user_id FROM " . $bp['messages']['table_name_recipients'] . " WHERE thread_id = %d", $this->thread_id ) ); 379 388 } 380 389
Note: See TracChangeset
for help on using the changeset viewer.