1
1
Fork 0

Merge pull request #6280 from MrPetovan/bug/4738-fix-message-list-query

Fix message list query
This commit is contained in:
Michael Vogel 2018-12-21 22:17:20 +01:00 committed by GitHub
commit 1cab44827f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 20 deletions

View file

@ -431,24 +431,56 @@ function message_content(App $a)
} }
} }
function get_messages($user, $lstart, $lend) /**
* @param int $uid
* @param int $start
* @param int $limit
* @return array
*/
function get_messages($uid, $start, $limit)
{ {
//TODO: rewritte with a sub-query to get the first message of each private thread with certainty return DBA::toArray(DBA::p('SELECT
return q("SELECT max(`mail`.`created`) AS `mailcreated`, min(`mail`.`seen`) AS `mailseen`, m.`id`,
ANY_VALUE(`mail`.`id`) AS `id`, ANY_VALUE(`mail`.`uid`) AS `uid`, ANY_VALUE(`mail`.`guid`) AS `guid`, m.`uid`,
ANY_VALUE(`mail`.`from-name`) AS `from-name`, ANY_VALUE(`mail`.`from-photo`) AS `from-photo`, m.`guid`,
ANY_VALUE(`mail`.`from-url`) AS `from-url`, ANY_VALUE(`mail`.`contact-id`) AS `contact-id`, m.`from-name`,
ANY_VALUE(`mail`.`convid`) AS `convid`, ANY_VALUE(`mail`.`title`) AS `title`, ANY_VALUE(`mail`.`body`) AS `body`, m.`from-photo`,
ANY_VALUE(`mail`.`seen`) AS `seen`, ANY_VALUE(`mail`.`reply`) AS `reply`, ANY_VALUE(`mail`.`replied`) AS `replied`, m.`from-url`,
ANY_VALUE(`mail`.`unknown`) AS `unknown`, ANY_VALUE(`mail`.`uri`) AS `uri`, m.`contact-id`,
`mail`.`parent-uri`, m.`convid`,
ANY_VALUE(`mail`.`created`) AS `created`, ANY_VALUE(`contact`.`name`) AS `name`, ANY_VALUE(`contact`.`url`) AS `url`, m.`title`,
ANY_VALUE(`contact`.`thumb`) AS `thumb`, ANY_VALUE(`contact`.`network`) AS `network`, m.`body`,
count( * ) as `count` m.`seen`,
FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id` m.`reply`,
WHERE `mail`.`uid` = %d GROUP BY `parent-uri` ORDER BY `mailcreated` DESC LIMIT %d , %d ", m.`replied`,
intval($user), intval($lstart), intval($lend) m.`unknown`,
); m.`uri`,
m.`parent-uri`,
m.`created`,
c.`name`,
c.`url`,
c.`thumb`,
c.`network`,
m2.`count`,
m2.`mailcreated`,
m2.`mailseen`
FROM `mail` m
JOIN (
SELECT
`parent-uri`,
MIN(`id`) AS `id`,
COUNT(*) AS `count`,
MAX(`created`) AS `mailcreated`,
MIN(`seen`) AS `mailseen`
FROM `mail`
WHERE `uid` = ?
GROUP BY `parent-uri`
) m2 ON m.`parent-uri` = m2.`parent-uri` AND m.`id` = m2.`id`
LEFT JOIN `contact` c ON m.`contact-id` = c.`id`
WHERE m.`uid` = ?
ORDER BY m2.`mailcreated` DESC
LIMIT ?, ?'
, $uid, $uid, $start, $limit));
} }
function render_messages(array $msg, $t) function render_messages(array $msg, $t)

View file

@ -1,4 +1,2 @@
<h3>{{$messages}}</h3> <h3>{{$messages}}</h3>
{{$tab_content}}

View file

@ -16,4 +16,3 @@
</div> </div>
<div class="clear"></div> <div class="clear"></div>
{{$tab_content}}