the order of auto download attachment was wrong 84/94984/1
authorSan Cho <san.cho@samsung.com>
Mon, 11 Jul 2016 08:02:07 +0000 (17:02 +0900)
committerintae jeon <intae.jeon@samsung.com>
Wed, 2 Nov 2016 05:24:29 +0000 (22:24 -0700)
[Problem] the order of auto download attachment was wrong
[Cause & Measure] Cause: the older mail's attachment was downloaded first.
Measure: sorting mails by server id and download attachment.

Change-Id: Ib7d4649ba3b960bc2a66e23f8032ea0d068d157e
(cherry picked from commit df03367cd6d9cd10d47c26c402819b1122ec8813)

email-core/email-core-auto-download.c

index 156ec89..b990f97 100755 (executable)
@@ -59,6 +59,7 @@ INTERNAL_FUNC int auto_download_thread_run = 0;
 #define AUTO_DOWNLOAD_QUEUE_MAX 100
 
 static void* worker_auto_download_queue(void *arg);
+static gint auto_download_compare_func(gconstpointer a, gconstpointer b, gpointer user_data);
 
 INTERNAL_FUNC int emcore_start_auto_download_loop(int *err_code)
 {
@@ -175,14 +176,9 @@ INTERNAL_FUNC int emcore_insert_auto_download_event(email_event_auto_download *e
                EM_DEBUG_EXCEPTION("auto download que is full...");
                error = EMAIL_ERROR_EVENT_QUEUE_FULL;
                ret = false;
-       } else if (event_data->status == EMAIL_EVENT_STATUS_DIRECT) {
-               event_data->status = EMAIL_EVENT_STATUS_WAIT;
-               g_queue_push_head(g_auto_download_que, event_data);
-               //WAKE_CONDITION_VARIABLE(_auto_downalod_available_signal);
-               ret = true;
        } else {
                event_data->status = EMAIL_EVENT_STATUS_WAIT;
-               g_queue_push_tail(g_auto_download_que, event_data);
+               g_queue_insert_sorted(g_auto_download_que, event_data, auto_download_compare_func, event_data);
                //WAKE_CONDITION_VARIABLE(_auto_downalod_available_signal);
                ret = true;
        }
@@ -467,7 +463,7 @@ static void* worker_auto_download_queue(void *arg)
                                                }
 
                                                activity->activity_id = activity_list[di].activity_id;
-                                               activity->status = 0;
+                                               activity->status = EMAIL_EVENT_STATUS_DIRECT;
                                                activity->account_id = activity_list[di].account_id;
                                                activity->mail_id = activity_list[di].mail_id;
                                                activity->server_mail_id = activity_list[di].server_mail_id;
@@ -862,4 +858,12 @@ FINISH_OFF:
        return ret;
 }
 
-
+static gint auto_download_compare_func(gconstpointer a, gconstpointer b, gpointer user_data)
+{
+       email_event_auto_download *first = (email_event_auto_download*)a;
+       email_event_auto_download *second = (email_event_auto_download*)b;
+       if (first->server_mail_id == second->server_mail_id) return 0;
+       else if (first->server_mail_id > second->server_mail_id) return -1;
+       else return 1;
+       return 1;
+}