From 8d89c4bbcef4e11db6c031c8f5af1323eb055e49 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sat, 15 Sep 2018 01:20:49 +0200 Subject: Save combined view on calling first message in thread --- include/zot.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index e8ac2df02..f4feb1022 100644 --- a/include/zot.php +++ b/include/zot.php @@ -2341,6 +2341,26 @@ function process_mail_delivery($sender, $arr, $deliveries) { intval($r[0]['id']), intval($channel['channel_id']) ); + + // If it was a first message in thread + $z = q("SELECT * FROM mail WHERE mid = '%s' AND channel_id = %d", + dbesc($arr['mid']), + intval($channel['channel_id']) + ); + if (! $z) { + // Get new first message... + $r = q("SELECT mid, conv_guid FROM mail WHERE parent_mid = '%s' AND channel_id = %d ORDER BY id ASC LIMIT 1", + dbesc($arr['mid']), + intval($channel['channel_id']) + ); + // ...and refer whole thread to it + 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']), + dbesc($r[0]['conv_guid']), + intval($channel['channel_id']) + ); + } + $DR->update('mail recalled'); $result[] = $DR->get(); logger('mail_recalled'); -- cgit v1.2.3