From 34f405894cca981328688eb435d414552b2b345c Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Tue, 20 Aug 2013 12:12:39 +0200 Subject: [PATCH] Added JNI binding to get message storage id + added possibility to limit the number of messages to fetch --- coreapi/chat.c | 9 +++++++++ coreapi/linphonecore.h | 2 +- coreapi/linphonecore_jni.cc | 11 +++++++++-- .../common/org/linphone/core/LinphoneChatMessage.java | 6 ++++++ java/common/org/linphone/core/LinphoneChatRoom.java | 7 +++++++ .../org/linphone/core/LinphoneChatMessageImpl.java | 5 +++++ java/impl/org/linphone/core/LinphoneChatRoomImpl.java | 8 ++++++-- 7 files changed, 43 insertions(+), 5 deletions(-) diff --git a/coreapi/chat.c b/coreapi/chat.c index a0dc0a27e..0bf27b12b 100644 --- a/coreapi/chat.c +++ b/coreapi/chat.c @@ -494,6 +494,15 @@ bool_t linphone_chat_message_is_outgoing(LinphoneChatMessage* message) { return message->dir == LinphoneChatMessageOutgoing; } +/** + * Returns the id used to identify this message in the storage database + * @param message the message + * @return the id + */ +unsigned int linphone_chat_message_get_storage_id(LinphoneChatMessage* message) { + return message->storage_id; +} + /** * Duplicate a LinphoneChatMessage **/ diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index c9a4e0d8e..f632bf66d 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -897,7 +897,7 @@ LINPHONE_PUBLIC void linphone_chat_message_add_custom_header(LinphoneChatMessage LINPHONE_PUBLIC const char * linphone_chat_message_get_custom_header(LinphoneChatMessage* message, const char *header_name); LINPHONE_PUBLIC bool_t linphone_chat_message_is_read(LinphoneChatMessage* message); LINPHONE_PUBLIC bool_t linphone_chat_message_is_outgoing(LinphoneChatMessage* message); - +LINPHONE_PUBLIC unsigned int linphone_chat_message_get_storage_id(LinphoneChatMessage* message); /** * @} */ diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index c5ac65843..b3f47f016 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -2074,8 +2074,9 @@ extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getFriendByAddress(JNIE //LinphoneChatRoom extern "C" jlongArray Java_org_linphone_core_LinphoneChatRoomImpl_getHistory(JNIEnv* env ,jobject thiz - ,jlong ptr) { - MSList* history = linphone_chat_room_get_history((LinphoneChatRoom*)ptr, 0); + ,jlong ptr + ,jint limit) { + MSList* history = linphone_chat_room_get_history((LinphoneChatRoom*)ptr, limit); int historySize = ms_list_size(history); jlongArray jHistory = env->NewLongArray(historySize); jlong *jInternalArray = env->GetLongArrayElements(jHistory, NULL); @@ -2251,6 +2252,12 @@ extern "C" jboolean Java_org_linphone_core_LinphoneChatMessageImpl_isOutgoing(JN return (jboolean) linphone_chat_message_is_outgoing((LinphoneChatMessage*)ptr); } +extern "C" jint Java_org_linphone_core_LinphoneChatMessageImpl_getStorageId(JNIEnv* env + ,jobject thiz + ,jlong ptr) { + return (jint) linphone_chat_message_get_storage_id((LinphoneChatMessage*)ptr); +} + extern "C" jlongArray Java_org_linphone_core_LinphoneCoreImpl_getChatRooms(JNIEnv* env ,jobject thiz ,jlong ptr) { diff --git a/java/common/org/linphone/core/LinphoneChatMessage.java b/java/common/org/linphone/core/LinphoneChatMessage.java index f44997d5e..8345df382 100644 --- a/java/common/org/linphone/core/LinphoneChatMessage.java +++ b/java/common/org/linphone/core/LinphoneChatMessage.java @@ -135,4 +135,10 @@ public interface LinphoneChatMessage { * THIS METHOD IS ONLY USED TO IMPORT OLD MESSAGES, DON'T USE IT FOR ANY OTHER USAGE! */ void store(); + + /** + * Returns the id used to id this message in the database + * @return the id used to id this message in the database + */ + int getStorageId(); } diff --git a/java/common/org/linphone/core/LinphoneChatRoom.java b/java/common/org/linphone/core/LinphoneChatRoom.java index 44ed0b38d..5c87f5647 100644 --- a/java/common/org/linphone/core/LinphoneChatRoom.java +++ b/java/common/org/linphone/core/LinphoneChatRoom.java @@ -58,6 +58,13 @@ public interface LinphoneChatRoom { */ LinphoneChatMessage[] getHistory(); + /** + * Returns the chat history associated with the peer address associated with this chat room + * @param limit the maximum number of messages to fetch + * @return an array of LinphoneChatMessage + */ + LinphoneChatMessage[] getHistory(int limit); + /** * Destroys a LinphoneChatRoom. */ diff --git a/java/impl/org/linphone/core/LinphoneChatMessageImpl.java b/java/impl/org/linphone/core/LinphoneChatMessageImpl.java index 670d6f9a7..e86ab24b1 100644 --- a/java/impl/org/linphone/core/LinphoneChatMessageImpl.java +++ b/java/impl/org/linphone/core/LinphoneChatMessageImpl.java @@ -13,6 +13,7 @@ public class LinphoneChatMessageImpl implements LinphoneChatMessage { private native boolean isRead(long ptr); private native boolean isOutgoing(long ptr); private native void store(long ptr); + private native int getStorageId(long ptr); protected LinphoneChatMessageImpl(long aNativePtr) { nativePtr = aNativePtr; @@ -89,4 +90,8 @@ public class LinphoneChatMessageImpl implements LinphoneChatMessage { public void store() { store(nativePtr); } + + public int getStorageId() { + return getStorageId(nativePtr); + } } diff --git a/java/impl/org/linphone/core/LinphoneChatRoomImpl.java b/java/impl/org/linphone/core/LinphoneChatRoomImpl.java index 48fad0220..b756c0b6d 100644 --- a/java/impl/org/linphone/core/LinphoneChatRoomImpl.java +++ b/java/impl/org/linphone/core/LinphoneChatRoomImpl.java @@ -27,7 +27,7 @@ class LinphoneChatRoomImpl implements LinphoneChatRoom { private native long getPeerAddress(long ptr); private native void sendMessage(long ptr, String message); private native void sendMessage2(long ptr, long message, StateListener listener); - private native long[] getHistory(long ptr); + private native long[] getHistory(long ptr, int limit); private native void destroy(long ptr); private native int getUnreadMessagesCount(long ptr); private native void deleteHistory(long ptr); @@ -61,7 +61,11 @@ class LinphoneChatRoomImpl implements LinphoneChatRoom { } public LinphoneChatMessage[] getHistory() { - long[] typesPtr = getHistory(nativePtr); + return getHistory(0); + } + + public LinphoneChatMessage[] getHistory(int limit) { + long[] typesPtr = getHistory(nativePtr, limit); if (typesPtr == null) return null; LinphoneChatMessage[] messages = new LinphoneChatMessage[typesPtr.length];