Details
-
Type:
Bug
-
Status: Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.9.7, 3.3.3, 3.4
-
Component/s: Chat
-
Testing Instructions:
-
Difficulty:Easy
-
Affected Branches:MOODLE_19_STABLE, MOODLE_33_STABLE, MOODLE_34_STABLE
-
Fixed Branches:MOODLE_33_STABLE, MOODLE_34_STABLE
-
Pull from Repository:
-
Pull Master Branch:
MDL-24678-master-chat_get_latest_message
Description
This bug affects all moodle version, i think.
The bug is in the chat lib (mod/chat/lib.php), in the function chat_get_latest_message($chatid, $groupid=0)
If the chat message have the same timestamp, it could get wrong last chat message,
this is cause by this lines (line 440)
if (!$rs = $db->SelectLimit("SELECT *
FROM {$CFG->prefix}chat_messages
WHERE chatid = '$chatid' $groupselect
ORDER BY timestamp DESC", 1))
it's could be fix by change to this code:
if (!$rs = $db->SelectLimit("SELECT *
FROM {$CFG->prefix}chat_messages
WHERE chatid = '$chatid' $groupselect
ORDER BY timestamp DESC, id DESC", 1))
or with this query that not use any limit or sort
SELECT * FROM mdl_chat_messages WHERE chatid = <CHAT_ID> and timestamp=(SELECT MAX(timestamp) FROM mdl_chat_messages WHERE chatid = <CHAT_ID>) and id=(SELECT MAX(id) from mdl_chat_messages WHERE chatid = <CHAT_ID>);