Delete draft messages before saving draft message
[apps/home/message-app.git] / composer / src / ui-composer / msg-ui-composer-main.c
index 29f3361..0efcd5f 100755 (executable)
@@ -883,7 +883,23 @@ void msg_ui_composer_reset_request(MSG_COMPOSER_VIEW_DATA_S *cd, service_h svc_h
                        msg_ui_composer_message_init();
 
                        if (msg_ui_composer_get_message_data(cd) == COMPOSER_RETURN_SUCCESS) {
-                               msg_ui_composer_save_message(cd->msg_handle, cd->msg_id);
+                               /* delete draft message */
+                               msg_thread_id_t tid = 0;
+
+                               if (cd->msg_ug_mode == MSG_UG_MODE_BUBBLE_COMPOSER) {
+                                       PMSG_BUBBLE_DATA bubble_data = cd->bubble_data;
+                                       tid = bubble_data->threadId;
+                               } else {
+                                       GSList *address_list = msg_ui_composer_message_get_address();
+                                       msg_ui_composer_get_thread_id_by_address(cd->msg_handle, address_list, &tid);
+                               }
+
+                               D_MSG("tid = %d", tid);
+                               if (tid > 0)
+                                       msg_ui_composer_delete_draft_message(cd->msg_handle, tid);
+
+                               D_MSG("save draft message");
+                               msg_ui_composer_save_message(cd->msg_handle, 0);
                        }
 
                        msg_ui_composer_message_destroy();
@@ -941,7 +957,23 @@ void msg_ui_composer_reset_request(MSG_COMPOSER_VIEW_DATA_S *cd, service_h svc_h
                        msg_ui_composer_message_init();
 
                        if (msg_ui_composer_get_message_data(cd) == COMPOSER_RETURN_SUCCESS) {
-                               msg_ui_composer_save_message(cd->msg_handle, cd->msg_id);
+                               /* delete draft message */
+                               msg_thread_id_t tid = 0;
+
+                               if (cd->msg_ug_mode == MSG_UG_MODE_BUBBLE_COMPOSER) {
+                                       PMSG_BUBBLE_DATA bubble_data = cd->bubble_data;
+                                       tid = bubble_data->threadId;
+                               } else {
+                                       GSList *address_list = msg_ui_composer_message_get_address();
+                                       msg_ui_composer_get_thread_id_by_address(cd->msg_handle, address_list, &tid);
+                               }
+
+                               D_MSG("tid = %d", tid);
+                               if (tid > 0)
+                                       msg_ui_composer_delete_draft_message(cd->msg_handle, tid);
+
+                               D_MSG("save draft message");
+                               msg_ui_composer_save_message(cd->msg_handle, 0);
                        }
 
                        msg_ui_composer_message_destroy();
@@ -1118,12 +1150,27 @@ static void __msg_composer_auto_save_and_delete_msg(MSG_COMPOSER_VIEW_DATA_S *cd
        if (!cd->disable_auto_save_mode) {
                COMPOSER_EDIT_STATE_E edit_state = __msg_ui_composer_edit_check(cd);
                if (edit_state == COMPOSER_EDIT_RECIPIENT_AND_BODY) {
+
                        /* auto save composer data */
                        msg_ui_composer_message_init();
-
                        if (msg_ui_composer_get_message_data(cd) == COMPOSER_RETURN_SUCCESS) {
+                               /* delete draft message */
+                               msg_thread_id_t tid = 0;
+
+                               if (cd->msg_ug_mode == MSG_UG_MODE_BUBBLE_COMPOSER) {
+                                       PMSG_BUBBLE_DATA bubble_data = cd->bubble_data;
+                                       tid = bubble_data->threadId;
+                               } else {
+                                       GSList *address_list = msg_ui_composer_message_get_address();
+                                       msg_ui_composer_get_thread_id_by_address(cd->msg_handle, address_list, &tid);
+                               }
+
+                               D_MSG("tid = %d", tid);
+                               if (tid > 0)
+                                       msg_ui_composer_delete_draft_message(cd->msg_handle, tid);
+
                                D_MSG("save draft message");
-                               msg_ui_composer_save_message(cd->msg_handle, cd->msg_id);
+                               msg_ui_composer_save_message(cd->msg_handle, 0);
                                /* show saved ticker popup */
                                msg_ui_composer_common_tickernoti(cd, COMPOSER_TICKERNOTI_AUTO_SAVED);
                        }
@@ -1135,21 +1182,7 @@ static void __msg_composer_auto_save_and_delete_msg(MSG_COMPOSER_VIEW_DATA_S *cd
                                MSG_BUBBLE_DATA *bubble_data = cd->bubble_data;
 
                                if (bubble_data) {
-                                       msg_struct_list_s msg_list = {0,};
-
-                                       if (msg_get_message_list(cd->msg_handle, MSG_DRAFT_ID, bubble_data->threadId, 0, 0, &msg_list) == MSG_SUCCESS) {
-                                               int i = 0;
-                                               int msgid = 0;
-
-                                               D_MSG("delete draft message");
-                                               for (i = 0; i < msg_list.nCount; i++) {
-                                                       msg_get_int_value(msg_list.msg_struct_info[i], MSG_MESSAGE_ID_INT, &msgid);
-                                                       D_MSG("draft msg_id is %d", msgid);
-                                                       if (msg_delete_message(cd->msg_handle, msgid) != COMPOSER_RETURN_SUCCESS)
-                                                               D_EMSG("msg_ui_comp_core_delete_message is failed = %d", msgid);
-                                               }
-                                       }
-                                       msg_release_list_struct(&msg_list);
+                                       msg_ui_composer_delete_draft_message(cd->msg_handle, bubble_data->threadId);
                                }
                        }
                }