Conversation dropdown is now in sync with the notification list
authorAlexander Ebert <ebert@woltlab.com>
Fri, 28 Nov 2014 14:42:54 +0000 (15:42 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 28 Nov 2014 14:42:54 +0000 (15:42 +0100)
files/js/WCF.Conversation.js
files/lib/data/conversation/ConversationAction.class.php
templates/conversationListUnread.tpl

index 1d82c5b066e2e00645879951b3caed7eb10acb66..458ee548e15b8e5c42428113cee5dc10eae1471e 100644 (file)
@@ -1357,12 +1357,25 @@ WCF.Conversation.UserPanel = WCF.UserPanel.extend({
                $('<li><a href="' + this._addLink + '">' + WCF.Language.get('wcf.conversation.add') + '</a></li>').appendTo(dropdownMenu);
        },
        
+       /**
+        * @see WCF.UserPanel._after()
+        */
+       _after: function(dropdownMenu) {
+               var $items = dropdownMenu.children('.conversationItemUnread');
+               if ($items.length) {
+                       var $item = $items.last();
+                       if ($item.next('.conversationItem').length) {
+                               $('<li class="dropdownDivider" />').insertAfter($item);
+                       }
+               }
+       },
+       
        /**
         * @see WCF.UserPanel._getParameters()
         */
        _getParameters: function() {
                return {
-                       actionName: 'getUnreadConversations',
+                       actionName: 'getMixedConversationList',
                        className: 'wcf\\data\\conversation\\ConversationAction'
                };
        }
index c693993b5726d251cb69735452a30c4bb89fed05..f01fb72697d524a09205bc33158d765d59b4b5e0 100644 (file)
@@ -614,30 +614,49 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
        }
        
        /**
-        * Validates the 'getUnreadConversations' action.
+        * Validates parameters to return the mixed conversation list.
         */
-       public function validateGetUnreadConversations() {
+       public function validateGetMixedConversationList() {
                // does nothing
        }
        
        /**
-        * Returns the last 5 unread conversations.
+        * Returns a mixed conversation list with up to 5 unread conversations.
         * 
-        * @return      array
+        * @return      array<mixed>
         */
-       public function getUnreadConversations() {
-               $conversationList = new UserConversationList(WCF::getUser()->userID);
-               $conversationList->getConditionBuilder()->add('conversation_to_user.lastVisitTime < conversation.lastPostTime');
-               $conversationList->sqlLimit = 5;
-               $conversationList->sqlOrderBy = 'conversation.lastPostTime DESC';
-               $conversationList->readObjects();
+       public function getMixedConversationList() {
+               $unreadConversationList = new UserConversationList(WCF::getUser()->userID);
+               $unreadConversationList->getConditionBuilder()->add('conversation_to_user.lastVisitTime < conversation.lastPostTime');
+               $unreadConversationList->sqlLimit = 5;
+               $unreadConversationList->sqlOrderBy = 'conversation.lastPostTime DESC';
+               $unreadConversationList->readObjects();
+               
+               $conversations = array();
+               $count = 0;
+               foreach ($unreadConversationList as $conversation) {
+                       $conversations[] = $conversation;
+                       $count++;
+               }
+               
+               if ($count < 5) {
+                       $conversationList = new UserConversationList(WCF::getUser()->userID);
+                       $conversationList->getConditionBuilder()->add('conversation_to_user.lastVisitTime >= conversation.lastPostTime');
+                       $conversationList->sqlLimit = (5 - $count);
+                       $conversationList->sqlOrderBy = 'conversation.lastPostTime DESC';
+                       $conversationList->readObjects();
+                       
+                       foreach ($conversationList as $conversation) {
+                               $conversations[] = $conversation;
+                       }
+               }
                
                WCF::getTPL()->assign(array(
-                       'conversations' => $conversationList->getObjects()
+                       'conversations' => $conversations
                ));
                
                $totalCount = ConversationHandler::getInstance()->getUnreadConversationCount();
-               if (count($conversationList) < $totalCount) {
+               if ($count < 5 && $count < $totalCount) {
                        UserStorageHandler::getInstance()->reset(array(WCF::getUser()->userID), 'unreadConversationCount');
                }
                
index 0498256d9ceb100b8a62b4efe08b08a3c3d79c19..d422dfa3c49969fc8330ea0fe69e85e05078caf0 100644 (file)
@@ -1,5 +1,5 @@
 {foreach from=$conversations item=conversation}
-       <li>
+       <li class="conversationItem{if $conversation->lastVisitTime < $conversation->lastPostTime} conversationItemUnread{/if}">
                <a href="{link controller='Conversation' object=$conversation}action=firstNew{/link}" class="box24">
                        <div class="framed">
                                {if $conversation->lastPosterID}
@@ -9,7 +9,7 @@
                                {/if}
                        </div>
                        <div>
-                               <h3>{$conversation->subject}</h3>
+                               <h3>{if $conversation->lastVisitTime < $conversation->lastPostTime}<span class="badge label newContentBadge">{lang}wcf.message.new{/lang}</span> {/if}{$conversation->subject}</h3>
                                <small>{if $conversation->lastPosterID}{$conversation->lastPoster}{else}{$conversation->username}{/if} - {@$conversation->lastPostTime|time}</small>
                        </div>
                </a>