Fixed 'hideConversation' handling
authorAlexander Ebert <ebert@woltlab.com>
Sat, 9 Mar 2013 17:41:25 +0000 (18:41 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 9 Mar 2013 17:41:25 +0000 (18:41 +0100)
Fixes #55

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

index 70386c8d111f5f030fdd27f21115ebeaf6c7e10e..fc56a9a71b006c95356bf969764400f169b25829 100644 (file)
@@ -150,15 +150,20 @@ class Conversation extends DatabaseObject implements IBreadcrumbProvider, IRoute
        /**
         * Gets a list of all participants.
         * 
+        * @param       boolean         $excludeLeftParticipants
         * @return      array<integer>
         */
-       public function getParticipantIDs() {
-               $participantIDs = array();
+       public function getParticipantIDs($excludeLeftParticipants = false) {
+               $conditions = new PreparedStatementConditionBuilder();
+               $conditions->add("conversationID = ?", array($this->conversationID));
+               if ($excludeLeftParticipants) $conditions->add("hideConversation <> ?", array(2));
+               
                $sql = "SELECT          participantID
                        FROM            wcf".WCF_N."_conversation_to_user
-                       WHERE           conversationID = ?";
+                       ".$conditions;
                $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute(array($this->conversationID));
+               $statement->execute($conditions->getParameters());
+               $participantIDs = array();
                while ($row = $statement->fetchArray()) {
                        $participantIDs[] = $row['participantID'];
                }
index 0c1892ba803033f1142ca571c19093bd7ccc0ee2..acb6efad323bb75171f88c9b8250782a1244b9f3 100644 (file)
@@ -83,7 +83,7 @@ class ConversationMessageAction extends AbstractDatabaseObjectAction implements
                        
                        // fire notification event
                        if (!$conversation->isDraft) {
-                               $notificationRecipients = array_diff($conversation->getParticipantIDs(), array($message->userID)); // don't notify message author
+                               $notificationRecipients = array_diff($conversation->getParticipantIDs(true), array($message->userID)); // don't notify message author
                                if (!empty($notificationRecipients)) {
                                        UserNotificationHandler::getInstance()->fireEvent('conversationMessage', 'com.woltlab.wcf.conversation.message.notification', new ConversationMessageUserNotificationObject($message), $notificationRecipients);
                                }
@@ -96,6 +96,18 @@ class ConversationMessageAction extends AbstractDatabaseObjectAction implements
                                        AND conversationID = ?";
                        $statement = WCF::getDB()->prepareStatement($sql);
                        $statement->execute(array($message->userID, $conversation->conversationID));
+                       
+                       // reset visibility if it was hidden but not left
+                       $sql = "UPDATE  wcf".WCF_N."_conversation_to_user
+                               SET     hideConversation = ?
+                               WHERE   conversationID = ?
+                                       AND hideConversation = ?";
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       $statement->execute(array(
+                               0,
+                               $conversation->conversationID,
+                               1
+                       ));
                }
                
                // reset storage