Commit 55b640b0 authored by Sylvain Berfini's avatar Sylvain Berfini
Browse files

Added a method that returns the existing chatroom if possible instead of...

Added a method that returns the existing chatroom if possible instead of always creating a new one + added JNI binding for this method
parent 8fbe7ee1
......@@ -59,6 +59,28 @@ LinphoneChatRoom * linphone_core_create_chat_room(LinphoneCore *lc, const char *
return NULL;
static int chat_room_compare(LinphoneChatRoom* room, const char* to) {
return strcmp(linphone_address_as_string_uri_only(linphone_chat_room_get_peer_address(room)), to); /*return 0 if equals*/
* Create a new chat room for messaging from a sip uri like if not already existing, else return exisiting one
* @param lc #LinphoneCore object
* @param to destination address for messages
* @return #LinphoneChatRoom where messaging can take place.
LinphoneChatRoom* linphone_core_get_or_create_chat_room(LinphoneCore* lc, const char* to) {
if (ms_list_size(lc->chatrooms) == 0)
return linphone_core_create_chat_room(lc, to);
MSList* found = ms_list_find_custom(lc->chatrooms, (MSCompareFunc) chat_room_compare, to);
if (found != NULL) {
return (LinphoneChatRoom*)found->data;
} else {
return linphone_core_create_chat_room(lc, to);
* Destroy a LinphoneChatRoom.
......@@ -119,7 +119,7 @@ public class TutorialChatRoom implements LinphoneCoreListener, LinphoneChatMessa
try {
// Next step is to create a chat room
LinphoneChatRoom chatRoom = lc.createChatRoom(destinationSipAddress);
LinphoneChatRoom chatRoom = lc.getOrCreateChatRoom(destinationSipAddress);
// Send message
LinphoneChatMessage chatMessage = chatRoom.createLinphoneChatMessage("Hello world");
......@@ -852,6 +852,7 @@ typedef void (*LinphoneChatMessageStateChangeCb)(LinphoneChatMessage* msg,Linpho
LINPHONE_PUBLIC void linphone_core_set_chat_database_path(LinphoneCore *lc, const char *path);
LINPHONE_PUBLIC LinphoneChatRoom * linphone_core_create_chat_room(LinphoneCore *lc, const char *to);
LINPHONE_PUBLIC LinphoneChatRoom * linphone_core_get_or_create_chat_room(LinphoneCore *lc, const char *to);
LINPHONE_PUBLIC LinphoneChatRoom *linphone_core_get_chat_room(LinphoneCore *lc, const LinphoneAddress *addr);
LINPHONE_PUBLIC void linphone_chat_room_destroy(LinphoneChatRoom *cr);
LINPHONE_PUBLIC LinphoneChatMessage* linphone_chat_room_create_message(LinphoneChatRoom *cr,const char* message);
......@@ -1123,13 +1123,13 @@ JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCoreImpl_getPresenceMod
RETURN_USER_DATA_OBJECT("PresenceModelImpl", linphone_presence_model, model)
extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_createChatRoom(JNIEnv* env
extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getOrCreateChatRoom(JNIEnv* env
,jobject thiz
,jlong lc
,jstring jto) {
const char* to = env->GetStringUTFChars(jto, NULL);
LinphoneChatRoom* lResult = linphone_core_create_chat_room((LinphoneCore*)lc,to);
LinphoneChatRoom* lResult = linphone_core_get_or_create_chat_room((LinphoneCore*)lc,to);
env->ReleaseStringUTFChars(jto, to);
return (jlong)lResult;
......@@ -705,7 +705,7 @@ public interface LinphoneCore {
* @return {@link LinphoneChatRoom} where messaging can take place.
LinphoneChatRoom createChatRoom(String to);
LinphoneChatRoom getOrCreateChatRoom(String to);
* Set the native video window id where the video is to be displayed.
* On Android, it must be of type {@link AndroidVideoWindowImpl}
......@@ -83,7 +83,7 @@ class LinphoneCoreImpl implements LinphoneCore {
private native int getPresenceInfo(long nativePtr);
private native void setPresenceModel(long nativePtr, long presencePtr);
private native Object getPresenceModel(long nativePtr);
private native long createChatRoom(long nativePtr,String to);
private native long getOrCreateChatRoom(long nativePtr,String to);
private native void enableVideo(long nativePtr,boolean vcap_enabled,boolean display_enabled);
private native boolean isVideoEnabled(long nativePtr);
private native void setFirewallPolicy(long nativePtr, int enum_value);
......@@ -385,8 +385,8 @@ class LinphoneCoreImpl implements LinphoneCore {
public synchronized PresenceModel getPresenceModel() {
return (PresenceModel)getPresenceModel(nativePtr);
public synchronized LinphoneChatRoom createChatRoom(String to) {
return new LinphoneChatRoomImpl(createChatRoom(nativePtr,to));
public synchronized LinphoneChatRoom getOrCreateChatRoom(String to) {
return new LinphoneChatRoomImpl(getOrCreateChatRoom(nativePtr,to));
public synchronized void setPreviewWindow(Object w) {
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