TizenRefApp-6875 Draft isn't saved when removing all messages from conversation 63/86963/1
authorDenis Dolzhenko <d.dolzhenko@samsung.com>
Mon, 5 Sep 2016 16:10:17 +0000 (19:10 +0300)
committerDenis Dolzhenko <d.dolzhenko@samsung.com>
Mon, 5 Sep 2016 16:10:17 +0000 (19:10 +0300)
Change-Id: I77bfd818851f369aafbe358b8f8371395d6109fb
Signed-off-by: Denis Dolzhenko <d.dolzhenko@samsung.com>
src/Conversation/Body/Controller/src/Body.cpp
src/Conversation/Main/Controller/inc/Conversation.h
src/Conversation/Main/Controller/src/Conversation.cpp
src/Conversation/Recipients/Controller/inc/ConvRecipientsPanel.h
src/Conversation/Recipients/Controller/src/ConvRecipientsPanel.cpp

index 01f8ebf..a2ecafb 100644 (file)
@@ -197,6 +197,7 @@ void Body::read(Message &msg)
 
 void Body::write(const Message &msg)
 {
+    clear();
     if(const MessageSMS *sms = dynamic_cast<const MessageSMS*>(&msg))
         write(*sms);
     else if(const MessageMms *mms = dynamic_cast<const MessageMms*>(&msg))
index d6ccd6d..684ebdf 100644 (file)
@@ -187,6 +187,7 @@ namespace Msg
             void write(const Message &msg);
             MsgId saveDraftMsg();
             void editDraftMsg(MsgId id);
+            void createNewMsgThread();
 
             void onNaviOkButtonClicked();
             void onNaviCenterButtonClicked();
@@ -201,6 +202,7 @@ namespace Msg
             ConvRecipientsPanel *m_pRecipPanel;
             ConvContactList *m_pContactsList;
             ThreadId m_ThreadId;
+            MsgAddressListRef m_AddressList;
             bool m_IsMms; // Compose message type
             bool m_DispIsMms; // Last displayed message type for user.
             Ecore_Idler *m_NnotifyConvertMsgTypeIdler;
index 1a855f4..b647ddf 100644 (file)
@@ -261,23 +261,21 @@ void Conversation::navigateToBottom()
 void Conversation::setThreadId(ThreadId id, const std::string &searchWord)
 {
     m_ThreadId = id;
+    if(id.isValid())
+        m_AddressList = getMsgEngine().getStorage().getAddressList(id);
+    else
+        m_AddressList.reset();
+
     setMode(m_ThreadId.isValid() ? ConversationMode : NewMessageMode);
 
     if(m_pBody)
-    {
-        m_pBody->clear();
         m_pBody->setMmsRecipFlag(getMsgEngine().getStorage().hasEmail(m_ThreadId));
-    }
 
     if(m_pRecipPanel)
-    {
-        m_pRecipPanel->clear();
         m_pRecipPanel->update(m_ThreadId);
-    }
+
     if(m_pConvList)
-    {
         m_pConvList->setThreadId(m_ThreadId, searchWord);
-    }
 
     markAsRead();
     checkAndSetMsgType();
@@ -302,7 +300,7 @@ void Conversation::forwardMsg(MsgId id)
 
 MsgAddressListRef Conversation::getAddressList()
 {
-    return getMsgEngine().getStorage().getAddressList(m_ThreadId);
+    return m_AddressList ? m_AddressList : getMsgEngine().getStorage().getAddressList(m_ThreadId);
 }
 
 void Conversation::setMode(Mode mode)
@@ -341,7 +339,7 @@ void Conversation::setNewMessageMode()
     m_pRecipPanel->update(m_ThreadId);
     m_pRecipPanel->showMbe(!m_pRecipPanel->isMbeEmpty());
     m_pRecipPanel->showEntry(true);
-    m_pRecipPanel->setFocus(true);
+    m_pRecipPanel->setFocus(true); // TODO: Not bad to remove from here
 }
 
 void Conversation::setConversationMode()
@@ -357,7 +355,7 @@ void Conversation::setConversationMode()
     {
         createRecipPanel(*m_pLayout);
         m_pRecipPanel->showEntry(false);
-        m_pRecipPanel->update(*addressList);
+        m_pRecipPanel->update(addressList);
     }
     else
     {
@@ -532,11 +530,7 @@ void Conversation::sendMessage()
 
     if(sendRes == MsgTransport::SendSuccess && m_ThreadId.isValid())
     {
-        if(m_Mode == NewMessageMode)
-            setMode(ConversationMode);
-
-        m_pConvList->setThreadId(m_ThreadId);
-        m_IsMms = false;
+        setThreadId(m_ThreadId);
         m_pMsgInputPanel->disabledButton(MessageInputPanel::SendButtonId, true);
         m_pBody->clear();
     }
@@ -586,6 +580,14 @@ void Conversation::editDraftMsg(MsgId id)
     }
 }
 
+void Conversation::createNewMsgThread()
+{
+    MsgAddressListRef addressList = getAddressList();
+    setThreadId(ThreadId());
+    if(m_pRecipPanel)
+        m_pRecipPanel->update(addressList);
+}
+
 void Conversation::notifyConvertMsgType()
 {
     if(!m_NnotifyConvertMsgTypeIdler)
@@ -1126,8 +1128,9 @@ void Conversation::onAddRecipientsItemPressed(PopupListItem &item)
 {
     MSG_LOG("");
     item.getParent().destroy();
-    setMode(NewMessageMode);
-    m_ThreadId.reset();
+    createNewMsgThread();
+    if(m_pRecipPanel)
+        m_pRecipPanel->setEntryFocus(true);
 }
 
 void Conversation::onMakeVoiceItemPressed(PopupListItem &item)
@@ -1184,8 +1187,19 @@ void Conversation::onAllConvItemsDeleted(ConvList &list)
     if(m_Mode != NewMessageMode)
     {
         auto convList = getMsgEngine().getStorage().getConversationList(m_ThreadId);
-        if(convList && convList->getLength() == 0)
-            onHwBackButtonClicked();
+        if((convList && convList->getLength() == 0) || !convList)
+        {
+            if(m_pBody->isEmpty())
+            {
+                onHwBackButtonClicked();
+            }
+            else
+            {
+                // Current MsgThread is dead, so create new MsgThread from existing recipients.
+                createNewMsgThread();
+                m_pBody->setFocus(true);
+            }
+        }
     }
 }
 
index b493c2a..ee968a2 100644 (file)
@@ -45,6 +45,7 @@ namespace Msg
             bool isMms() const;
             void setListener(IConvRecipientsPanelListener *l);
             void update(const ThreadId &threadId);
+            void update(const MsgAddressListRef &addressList);
             void update(const MsgAddressList &addressList);
             void execCmd(const AppControlComposeRef &cmd);
             MbeRecipients::AppendItemStatus appendItem(const std::string &address, MsgAddress::AddressType addressType = MsgAddress::UnknownAddressType);
@@ -89,6 +90,7 @@ namespace Msg
             IConvRecipientsPanelListener *m_pListener;
             ContactPicker m_Picker;
             MbeRecipients *m_pMbe;
+            ThreadId m_ThreadId;
     };
 
     class IConvRecipientsPanelListener
index 26460c1..9cd11ed 100644 (file)
@@ -122,6 +122,11 @@ MbeRecipients &ConvRecipientsPanel::getMbeRecipients()
     return *m_pMbe;
 }
 
+void ConvRecipientsPanel::update(const MsgAddressListRef &addressList)
+{
+    addressList ? update(*addressList) : clearMbe();
+}
+
 void ConvRecipientsPanel::update(const MsgAddressList &addressList)
 {
     clearMbe();
@@ -135,7 +140,12 @@ void ConvRecipientsPanel::update(const MsgAddressList &addressList)
 
 void ConvRecipientsPanel::update(const ThreadId &threadId)
 {
-    m_pMbe->update(threadId);
+    if(m_ThreadId != threadId)
+    {
+        clear();
+        m_ThreadId = threadId;
+        m_pMbe->update(threadId);
+    }
 }
 
 MbeRecipients::AppendItemStatus ConvRecipientsPanel::appendItem(const std::string &address,