diff --git a/coreapi/chat.c b/coreapi/chat.c index 537a4b7ae..0be6b0bbd 100644 --- a/coreapi/chat.c +++ b/coreapi/chat.c @@ -136,7 +136,7 @@ static void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatM } msg->dir=LinphoneChatMessageOutgoing; msg->from=linphone_address_new(identity); - linphone_chat_message_store(msg); + msg->storage_id=linphone_chat_message_store(msg); } /** @@ -220,7 +220,7 @@ void linphone_core_message_received(LinphoneCore *lc, SalOp *op, const SalMessag linphone_chat_message_set_external_body_url(msg, sal_msg->url); } linphone_address_destroy(addr); - linphone_chat_message_store(msg); + msg->storage_id=linphone_chat_message_store(msg); linphone_chat_room_message_received(cr,lc,msg); ms_free(cleanfrom); ms_free(from); @@ -473,6 +473,7 @@ LinphoneChatMessage* linphone_chat_message_clone(const LinphoneChatMessage* msg) new_message->cb=msg->cb; new_message->time=msg->time; new_message->state=msg->state; + new_message->storage_id=msg->storage_id; if (msg->from) new_message->from=linphone_address_clone(msg->from); return new_message; } diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 2c9e46404..0e5963bf5 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -862,6 +862,7 @@ LINPHONE_PUBLIC void linphone_chat_room_send_message(LinphoneChatRoom *cr, const LINPHONE_PUBLIC void linphone_chat_room_send_message2(LinphoneChatRoom *cr, LinphoneChatMessage* msg,LinphoneChatMessageStateChangeCb status_cb,void* ud); LINPHONE_PUBLIC MSList *linphone_chat_room_get_history(LinphoneChatRoom *cr,int nb_message); LINPHONE_PUBLIC void linphone_chat_room_mark_as_read(LinphoneChatRoom *cr); +LINPHONE_PUBLIC void linphone_chat_room_delete_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg); LINPHONE_PUBLIC void linphone_chat_room_delete_history(LinphoneChatRoom *cr); LINPHONE_PUBLIC int linphone_chat_room_get_unread_messages_count(LinphoneChatRoom *cr); LINPHONE_PUBLIC LinphoneCore* linphone_chat_room_get_lc(LinphoneChatRoom *cr); diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index b877a1f1b..19be90590 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -2088,6 +2088,12 @@ extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_deleteHistory(JNIEnv ,jlong ptr) { linphone_chat_room_delete_history((LinphoneChatRoom*)ptr); } +extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_deleteMessage(JNIEnv* env + ,jobject thiz + ,jlong room + ,jlong msg) { + linphone_chat_room_delete_message((LinphoneChatRoom*)room, (LinphoneChatMessage*)msg); +} extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_markAsRead(JNIEnv* env ,jobject thiz ,jlong ptr) { diff --git a/coreapi/message_storage.c b/coreapi/message_storage.c index d9195166d..016188d6b 100644 --- a/coreapi/message_storage.c +++ b/coreapi/message_storage.c @@ -73,6 +73,7 @@ static void create_chat_message(char **argv, void *data){ new_message->time=argv[5]!=NULL ? mktime(&ret) : time(NULL); new_message->is_read=atoi(argv[6]); new_message->state=atoi(argv[7]); + new_message->storage_id=atoi(argv[0]); cr->messages_hist=ms_list_prepend(cr->messages_hist,new_message); } @@ -120,8 +121,9 @@ void linphone_sql_request_all(sqlite3* db,const char *stmt, LinphoneCore* lc){ } } -void linphone_chat_message_store(LinphoneChatMessage *msg){ +unsigned int linphone_chat_message_store(LinphoneChatMessage *msg){ LinphoneCore *lc=linphone_chat_room_get_lc(msg->chat_room); + int id=0; if (lc->db){ char *peer=linphone_address_as_string_uri_only(linphone_chat_room_get_peer_address(msg->chat_room)); char *local_contact=linphone_address_as_string_uri_only(linphone_chat_message_get_local_address(msg)); @@ -132,7 +134,9 @@ void linphone_chat_message_store(LinphoneChatMessage *msg){ sqlite3_free(buf); ms_free(local_contact); ms_free(peer); + id = (unsigned int) sqlite3_last_insert_rowid (lc->db); } + return id; } void linphone_chat_message_store_state(LinphoneChatMessage *msg){ @@ -181,6 +185,16 @@ int linphone_chat_room_get_unread_messages_count(LinphoneChatRoom *cr){ return numrows; } +void linphone_chat_room_delete_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg) { + LinphoneCore *lc=cr->lc; + + if (lc->db==NULL) return ; + + char *buf=sqlite3_mprintf("delete from history where id = %i;", msg->storage_id); + linphone_sql_request(lc->db,buf); + sqlite3_free(buf); +} + void linphone_chat_room_delete_history(LinphoneChatRoom *cr){ LinphoneCore *lc=cr->lc; @@ -264,7 +278,7 @@ void linphone_core_message_storage_close(LinphoneCore *lc){ #else -void linphone_chat_message_store(LinphoneChatMessage *cr){ +unsigned int linphone_chat_message_store(LinphoneChatMessage *cr){ } void linphone_chat_message_store_state(LinphoneChatMessage *cr){ @@ -277,6 +291,9 @@ MSList *linphone_chat_room_get_history(LinphoneChatRoom *cr,int nb_message){ return NULL; } +void linphone_chat_room_delete_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg) { +} + void linphone_chat_room_delete_history(LinphoneChatRoom *cr){ } diff --git a/coreapi/private.h b/coreapi/private.h index 2cd0279ee..c61344b40 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -141,6 +141,7 @@ struct _LinphoneChatMessage { SalCustomHeader *custom_headers; LinphoneChatMessageState state; bool_t is_read; + unsigned int storage_id; }; typedef struct StunCandidate{ @@ -734,7 +735,7 @@ void linphone_upnp_destroy(LinphoneCore *lc); sqlite3 * linphone_message_storage_init(); void linphone_message_storage_init_chat_rooms(LinphoneCore *lc); #endif -void linphone_chat_message_store(LinphoneChatMessage *msg); +unsigned int linphone_chat_message_store(LinphoneChatMessage *msg); void linphone_chat_message_store_state(LinphoneChatMessage *msg); void linphone_core_message_storage_init(LinphoneCore *lc); void linphone_core_message_storage_close(LinphoneCore *lc); diff --git a/java/common/org/linphone/core/LinphoneChatRoom.java b/java/common/org/linphone/core/LinphoneChatRoom.java index 9b1c4d289..c55d495a8 100644 --- a/java/common/org/linphone/core/LinphoneChatRoom.java +++ b/java/common/org/linphone/core/LinphoneChatRoom.java @@ -75,4 +75,10 @@ public interface LinphoneChatRoom { * Marks all the messages in this conversation as read */ void markAsRead(); + + /** + * Deletes a message + * @param message the message to delete + */ + void deleteMessage(LinphoneChatMessage message); } diff --git a/java/impl/org/linphone/core/LinphoneChatRoomImpl.java b/java/impl/org/linphone/core/LinphoneChatRoomImpl.java index 8885dbac2..e576fad0b 100644 --- a/java/impl/org/linphone/core/LinphoneChatRoomImpl.java +++ b/java/impl/org/linphone/core/LinphoneChatRoomImpl.java @@ -31,6 +31,7 @@ class LinphoneChatRoomImpl implements LinphoneChatRoom { private native int getUnreadMessagesCount(long ptr); private native void deleteHistory(long ptr); private native void markAsRead(long ptr); + private native void deleteMessage(long room, long message); protected LinphoneChatRoomImpl(long aNativePtr) { nativePtr = aNativePtr; @@ -82,4 +83,9 @@ class LinphoneChatRoomImpl implements LinphoneChatRoom { public void markAsRead() { markAsRead(nativePtr); } + + public void deleteMessage(LinphoneChatMessage message) { + if (message != null) + deleteMessage(nativePtr, message.getNativePtr()); + } }