From c53f70e256c464fef9dc3eea88583ffdc069fc10 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Tue, 19 Aug 2014 15:06:38 +0200 Subject: [PATCH] Fix erroneous documentation from conversation history new methods --- coreapi/linphonecore.h | 2 +- coreapi/message_storage.c | 8 +++++--- java/common/org/linphone/core/LinphoneChatRoom.java | 2 +- tester/message_tester.c | 7 +++++++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index ec96715af..773701d52 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -1355,7 +1355,7 @@ LINPHONE_PUBLIC void linphone_chat_room_delete_history(LinphoneChatRoom *cr); LINPHONE_PUBLIC int linphone_chat_room_get_history_size(LinphoneChatRoom *cr); /** - * Gets the partial list of messages in the given range, sorted from most recent to oldest. + * Gets the partial list of messages in the given range, sorted from oldest to most recent. * @param[in] cr The #LinphoneChatRoom object corresponding to the conversation for which messages should be retrieved * @param[in] begin The first message of the range to be retrieved. History most recent message has index 0. * @param[in] end The last message of the range to be retrieved. History oldest message has index of history size - 1 (use #linphone_chat_room_get_history_size to retrieve history size) diff --git a/coreapi/message_storage.c b/coreapi/message_storage.c index 89120aee3..adba8f00e 100644 --- a/coreapi/message_storage.c +++ b/coreapi/message_storage.c @@ -112,7 +112,7 @@ void linphone_sql_request_message(sqlite3 *db,const char *stmt,LinphoneChatRoom int ret; ret=sqlite3_exec(db,stmt,callback,cr,&errmsg); if(ret != SQLITE_OK) { - ms_error("Error in creation: %s.\n", errmsg); + ms_error("Error in creation: %s.", errmsg); sqlite3_free(errmsg); } } @@ -122,7 +122,7 @@ int linphone_sql_request(sqlite3* db,const char *stmt){ int ret; ret=sqlite3_exec(db,stmt,NULL,NULL,&errmsg); if(ret != SQLITE_OK) { - ms_error("linphone_sql_request: error sqlite3_exec(): %s.\n", errmsg); + ms_error("linphone_sql_request: error sqlite3_exec(): %s.", errmsg); sqlite3_free(errmsg); } return ret; @@ -134,7 +134,7 @@ void linphone_sql_request_all(sqlite3* db,const char *stmt, LinphoneCore* lc){ int ret; ret=sqlite3_exec(db,stmt,callback_all,lc,&errmsg); if(ret != SQLITE_OK) { - ms_error("linphone_sql_request_all: error sqlite3_exec(): %s.\n", errmsg); + ms_error("linphone_sql_request_all: error sqlite3_exec(): %s.", errmsg); sqlite3_free(errmsg); } } @@ -285,6 +285,8 @@ MSList *linphone_chat_room_get_history_range(LinphoneChatRoom *cr, int startm, i buf=ms_malloc(buf_max_size); buf=sqlite3_snprintf(buf_max_size-1,buf,"SELECT * FROM history WHERE remoteContact = %Q ORDER BY id DESC",peer); + if (startm<0) startm=0; + if (endm>0&&endm>=startm){ buf=sqlite3_snprintf(buf_max_size-1,buf,"%s LIMIT %i ",buf,endm+1-startm); }else if(startm>0){ diff --git a/java/common/org/linphone/core/LinphoneChatRoom.java b/java/common/org/linphone/core/LinphoneChatRoom.java index 0d677760c..722073779 100644 --- a/java/common/org/linphone/core/LinphoneChatRoom.java +++ b/java/common/org/linphone/core/LinphoneChatRoom.java @@ -66,7 +66,7 @@ public interface LinphoneChatRoom { LinphoneChatMessage[] getHistory(int limit); /** - * Returns the chat history associated with the peer address associated with this chat room for the given range + * Returns the chat history associated with the peer address associated with this chat room for the given range, sorted from oldest to most recent * @param begin the first (most recent) message to retrieve. Newest message has index 0. If negative, use value 0 instead. * @param end the last (oldest) message to retrieve. Oldest message has value "history size" - 1 (equivalent to -1). If negative or lower than begin value, value is given, use -1. * @return an array of LinphoneChatMessage, empty if nothing has been found diff --git a/tester/message_tester.c b/tester/message_tester.c index d8bd79174..9a0a21b6c 100644 --- a/tester/message_tester.c +++ b/tester/message_tester.c @@ -824,6 +824,9 @@ static void message_storage_migration() { // check that all messages have been migrated to the UTC time storage CU_ASSERT(sqlite3_exec(marie->lc->db, "SELECT * FROM history WHERE time != '-1';", check_no_strange_time, NULL, NULL) == SQLITE_OK ); + + linphone_core_manager_destroy(marie); + remove(tmp_db); } static void history_messages_count() { @@ -859,9 +862,13 @@ static void history_messages_count() { /*test limit without offset*/ CU_ASSERT_EQUAL(ms_list_size(linphone_chat_room_get_history_range(chatroom, 0, 5)), 6); + + /*test invalid start*/ + CU_ASSERT_EQUAL(ms_list_size(linphone_chat_room_get_history_range(chatroom, 1265, 1260)), 1270-1265); } linphone_core_manager_destroy(marie); linphone_address_destroy(jehan_addr); + remove(tmp_db); }