From: Kyeonghun Lee Date: Wed, 9 Nov 2016 04:28:14 +0000 (+0900) Subject: [TSAM-9561] fix logical error occured when unread msg count is 0 X-Git-Tag: submit/tizen_3.0/20161109.043951~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=59aab749dfc66bd8bb48c488cdca64ded295608b;p=platform%2Fcore%2Fmessaging%2Fmsg-service.git [TSAM-9561] fix logical error occured when unread msg count is 0 Change-Id: Ib697a297e2cf155dc289d28883ee07a7abf06ce8 Signed-off-by: Kyeonghun Lee --- diff --git a/manager/src/msg-manager-notification.cpp b/manager/src/msg-manager-notification.cpp index 8226d49..eea62c9 100644 --- a/manager/src/msg-manager-notification.cpp +++ b/manager/src/msg-manager-notification.cpp @@ -1878,6 +1878,35 @@ int getLatestMsgInfo(MSG_MGR_NOTI_INFO_S *noti_info, bool isForInstantMessage) msg_db_free(msg_handle, db_res); + noti_info->count = smsUnreadCnt + mmsUnreadCnt; + + if (noti_info->count == 0) { + MSG_MGR_DEBUG("No unread message."); + MSG_MGR_DEBUG("notiPrivId [%d]", noti_info->id); + + if (!isForInstantMessage) { + /* No unread message. */ + if (noti_info->id > 0) { + noti_err = notification_delete_by_priv_id(MSG_DEFAULT_APP_ID, NOTIFICATION_TYPE_NOTI, noti_info->id); + if (noti_err != NOTIFICATION_ERROR_NONE) { + MSG_MGR_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err); + } + } + + noti_info->id = 0; + + if (vconf_set_int(NOTIFICATION_PRIV_ID, noti_info->id) != 0) + MSG_MGR_DEBUG("vconf_set_int fail : NOTIFICATION_PRIV_ID"); + + vconf_set_int(VCONFKEY_MESSAGE_RECV_SMS_STATE, 0); + vconf_set_int(VCONFKEY_MESSAGE_RECV_MMS_STATE, 0); + MsgMgrInsertBadge(0); + MsgMgrSoundSetRepeatAlarm(); + } + + return -1; + } + memset(sqlQuery, 0x00, sizeof(sqlQuery)); #ifdef MSG_NOTI_INTEGRATION snprintf(sqlQuery, sizeof(sqlQuery), @@ -1935,110 +1964,79 @@ int getLatestMsgInfo(MSG_MGR_NOTI_INFO_S *noti_info, bool isForInstantMessage) attachmentCnt = atoi(db_res[col_cnt+8]); noti_info->sim_idx = atoi(db_res[col_cnt+9]); - noti_info->count = smsUnreadCnt + mmsUnreadCnt; - - if (noti_info->count > 0) { - snprintf(noti_info->number, sizeof(noti_info->number), "%s", db_res[col_cnt]); - - noti_info->time = (time_t)atoi(db_res[col_cnt+1]); - - noti_info->msg_id = (msg_message_id_t)atoi(db_res[col_cnt+2]); - - noti_info->conv_id = atoi(db_res[col_cnt+6]); - - mainType = (unsigned char)atoi(db_res[col_cnt+5]); - - if (mainType == MSG_MMS_TYPE) { - snprintf(noti_info->text, sizeof(noti_info->text), "%s", db_res[col_cnt+3]); - if (noti_info->text[0] == '\0') { - char *noti_text = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MSG_NO_SUBJECT); - snprintf(noti_info->text, sizeof(noti_info->text), "%s", noti_text); - g_free(noti_text); - } - - char *prefix_subject = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MSG_SUBJECT_COLON); - if (prefix_subject) { - snprintf(noti_info->active_subject, MSG_NOTI_TEXT_LEN_S, "%s%s", prefix_subject, noti_info->text); - g_free(prefix_subject); - } else { - snprintf(noti_info->active_subject, MSG_NOTI_TEXT_LEN_S, "%s", noti_info->text); - } + snprintf(noti_info->number, sizeof(noti_info->number), "%s", db_res[col_cnt]); - if (msgSize > -1) { - int kb_msg_size = msgSize / 1024; - if (kb_msg_size == 0 && msgSize > 0) - kb_msg_size = 1; - else if (msgSize % 1024 >= 512) - kb_msg_size++; + noti_info->time = (time_t)atoi(db_res[col_cnt+1]); - char *msg_size_string = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MESSAGE_SIZE_STRING); - char *msg_size_unit_kb = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MESSAGE_SIZE_UNIT_KB); + noti_info->msg_id = (msg_message_id_t)atoi(db_res[col_cnt+2]); - snprintf(noti_info->active_text, MSG_NOTI_TEXT_LEN, "%s : %d%s", msg_size_string, kb_msg_size, msg_size_unit_kb); + noti_info->conv_id = atoi(db_res[col_cnt+6]); - g_free(msg_size_string); - g_free(msg_size_unit_kb); - } + mainType = (unsigned char)atoi(db_res[col_cnt+5]); - noti_info->active_media_cnt = attachmentCnt; + if (mainType == MSG_MMS_TYPE) { + snprintf(noti_info->text, sizeof(noti_info->text), "%s", db_res[col_cnt+3]); + if (noti_info->text[0] == '\0') { + char *noti_text = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MSG_NO_SUBJECT); + snprintf(noti_info->text, sizeof(noti_info->text), "%s", noti_text); + g_free(noti_text); + } + char *prefix_subject = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MSG_SUBJECT_COLON); + if (prefix_subject) { + snprintf(noti_info->active_subject, MSG_NOTI_TEXT_LEN_S, "%s%s", prefix_subject, noti_info->text); + g_free(prefix_subject); } else { - snprintf(noti_info->text, sizeof(noti_info->text), "%s", db_res[col_cnt+4]); + snprintf(noti_info->active_subject, MSG_NOTI_TEXT_LEN_S, "%s", noti_info->text); } - if (noti_info->active_text[0] == '\0') - snprintf(noti_info->active_text, MSG_NOTI_TEXT_LEN, "%s", db_res[col_cnt+4]); + if (msgSize > -1) { + int kb_msg_size = msgSize / 1024; + if (kb_msg_size == 0 && msgSize > 0) + kb_msg_size = 1; + else if (msgSize % 1024 >= 512) + kb_msg_size++; - MSG_MGR_DEBUG("unread message ID [%d].", noti_info->msg_id); + char *msg_size_string = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MESSAGE_SIZE_STRING); + char *msg_size_unit_kb = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MESSAGE_SIZE_UNIT_KB); - MSG_MGR_DEBUG("active sender [%s]", noti_info->active_sender); - MSG_MGR_DEBUG("active subject [%s]", noti_info->active_subject); - MSG_MGR_DEBUG("active text [%s]", noti_info->active_text); + snprintf(noti_info->active_text, MSG_NOTI_TEXT_LEN, "%s : %d%s", msg_size_string, kb_msg_size, msg_size_unit_kb); - if (!isForInstantMessage) { - if (noti_info->id > 0 && noti_info->count == 1) { - noti_err = notification_delete_by_priv_id(MSG_DEFAULT_APP_ID, NOTIFICATION_TYPE_NOTI, noti_info->id); - if (noti_err != NOTIFICATION_ERROR_NONE) { - MSG_MGR_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err); - } + g_free(msg_size_string); + g_free(msg_size_unit_kb); + } - noti_info->id = 0; - if (vconf_set_int(NOTIFICATION_PRIV_ID, noti_info->id) != 0) - MSG_MGR_DEBUG("vconf_set_int fail : NOTIFICATION_PRIV_ID"); - } + noti_info->active_media_cnt = attachmentCnt; - vconf_set_int(VCONFKEY_MESSAGE_RECV_SMS_STATE, smsUnreadCnt); - vconf_set_int(VCONFKEY_MESSAGE_RECV_MMS_STATE, mmsUnreadCnt); - MsgMgrInsertBadge(noti_info->count); - MsgMgrSoundSetRepeatAlarm(); - } } else { - MSG_MGR_DEBUG("No unread message."); - MSG_MGR_DEBUG("notiPrivId [%d]", noti_info->id); + snprintf(noti_info->text, sizeof(noti_info->text), "%s", db_res[col_cnt+4]); + } - msg_db_free(msg_handle, db_res); + if (noti_info->active_text[0] == '\0') + snprintf(noti_info->active_text, MSG_NOTI_TEXT_LEN, "%s", db_res[col_cnt+4]); - if (!isForInstantMessage) { - /* No unread message. */ - if (noti_info->id > 0) { - noti_err = notification_delete_by_priv_id(MSG_DEFAULT_APP_ID, NOTIFICATION_TYPE_NOTI, noti_info->id); - if (noti_err != NOTIFICATION_ERROR_NONE) { - MSG_MGR_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err); - } + MSG_MGR_DEBUG("unread message ID [%d].", noti_info->msg_id); + + MSG_MGR_DEBUG("active sender [%s]", noti_info->active_sender); + MSG_MGR_DEBUG("active subject [%s]", noti_info->active_subject); + MSG_MGR_DEBUG("active text [%s]", noti_info->active_text); + + if (!isForInstantMessage) { + if (noti_info->id > 0 && noti_info->count == 1) { + noti_err = notification_delete_by_priv_id(MSG_DEFAULT_APP_ID, NOTIFICATION_TYPE_NOTI, noti_info->id); + if (noti_err != NOTIFICATION_ERROR_NONE) { + MSG_MGR_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err); } noti_info->id = 0; - if (vconf_set_int(NOTIFICATION_PRIV_ID, noti_info->id) != 0) MSG_MGR_DEBUG("vconf_set_int fail : NOTIFICATION_PRIV_ID"); - - vconf_set_int(VCONFKEY_MESSAGE_RECV_SMS_STATE, 0); - vconf_set_int(VCONFKEY_MESSAGE_RECV_MMS_STATE, 0); - MsgMgrInsertBadge(0); - MsgMgrSoundSetRepeatAlarm(); } - return -1; + vconf_set_int(VCONFKEY_MESSAGE_RECV_SMS_STATE, smsUnreadCnt); + vconf_set_int(VCONFKEY_MESSAGE_RECV_MMS_STATE, mmsUnreadCnt); + MsgMgrInsertBadge(noti_info->count); + MsgMgrSoundSetRepeatAlarm(); } } else { MSG_MGR_DEBUG("sqlQuery [%s]", sqlQuery);