From: Kyeonghun Lee Date: Thu, 27 Apr 2017 08:04:52 +0000 (+0900) Subject: [MPR-967] add new api for thread list with condition X-Git-Tag: submit/tizen/20170518.052800~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fcb6ef20954db28f58d27c243fd628c13e96e22b;p=platform%2Fcore%2Fmessaging%2Fmsg-service.git [MPR-967] add new api for thread list with condition Change-Id: I848dcff36f7866f48fec5048a1f0d2bd64a0e33a Signed-off-by: Kyeonghun Lee --- diff --git a/include/mapi/msg_storage.h b/include/mapi/msg_storage.h index 7ace64c..a51008d 100755 --- a/include/mapi/msg_storage.h +++ b/include/mapi/msg_storage.h @@ -460,7 +460,7 @@ int msg_get_vobject_data(msg_handle_t handle, msg_message_id_t msg_id, void** en * @remarks However, if this function fails, the memory for a list is NOT allocated in this function. * * @param[in] handle The Message handle - * @param[in] sourt_rule This indicates a sort type and sort order for querying messages + * @param[in] sort_rule This indicates a sort type and sort order for querying messages * @param[out] msg_thread_view_list A pointer to an #msg_struct_list_s structure * * @return @c 0 on success, @@ -476,6 +476,34 @@ int msg_get_vobject_data(msg_handle_t handle, msg_message_id_t msg_id, void** en int msg_get_thread_view_list(msg_handle_t handle, const msg_struct_t sort_rule, msg_struct_list_s *msg_thread_view_list); +/** + * @brief Gets the information of all peers to whom messages have been sent or received. + * + * @since_tizen 4.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/message.read + * + * @remarks The memory for a list will be allocated in this function. + * @remarks Applications need to call msg_release_thread_view_list() to free the memory. + * @remarks However, if this function fails, the memory for a list is NOT allocated in this function. + * + * @param[in] handle The Message handle + * @param[in] msg_list_conditions A pointer to a #msg_struct_t structure for getting conditions + * @param[out] msg_thread_view_list A pointer to an #msg_struct_list_s structure + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval MSG_SUCCESS Success in operation + * @retval MSG_ERR_INVALID_PARAMETER Parameter is invalid + * @retval MSG_ERR_STORAGE_ERROR Storage error + * @retval MSG_ERR_PERMISSION_DENIED The application does not have the privilege to call this method + * @retval MSG_ERR_NOT_SUPPORTED Not supported + */ + +int msg_get_thread_view_list2(msg_handle_t handle, const msg_struct_t msg_list_conditions, msg_struct_list_s *msg_thread_view_list); + + /** * @briefs Gets the common information list of messages with the selected thread ID. * diff --git a/include/mapi/msg_types.h b/include/mapi/msg_types.h index 4abcebf..e319804 100755 --- a/include/mapi/msg_types.h +++ b/include/mapi/msg_types.h @@ -1033,11 +1033,11 @@ enum MSG_REPORT_E { * This enum is used as member of #msg_struct_t for MSG_STRUCT_MSG_LIST_CONDITION. */ enum MSG_LIST_CONDITION_E { - MSG_LIST_CONDITION_FOLDER_ID_INT = MSG_STRUCT_MSG_LIST_CONDITION+1, /**< Indicates the folder ID for searching messages. See enum _MSG_FOLDER_ID_E */ + MSG_LIST_CONDITION_FOLDER_ID_INT = MSG_STRUCT_MSG_LIST_CONDITION+1, /**< Indicates the folder ID for searching messages. See enum _MSG_FOLDER_ID_E (Can be used with msg_get_thread_view_list2) */ MSG_LIST_CONDITION_THREAD_ID_INT, /**< Indicates the thread ID for searching messages. */ MSG_LIST_CONDITION_STORAGE_ID_INT, /**< Indicates the storage ID for searching messages. See enum _MSG_STORAGE_ID_E */ MSG_LIST_CONDITION_MSGTYPE_INT, /**< Indicates the message type for searching messages. See enum _MSG_MESSAGE_TYPE_E */ - MSG_LIST_CONDITION_PROTECTED_BOOL, /**< Indicates the protected flag for searching messages*/ + MSG_LIST_CONDITION_PROTECTED_BOOL, /**< Indicates the protected flag for searching messages (Can be used with msg_get_thread_view_list2) */ MSG_LIST_CONDITION_SCHEDULED_BOOL, /**< Indicates the scheduled flag for searching messages*/ MSG_LIST_CONDITION_ADDRESS_VALUE_STR, /**< The address value for searching messages. */ MSG_LIST_CONDITION_TEXT_VALUE_STR, /**< The string to search */ diff --git a/include/proxy/MsgHandle.h b/include/proxy/MsgHandle.h index bcf590b..6fe692e 100755 --- a/include/proxy/MsgHandle.h +++ b/include/proxy/MsgHandle.h @@ -84,7 +84,7 @@ public: msg_error_t deleteFolder(msg_folder_id_t FolderId); msg_error_t getFolderList(msg_struct_list_s *pFolderList); - msg_error_t getThreadViewList(const MSG_SORT_RULE_S *pSortRule, msg_struct_list_s *pThreadViewList); + msg_error_t getThreadViewList(const MSG_SORT_RULE_S *pSortRule, const MSG_LIST_CONDITION_S *pListCond, msg_struct_list_s *pThreadViewList); msg_error_t getConversationViewList(msg_thread_id_t ThreadId, msg_struct_list_s *pConvViewList); msg_error_t deleteThreadMessageList(msg_thread_id_t thread_id, bool include_protected_msg); msg_error_t getQuickPanelData(msg_quickpanel_type_t Type, MSG_MESSAGE_HIDDEN_S *pMsg); diff --git a/include/utils/MsgUtilStorage.h b/include/utils/MsgUtilStorage.h index b5a3083..3c88177 100755 --- a/include/utils/MsgUtilStorage.h +++ b/include/utils/MsgUtilStorage.h @@ -74,6 +74,7 @@ msg_error_t MsgStoUpdateNetworkStatus(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_ /* Lists */ msg_error_t MsgStoGetThreadViewList(const MSG_SORT_RULE_S *pSortRule, msg_struct_list_s *pThreadViewList); +msg_error_t MsgStoGetThreadViewListWithCondition(const MSG_SORT_RULE_S *pSortRule, const MSG_LIST_CONDITION_S *pListCond, msg_struct_list_s *pThreadViewList); msg_error_t MsgStoGetConversationViewItem(msg_message_id_t msgId, MSG_CONVERSATION_VIEW_S *pConv); msg_error_t MsgStoGetConversationViewList(msg_thread_id_t ThreadId, msg_struct_list_s *pConvViewList); msg_error_t MsgStoSearchMessage(const char *pSearchString, msg_struct_list_s *pThreadViewList, int contactCount); diff --git a/mapi/msg_storage.cpp b/mapi/msg_storage.cpp index 7407a6e..b7ba883 100755 --- a/mapi/msg_storage.cpp +++ b/mapi/msg_storage.cpp @@ -461,9 +461,9 @@ EXPORT_API int msg_get_thread_view_list(msg_handle_t handle, const msg_struct_t sortRule.sortType = MSG_SORT_BY_THREAD_DATE; sortRule.bAscending = false; - err = pHandle->getThreadViewList(&sortRule, msg_thread_view_list); + err = pHandle->getThreadViewList(&sortRule, NULL, msg_thread_view_list); } else { - err = pHandle->getThreadViewList((MSG_SORT_RULE_S *)pStruct->data, msg_thread_view_list); + err = pHandle->getThreadViewList((MSG_SORT_RULE_S *)pStruct->data, NULL, msg_thread_view_list); } } catch (MsgException& e) { MSG_FATAL("%s", e.what()); @@ -474,6 +474,37 @@ EXPORT_API int msg_get_thread_view_list(msg_handle_t handle, const msg_struct_t } +EXPORT_API int msg_get_thread_view_list2(msg_handle_t handle, const msg_struct_t msg_list_conditions, msg_struct_list_s *msg_thread_view_list) +{ + CHECK_MSG_SUPPORTED(MSG_TELEPHONY_SMS_FEATURE); + msg_error_t err = MSG_SUCCESS; + + if (handle == NULL || msg_thread_view_list == NULL) + return MSG_ERR_INVALID_PARAMETER; + + MsgHandle* pHandle = (MsgHandle*)handle; + msg_struct_s *pCondition =(msg_struct_s *)msg_list_conditions; + if (pCondition) + MSG_TYPE_CHECK(pCondition->type, MSG_STRUCT_MSG_LIST_CONDITION); + + MSG_LIST_CONDITION_S *pListCond = pCondition ? (MSG_LIST_CONDITION_S *)pCondition->data : NULL; + + try { + MSG_SORT_RULE_S sortRule = {0}; + + sortRule.sortType = MSG_SORT_BY_THREAD_DATE; + sortRule.bAscending = false; + + err = pHandle->getThreadViewList(&sortRule, pListCond, msg_thread_view_list); + } catch (MsgException& e) { + MSG_FATAL("%s", e.what()); + return MSG_ERR_STORAGE_ERROR; + } + + return err; +} + + EXPORT_API int msg_get_conversation_view_list(msg_handle_t handle, msg_thread_id_t thread_id, msg_struct_list_s *msg_conv_view_list) { CHECK_MSG_SUPPORTED(MSG_TELEPHONY_SMS_FEATURE); diff --git a/proxy/MsgHandleStorage.cpp b/proxy/MsgHandleStorage.cpp index ab2f93c..e433e60 100755 --- a/proxy/MsgHandleStorage.cpp +++ b/proxy/MsgHandleStorage.cpp @@ -889,7 +889,7 @@ msg_error_t MsgHandle::getFolderList(msg_struct_list_s *pFolderList) } -msg_error_t MsgHandle::getThreadViewList(const MSG_SORT_RULE_S *pSortRule, msg_struct_list_s *pThreadViewList) +msg_error_t MsgHandle::getThreadViewList(const MSG_SORT_RULE_S *pSortRule, const MSG_LIST_CONDITION_S *pListCond, msg_struct_list_s *pThreadViewList) { msg_error_t err = MSG_SUCCESS; /* @@ -901,10 +901,9 @@ msg_error_t MsgHandle::getThreadViewList(const MSG_SORT_RULE_S *pSortRule, msg_s } */ - err = MsgStoGetThreadViewList(pSortRule, pThreadViewList); - + err = MsgStoGetThreadViewListWithCondition(pSortRule, pListCond, pThreadViewList); if (err != MSG_SUCCESS) { - MSG_DEBUG("MsgStoGetThreadViewList() Error!!"); + MSG_ERR("MsgStoGetThreadViewListWithCondition() Error!!"); return err; } diff --git a/utils/MsgUtilStorage.cpp b/utils/MsgUtilStorage.cpp index 9305c8c..8da7f11 100755 --- a/utils/MsgUtilStorage.cpp +++ b/utils/MsgUtilStorage.cpp @@ -1800,6 +1800,181 @@ msg_error_t MsgStoGetThreadViewList(const MSG_SORT_RULE_S *pSortRule, msg_struct } +msg_error_t MsgStoGetThreadViewListWithCondition(const MSG_SORT_RULE_S *pSortRule, const MSG_LIST_CONDITION_S *pListCond, msg_struct_list_s *pThreadViewList) +{ + msg_error_t err = MSG_SUCCESS; + + if (!pListCond) { + err = MsgStoGetThreadViewList(pSortRule, pThreadViewList); + if (err != MSG_SUCCESS) { + MSG_ERR("MsgStoGetThreadViewList() Error!!"); + } + + return err; + } + + MsgDbHandler *dbHandle = getDbHandle(); + dbHandle->connectReadOnly(); + + pThreadViewList->nCount = 0; + pThreadViewList->msg_struct_info = NULL; + + int rowCnt = 0, index = 0; + + char sqlQuery[MAX_QUERY_LEN+1]; + char sqlQuerySubset[MAX_QUERY_LEN+1]; + char conditionQuery[MAX_QUERY_LEN+1] = {0}; + + if (pListCond->bProtected == true) { + memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset)); + snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "PROTECTED = 1 AND "); + strncat(conditionQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(conditionQuery)); + } + + if (pListCond->folderId > MSG_ALLBOX_ID) { + memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset)); + snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "FOLDER_ID = %d ", pListCond->folderId); + strncat(conditionQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(conditionQuery)); + } else { + memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset)); + snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "FOLDER_ID > %d AND FOLDER_ID < %d ", MSG_ALLBOX_ID, MSG_SPAMBOX_ID); + strncat(conditionQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(conditionQuery)); + } + + memset(sqlQuery, 0x00, sizeof(sqlQuery)); + snprintf(sqlQuery, sizeof(sqlQuery), "SELECT DISTINCT(CONV_ID) FROM %s WHERE ", MSGFW_MESSAGE_TABLE_NAME); + + strncat(sqlQuery, conditionQuery, MAX_QUERY_LEN-strlen(sqlQuery)); + + memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset)); + snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "ORDER BY DISPLAY_TIME DESC;"); + strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery)); + + + err = dbHandle->getTable(sqlQuery, &rowCnt, NULL); + if (err == MSG_ERR_DB_NORECORD) { + return MSG_SUCCESS; + } else if (err != MSG_SUCCESS) { + MSG_ERR("Fail to getTable(). [%d]", err); + dbHandle->freeTable(); + return err; + } + + msg_thread_id_t conv_ids[rowCnt]; + for (int i = 1; i <= rowCnt; i++) { + conv_ids[i - 1] = dbHandle->getColumnToInt(i); + } + + dbHandle->freeTable(); + + pThreadViewList->nCount = rowCnt; + MSG_DEBUG("pThreadViewList->nCount [%d]", pThreadViewList->nCount); + + pThreadViewList->msg_struct_info = (msg_struct_t *)calloc(rowCnt, sizeof(msg_struct_t)); + if (pThreadViewList->msg_struct_info == NULL) { + MSG_ERR("calloc failed"); + return MSG_ERR_MEMORY_ERROR; + } + + MSG_THREAD_VIEW_S *pTmp = NULL; + msg_struct_s *thread_t = NULL; + + for (int i = 0; i < pThreadViewList->nCount; i++) { + thread_t = (msg_struct_s *)new msg_struct_s; + pThreadViewList->msg_struct_info[i] = (msg_struct_t)thread_t; + thread_t->type = MSG_STRUCT_THREAD_INFO; + thread_t->data = new MSG_THREAD_VIEW_S; + + pTmp = (MSG_THREAD_VIEW_S *)thread_t->data; + memset(pTmp, 0x00, sizeof(MSG_THREAD_VIEW_S)); + + pTmp->threadId = conv_ids[i]; + + memset(sqlQuery, 0x00, sizeof(sqlQuery)); + snprintf(sqlQuery, MAX_QUERY_LEN, "SELECT DISPLAY_NAME FROM %s WHERE CONV_ID = %d;", + MSGFW_CONVERSATION_TABLE_NAME, conv_ids[i]); + + err = dbHandle->getTable(sqlQuery, &rowCnt, &index); + if (err != MSG_SUCCESS) { + MSG_ERR("Fail to getTable(). [%d]", err); + dbHandle->freeTable(); + return err; + } + + dbHandle->getColumnToString(index++, MAX_THREAD_NAME_LEN, pTmp->threadName); + + dbHandle->freeTable(); + + memset(sqlQuery, 0x00, sizeof(sqlQuery)); + snprintf(sqlQuery, MAX_QUERY_LEN, "SELECT " + "(COUNT(DISTINCT(CASE WHEN READ_STATUS = 0 THEN MSG_ID END))) AS UNREAD_CNT, " + "(COUNT(DISTINCT(CASE WHEN MAIN_TYPE = %d THEN MSG_ID END))) AS SMS_CNT, " + "(COUNT(DISTINCT(CASE WHEN MAIN_TYPE = %d THEN MSG_ID END))) AS MMS_CNT " + "FROM %s WHERE CONV_ID = %d AND ", + MSG_SMS_TYPE, + MSG_MMS_TYPE, + MSGFW_MESSAGE_TABLE_NAME, conv_ids[i]); + + strncat(sqlQuery, conditionQuery, MAX_QUERY_LEN-strlen(sqlQuery)); + snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), ";"); + strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery)); + + err = dbHandle->getTable(sqlQuery, &rowCnt, &index); + if (err != MSG_SUCCESS) { + MSG_ERR("Fail to getTable(). [%d]", err); + dbHandle->freeTable(); + return err; + } + + pTmp->unreadCnt = dbHandle->getColumnToInt(index++); + pTmp->smsCnt = dbHandle->getColumnToInt(index++); + pTmp->mmsCnt = dbHandle->getColumnToInt(index++); + + dbHandle->freeTable(); + + memset(sqlQuery, 0x00, MAX_QUERY_LEN); + snprintf(sqlQuery, sizeof(sqlQuery), + "SELECT MAIN_TYPE, SUB_TYPE, MSG_DIRECTION, DISPLAY_TIME, DPM_RESTRICTED, (CASE WHEN LENGTH(SUBJECT) > 0 THEN SUBJECT ELSE MSG_TEXT END) " + "FROM %s WHERE CONV_ID = %d AND ", + MSGFW_MESSAGE_TABLE_NAME, conv_ids[i]); + + strncat(sqlQuery, conditionQuery, MAX_QUERY_LEN-strlen(sqlQuery)); + snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "ORDER BY DISPLAY_TIME DESC LIMIT 1;"); + strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery)); + + err = dbHandle->getTable(sqlQuery, &rowCnt, &index); + if (err != MSG_SUCCESS) { + MSG_ERR("Fail to getTable(). [%d]", err); + dbHandle->freeTable(); + return err; + } + + pTmp->mainType = (MSG_MAIN_TYPE_T)dbHandle->getColumnToInt(index++); + pTmp->subType = (MSG_SUB_TYPE_T)dbHandle->getColumnToInt(index++); + pTmp->direction = (msg_direction_type_t)dbHandle->getColumnToInt(index++); + pTmp->threadTime = (time_t)dbHandle->getColumnToInt(index++); + bool dpm_restricted = dbHandle->getColumnToInt(index++); + char tmpData[MAX_THREAD_DATA_LEN + 1] = {0}; + if (!dpm_restricted) { + dbHandle->getColumnToString(index++, MAX_THREAD_DATA_LEN, tmpData); + } else { + snprintf(tmpData, sizeof(tmpData), "restricted message"); + } + + char *end = NULL; + if (g_utf8_validate(tmpData, -1, (const gchar **)&end) == true) { + g_utf8_strncpy(pTmp->threadData, tmpData, g_utf8_strlen(tmpData, -1)); + } else { + g_utf8_strncpy(pTmp->threadData, tmpData, g_utf8_strlen(tmpData, end - tmpData)); + } + + dbHandle->freeTable(); + } + + return MSG_SUCCESS; +} + + msg_error_t MsgStoGetConversationPreview(MsgDbHandler *pDbHandle, MSG_CONVERSATION_VIEW_S *pConv) { char sqlQuery[MAX_QUERY_LEN + 1];