mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-29 09:09:21 +00:00
message_storage.c: minor refactoring
This commit is contained in:
parent
73430e1698
commit
a722c76515
2 changed files with 28 additions and 29 deletions
|
|
@ -94,6 +94,16 @@ static void fetch_content_from_database(sqlite3 *db, LinphoneChatMessage *messag
|
|||
sqlite3_free(buf);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Called when fetching all conversations from database
|
||||
static int callback_all(void *data, int argc, char **argv, char **colName){
|
||||
LinphoneCore* lc = (LinphoneCore*) data;
|
||||
char* address = argv[0];
|
||||
linphone_core_get_or_create_chat_room(lc, address);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* DB layout:
|
||||
* | 0 | storage_id
|
||||
* | 1 | localContact
|
||||
|
|
@ -108,10 +118,12 @@ static void fetch_content_from_database(sqlite3 *db, LinphoneChatMessage *messag
|
|||
* | 10 | app data text
|
||||
* | 11 | linphone content
|
||||
*/
|
||||
static void create_chat_message(char **argv, void *data){
|
||||
static int create_chat_message(void *data, int argc, char **argv, char **colName){
|
||||
LinphoneChatRoom *cr = (LinphoneChatRoom *)data;
|
||||
LinphoneAddress *from;
|
||||
LinphoneAddress *to;
|
||||
uint64_t begin, end;
|
||||
begin=ortp_get_cur_time_ms();
|
||||
|
||||
unsigned int storage_id = atoi(argv[0]);
|
||||
|
||||
|
|
@ -136,17 +148,12 @@ static void create_chat_message(char **argv, void *data){
|
|||
linphone_address_destroy(to);
|
||||
}
|
||||
|
||||
if( argv[9] != NULL ){
|
||||
new_message->time = (time_t)atol(argv[9]);
|
||||
} else {
|
||||
new_message->time = time(NULL);
|
||||
}
|
||||
|
||||
new_message->time = (time_t)atol(argv[9]);
|
||||
new_message->is_read=atoi(argv[6]);
|
||||
new_message->state=atoi(argv[7]);
|
||||
new_message->storage_id=storage_id;
|
||||
new_message->external_body_url= argv[8] ? ms_strdup(argv[8]) : NULL;
|
||||
new_message->appdata = argv[10]? ms_strdup(argv[10]) : NULL;
|
||||
new_message->external_body_url= ms_strdup(argv[8]);
|
||||
new_message->appdata = ms_strdup(argv[10]);
|
||||
|
||||
if (argv[11] != NULL) {
|
||||
int id = atoi(argv[11]);
|
||||
|
|
@ -156,25 +163,17 @@ static void create_chat_message(char **argv, void *data){
|
|||
}
|
||||
}
|
||||
cr->messages_hist=ms_list_prepend(cr->messages_hist,new_message);
|
||||
}
|
||||
|
||||
// Called when fetching all conversations from database
|
||||
static int callback_all(void *data, int argc, char **argv, char **colName){
|
||||
LinphoneCore* lc = (LinphoneCore*) data;
|
||||
char* address = argv[0];
|
||||
linphone_core_get_or_create_chat_room(lc, address);
|
||||
return 0;
|
||||
}
|
||||
end=ortp_get_cur_time_ms();
|
||||
ms_message("\t%s(): completed in %i ms",__FUNCTION__, (int)(end-begin));
|
||||
|
||||
static int callback(void *data, int argc, char **argv, char **colName){
|
||||
create_chat_message(argv,data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void linphone_sql_request_message(sqlite3 *db,const char *stmt,LinphoneChatRoom *cr){
|
||||
char* errmsg=NULL;
|
||||
int ret;
|
||||
ret=sqlite3_exec(db,stmt,callback,cr,&errmsg);
|
||||
ret=sqlite3_exec(db,stmt,create_chat_message,cr,&errmsg);
|
||||
if(ret != SQLITE_OK) {
|
||||
ms_error("Error in creation: %s.", errmsg);
|
||||
sqlite3_free(errmsg);
|
||||
|
|
@ -287,7 +286,7 @@ void linphone_chat_room_mark_as_read(LinphoneChatRoom *cr){
|
|||
char *buf;
|
||||
|
||||
if (lc->db==NULL) return ;
|
||||
|
||||
|
||||
// optimization: do not modify the database if no message is marked as unread
|
||||
if(linphone_chat_room_get_unread_messages_count(cr) == 0) return;
|
||||
|
||||
|
|
@ -297,7 +296,7 @@ void linphone_chat_room_mark_as_read(LinphoneChatRoom *cr){
|
|||
linphone_sql_request(lc->db,buf);
|
||||
sqlite3_free(buf);
|
||||
ms_free(peer);
|
||||
|
||||
|
||||
cr->unread_count = 0;
|
||||
}
|
||||
|
||||
|
|
@ -321,7 +320,7 @@ static int linphone_chat_room_get_messages_count(LinphoneChatRoom *cr, bool_t un
|
|||
int returnValue;
|
||||
|
||||
if (lc->db==NULL) return 0;
|
||||
|
||||
|
||||
// optimization: do not read database if the count is already available in memory
|
||||
if(unread_only && cr->unread_count >= 0) return cr->unread_count;
|
||||
|
||||
|
|
@ -336,11 +335,11 @@ static int linphone_chat_room_get_messages_count(LinphoneChatRoom *cr, bool_t un
|
|||
sqlite3_finalize(selectStatement);
|
||||
sqlite3_free(buf);
|
||||
ms_free(peer);
|
||||
|
||||
|
||||
/* no need to test the sign of cr->unread_count here
|
||||
* because it has been tested above */
|
||||
if(unread_only) cr->unread_count = numrows;
|
||||
|
||||
|
||||
return numrows;
|
||||
}
|
||||
|
||||
|
|
@ -361,7 +360,7 @@ void linphone_chat_room_delete_message(LinphoneChatRoom *cr, LinphoneChatMessage
|
|||
buf=sqlite3_mprintf("DELETE FROM history WHERE id = %i;", msg->storage_id);
|
||||
linphone_sql_request(lc->db,buf);
|
||||
sqlite3_free(buf);
|
||||
|
||||
|
||||
if(cr->unread_count >= 0 && !msg->is_read) {
|
||||
assert(cr->unread_count > 0);
|
||||
cr->unread_count--;
|
||||
|
|
@ -380,7 +379,7 @@ void linphone_chat_room_delete_history(LinphoneChatRoom *cr){
|
|||
linphone_sql_request(lc->db,buf);
|
||||
sqlite3_free(buf);
|
||||
ms_free(peer);
|
||||
|
||||
|
||||
if(cr->unread_count > 0) cr->unread_count = 0;
|
||||
}
|
||||
|
||||
|
|
@ -627,7 +626,7 @@ static int _linphone_sqlite3_open(const char *db_file, sqlite3 **db) {
|
|||
char *inbuf=db_file_locale, *outbuf=db_file_utf8;
|
||||
size_t inbyteleft = MAX_PATH_SIZE, outbyteleft = MAX_PATH_SIZE;
|
||||
iconv_t cb;
|
||||
|
||||
|
||||
strncpy(db_file_locale, db_file, MAX_PATH_SIZE-1);
|
||||
cb = iconv_open("UTF-8", nl_langinfo(CODESET));
|
||||
if(cb != (iconv_t)-1) {
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 3a3e9505237dfc8228ae7185ba98ed641fccadde
|
||||
Subproject commit 29eca39f7ecd0cc192e9d43f8d90cb486b7dd6fb
|
||||
Loading…
Add table
Reference in a new issue