Skip to content
Browse files

Merge branch 'unstable' of github.com:vanillaforums/Garden into unstable

  • Loading branch information...
2 parents 1051911 + 6c786f9 commit 874efe4da7c84e2e558c764474278aa8ba151d9f @markosullivan markosullivan committed Dec 31, 2010
View
27 applications/conversations/controllers/class.conversationscontroller.php
@@ -7,9 +7,19 @@
You should have received a copy of the GNU General Public License along with Garden. If not, see <http://www.gnu.org/licenses/>.
Contact Vanilla Forums Inc. at support [at] vanillaforums [dot] com
*/
-
+/**
+ * Conversations Controller
+ *
+ * @package Conversations
+ */
+
+/**
+ * Master controller for Conversations for others to extend.
+ *
+ * @since 2.0.0
+ * @package Conversations
+ */
class ConversationsController extends Gdn_Controller {
-
/**
* Returns an array of pages that contain settings information for this application.
*
@@ -19,10 +29,23 @@ public function GetSettingsPages(&$Menu) {
// There are no configuration pages for Conversations
}
+ /**
+ * Do-nothing construct to let children constructs bubble up.
+ *
+ * @access public
+ */
public function __construct() {
parent::__construct();
}
+ /**
+ * Include JS, CSS, and modules used by all methods.
+ *
+ * Always called by dispatcher before controller's requested method.
+ *
+ * @since 2.0.0
+ * @access public
+ */
public function Initialize() {
$this->Permission('Garden.SignIn.Allow');
if ($this->DeliveryType() == DELIVERY_TYPE_ALL) {
View
144 applications/conversations/controllers/class.messagescontroller.php
@@ -7,21 +7,66 @@
You should have received a copy of the GNU General Public License along with Garden. If not, see <http://www.gnu.org/licenses/>.
Contact Vanilla Forums Inc. at support [at] vanillaforums [dot] com
*/
-
+/**
+ * Messages Controller
+ *
+ * @package Conversations
+ */
+
/**
* MessagesController handles displaying lists of conversations and conversation messages.
+ *
+ * @since 2.0.0
+ * @package Conversations
*/
class MessagesController extends ConversationsController {
-
+ /**
+ * Models to include.
+ *
+ * @since 2.0.0
+ * @access public
+ * @var array
+ */
public $Uses = array('Form', 'ConversationModel', 'ConversationMessageModel');
+ /**
+ * A dataset of users taking part in this discussion. Used by $this->Index.
+ *
+ * @since 2.0.0
+ * @access public
+ * @var object
+ */
+ public $RecipientData;
+
+ /**
+ * The current offset of the paged data set. Defined and used by $this->Index and $this->All.
+ *
+ * @since 2.0.0
+ * @access public
+ * @var int
+ */
+ public $Offset;
+
+ /**
+ * Highlight route and include JS, CSS, and modules used by all methods.
+ *
+ * Always called by dispatcher before controller's requested method.
+ *
+ * @since 2.0.0
+ * @access public
+ */
public function Initialize() {
parent::Initialize();
$this->Menu->HighlightRoute('/messages/all');
}
/**
- * Add a new conversations.
+ * Start a new conversation.
+ *
+ * @since 2.0.0
+ * @access public
+ *
+ * @param string $Recipient Username of the recipient.
*/
public function Add($Recipient = '') {
$this->Form->SetModel($this->ConversationModel);
@@ -49,6 +94,11 @@ public function Add($Recipient = '') {
/**
* Add a message to a conversation.
+ *
+ * @since 2.0.0
+ * @access public
+ *
+ * @param int $ConversationID Unique ID of the conversation.
*/
public function AddMessage($ConversationID = '') {
$this->Form->SetModel($this->ConversationMessageModel);
@@ -84,21 +134,33 @@ public function AddMessage($ConversationID = '') {
/**
* Show all conversations for the currently authenticated user.
+ *
+ * @since 2.0.0
+ * @access public
+ *
+ * @param int $Offset Number to skip.
+ * @param int $Limit Number to show.
+ * @param bool $BookmarkedOnly Whether to limit to only bookmarked conversations.
*/
public function All($Offset = 0, $Limit = '', $BookmarkedOnly = FALSE) {
+ $Session = Gdn::Session();
$this->Title(T('Conversations'));
+
+ // Calculate offset
$this->Offset = $Offset;
- $Session = Gdn::Session();
if (!is_numeric($this->Offset) || $this->Offset < 0)
$this->Offset = 0;
+ // Calculate limit
if ($Limit == '' || !is_numeric($Limit) || $Limit < 0)
$Limit = Gdn::Config('Conversations.Conversations.PerPage', 50);
-
+
+ // Limit to bookmarks?
$Wheres = array();
if ($BookmarkedOnly !== FALSE)
$Wheres['Bookmarked'] = '1';
-
+
+ // Fetch from model
$this->ConversationData = $this->ConversationModel->Get(
$Session->UserID,
$this->Offset,
@@ -128,56 +190,70 @@ public function All($Offset = 0, $Limit = '', $BookmarkedOnly = FALSE) {
$this->View = 'conversations';
}
+ // Build and display page
$this->AddModule('SignedInModule');
$this->AddModule('NewConversationModule');
$this->Render();
}
/**
* Clear the message history for a specific conversation & user.
+ *
+ * @since 2.0.0
+ * @access public
+ *
+ * @param int $ConversationID Unique ID of conversation to clear.
*/
public function Clear($ConversationID = FALSE) {
$Session = Gdn::Session();
+
+ // Yes/No response
$this->_DeliveryType = DELIVERY_TYPE_BOOL;
+
+ // Clear it
if (is_numeric($ConversationID) && $ConversationID > 0 && $Session->IsValid())
$this->ConversationModel->Clear($ConversationID, $Session->UserID);
-
+
$this->StatusMessage = T('The conversation has been cleared.');
$this->RedirectUrl = Url('/messages/all');
$this->Render();
}
/**
- * A dataset of users taking part in this discussion. Used by $this->Index.
- */
- public $RecipientData;
-
- /**
- * The current offset of the paged data set. Defined and used by $this->Index and $this->All.
- */
- public $Offset;
-
- /**
* Shows all uncleared messages within a conversation for the viewing user
+ *
+ * @since 2.0.0
+ * @access public
+ *
+ * @param int $ConversationID Unique ID of conversation to view.
+ * @param int $Offset Number to skip.
+ * @param int $Limit Number to show.
*/
public function Index($ConversationID = FALSE, $Offset = -1, $Limit = '') {
$this->Offset = $Offset;
$Session = Gdn::Session();
+
+ // Figure out Conversation ID
if (!is_numeric($ConversationID) || $ConversationID < 0)
$ConversationID = 0;
+ // Form setup for adding comments
$this->Form->SetModel($this->ConversationMessageModel);
$this->Form->AddHidden('ConversationID', $ConversationID);
+ // Get conversation data
$this->RecipientData = $this->ConversationModel->GetRecipients($ConversationID);
$this->Conversation = $this->ConversationModel->GetID($ConversationID, $Session->UserID);
+ // Bad conversation? Redirect
if ($this->Conversation === FALSE)
Redirect('dashboard/home/filenotfound');
-
+
+ // Get limit
if ($Limit == '' || !is_numeric($Limit) || $Limit < 0)
$Limit = Gdn::Config('Conversations.Messages.PerPage', 50);
+ // Calculate counts
if (!is_numeric($this->Offset) || $this->Offset < 0) {
// Round down to the appropriate offset based on the user's read messages & messages per page
$CountReadMessages = $this->Conversation->CountMessages - $this->Conversation->CountNewMessages;
@@ -190,14 +266,16 @@ public function Index($ConversationID = FALSE, $Offset = -1, $Limit = '') {
// (((67 comments / 10 perpage) = 6.7) rounded down = 6) * 10 perpage = offset 60;
$this->Offset = floor($CountReadMessages / $Limit) * $Limit;
}
-
+
+ // Fetch message data
$this->MessageData = $this->ConversationMessageModel->Get(
$ConversationID,
$Session->UserID,
$this->Offset,
$Limit
);
+ // Figure out who's participating.
$this->Participants = '';
$Count = 0;
$Users = array();
@@ -241,6 +319,7 @@ public function Index($ConversationID = FALSE, $Offset = -1, $Limit = '') {
$this->View = 'messages';
}
+ // Add modules
$this->AddModule('SignedInModule');
$this->AddModule('NewConversationModule');
@@ -254,16 +333,25 @@ public function Index($ConversationID = FALSE, $Offset = -1, $Limit = '') {
$this->AddModule('AddPeopleModule');
+ // Render view
$this->Render();
}
/**
* Allows users to bookmark conversations.
+ *
+ * @since 2.0.0
+ * @access public
+ *
+ * @param int $ConversationID Unique ID of conversation to view.
+ * @param string $TransientKey Single-use hash to prove intent.
*/
public function Bookmark($ConversationID = '', $TransientKey = '') {
$Session = Gdn::Session();
$Success = FALSE;
$Star = FALSE;
+
+ // Validate & do bookmarking
if (
is_numeric($ConversationID)
&& $ConversationID > 0
@@ -273,6 +361,7 @@ public function Bookmark($ConversationID = '', $TransientKey = '') {
$Bookmark = $this->ConversationModel->Bookmark($ConversationID, $Session->UserID);
}
+ // Report success or error
if ($Bookmark === FALSE)
$this->Form->AddError('ErrorBool');
else
@@ -288,14 +377,27 @@ public function Bookmark($ConversationID = '', $TransientKey = '') {
/**
* Show bookmarked conversations for the current user.
*
- * @param int
- * @param string
+ * @since 2.0.0
+ * @access public
+ *
+ * @param int $Offset Number to skip.
+ * @param string $Limit Number to show.
*/
public function Bookmarked($Offset = 0, $Limit = '') {
$this->View = 'All';
$this->All($Offset, $Limit, TRUE);
}
+ /**
+ * Show bookmarked conversations for the current user.
+ *
+ * @since 2.0.0
+ * @access public
+ *
+ * @param int $Offset Number to skip.
+ * @param string $Limit Number to show.
+ * @param bool $BookmarkedOnly Whether to show only bookmarks
+ */
public function Inbox($Offset = 0, $Limit = '', $BookmarkedOnly = FALSE) {
$this->View = 'All';
$this->All($Offset, $Limit, $BookmarkedOnly);
View
2 applications/dashboard/settings/structure.php
@@ -55,7 +55,7 @@
$Construct
->PrimaryKey('UserID')
- ->Column('Name', 'varchar(20)', FALSE, 'key')
+ ->Column('Name', 'varchar(50)', FALSE, 'key')
->Column('Password', 'varbinary(100)') // keep this longer because of some imports.
->Column('HashMethod', 'varchar(10)', TRUE)
->Column('Photo', 'varchar(255)', NULL)
View
4 applications/vanilla/models/class.discussionmodel.php
@@ -299,6 +299,10 @@ public function GetAnnouncements($Wheres = '') {
$this->AddDiscussionColumns($Data);
+ // Prep and fire event
+ $this->EventArguments['Data'] = $Data;
+ $this->FireEvent('AfterAddColumns');
+
return $Data;
}
View
2 library/core/class.format.php
@@ -608,7 +608,7 @@ public static function Mentions($Mixed) {
// Handle @mentions.
if(C('Garden.Format.Mentions')) {
$Mixed = preg_replace(
- '/(^|[\s,\.])@(\w{1,20})\b/i', //{3,20}
+ '/(^|[\s,\.])@(\w{1,50})\b/i', //{3,20}
'\1'.Anchor('@\2', '/profile/\\2'),
$Mixed
);
View
62 plugins/AllViewed/class.allviewed.plugin.php
@@ -4,15 +4,17 @@
$PluginInfo['AllViewed'] = array(
'Name' => 'Mark All Viewed',
'Description' => 'Allows users to mark all discussions as viewed.',
- 'Version' => '1.0',
+ 'Version' => '1.1',
'Author' => "Matt Lincoln Russell",
'AuthorEmail' => 'lincolnwebs@gmail.com',
'AuthorUrl' => 'http://www.tmprod.com/web-development/vanilla.php',
'License' => 'GNU GPLv2'
);
class AllViewedPlugin extends Gdn_Plugin {
-
+ /**
+ * Adds "Mark All Viewed" to main menu.
+ */
public function Base_Render_Before(&$Sender) {
// Add "Mark All Viewed" to menu
$Session = Gdn::Session();
@@ -32,6 +34,34 @@ function DiscussionsController_MarkAllViewed_Create(&$Sender) {
}
/**
+ * Get the number of comments inserted since the given timestamp.
+ */
+ function GetCommentCountSince($DiscussionID, $DateSince) {
+ if (!C('Plugins.AllViewed.Enabled')) return;
+ // Only for members
+ $Session = Gdn::Session();
+ if(!$Session->IsValid()) return;
+
+ // Validate DiscussionID
+ $DiscussionID = (int) $DiscussionID;
+ if (!$DiscussionID)
+ throw new Exception('A valid DiscussionID is required in GetCommentCountSince.');
+
+ // Prep DB
+ $Database = Gdn::Database();
+ $SQL = $Database->SQL();
+
+ // Get new comment count
+ return $SQL
+ ->Select('c.CommentID')
+ ->From('Comment c')
+ ->Where('DiscussionID = '.$DiscussionID)
+ ->Where("DateInserted > '".$DateSince."'")
+ ->Get()
+ ->Count;
+ }
+
+ /**
* Modify CountUnreadComments to account for DateAllViewed
*
* Required in DiscussionModel->Get() just before the return:
@@ -48,13 +78,13 @@ function DiscussionModel_AfterAddColumns_Handler(&$Sender) {
// Recalculate New count with user's DateAllViewed
$Sender->Data = GetValue('Data', $Sender->EventArguments, '');
$Result = &$Sender->Data->Result();
+ $DateAllViewed = Gdn_Format::ToTimestamp($Session->User->DateAllViewed);
foreach($Result as &$Discussion) {
- if(Gdn_Format::ToTimestamp($Discussion->DateLastComment) <= Gdn_Format::ToTimestamp($Session->User->DateAllViewed)) {
- $Discussion->CountUnreadComments = 0; // Covered by AllViewed
- }
- elseif($Discussion->CountCommentWatch == 0) { // AllViewed used, but new comments since then
- $Discussion->CountCommentWatch = -1; // hack around "incomplete comment count" logic in WriteDiscussion
- $Discussion->CountUnreadComments = $Discussion->CountComments;
+ if ($DateAllViewed != 0) { // Only if they've used AllViewed
+ if (Gdn_Format::ToTimestamp($Discussion->DateLastComment) <= $DateAllViewed)
+ $Discussion->CountUnreadComments = 0; // Covered by AllViewed
+ elseif ($Discussion->DateLastViewed == $DateAllViewed) // AllViewed used since last "real" view, but new comments since then
+ $Discussion->CountUnreadComments = $this->GetCommentCountSince($Discussion->DiscussionID, $DateAllViewed);
}
}
}
@@ -70,21 +100,23 @@ function UserModel_UpdateAllViewed_Create(&$Sender) {
$UserID = $Session->User->UserID; // Can only activate on yourself
- // Validity check (in case UserID passed from elsewhere some day)
+ // Validite UserID
$UserID = (int) $UserID;
- if (!$UserID) {
+ if (!$UserID)
throw new Exception('A valid UserId is required.');
- }
+
+ // Create timestamp first so all uses match.
+ $AllViewed = Gdn_Format::ToDateTime();
// Update User timestamp
$Sender->SQL->Update('User')
- ->Set('DateAllViewed', Gdn_Format::ToDateTime());
+ ->Set('DateAllViewed', $AllViewed);
$Sender->SQL->Where('UserID', $UserID)->Put();
- // Update CountComments = 0
+ // Update DateLastViewed = now
$Sender->SQL->Update('UserDiscussion')
- ->Set('CountComments', 0); // Hack to avoid massive update query
- $Sender->SQL->Where('UserID', $UserID)->Put();
+ ->Set('DateLastViewed', $AllViewed)
+ ->Where('UserID', $UserID)->Put();
// Set in current session
$Session->User->DateAllViewed = Gdn_Format::ToDateTime();

0 comments on commit 874efe4

Please sign in to comment.
Something went wrong with that request. Please try again.