* @return boolean
*/
public function canAddParticipants() {
- if (WCF::getUser()->userID == $this->userID || $this->participantCanInvite) {
- return true;
+ // check permissions
+ if (WCF::getUser()->userID != $this->userID && !$this->participantCanInvite) {
+ return false;
}
- return false;
+ // check for maximum number of participants
+ // note: 'participants' does not track invisible participants, this will be checked on the fly!
+ if ($this->participants >= WCF::getSession()->getPermission('user.conversation.maxParticipants')) {
+ return false;
+ }
+
+ return true;
}
/**
);
}
+ // validate limit
+ $newCount = $this->conversation->participants + count($participantIDs);
+ if ($newCount > WCF::getSession()->getPermission('user.conversation.maxParticipants')) {
+ return array(
+ 'actionName' => 'addParticipants',
+ 'errorMessage' => WCF::getLanguage()->getDynamicVariable('wcf.conversation.participants.error.tooManyParticipants', array('remaining' => WCF::getSession()->getPermission('user.conversation.maxParticipants') - $newCount))
+ );
+ }
+
$count = 0;
$successMessage = '';
if (!empty($participantIDs)) {
}
WCF::getDB()->commitTransaction();
}
+
+ $this->updateParticipantCount();
+ }
+
+ /**
+ * Updates participant count.
+ */
+ public function updateParticipantCount() {
+ $sql = "UPDATE wcf".WCF_N."_conversation
+ SET participants = (
+ SELECT COUNT(*) AS count
+ FROM wcf".WCF_N."_conversation_to_user conversation_to_user
+ WHERE conversation_to_user.conversationID = conversationID
+ AND hideConversation <> ?
+ AND participantID <> ?
+ )
+ WHERE conversationID = ?";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute(array(
+ Conversation::STATE_LEFT,
+ $this->userID,
+ $this->conversationID
+ ));
}
/**
$this->conversationID,
$userID
));
+
+ // decrease participant count unless it is the author
+ if ($userID != $this->userID) {
+ $this->updateCounters(array(
+ 'participants' => -1
+ ));
+ }
}
/**