msglib.php 847 Bytes
Newer Older
Max Kostikov's avatar
Max Kostikov committed
1 2 3 4 5 6 7 8
<?php

/* Common private message processing functions */

function msg_drop($message_id, $channel_id, $conv_guid) {

    // Delete message
    $r = q("DELETE FROM mail WHERE id = %d AND channel_id = %d",
Max Kostikov's avatar
Max Kostikov committed
9 10
        intval($message_id),
        intval($channel_id)
Max Kostikov's avatar
Max Kostikov committed
11
    );
Max Kostikov's avatar
Max Kostikov committed
12

Max Kostikov's avatar
Max Kostikov committed
13 14
    // Get new first message...
    $r = q("SELECT mid, parent_mid FROM mail WHERE conv_guid = '%s' AND channel_id = %d ORDER BY id ASC LIMIT 1",
Max Kostikov's avatar
Max Kostikov committed
15 16
        dbesc($conv_guid),
        intval($channel_id)
Max Kostikov's avatar
Max Kostikov committed
17
    );
Max Kostikov's avatar
Max Kostikov committed
18 19 20
    // ...and if wasn't first before...
    if ($r[0]['mid'] != $r[0]['parent_mid']) {
        // ...refer whole thread to it
Max Kostikov's avatar
Max Kostikov committed
21 22
        q("UPDATE mail SET parent_mid = '%s', mail_isreply = abs(mail_isreply - 1) WHERE conv_guid = '%s' AND channel_id = %d",
            dbesc($r[0]['mid']),
Max Kostikov's avatar
Max Kostikov committed
23 24
            dbesc($conv_guid),
            intval($channel_id)
Max Kostikov's avatar
Max Kostikov committed
25 26
        );
    }
Max Kostikov's avatar
Max Kostikov committed
27 28

}