Commit 5e89a041 authored by jehan's avatar jehan
Browse files

add function to chatroom to find a message with a given direction.

It re-enable to send messages to itself on the same device
parent 88fe8d00
...@@ -668,8 +668,9 @@ LinphoneReason linphone_core_message_received(LinphoneCore *lc, SalOp *op, const ...@@ -668,8 +668,9 @@ LinphoneReason linphone_core_message_received(LinphoneCore *lc, SalOp *op, const
cr = linphone_core_get_chat_room(lc, addr); cr = linphone_core_get_chat_room(lc, addr);
/* Check if this is a duplicate message */ /* Check if this is a duplicate message */
if (linphone_chat_room_find_message(cr, sal_op_get_call_id(op)) != NULL) { if ((msg = linphone_chat_room_find_message_with_dir(cr, sal_op_get_call_id(op), LinphoneChatMessageIncoming))) {
reason = lc->chat_deny_code; reason = lc->chat_deny_code;
linphone_chat_message_unref(msg);
goto end; goto end;
} }
...@@ -882,7 +883,7 @@ static void process_imdn(LinphoneChatRoom *cr, xmlparsing_context_t *xml_ctx) { ...@@ -882,7 +883,7 @@ static void process_imdn(LinphoneChatRoom *cr, xmlparsing_context_t *xml_ctx) {
} }
if ((message_id_str != NULL) && (datetime_str != NULL)) { if ((message_id_str != NULL) && (datetime_str != NULL)) {
LinphoneChatMessage *cm = linphone_chat_room_find_message(cr, message_id_str); LinphoneChatMessage *cm = linphone_chat_room_find_message_with_dir(cr, message_id_str, LinphoneChatMessageOutgoing);
if (cm == NULL) { if (cm == NULL) {
ms_warning("Received IMDN for unknown message %s", message_id_str); ms_warning("Received IMDN for unknown message %s", message_id_str);
} else { } else {
......
...@@ -627,11 +627,12 @@ bctbx_list_t *linphone_chat_room_get_history(LinphoneChatRoom *cr,int nb_message ...@@ -627,11 +627,12 @@ bctbx_list_t *linphone_chat_room_get_history(LinphoneChatRoom *cr,int nb_message
return linphone_chat_room_get_history_range(cr, 0, nb_message-1); return linphone_chat_room_get_history_range(cr, 0, nb_message-1);
} }
LinphoneChatMessage * linphone_chat_room_find_message(LinphoneChatRoom *cr, const char *message_id) {
bctbx_list_t* linphone_chat_room_find_messages(LinphoneChatRoom *cr, const char *message_id) {
LinphoneCore *lc = linphone_chat_room_get_core(cr); LinphoneCore *lc = linphone_chat_room_get_core(cr);
LinphoneChatMessage *cm = NULL;
char *buf; char *buf;
char *peer; char *peer;
bctbx_list_t* messages;
if (lc->db == NULL) return NULL; if (lc->db == NULL) return NULL;
peer = linphone_address_as_string_uri_only(linphone_chat_room_get_peer_address(cr)); peer = linphone_address_as_string_uri_only(linphone_chat_room_get_peer_address(cr));
...@@ -639,13 +640,39 @@ LinphoneChatMessage * linphone_chat_room_find_message(LinphoneChatRoom *cr, cons ...@@ -639,13 +640,39 @@ LinphoneChatMessage * linphone_chat_room_find_message(LinphoneChatRoom *cr, cons
buf = sqlite3_mprintf("SELECT * FROM history WHERE remoteContact = %Q AND messageId = %Q", peer, message_id); buf = sqlite3_mprintf("SELECT * FROM history WHERE remoteContact = %Q AND messageId = %Q", peer, message_id);
linphone_sql_request_message(lc->db, buf, cr); linphone_sql_request_message(lc->db, buf, cr);
sqlite3_free(buf); sqlite3_free(buf);
ms_free(peer);
messages = cr->messages_hist;
cr->messages_hist = NULL;
return messages;
}
if (cr->messages_hist) { LinphoneChatMessage * linphone_chat_room_find_message_with_dir(LinphoneChatRoom *cr, const char *message_id, LinphoneChatMessageDir dir) {
cm = (LinphoneChatMessage *)bctbx_list_nth_data(cr->messages_hist, 0); bctbx_list_t* messages = linphone_chat_room_find_messages(cr, message_id);
bctbx_list_t* it;
LinphoneChatMessage *ret = NULL;
for (it = messages; it != NULL; it = it->next) {
LinphoneChatMessage * cm = (LinphoneChatMessage*)it->data;
if (cm->dir == dir) {
linphone_chat_message_ref(cm);
ret = cm;
break;
} }
}
if (messages)
bctbx_list_free_with_data(messages, (bctbx_list_free_func)linphone_chat_message_unref);
cr->messages_hist = NULL; return ret;
ms_free(peer);
}
LinphoneChatMessage * linphone_chat_room_find_message(LinphoneChatRoom *cr, const char *message_id) {
bctbx_list_t* messages = linphone_chat_room_find_messages(cr, message_id);
LinphoneChatMessage *cm = NULL;
if (messages) {
cm = (LinphoneChatMessage *)bctbx_list_nth_data(messages, 0);
linphone_chat_message_ref(cm);
bctbx_list_free_with_data(messages, (bctbx_list_free_func)linphone_chat_message_unref);
}
return cm; return cm;
} }
......
...@@ -278,6 +278,11 @@ struct _LinphoneChatMessage { ...@@ -278,6 +278,11 @@ struct _LinphoneChatMessage {
#endif #endif
}; };
/*
*Gets a Message with a given message id and direction.
*/
LINPHONE_PUBLIC LinphoneChatMessage * linphone_chat_room_find_message_with_dir(LinphoneChatRoom *cr, const char *message_id,LinphoneChatMessageDir dir);
BELLE_SIP_DECLARE_VPTR_NO_EXPORT(LinphoneChatMessage); BELLE_SIP_DECLARE_VPTR_NO_EXPORT(LinphoneChatMessage);
typedef struct StunCandidate{ typedef struct StunCandidate{
......
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