Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/30/2008 12:18:36 AM (17 years ago)
Author:
apeatling
Message:

Added message email notifications.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-messages/bp-messages-classes.php

    r391 r462  
    284284   
    285285    var $thread_id;
    286     var $recipients;
     286    var $recipients = false;
    287287
    288288    function bp_messages_message( $id = null ) {
     
    318318
    319319        // 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           
    325323        // Next, if thread_id is set, we are adding to an existing thread, if not, start a new one.
    326324        if ( $this->thread_id ) {
     
    331329            $message_ids = serialize($message_ids);
    332330           
     331            // We need this so we can return the new message ID.
     332            $message_id = $wpdb->insert_id;
     333           
    333334            // Update the sender ids for the thread
    334335            $sender_ids = unserialize($the_ids->sender_ids);
     
    345346           
    346347            // 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 ) );
    352354            }
    353355        } else {
     
    374376            }
    375377        }
    376         update_usermeta( $userdata->ID, 'last_activity', date( 'Y-m-d H:i:s' ) );
     378       
     379        $this->id = $message_id;
    377380       
    378381        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 ) );
    379388    }
    380389   
Note: See TracChangeset for help on using the changeset viewer.