Fixed multiple conversation issues
authorMarcel Werk <burntime@woltlab.com>
Sat, 30 Mar 2013 13:51:37 +0000 (14:51 +0100)
committerMarcel Werk <burntime@woltlab.com>
Sat, 30 Mar 2013 13:51:37 +0000 (14:51 +0100)
files/js/WCF.Conversation.js
files/lib/data/conversation/Conversation.class.php
files/lib/data/conversation/ConversationAction.class.php
files/lib/data/conversation/ConversationEditor.class.php

index a2716bc1f19692d7d9640fdcb0c23a56b74ba5d5..f41b73a640a899afae79111c1490e2a970bf5895 100644 (file)
@@ -724,6 +724,7 @@ WCF.Conversation.AddParticipants = Class.extend({
                        case 'addParticipants':
                                if (data.returnValues.errorMessage) {
                                        this._dialog.find('dl.jsAddParticipants').addClass('formError');
+                                       this._dialog.find('dl.jsAddParticipants > dd small.innerError').remove();
                                        $('<small class="innerError">' + data.returnValues.errorMessage + '</small>').appendTo(this._dialog.find('dl.jsAddParticipants > dd'));
                                        return;
                                }
index 010a60faffad2d4ae1bf91cac4ba51faefb844bb..d51dbb878c3e9d35569d87b39e0f17a6baa29a74 100644 (file)
@@ -247,9 +247,10 @@ class Conversation extends DatabaseObject implements IBreadcrumbProvider, IRoute
         * 
         * @param       string          $participants
         * @param       string          $field
+        * @param       array<integer>  $existingParticipants
         * @return      array           $result
         */
-       public static function validateParticipants($participants, $field = 'participants') {
+       public static function validateParticipants($participants, $field = 'participants', array $existingParticipants = array()) {
                $result = array();
                $error = array();
                
@@ -275,7 +276,7 @@ class Conversation extends DatabaseObject implements IBreadcrumbProvider, IRoute
                                if ($user->userID == WCF::getUser()->userID) {
                                        throw new UserInputException($field, 'isAuthor');
                                }
-                               else if (in_array($user->userID, $result)) {
+                               else if (in_array($user->userID, $existingParticipants)) {
                                        throw new UserInputException($field, 'duplicate');
                                }
                                
@@ -283,7 +284,7 @@ class Conversation extends DatabaseObject implements IBreadcrumbProvider, IRoute
                                self::validateParticipant($user, $field);
                                
                                // no error
-                               $result[] = $user->userID;
+                               $existingParticipants[] = $result[] = $user->userID;
                        }
                        catch (UserInputException $e) {
                                $error[] = array('type' => $e->getType(), 'username' => $participant);
index 67dff6c82e7fc9c6198d8df8a0eaa7344b96d7f7..3f6fff536539216a07958a9cf815dfea3251751c 100644 (file)
@@ -522,7 +522,6 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
                        UserStorageHandler::getInstance()->reset(array(WCF::getUser()->userID), 'unreadConversationCount');
                }
                
-               
                // add modification log entry
                if ($this->parameters['hideConversation'] == Conversation::STATE_LEFT) {
                        if (empty($this->objects)) $this->readObjects();
@@ -644,13 +643,13 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
         */
        public function addParticipants() {
                try {
-                       $participantIDs = Conversation::validateParticipants($this->parameters['participants']);
+                       $participantIDs = Conversation::validateParticipants($this->parameters['participants'], 'participants', $this->conversation->getParticipantIDs(true));
                }
                catch (UserInputException $e) {
                        $errorMessage = '';
                        foreach ($e->getType() as $type) {
                                if (!empty($errorMessage)) $errorMessage .= ' ';
-                               $errorMessage .= WCF::getLanguage()->getDynamicVariable('wcf.conversation.participants.error.'.$type['type'], array('username' => $type['username']));
+                               $errorMessage .= WCF::getLanguage()->getDynamicVariable('wcf.conversation.participants.error.'.$type['type'], array('errorData' => array('username' => $type['username'])));
                        }
                        
                        return array(
@@ -663,30 +662,27 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
                $successMessage = '';
                if (!empty($participantIDs)) {
                        // check for already added participants
-                       $participantIDs = array_diff($participantIDs, $this->conversation->getParticipantIDs());
-                       if (!empty($participantIDs)) {
-                               $data = array();
-                               if ($this->conversation->isDraft) {
-                                       $draftData = unserialize($this->conversation->draftData);
-                                       $draftData['participants'] = array_merge($draftData['participants'], $participantIDs);
-                                       $data = array('data' => array('draftData' => serialize($draftData)));
-                               }
-                               else {
-                                       $data = array('participants' => $participantIDs);
-                               }
-                               
-                               $conversationAction = new ConversationAction(array($this->conversation), 'update', $data);
-                               $conversationAction->executeAction();
-                               
-                               $count = count($participantIDs);
-                               $successMessage = WCF::getLanguage()->getDynamicVariable('wcf.conversation.edit.addParticipants.success', array('count' => $count));
-                               
-                               ConversationModificationLogHandler::getInstance()->addParticipants($this->conversation->getDecoratedObject(), $participantIDs);
-                               
-                               if (!$this->conversation->isDraft) {
-                                       // update participant summary
-                                       $this->conversation->updateParticipantSummary();
-                               }
+                       $data = array();
+                       if ($this->conversation->isDraft) {
+                               $draftData = unserialize($this->conversation->draftData);
+                               $draftData['participants'] = array_merge($draftData['participants'], $participantIDs);
+                               $data = array('data' => array('draftData' => serialize($draftData)));
+                       }
+                       else {
+                               $data = array('participants' => $participantIDs);
+                       }
+                       
+                       $conversationAction = new ConversationAction(array($this->conversation), 'update', $data);
+                       $conversationAction->executeAction();
+                       
+                       $count = count($participantIDs);
+                       $successMessage = WCF::getLanguage()->getDynamicVariable('wcf.conversation.edit.addParticipants.success', array('count' => $count));
+                       
+                       ConversationModificationLogHandler::getInstance()->addParticipants($this->conversation->getDecoratedObject(), $participantIDs);
+                       
+                       if (!$this->conversation->isDraft) {
+                               // update participant summary
+                               $this->conversation->updateParticipantSummary();
                        }
                }
                
index 9863bcb7bd742742466add4e7f1df207f73e0ecc..d66a963d5fb6acdc4b62d299d1731cd99e88ca65 100644 (file)
@@ -55,24 +55,33 @@ class ConversationEditor extends DatabaseObjectEditor {
         * @param       array<integer>  $invisibleParticipantIDs
         */
        public function updateParticipants(array $participantIDs, array $invisibleParticipantIDs = array()) {
-               $sql = "INSERT INTO     wcf".WCF_N."_conversation_to_user
-                                       (conversationID, participantID, isInvisible)
-                       VALUES          (?, ?, ?)";
-               $statement = WCF::getDB()->prepareStatement($sql);
-               
-               WCF::getDB()->beginTransaction();
                if (!empty($participantIDs)) {
+                       WCF::getDB()->beginTransaction();
+                       $sql = "INSERT INTO             wcf".WCF_N."_conversation_to_user
+                                                       (conversationID, participantID, isInvisible)
+                               VALUES                  (?, ?, ?)
+                               ON DUPLICATE KEY
+                               UPDATE                  hideConversation = 0";
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       
                        foreach ($participantIDs as $userID) {
                                $statement->execute(array($this->conversationID, $userID, 0));
                        }
+                       WCF::getDB()->commitTransaction();
                }
                
                if (!empty($invisibleParticipantIDs)) {
+                       WCF::getDB()->beginTransaction();
+                       $sql = "INSERT INTO             wcf".WCF_N."_conversation_to_user
+                                                       (conversationID, participantID, isInvisible)
+                               VALUES                  (?, ?, ?)";
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       
                        foreach ($invisibleParticipantIDs as $userID) {
                                $statement->execute(array($this->conversationID, $userID, 1));
                        }
+                       WCF::getDB()->commitTransaction();
                }
-               WCF::getDB()->commitTransaction();
        }
        
        /**