Added JNI binding to get message storage id + added possibility to limit the number of messages to fetch

This commit is contained in:
Sylvain Berfini 2013-08-20 12:12:39 +02:00
parent 4462b0aed0
commit 34f405894c
7 changed files with 43 additions and 5 deletions

View file

@ -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
**/

View file

@ -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);
/**
* @}
*/

View file

@ -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) {

View file

@ -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();
}

View file

@ -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.
*/

View file

@ -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);
}
}

View file

@ -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];