TizenRefApp-5961 Conversation is not Scrolled down to the Latest Message 92/63892/2
authorDenis Dolzhenko <d.dolzhenko@samsung.com>
Mon, 28 Mar 2016 09:34:25 +0000 (12:34 +0300)
committerDenis Dolzhenko <d.dolzhenko@samsung.com>
Mon, 28 Mar 2016 14:45:19 +0000 (17:45 +0300)
Change-Id: I865a53073d0ecdbc6dd5ede9449511a64259ec22
Signed-off-by: Denis Dolzhenko <d.dolzhenko@samsung.com>
src/Conversation/ConvList/Controller/inc/ConvList.h
src/Conversation/ConvList/Controller/inc/ConvListItem.h
src/Conversation/ConvList/Controller/src/ConvList.cpp
src/Conversation/ConvList/Controller/src/ConvListItem.cpp
src/Conversation/Main/Controller/inc/Conversation.h
src/Conversation/Main/Controller/src/Conversation.cpp
src/MsgThread/Controller/src/MsgThread.cpp

index 3dc0c89..5129ea5 100644 (file)
@@ -83,12 +83,17 @@ namespace Msg
             void setThreadId(ThreadId id,const std::string &searchWord = std::string());
 
             /**
-             * @brief Navigate to mesage
+             * @brief Navigate to message
              * @param[in] msgId message id to navigate
              */
             void navigateTo(MsgId msgId);
 
             /**
+             * @brief Navigate to last message
+             */
+            void navigateToLastMsg();
+
+            /**
              * @brief Deletes selected items in SelectMode
              */
             void deleteSelectedItems();
index f4b0833..3973455 100644 (file)
@@ -50,7 +50,7 @@ namespace Msg
                          App &app,
                          WorkingDirRef workingDir,
                          const std::string &searchWord,
-                         ThumbnailMaker::ThumbId &thumbId);
+                         const ThumbnailMaker::ThumbId &thumbId);
 
             virtual ~ConvListItem();
 
@@ -114,7 +114,7 @@ namespace Msg
             Message::Type m_Type;
             time_t m_Time;
             BubbleEntity m_BubbleEntity;
-            ThumbnailMaker::ThumbId &m_ThumbId;
+            const ThumbnailMaker::ThumbId &m_ThumbId;
     };
 
     class IConvListItemListener
index a6228e9..1493780 100644 (file)
@@ -118,18 +118,15 @@ void ConvList::fill()
 
     MsgConversationListRef convList = m_MsgEngine.getStorage().getConversationList(m_ThreadId);
     int convListLen = convList->getLength();
-    m_ConvListItemMap.reserve(convListLen <= minMessagesBulk/2 ? minMessagesBulk : convListLen + additionalMessagesBulk);
-    m_DateLineItemMap.reserve(convListLen <= minMessagesBulk/2 ? minMessagesBulk : convListLen + additionalMessagesBulk);
+    int reserveSize = convListLen <= minMessagesBulk/2 ? minMessagesBulk : convListLen + additionalMessagesBulk;
+    m_ConvListItemMap.reserve(reserveSize);
+    m_DateLineItemMap.reserve(reserveSize);
 
     for(int i = 0; i < convListLen; ++i)
     {
         MsgConversationItem &item = convList->at(i);
-        ConvListItem *listItem = nullptr;
-        if(item.getDirection() == Message::MD_Received)
-            listItem = new ConvListItem(item, m_App, m_WorkingDir,  m_SearchWord, m_RecipThumbId);
-        else
-            listItem = new ConvListItem(item, m_App, m_WorkingDir, m_SearchWord, m_OwnerThumbId);
-        appendItem(listItem);
+        const ThumbnailMaker::ThumbId &thumbId = item.getDirection() == Message::MD_Received ? m_RecipThumbId : m_OwnerThumbId;
+        appendItem(new ConvListItem(item, m_App, m_WorkingDir, m_SearchWord, thumbId));
     }
 }
 
@@ -174,6 +171,13 @@ void ConvList::navigateTo(MsgId msgId)
         m_pList->showItem(*item, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
 }
 
+void ConvList::navigateToLastMsg()
+{
+    ListItem *item = m_pList->getLastItem();
+    if(item)
+        m_pList->showItem(*item, ELM_GENLIST_ITEM_SCROLLTO_TOP);
+}
+
 ConvListItem *ConvList::getItem(MsgId msgId) const
 {
     auto it = m_ConvListItemMap.find(msgId);
@@ -331,18 +335,19 @@ void ConvList::onMsgStorageUpdate(const MsgIdList &msgIdList)
 
 void ConvList::onMsgStorageInsert(const MsgIdList &msgIdList)
 {
+    bool inserted = false;
     for(auto &itemId: msgIdList)
     {
-        if(m_ThreadId == m_MsgEngine.getStorage().getMessage(itemId)->getThreadId())
+        if(m_ThreadId == m_MsgEngine.getStorage().getMessage(itemId)->getThreadId() && !getItem(itemId))
         {
-            if(!getItem(itemId))
-            {
-                MsgConversationItemRef item = m_MsgEngine.getStorage().getConversationItem(itemId);
-                ThumbnailMaker::ThumbId thumbId = item->getDirection() == Message::MD_Received ? m_RecipThumbId : m_OwnerThumbId;
-                appendItem(new ConvListItem(*item, m_App, m_WorkingDir, m_SearchWord, thumbId));
-            }
+            MsgConversationItemRef item = m_MsgEngine.getStorage().getConversationItem(itemId);
+            const ThumbnailMaker::ThumbId &thumbId = item->getDirection() == Message::MD_Received ? m_RecipThumbId : m_OwnerThumbId;
+            appendItem(new ConvListItem(*item, m_App, m_WorkingDir, m_SearchWord, thumbId));
+            inserted = true;
         }
     }
+    if(inserted)
+        navigateToLastMsg();
 }
 
 void ConvList::onMsgStorageDelete(const MsgIdList &msgIdList)
index 3796906..1fb1485 100644 (file)
@@ -34,7 +34,7 @@ ConvListItem::ConvListItem(const MsgConversationItem &item,
                            App &app,
                            WorkingDirRef workingDir,
                            const std::string &searchWord,
-                           ThumbnailMaker::ThumbId &thumbId)
+                           const ThumbnailMaker::ThumbId &thumbId)
     : ConvListViewItem(getConvItemType(item))
     , m_pListener(nullptr)
     , m_App(app)
index b4c775a..3bd6402 100644 (file)
@@ -59,6 +59,7 @@ namespace Msg
             virtual ~Conversation();
 
             void navigateTo(MsgId msgId);
+            void navigateToLastMsg();
             void execCmd(const AppControlComposeRef &cmd);
             void execCmd(const AppControlDefaultRef &cmd);
             void setThreadId(ThreadId id, const std::string &searchWord = std::string());
index 49ec5f5..ee669dd 100644 (file)
@@ -220,6 +220,11 @@ void Conversation::navigateTo(MsgId msgId)
     m_pConvList->navigateTo(msgId);
 }
 
+void Conversation::navigateToLastMsg()
+{
+    m_pConvList->navigateToLastMsg();
+}
+
 void Conversation::setThreadId(ThreadId id, const std::string &searchWord)
 {
     m_ThreadId = id;
index a7020e4..59e2b03 100644 (file)
@@ -110,6 +110,8 @@ void MsgThread::navigateToConversation(ThreadId threadId, MsgId msgId, const std
     frame->setThreadId(threadId, searchWord);
     if(msgId.isValid())
         frame->navigateTo(msgId);
+    else
+        frame->navigateToLastMsg();
     getParent().push(*frame);
 }