Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-24678

The chat_get_latest_message function does not discriminate if chat messages have the same timestamp

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.9.7, 3.3.3, 3.4
    • Fix Version/s: 3.3.4, 3.4.1
    • Component/s: Chat
    • Labels:

      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))

      { return false; }

      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))

      { return false; }

      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>);

        Attachments

        1. MDL-24678.patch
          0.5 kB
          Carlos Alexandre S. da Fonseca

          Activity

            People

            Assignee:
            bozohrj Carlos Alexandre S. da Fonseca
            Reporter:
            bozohrj Carlos Alexandre S. da Fonseca
            Integrator:
            Damyon Wiese
            Tester:
            CiBoT
            Participants:
            Component watchers:
            Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              15/Jan/18