Commit f9ae4317 authored by Ghislain MARY's avatar Ghislain MARY
Browse files

The (is_)read field of a LinphoneChatMessage is now deprecated, the...

The (is_)read field of a LinphoneChatMessage is now deprecated, the LinphoneChatMessageStateDisplayed state is used instead.
parent 7889b061
......@@ -448,7 +448,7 @@ void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatMessage
msg->message_id = ms_strdup(sal_op_get_call_id(op)); /* must be known at that time */
msg->storage_id = linphone_chat_message_store(msg);
if (cr->unread_count >= 0 && !msg->is_read)
if (cr->unread_count >= 0 && !linphone_chat_message_is_read(msg))
cr->unread_count++;
if (cr->is_composing == LinphoneIsComposingActive) {
......@@ -526,7 +526,6 @@ LinphoneReason linphone_core_message_received(LinphoneCore *lc, SalOp *op, const
msg->time = sal_msg->time;
msg->state = LinphoneChatMessageStateDelivered;
msg->is_read = FALSE;
msg->dir = LinphoneChatMessageIncoming;
msg->message_id = ms_strdup(sal_op_get_call_id(op));
......@@ -870,7 +869,6 @@ LinphoneChatMessage *linphone_chat_room_create_message(LinphoneChatRoom *cr, con
msg->callbacks = linphone_chat_message_cbs_new();
msg->chat_room = (LinphoneChatRoom *)cr;
msg->message = message ? ms_strdup(message) : NULL;
msg->is_read = TRUE;
msg->content_type = NULL; /* this property is used only when transfering file */
msg->file_transfer_information = NULL; /* this property is used only when transfering file */
msg->http_request = NULL;
......@@ -885,7 +883,6 @@ LinphoneChatMessage *linphone_chat_room_create_message_2(LinphoneChatRoom *cr, c
LinphoneCore *lc = linphone_chat_room_get_core(cr);
msg->external_body_url = external_body_url ? ms_strdup(external_body_url) : NULL;
msg->time = time;
msg->is_read = is_read;
linphone_chat_message_set_state(msg, state);
if (is_incoming) {
msg->dir = LinphoneChatMessageIncoming;
......@@ -1209,7 +1206,6 @@ void linphone_core_real_time_text_received(LinphoneCore *lc, LinphoneChatRoom *c
linphone_address_new(linphone_core_get_identity(lc));
msg->time = ms_time(0);
msg->state = LinphoneChatMessageStateDelivered;
msg->is_read = FALSE;
msg->dir = LinphoneChatMessageIncoming;
if (lp_config_get_int(lc->config, "misc", "store_rtt_messages", 1) == 1) {
......@@ -1263,8 +1259,7 @@ int linphone_chat_message_put_char(LinphoneChatMessage *msg, uint32_t character)
if (lc && lp_config_get_int(lc->config, "misc", "store_rtt_messages", 1) == 1) {
ms_debug("New line sent, forge a message with content %s", msg->message);
msg->time = ms_time(0);
msg->state = LinphoneChatMessageStateDelivered;
msg->is_read = TRUE;
msg->state = LinphoneChatMessageStateDisplayed;
msg->dir = LinphoneChatMessageOutgoing;
if (msg->from) linphone_address_destroy(msg->from);
msg->from = linphone_address_new(linphone_core_get_identity(lc));
......@@ -1441,7 +1436,7 @@ void linphone_chat_message_remove_custom_header(LinphoneChatMessage *msg, const
}
bool_t linphone_chat_message_is_read(LinphoneChatMessage *msg) {
return msg->is_read;
return (msg->state == LinphoneChatMessageStateDisplayed) ? TRUE : FALSE;
}
bool_t linphone_chat_message_is_outgoing(LinphoneChatMessage *msg) {
......
......@@ -644,7 +644,6 @@ LinphoneChatMessage *linphone_chat_room_create_file_transfer_message(LinphoneCha
msg->callbacks = linphone_chat_message_cbs_new();
msg->chat_room = (LinphoneChatRoom *)cr;
msg->message = NULL;
msg->is_read = TRUE;
msg->file_transfer_information = linphone_content_copy(initial_content);
msg->dir = LinphoneChatMessageOutgoing;
linphone_chat_message_set_to(msg, linphone_chat_room_get_peer_address(cr));
......
......@@ -336,7 +336,7 @@ unsigned int linphone_chat_message_store(LinphoneChatMessage *msg){
msg->dir,
msg->message,
"-1", /* use UTC field now */
msg->is_read,
FALSE, /* use state == LinphoneChatMessageStateDisplayed now */
msg->state,
msg->external_body_url,
(int64_t)msg->time,
......@@ -375,7 +375,7 @@ void linphone_chat_message_store_appdata(LinphoneChatMessage* msg){
void linphone_chat_room_mark_as_read(LinphoneChatRoom *cr){
LinphoneCore *lc=linphone_chat_room_get_core(cr);
int read=1;
bctbx_list_t *item;
char *peer;
char *buf;
......@@ -385,8 +385,17 @@ void linphone_chat_room_mark_as_read(LinphoneChatRoom *cr){
if(linphone_chat_room_get_unread_messages_count(cr) == 0) return;
peer=linphone_address_as_string_uri_only(linphone_chat_room_get_peer_address(cr));
buf=sqlite3_mprintf("UPDATE history SET read=%i WHERE remoteContact = %Q;",
read,peer);
buf = sqlite3_mprintf("SELECT * FROM history WHERE remoteContact = %Q AND direction=%i", peer, LinphoneChatMessageIncoming);
linphone_sql_request_message(lc->db, buf, cr);
sqlite3_free(buf);
for (item = cr->messages_hist; item != NULL; item = bctbx_list_next(item)) {
LinphoneChatMessage *cm = (LinphoneChatMessage *)bctbx_list_get_data(item);
linphone_chat_message_send_display_notification(cm);
}
bctbx_list_free_with_data(cr->messages_hist, (bctbx_list_free_func)linphone_chat_message_unref);
cr->messages_hist = NULL;
buf=sqlite3_mprintf("UPDATE history SET status=%i WHERE remoteContact=%Q AND direction=%i;",
LinphoneChatMessageStateDisplayed, peer, LinphoneChatMessageIncoming);
linphone_sql_request(lc->db,buf);
sqlite3_free(buf);
ms_free(peer);
......@@ -410,6 +419,7 @@ static int linphone_chat_room_get_messages_count(LinphoneChatRoom *cr, bool_t un
int numrows=0;
char *peer;
char *buf;
char *option;
sqlite3_stmt *selectStatement;
int returnValue;
......@@ -419,7 +429,10 @@ static int linphone_chat_room_get_messages_count(LinphoneChatRoom *cr, bool_t un
if(unread_only && cr->unread_count >= 0) return cr->unread_count;
peer=linphone_address_as_string_uri_only(linphone_chat_room_get_peer_address(cr));
buf=sqlite3_mprintf("SELECT count(*) FROM history WHERE remoteContact = %Q %s;",peer,unread_only?"AND read = 0":"");
if (unread_only) {
option = bctbx_strdup_printf("AND status!=%i AND direction=%i", LinphoneChatMessageStateDisplayed, LinphoneChatMessageIncoming);
}
buf=sqlite3_mprintf("SELECT count(*) FROM history WHERE remoteContact = %Q %s;",peer,unread_only?option:"");
returnValue = sqlite3_prepare_v2(lc->db,buf,-1,&selectStatement,NULL);
if (returnValue == SQLITE_OK){
if(sqlite3_step(selectStatement) == SQLITE_ROW){
......@@ -432,7 +445,10 @@ static int linphone_chat_room_get_messages_count(LinphoneChatRoom *cr, bool_t un
/* no need to test the sign of cr->unread_count here
* because it has been tested above */
if(unread_only) cr->unread_count = numrows;
if(unread_only) {
cr->unread_count = numrows;
bctbx_free(option);
}
return numrows;
}
......@@ -655,6 +671,7 @@ static void linphone_migrate_timestamps(sqlite3* db){
void linphone_update_table(sqlite3* db) {
char* errmsg=NULL;
char *buf;
int ret;
// for image url storage
......@@ -733,6 +750,11 @@ void linphone_update_table(sqlite3* db) {
} else {
ms_message("Table history updated successfully for message_id data.");
}
// Convert is_read to LinphoneChatMessageStateDisplayed
buf = sqlite3_mprintf("UPDATE history SET status=%i WHERE read=1 AND direction=%i;", LinphoneChatMessageStateDisplayed, LinphoneChatMessageIncoming);
linphone_sql_request(db, buf);
sqlite3_free(buf);
}
void linphone_message_storage_init_chat_rooms(LinphoneCore *lc) {
......
......@@ -905,9 +905,8 @@ static void imdn_notifications(void) {
received_cm = (LinphoneChatMessage *)bctbx_list_nth_data(history, 0);
BC_ASSERT_PTR_NOT_NULL(received_cm);
if (received_cm != NULL) {
linphone_chat_message_notify_delivery(received_cm);
BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &pauline->stat.number_of_LinphoneMessageDeliveredToUser, 1));
linphone_chat_message_notify_display(received_cm);
linphone_chat_room_mark_as_read(marie_chat_room); /* This sends the display notification */
BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &pauline->stat.number_of_LinphoneMessageDisplayed, 1));
bctbx_list_free_with_data(history, (bctbx_list_free_func)linphone_chat_message_unref);
}
......@@ -1393,6 +1392,7 @@ static void database_migration(void) {
char *src_db = bc_tester_res("messages.db");
char *tmp_db = bc_tester_file("tmp.db");
const bctbx_list_t* chatrooms;
LinphoneChatRoom *cr;
BC_ASSERT_EQUAL(message_tester_copy_file(src_db, tmp_db), 0, int, "%d");
......@@ -1409,7 +1409,11 @@ static void database_migration(void) {
BC_ASSERT(bctbx_list_size(chatrooms) > 0);
// check that all messages have been migrated to the UTC time storage
BC_ASSERT(sqlite3_exec(marie->lc->db, "SELECT COUNT(*) FROM history WHERE time != '-1';", check_no_strange_time, NULL, NULL) == SQLITE_OK );
BC_ASSERT(sqlite3_exec(marie->lc->db, "SELECT COUNT(*) FROM history WHERE time != '-1';", check_no_strange_time, NULL, NULL) == SQLITE_OK);
// check that the read messages (field read=1) has been migrated to the LinphoneChatMessageStateDisplayed state
cr = linphone_core_get_chat_room_from_uri(marie->lc, "sip:Marielle@sip.linphone.org");
BC_ASSERT_EQUAL(linphone_chat_room_get_unread_messages_count(cr), 8, int, "%i");
end:
linphone_core_manager_destroy(marie);
......
No preview for this file type
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment