Add previous participants unless they left by their own choice
authorMarcel Werk <burntime@woltlab.com>
Tue, 9 Apr 2019 13:56:43 +0000 (15:56 +0200)
committerMarcel Werk <burntime@woltlab.com>
Tue, 9 Apr 2019 13:56:43 +0000 (15:56 +0200)
Closes #120

files/lib/data/conversation/Conversation.class.php
files/lib/data/conversation/ConversationAction.class.php
files/lib/data/conversation/ConversationEditor.class.php
install.sql

index 57e4b079353de665294bbeb92d99128fd65b20de..23fb740c0554f2b18c6fd02dfff90c421a159d08 100644 (file)
@@ -339,12 +339,14 @@ class Conversation extends DatabaseObject implements IRouteController, ITitledLi
         * Returns a list of the usernames of all participants.
         *
         * @param       boolean         $excludeSelf
+        * @param       boolean         $leftByOwnChoice                           
         * @return      string[]
         */
-       public function getParticipantNames($excludeSelf = false) {
+       public function getParticipantNames($excludeSelf = false, $leftByOwnChoice = false) {
                $conditions = new PreparedStatementConditionBuilder();
                $conditions->add("conversationID = ?", [$this->conversationID]);
                if ($excludeSelf) $conditions->add("conversation_to_user.participantID <> ?", [WCF::getUser()->userID]);
+               if ($leftByOwnChoice) $conditions->add("conversation_to_user.leftByOwnChoice = ?", [1]);
 
                $sql = "SELECT          user_table.username
                        FROM            wcf".WCF_N."_conversation_to_user conversation_to_user
index 59a1623bfe11944e24ac8e95bcb268e98a1ece57..4ee4d84714c5198cb3bb73178500d8dd9bb5ad87 100644 (file)
@@ -776,7 +776,7 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
         */
        public function getAddParticipantsForm() {
                return [
-                       'excludedSearchValues' => $this->conversation->getParticipantNames(),
+                       'excludedSearchValues' => $this->conversation->getParticipantNames(false, true),
                        'maxItems' => WCF::getSession()->getPermission('user.conversation.maxParticipants') - $this->conversation->participants,
                        'canAddGroupParticipants' => WCF::getSession()->getPermission('user.conversation.canAddGroupParticipants'),
                        'template' => WCF::getTPL()->fetch('conversationAddParticipants', 'wcf', ['conversation' => $this->conversation])
index 9eaf4e3153154497e20a2fdb2d5cc256e011db36..3b49e5731341e1094a27171d4721449cbb3b9df9 100644 (file)
@@ -78,7 +78,7 @@ class ConversationEditor extends DatabaseObjectEditor {
                                                        (conversationID, participantID, username, isInvisible, joinedAt)
                                VALUES                  (?, ?, ?, ?, ?)
                                ON DUPLICATE KEY
-                               UPDATE                  hideConversation = 0";
+                               UPDATE                  hideConversation = 0, leftAt = 0, leftByOwnChoice = 1";
                        $statement = WCF::getDB()->prepareStatement($sql);
                        
                        foreach ($participantIDs as $userID) {
@@ -182,13 +182,15 @@ class ConversationEditor extends DatabaseObjectEditor {
                
                $sql = "UPDATE  wcf".WCF_N."_conversation_to_user
                        SET     leftAt = ?,
-                               lastMessageID = ?
+                               lastMessageID = ?,
+                               leftByOwnChoice = ?
                        WHERE   conversationID = ?
                                AND participantID = ?";
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute([
                        TIME_NOW,
                        $lastMessageID ?: null,
+                       0,
                        $this->conversationID,
                        $userID
                ]);
index f3b1664269dc71b9c6c8206f19716d96f445afc5..2a8cd2fbdc5419d57e41f1f6dc8bd188868c4cd2 100644 (file)
@@ -32,6 +32,7 @@ CREATE TABLE wcf1_conversation_to_user (
        joinedAt INT(10) NOT NULL DEFAULT 0,
        leftAt INT(10) NOT NULL DEFAULT 0,
        lastMessageID INT(10) NULL,
+       leftByOwnChoice TINYINT(1) NOT NULL DEFAULT 1,
        
        UNIQUE KEY (participantID, conversationID),
        KEY (participantID, hideConversation)