Correctly update the participant counter when removing an invisible participant
authorTim Düsterhus <duesterhus@woltlab.com>
Tue, 26 Sep 2023 13:45:41 +0000 (15:45 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Tue, 26 Sep 2023 13:45:41 +0000 (15:45 +0200)
files/lib/data/conversation/ConversationEditor.class.php

index 1c98e7806032ca7f80071cec2095403362f07750..ce1d7f9d604bac64927e17900639c83018f545b4 100644 (file)
@@ -170,13 +170,13 @@ class ConversationEditor extends DatabaseObjectEditor
      */
     public function removeParticipant($userID)
     {
-        $sql = "SELECT  joinedAt
+        $sql = "SELECT  joinedAt, isInvisible
                 FROM    wcf1_conversation_to_user
                 WHERE   conversationID = ?
                     AND participantID = ?";
         $statement = WCF::getDB()->prepare($sql, 1);
         $statement->execute([$this->conversationID, $userID]);
-        $joinedAt = $statement->fetchSingleColumn();
+        $participantData = $statement->fetchSingleRow();
 
         $sql = "SELECT      messageID
                 FROM        wcf1_conversation_message
@@ -187,7 +187,7 @@ class ConversationEditor extends DatabaseObjectEditor
         $statement = WCF::getDB()->prepare($sql, 1);
         $statement->execute([
             $this->conversationID,
-            $joinedAt,
+            $participantData['joinedAt'],
             TIME_NOW,
         ]);
         $lastMessageID = $statement->fetchSingleColumn();
@@ -207,8 +207,8 @@ class ConversationEditor extends DatabaseObjectEditor
             $userID,
         ]);
 
-        // decrease participant count unless it is the author
-        if ($userID != $this->userID) {
+        // The author and invisible participants are not included in the count.
+        if ($userID != $this->userID && !$participantData['isInvisible']) {
             $this->updateCounters([
                 'participants' => -1,
             ]);