Fix Conversation::hasOtherParticipants()
authorTim Düsterhus <duesterhus@woltlab.com>
Tue, 26 Sep 2023 13:28:52 +0000 (15:28 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Tue, 26 Sep 2023 13:31:04 +0000 (15:31 +0200)
The previous implementation did not correctly handle invisible participants,
because they are not included in the participant counter.

It has been verified that the warning correctly shows when all other
participants are invisible and the creator as the only visible participant
left.

see https://www.woltlab.com/community/thread/301790/

files/lib/data/conversation/Conversation.class.php

index c553c2c6d746ca484d54bddd4334cf9a190b2b32..62a4fb7c84a2729a38793f6459a6cf8eec6a6a76 100644 (file)
@@ -411,39 +411,16 @@ class Conversation extends DatabaseObject implements IPopoverObject, IRouteContr
      */
     public function hasOtherParticipants()
     {
-        if ($this->userID == WCF::getUser()->userID) {
-            // author
-            if ($this->participants == 0) {
-                return false;
-            }
-
-            return true;
-        } else {
-            if ($this->participants > 1) {
-                return true;
-            }
-            if ($this->isInvisible && $this->participants > 0) {
-                return true;
-            }
-
-            if ($this->userID) {
-                // check if author has left the conversation
-                $sql = "SELECT  hideConversation
-                        FROM    wcf" . WCF_N . "_conversation_to_user
-                        WHERE   conversationID = ?
-                            AND participantID = ?";
-                $statement = WCF::getDB()->prepareStatement($sql);
-                $statement->execute([$this->conversationID, $this->userID]);
-                $row = $statement->fetchArray();
-                if ($row !== false) {
-                    if ($row['hideConversation'] != self::STATE_LEFT) {
-                        return true;
-                    }
-                }
-            }
+        $participantList = new ConversationParticipantList(
+            $this->conversationID,
+            WCF::getUser()->userID,
+            $this->userID == WCF::getUser()->userID
+        );
+        $participantList->getConditionBuilder()->add('conversation_to_user.hideConversation <> ?', [self::STATE_LEFT]);
+        $participantList->getConditionBuilder()->add('conversation_to_user.leftAt = ?', [0]);
+        $participantList->readObjectIDs();
 
-            return false;
-        }
+        return \count($participantList->getObjectIDs()) > 1;
     }
 
     /**