Skip to content

Commit

Permalink
Merge branch 'MDL-59317' of https://github.com/NeillM/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Jul 10, 2017
2 parents bef9a71 + 22481f3 commit bf51478
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions message/classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,14 @@ public static function get_conversations($userid, $limitfrom = 0, $limitnum = 20
FROM {message}
WHERE
(useridto = ? AND timeusertodeleted = 0 AND notification = 0)
OR
UNION ALL
SELECT
id, useridfrom, useridto, subject, fullmessage, fullmessageformat,
fullmessagehtml, smallmessage, notification, contexturl,
contexturlname, timecreated, timeuserfromdeleted, timeusertodeleted,
component, eventtype, 0 as timeread
FROM {message}
WHERE
(useridfrom = ? AND timeuserfromdeleted = 0 AND notification = 0)
UNION ALL
SELECT
Expand All @@ -294,7 +301,14 @@ public static function get_conversations($userid, $limitfrom = 0, $limitnum = 20
FROM {message_read}
WHERE
(useridto = ? AND timeusertodeleted = 0 AND notification = 0)
OR
UNION ALL
SELECT
id, useridfrom, useridto, subject, fullmessage, fullmessageformat,
fullmessagehtml, smallmessage, notification, contexturl,
contexturlname, timecreated, timeuserfromdeleted, timeusertodeleted,
component, eventtype, timeread
FROM {message_read}
WHERE
(useridfrom = ? AND timeuserfromdeleted = 0 AND notification = 0)";
$allmessagesparams = [$userid, $userid, $userid, $userid];

Expand Down Expand Up @@ -350,22 +364,31 @@ public static function get_conversations($userid, $limitfrom = 0, $limitnum = 20
FROM {message}
WHERE
(useridto = ? AND timeusertodeleted = 0 AND notification = 0)
OR
AND timecreated $timecreatedsql
UNION ALL
SELECT id, useridfrom, useridto, timecreated
FROM {message}
WHERE
(useridfrom = ? AND timeuserfromdeleted = 0 AND notification = 0)
AND timecreated $timecreatedsql
UNION ALL
SELECT id, useridfrom, useridto, timecreated
FROM {message_read}
WHERE
(useridto = ? AND timeusertodeleted = 0 AND notification = 0)
OR
AND timecreated $timecreatedsql
UNION ALL
SELECT id, useridfrom, useridto, timecreated
FROM {message_read}
WHERE
(useridfrom = ? AND timeuserfromdeleted = 0 AND notification = 0)
AND timecreated $timecreatedsql";
$messageidsql = "SELECT $convosig, max(id) as id, timecreated
FROM ($allmessagestimecreated) x
WHERE $messageidwhere
GROUP BY $convocase, timecreated";
$messageidparams = array_merge([$userid, $userid], $timecreatedparams, [$userid, $userid], $timecreatedparams);
$messageidparams = array_merge([$userid], $timecreatedparams, [$userid], $timecreatedparams,
[$userid], $timecreatedparams, [$userid], $timecreatedparams);
$messageidrecords = $DB->get_records_sql($messageidsql, $messageidparams);

// Ok, let's recap. We've pulled a descending ordered list of conversations by latest time created
Expand Down

0 comments on commit bf51478

Please sign in to comment.