Commit b7d0c708 authored by Sylvain Berfini's avatar Sylvain Berfini 🐮
Browse files

Chat room API rework

Created linphone_core_search_chat_room to replace all linphone_core_get_chat_room and linphone_core_find_chat_room methods
Created linphone_core_create_chat_room_6 to replace all previous chat room creation methods
parent 5554f374
......@@ -81,69 +81,81 @@ const bctbx_list_t *linphone_core_get_chat_rooms (LinphoneCore *lc) {
return lc->chat_rooms;
}
static LinphoneChatRoom *linphone_chat_room_new (LinphoneCore *core, const LinphoneAddress *addr) {
return L_GET_C_BACK_PTR(L_GET_CPP_PTR_FROM_C_OBJECT(core)->getOrCreateBasicChatRoom(
*L_GET_CPP_PTR_FROM_C_OBJECT(addr),
!!linphone_core_realtime_text_enabled(core)
));
}
LinphoneChatRoom *_linphone_core_create_chat_room_from_call(LinphoneCall *call){
LinphoneChatRoom *cr = linphone_chat_room_new(linphone_call_get_core(call),
linphone_address_clone(linphone_call_get_remote_address(call)));
linphone_chat_room_set_call(cr, call);
return cr;
}
LinphoneChatRoom *linphone_core_get_chat_room (LinphoneCore *lc, const LinphoneAddress *peerAddr) {
return L_GET_C_BACK_PTR(L_GET_CPP_PTR_FROM_C_OBJECT(lc)->getOrCreateBasicChatRoom(*L_GET_CPP_PTR_FROM_C_OBJECT(peerAddr)));
}
LinphoneChatRoom *linphone_core_get_chat_room_2 (
LinphoneCore *lc,
const LinphoneAddress *peer_addr,
const LinphoneAddress *local_addr
) {
return L_GET_C_BACK_PTR(L_GET_CPP_PTR_FROM_C_OBJECT(lc)->getOrCreateBasicChatRoom(LinphonePrivate::ConferenceId(
LinphonePrivate::IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(peer_addr)),
LinphonePrivate::IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(local_addr))
)));
}
//Deprecated
//Deprecated see linphone_core_create_chat_room_6
LinphoneChatRoom *linphone_core_create_client_group_chat_room(LinphoneCore *lc, const char *subject, bool_t fallback) {
return linphone_core_create_client_group_chat_room_2(lc, subject, fallback, FALSE);
}
//Deprecated
//Deprecated see linphone_core_create_chat_room_6
LinphoneChatRoom *linphone_core_create_client_group_chat_room_2(LinphoneCore *lc, const char *subject, bool_t fallback, bool_t encrypted) {
return L_GET_C_BACK_PTR(L_GET_PRIVATE_FROM_C_OBJECT(lc)->createClientGroupChatRoom(L_C_TO_STRING(subject), !!fallback, !!encrypted));
}
//Deprecated see linphone_core_create_chat_room_6
LinphoneChatRoom *linphone_core_create_chat_room(LinphoneCore *lc, const LinphoneChatRoomParams *params, const LinphoneAddress *localAddr, const char *subject, const bctbx_list_t *participants) {
return L_GET_C_BACK_PTR(L_GET_PRIVATE_FROM_C_OBJECT(lc)->createChatRoom(LinphonePrivate::ChatRoomParams::toCpp(params)->clone()->toSharedPtr(), LinphonePrivate::IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(localAddr)), L_C_TO_STRING(subject), L_GET_CPP_LIST_FROM_C_LIST_2(participants, LinphoneAddress *, LinphonePrivate::IdentityAddress, [] (LinphoneAddress *addr) {
return LinphonePrivate::IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(addr));
})));
LinphoneChatRoomParams *params2 = linphone_chat_room_params_clone(params);
linphone_chat_room_params_set_subject(params2, subject);
LinphoneChatRoom *result = linphone_core_create_chat_room_6(lc, params2, localAddr, participants);
linphone_chat_room_params_unref(params2);
return result;
}
//Deprecated see linphone_core_create_chat_room_6
LinphoneChatRoom *linphone_core_create_chat_room_2(LinphoneCore *lc, const LinphoneChatRoomParams *params, const char *subject, const bctbx_list_t *participants) {
return L_GET_C_BACK_PTR(L_GET_PRIVATE_FROM_C_OBJECT(lc)->createChatRoom(LinphonePrivate::ChatRoomParams::toCpp(params)->clone()->toSharedPtr(), L_C_TO_STRING(subject), L_GET_CPP_LIST_FROM_C_LIST_2(participants, LinphoneAddress *, LinphonePrivate::IdentityAddress, [] (LinphoneAddress *addr) {
return LinphonePrivate::IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(addr));
})));
LinphoneChatRoomParams *params2 = linphone_chat_room_params_clone(params);
linphone_chat_room_params_set_subject(params2, subject);
LinphoneChatRoom *result = linphone_core_create_chat_room_6(lc, params2, NULL, participants);
linphone_chat_room_params_unref(params2);
return result;
}
//Deprecated see linphone_core_create_chat_room_6
LinphoneChatRoom *linphone_core_create_chat_room_3(LinphoneCore *lc, const char *subject, const bctbx_list_t *participants) {
return L_GET_C_BACK_PTR(L_GET_PRIVATE_FROM_C_OBJECT(lc)->createChatRoom(L_C_TO_STRING(subject), L_GET_CPP_LIST_FROM_C_LIST_2(participants, LinphoneAddress *, LinphonePrivate::IdentityAddress, [] (LinphoneAddress *addr) {
return LinphonePrivate::IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(addr));
})));
LinphoneChatRoomParams *params = linphone_core_create_default_chat_room_params(lc);
linphone_chat_room_params_set_subject(params, subject);
LinphoneChatRoom *result = linphone_core_create_chat_room_6(lc, params, NULL, participants);
linphone_chat_room_params_unref(params);
return result;
}
//Deprecated see linphone_core_create_chat_room_6
LinphoneChatRoom *linphone_core_create_chat_room_4(LinphoneCore *lc, const LinphoneChatRoomParams *params, const LinphoneAddress *localAddr, const LinphoneAddress *participant) {
return L_GET_C_BACK_PTR(L_GET_PRIVATE_FROM_C_OBJECT(lc)->createChatRoom(LinphonePrivate::ChatRoomParams::toCpp(params)->clone()->toSharedPtr(), LinphonePrivate::IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(localAddr)), LinphonePrivate::IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(participant))));
bctbx_list_t *paricipants = bctbx_list_prepend(NULL, (LinphoneAddress *)participant);
LinphoneChatRoom *result = linphone_core_create_chat_room_6(lc, params, localAddr, paricipants);
bctbx_list_free(paricipants);
return result;
}
//Deprecated see linphone_core_create_chat_room_6
LinphoneChatRoom *linphone_core_create_chat_room_5(LinphoneCore *lc, const LinphoneAddress *participant) {
return L_GET_C_BACK_PTR(L_GET_PRIVATE_FROM_C_OBJECT(lc)->createChatRoom(LinphonePrivate::IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(participant))));
bctbx_list_t *paricipants = bctbx_list_prepend(NULL, (LinphoneAddress *)participant);
LinphoneChatRoomParams *params = linphone_core_create_default_chat_room_params(lc);
LinphoneChatRoom *result = linphone_core_create_chat_room_6(lc, params, NULL, paricipants);
linphone_chat_room_params_unref(params);
bctbx_list_free(paricipants);
return result;
}
LinphoneChatRoom *linphone_core_create_chat_room_6(LinphoneCore *lc, const LinphoneChatRoomParams *params, const LinphoneAddress *localAddr, const bctbx_list_t *participants) {
shared_ptr<LinphonePrivate::ChatRoomParams> chatRoomParams = params ? LinphonePrivate::ChatRoomParams::toCpp(params)->clone()->toSharedPtr() : nullptr;
const list<LinphonePrivate::IdentityAddress> participantsList = L_GET_CPP_LIST_FROM_C_LIST_2(participants, LinphoneAddress *, LinphonePrivate::IdentityAddress, [] (LinphoneAddress *addr) {
return LinphonePrivate::IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(addr));
});
bool withGruu = chatRoomParams ? chatRoomParams->getChatRoomBackend() == LinphonePrivate::ChatRoomParams::ChatRoomBackend::FlexisipChat : false;
LinphonePrivate::IdentityAddress identityAddress = localAddr ? LinphonePrivate::IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(localAddr)) : L_GET_PRIVATE_FROM_C_OBJECT(lc)->getDefaultLocalAddress(nullptr, withGruu);
shared_ptr<LinphonePrivate::AbstractChatRoom> room = L_GET_PRIVATE_FROM_C_OBJECT(lc)->createChatRoom(chatRoomParams, identityAddress, participantsList);
return L_GET_C_BACK_PTR(room);
}
LinphoneChatRoom *linphone_core_search_chat_room(const LinphoneCore *lc, const LinphoneChatRoomParams *params, const LinphoneAddress *localAddr, const bctbx_list_t *participants) {
shared_ptr<LinphonePrivate::ChatRoomParams> chatRoomParams = params ? LinphonePrivate::ChatRoomParams::toCpp(params)->clone()->toSharedPtr() : nullptr;
const list<LinphonePrivate::IdentityAddress> participantsList = L_GET_CPP_LIST_FROM_C_LIST_2(participants, LinphoneAddress *, LinphonePrivate::IdentityAddress, [] (LinphoneAddress *addr) {
return LinphonePrivate::IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(addr));
});
bool withGruu = chatRoomParams ? chatRoomParams->getChatRoomBackend() == LinphonePrivate::ChatRoomParams::ChatRoomBackend::FlexisipChat : false;
LinphonePrivate::IdentityAddress identityAddress = localAddr ? LinphonePrivate::IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(localAddr)) : L_GET_PRIVATE_FROM_C_OBJECT(lc)->getDefaultLocalAddress(nullptr, withGruu);
shared_ptr<LinphonePrivate::AbstractChatRoom> room = L_GET_PRIVATE_FROM_C_OBJECT(lc)->searchChatRoom(chatRoomParams, identityAddress, participantsList);
return L_GET_C_BACK_PTR(room);
}
LinphoneChatRoomParams *linphone_core_create_default_chat_room_params(LinphoneCore *lc) {
......@@ -152,6 +164,12 @@ LinphoneChatRoomParams *linphone_core_create_default_chat_room_params(LinphoneCo
return params->toC();
}
static LinphoneChatRoomParams *_linphone_core_create_default_chat_room_params() {
auto params = LinphonePrivate::ChatRoomParams::getDefaults();
params->ref();
return params->toC();
}
LinphoneChatRoom *_linphone_core_create_server_group_chat_room (LinphoneCore *lc, LinphonePrivate::SalCallOp *op) {
return _linphone_server_group_chat_room_new(lc, op);
}
......@@ -160,44 +178,80 @@ void linphone_core_delete_chat_room (LinphoneCore *, LinphoneChatRoom *cr) {
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->deleteFromDb();
}
//Deprecated see linphone_core_search_chat_room
LinphoneChatRoom *linphone_core_get_chat_room (LinphoneCore *lc, const LinphoneAddress *peerAddr) {
return linphone_core_get_chat_room_2(lc, peerAddr, NULL);
}
//Deprecated see linphone_core_search_chat_room
LinphoneChatRoom *linphone_core_get_chat_room_2 (
LinphoneCore *lc,
const LinphoneAddress *peer_addr,
const LinphoneAddress *local_addr
) {
LinphoneChatRoomParams *params = linphone_core_create_default_chat_room_params(lc);
linphone_chat_room_params_set_backend(params, LinphoneChatRoomBackendBasic);
linphone_chat_room_params_enable_group(params, FALSE);
bctbx_list_t *paricipants = bctbx_list_prepend(NULL, (LinphoneAddress *)peer_addr);
LinphoneChatRoom *result = linphone_core_search_chat_room(lc, params, local_addr, paricipants);
if (result == NULL) {
result = linphone_core_create_chat_room_6(lc, params, local_addr, paricipants);
}
linphone_chat_room_params_unref(params);
bctbx_list_free(paricipants);
return result;
}
//Deprecated see linphone_core_search_chat_room
LinphoneChatRoom *linphone_core_get_chat_room_from_uri(LinphoneCore *lc, const char *to) {
return L_GET_C_BACK_PTR(L_GET_CPP_PTR_FROM_C_OBJECT(lc)->getOrCreateBasicChatRoomFromUri(L_C_TO_STRING(to)));
LinphoneAddress *addr = linphone_core_interpret_url(lc, to);
LinphoneChatRoom *room = linphone_core_get_chat_room(lc, addr);
if (addr) linphone_address_unref(addr);
return room;
}
//Deprecated see linphone_core_search_chat_room
LinphoneChatRoom *linphone_core_find_chat_room(
const LinphoneCore *lc,
const LinphoneAddress *peer_addr,
const LinphoneAddress *local_addr
) {
return L_GET_C_BACK_PTR(L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findChatRoom(LinphonePrivate::ConferenceId(
LinphonePrivate::IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(peer_addr)),
LinphonePrivate::IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(local_addr))
)));
bctbx_list_t *paricipants = bctbx_list_prepend(NULL, (LinphoneAddress *)peer_addr);
LinphoneChatRoom *result = linphone_core_search_chat_room(lc, NULL, local_addr, paricipants);
bctbx_list_free(paricipants);
return result;
}
//Deprecated see linphone_core_search_chat_room
LinphoneChatRoom *linphone_core_find_one_to_one_chat_room (
const LinphoneCore *lc,
const LinphoneAddress *local_addr,
const LinphoneAddress *participant_addr
) {
return L_GET_C_BACK_PTR(L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findOneToOneChatRoom(
LinphonePrivate::IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(local_addr)),
LinphonePrivate::IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(participant_addr)),
false, false)
);
bctbx_list_t *paricipants = bctbx_list_prepend(NULL, (LinphoneAddress *)participant_addr);
LinphoneChatRoomParams *params = _linphone_core_create_default_chat_room_params();
linphone_chat_room_params_enable_group(params, FALSE);
LinphoneChatRoom *result = linphone_core_search_chat_room(lc, params, local_addr, paricipants);
linphone_chat_room_params_unref(params);
bctbx_list_free(paricipants);
return result;
}
//Deprecated see linphone_core_search_chat_room
LinphoneChatRoom *linphone_core_find_one_to_one_chat_room_2 (
const LinphoneCore *lc,
const LinphoneAddress *local_addr,
const LinphoneAddress *participant_addr,
bool_t encrypted
) {
return L_GET_C_BACK_PTR(L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findOneToOneChatRoom(
LinphonePrivate::IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(local_addr)),
LinphonePrivate::IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(participant_addr)),
false, !!encrypted)
);
bctbx_list_t *paricipants = bctbx_list_prepend(NULL, (LinphoneAddress *)participant_addr);
LinphoneChatRoomParams *params = _linphone_core_create_default_chat_room_params();
linphone_chat_room_params_enable_group(params, FALSE);
linphone_chat_room_params_enable_encryption(params, encrypted);
LinphoneChatRoom *result = linphone_core_search_chat_room(lc, params, local_addr, paricipants);
linphone_chat_room_params_unref(params);
bctbx_list_free(paricipants);
return result;
}
LinphoneReason linphone_core_message_received(LinphoneCore *lc, LinphonePrivate::SalOp *op, const SalMessage *sal_msg) {
......
......@@ -423,7 +423,6 @@ LinphoneChatMessageStateChangedCb linphone_chat_message_get_message_state_change
void linphone_chat_message_set_message_state_changed_cb(LinphoneChatMessage* msg, LinphoneChatMessageStateChangedCb cb);
void linphone_chat_message_set_message_state_changed_cb_user_data(LinphoneChatMessage* msg, void *user_data);
void * linphone_chat_message_get_message_state_changed_cb_user_data(LinphoneChatMessage* msg);
LinphoneChatRoom *_linphone_core_create_chat_room_from_call(LinphoneCall *call);
bool_t linphone_core_tone_indications_enabled(LinphoneCore*lc);
const char *linphone_core_create_uuid(LinphoneCore *lc);
......
......@@ -39,6 +39,8 @@
**/
LINPHONE_PUBLIC LinphoneChatRoomParams *linphone_chat_room_params_new(void);
LinphoneChatRoomParams *linphone_chat_room_params_clone(const LinphoneChatRoomParams *params);
/**
* Acquire a reference to the chat room parameters.
* @param[in] params The chat room parameters.
......@@ -128,6 +130,19 @@ LINPHONE_PUBLIC void linphone_chat_room_params_enable_encryption(LinphoneChatRoo
**/
LINPHONE_PUBLIC void linphone_chat_room_params_enable_rtt(LinphoneChatRoomParams *params, bool_t rtt);
/**
* Get the subject of the chat room.
* @param[in] params The chat room params.
* @return The subject.
**/
LINPHONE_PUBLIC const char * linphone_chat_room_params_get_subject(LinphoneChatRoomParams *params);
/**
* Set the subject of the chat room.
* @param[in] params The chat room params.
* @param[in] subject The subject to set.
**/
LINPHONE_PUBLIC void linphone_chat_room_params_set_subject(LinphoneChatRoomParams *params, const char *subject);
/**
* @}
......
......@@ -5646,6 +5646,8 @@ LINPHONE_DEPRECATED LINPHONE_PUBLIC const char *linphone_core_get_chat_database_
* @param[in] subject The subject of the group chat room
* @param[in] fallback Boolean value telling whether we should plan on being able to fallback to a basic chat room if the client-side group chat room creation fails
* @return The newly created client-side group chat room.
* @maybenil
* @deprecated on 02/07/2020, use linphone_core_create_chat_room_6() instead
*/
LINPHONE_PUBLIC LINPHONE_DEPRECATED LinphoneChatRoom * linphone_core_create_client_group_chat_room(LinphoneCore *lc, const char *subject, bool_t fallback);
......@@ -5660,6 +5662,8 @@ LINPHONE_PUBLIC LINPHONE_DEPRECATED LinphoneChatRoom * linphone_core_create_clie
* @param[in] fallback Boolean value telling whether we should plan on being able to fallback to a basic chat room if the client-side group chat room creation fails
* @param[in] encrypted Boolean value telling whether we should apply encryption or not on chat messages sent and received on this room.
* @return The newly created client-side group chat room.
* @maybenil
* @deprecated on 02/07/2020, use linphone_core_create_chat_room_6() instead
*/
LINPHONE_PUBLIC LINPHONE_DEPRECATED LinphoneChatRoom *linphone_core_create_client_group_chat_room_2(LinphoneCore *lc, const char *subject, bool_t fallback, bool_t encrypted);
......@@ -5672,6 +5676,8 @@ LINPHONE_PUBLIC LINPHONE_DEPRECATED LinphoneChatRoom *linphone_core_create_clien
* @param[in] subject The subject of the group chat room
* @param[in] participants \bctbx_list{LinphoneAddress} The initial list of participants of the chat room
* @return The newly created chat room.
* @maybenil
* @deprecated on 02/07/2020, use linphone_core_create_chat_room_6() instead
*/
LINPHONE_PUBLIC LinphoneChatRoom *linphone_core_create_chat_room(LinphoneCore *lc, const LinphoneChatRoomParams *params, const LinphoneAddress *localAddr, const char *subject, const bctbx_list_t *participants);
......@@ -5682,6 +5688,8 @@ LINPHONE_PUBLIC LinphoneChatRoom *linphone_core_create_chat_room(LinphoneCore *l
* @param[in] params The chat room creation parameters #LinphoneChatRoomParams
* @param[in] participants \bctbx_list{LinphoneAddress} The initial list of participants of the chat room
* @return The newly created chat room.
* @maybenil
* @deprecated on 02/07/2020, use linphone_core_create_chat_room_6() instead
*/
LINPHONE_PUBLIC LinphoneChatRoom *linphone_core_create_chat_room_2(LinphoneCore *lc, const LinphoneChatRoomParams *params, const char *subject, const bctbx_list_t *participants);
......@@ -5691,6 +5699,8 @@ LINPHONE_PUBLIC LinphoneChatRoom *linphone_core_create_chat_room_2(LinphoneCore
* @param[in] subject The subject of the group chat room
* @param[in] participants \bctbx_list{LinphoneAddress} The initial list of participants of the chat room
* @return The newly created chat room.
* @maybenil
* @deprecated on 02/07/2020, use linphone_core_create_chat_room_6() instead
*/
LINPHONE_PUBLIC LinphoneChatRoom *linphone_core_create_chat_room_3(LinphoneCore *lc, const char *subject, const bctbx_list_t *participants);
......@@ -5701,6 +5711,8 @@ LINPHONE_PUBLIC LinphoneChatRoom *linphone_core_create_chat_room_3(LinphoneCore
* @param[in] localAddr #LinphoneAddress representing the local proxy configuration to use for the chat room creation
* @param[in] participant #LinphoneAddress representing the initial participant to add to the chat room
* @return The newly created chat room.
* @maybenil
* @deprecated on 02/07/2020, use linphone_core_create_chat_room_6() instead
*/
LINPHONE_PUBLIC LinphoneChatRoom *linphone_core_create_chat_room_4(LinphoneCore *lc, const LinphoneChatRoomParams *params, const LinphoneAddress *localAddr, const LinphoneAddress *participant);
......@@ -5709,15 +5721,44 @@ LINPHONE_PUBLIC LinphoneChatRoom *linphone_core_create_chat_room_4(LinphoneCore
* @param[in] lc A #LinphoneCore object
* @param[in] participant #LinphoneAddress representing the initial participant to add to the chat room
* @return The newly created chat room.
* @maybenil
* @deprecated on 02/07/2020, use linphone_core_create_chat_room_6() instead
*/
LINPHONE_PUBLIC LinphoneChatRoom *linphone_core_create_chat_room_5(LinphoneCore *lc, const LinphoneAddress *participant);
/**
* Create a chat room.
*
* @param[in] lc A #LinphoneCore object
* @param[in] params The chat room creation parameters #LinphoneChatRoomParams
* @param[in] localAddr #LinphoneAddress representing the local proxy configuration to use for the chat room creation or NULL @maybenil
* @param[in] participants \bctbx_list{LinphoneAddress} The initial list of participants of the chat room
* @return The newly created chat room or NULL.
* @maybenil
*/
LINPHONE_PUBLIC LinphoneChatRoom *linphone_core_create_chat_room_6(LinphoneCore *lc, const LinphoneChatRoomParams *params, const LinphoneAddress *localAddr, const bctbx_list_t *participants);
/**
* Find a chat room.
*
* @param[in] lc A #LinphoneCore object
* @param[in] params The chat room parameters to match #LinphoneChatRoomParams or NULL @maybenil
* @param[in] localAddr #LinphoneAddress representing the local proxy configuration or NULL @maybenil
* @param[in] participants \bctbx_list{LinphoneAddress} The participants that must be present in the chat room to find
* @return A matching chat room or NULL if none matches.
* @maybenil
*/
LINPHONE_PUBLIC LinphoneChatRoom *linphone_core_search_chat_room(const LinphoneCore *lc, const LinphoneChatRoomParams *params, const LinphoneAddress *localAddr, const bctbx_list_t *participants);
/**
* Get a basic chat room whose peer is the supplied address. If it does not exist yet, it will be created.
* No reference is transfered to the application. The #LinphoneCore keeps a reference on the chat room.
* @param lc the linphone core
* @param addr a linphone address.
* @return #LinphoneChatRoom where messaging can take place.
* @maybenil
* @deprecated on 02/07/2020, use linphone_core_search_chat_room() instead
**/
LINPHONE_PUBLIC LinphoneChatRoom *linphone_core_get_chat_room(LinphoneCore *lc, const LinphoneAddress *addr);
......@@ -5728,6 +5769,8 @@ LINPHONE_PUBLIC LinphoneChatRoom *linphone_core_get_chat_room(LinphoneCore *lc,
* @param peer_addr a linphone address.
* @param local_addr a linphone address.
* @return #LinphoneChatRoom where messaging can take place.
* @maybenil
* @deprecated on 02/07/2020, use linphone_core_search_chat_room() instead
**/
LINPHONE_PUBLIC LinphoneChatRoom *linphone_core_get_chat_room_2(
LinphoneCore *lc,
......@@ -5741,6 +5784,8 @@ LINPHONE_PUBLIC LinphoneChatRoom *linphone_core_get_chat_room_2(
* @param lc A #LinphoneCore object
* @param to The destination address for messages.
* @return #LinphoneChatRoom where messaging can take place.
* @maybenil
* @deprecated on 02/07/2020, use linphone_core_search_chat_room() instead
**/
LINPHONE_PUBLIC LinphoneChatRoom *linphone_core_get_chat_room_from_uri(LinphoneCore *lc, const char *to);
......@@ -5751,6 +5796,8 @@ LINPHONE_PUBLIC LinphoneChatRoom *linphone_core_get_chat_room_from_uri(LinphoneC
* @param peer_addr a linphone address.
* @param local_addr a linphone address.
* @return #LinphoneChatRoom where messaging can take place.
* @maybenil
* @deprecated on 02/07/2020, use linphone_core_search_chat_room() instead
**/
LINPHONE_PUBLIC LinphoneChatRoom *linphone_core_find_chat_room (
const LinphoneCore *lc,
......@@ -5765,7 +5812,7 @@ LINPHONE_PUBLIC LinphoneChatRoom *linphone_core_find_chat_room (
* @param local_addr a linphone address.
* @param participant_addr a linphone address.
* @return #LinphoneChatRoom where messaging can take place.
* @deprecated Use linphone_core_find_one_to_one_chat_room_2 instead
* @deprecated on 12/12/2018, use linphone_core_find_one_to_one_chat_room_2 instead
**/
LINPHONE_PUBLIC LinphoneChatRoom *linphone_core_find_one_to_one_chat_room (
const LinphoneCore *lc,
......@@ -5781,6 +5828,8 @@ LINPHONE_PUBLIC LinphoneChatRoom *linphone_core_find_one_to_one_chat_room (
* @param participant_addr a linphone address.
* @param encrypted whether to look for an encrypted chat room or not
* @return #LinphoneChatRoom where messaging can take place.
* @maybenil
* @deprecated on 02/07/2020, use linphone_core_search_chat_room() instead
**/
LINPHONE_PUBLIC LinphoneChatRoom *linphone_core_find_one_to_one_chat_room_2 (
const LinphoneCore *lc,
......
......@@ -19,6 +19,7 @@
#include "linphone/api/c-chat-room-params.h"
#include "chat/chat-room/chat-room-params.h"
#include "c-wrapper/c-wrapper.h"
// =============================================================================
......@@ -30,6 +31,10 @@ LinphoneChatRoomParams *linphone_chat_room_params_new(void) {
return ChatRoomParams::createCObject();
}
LinphoneChatRoomParams *linphone_chat_room_params_clone(const LinphoneChatRoomParams *params) {
return LinphonePrivate::ChatRoomParams::toCpp(params)->clone()->toC();
}
LinphoneChatRoomParams *linphone_chat_room_params_ref(LinphoneChatRoomParams *params) {
ChatRoomParams::toCpp(params)->ref();
return params;
......@@ -82,3 +87,11 @@ void linphone_chat_room_params_enable_encryption(LinphoneChatRoomParams *params,
void linphone_chat_room_params_enable_rtt(LinphoneChatRoomParams *params, bool_t rtt) {
ChatRoomParams::toCpp(params)->setRealTimeText(!!rtt);
}
const char * linphone_chat_room_params_get_subject(LinphoneChatRoomParams *params) {
return L_STRING_TO_C(ChatRoomParams::toCpp(params)->getSubject());
}
void linphone_chat_room_params_set_subject(LinphoneChatRoomParams *params, const char *subject) {
ChatRoomParams::toCpp(params)->setSubject(L_C_TO_STRING(subject));
}
......@@ -85,12 +85,11 @@ public:
char *tmp = linphone_address_as_string(linphone_proxy_config_get_contact(proxy)); //get the gruu address
IdentityAddress localAddress(tmp);
bctbx_free(tmp);
clientGroupChatRoom = static_pointer_cast<ClientGroupChatRoom>(
//make sure to have a one2one chatroom
chatRoom->getCore()->getPrivate()->createChatRoom(
ChatRoomParams::create(chatRoom->getCapabilities() & ChatRoom::Capabilities::Encrypted, false, ChatRoomParams::ChatRoomBackend::FlexisipChat), localAddress, chatRoom->getSubject(), {Address(chatRoom->getPeerAddress())}
)
);
string subject = chatRoom->getSubject();
if (subject.empty()) subject = "basic to client group migrated";
auto params = ChatRoomParams::create(subject, chatRoom->getCapabilities() & ChatRoom::Capabilities::Encrypted, false, ChatRoomParams::ChatRoomBackend::FlexisipChat);
//make sure to have a one2one chatroom
clientGroupChatRoom = static_pointer_cast<ClientGroupChatRoom>(chatRoom->getCore()->getPrivate()->createChatRoom(params, localAddress, subject, {Address(chatRoom->getPeerAddress())}));
clientGroupChatRoom->getPrivate()->setCallSessionListener(this);
clientGroupChatRoom->getPrivate()->setChatRoomListener(this);
}
......
......@@ -30,10 +30,14 @@ ChatRoomParams::ChatRoomParams() {
mEncrypted = false;
mGroup = false;
mRtt = false;
mSubject = "";
}
ChatRoomParams::ChatRoomParams(bool encrypted, bool group, ChatRoomBackend backend)
: mChatRoomBackend(backend), mEncrypted(encrypted), mGroup(group) {
: ChatRoomParams("", encrypted, group, backend) {}
ChatRoomParams::ChatRoomParams(string subject, bool encrypted, bool group, ChatRoomBackend backend)
: mChatRoomBackend(backend), mEncrypted(encrypted), mGroup(group), mSubject(subject) {
if (encrypted) {
mChatRoomEncryptionBackend = ChatRoomEncryptionBackend::Lime;
}
......@@ -45,6 +49,7 @@ ChatRoomParams::ChatRoomParams(const ChatRoomParams &other) : HybridObject(other
mEncrypted = other.mEncrypted;
mGroup = other.mGroup;
mRtt = other.mRtt;
mSubject = other.mSubject;
}
ChatRoomParams::ChatRoomBackend ChatRoomParams::getChatRoomBackend() const { return mChatRoomBackend; }
......@@ -57,6 +62,7 @@ bool ChatRoomParams::isGroup() const { return mGroup; }
bool ChatRoomParams::isRealTimeText() const { return mRtt; }
const string& ChatRoomParams::getSubject() const { return mSubject; }
void ChatRoomParams::setChatRoomBackend(ChatRoomParams::ChatRoomBackend backend) { mChatRoomBackend = backend; }
......@@ -79,6 +85,8 @@ void ChatRoomParams::setGroup(bool group) {
void ChatRoomParams::setRealTimeText(bool rtt) { mRtt = rtt; }
void ChatRoomParams::setSubject(string subject) { mSubject = subject; }
shared_ptr<ChatRoomParams> ChatRoomParams::getDefaults() {
return ChatRoomParams::create();
}
......@@ -148,12 +156,16 @@ bool ChatRoomParams::isValid() const {
if (mRtt && mChatRoomBackend == ChatRoomBackend::FlexisipChat) {
return false;
}
if (mSubject.empty() && mChatRoomBackend == ChatRoomBackend::FlexisipChat) {
return false;
}
return true;
}
std::string ChatRoomParams::toString() const {
std::ostringstream ss;
ss << "Subject[" << mSubject << "];";
ss << "Encrypted[" << mEncrypted << "];";
ss << "Group[" << mGroup << "];";
ss << "Rtt[" << mRtt << "];";
......
......@@ -61,8 +61,9 @@ public:
//Base constructor is protected anyways to prevent unmanaged creation.
ChatRoomParams();
ChatRoomParams(const ChatRoomParams &other);
//Convenience constructor
//Convenience constructors
ChatRoomParams(bool encrypted, bool group, ChatRoomBackend backend);
ChatRoomParams(std::string subject, bool encrypted, bool group, ChatRoomBackend backend);
ChatRoomParams *clone() const override { return new ChatRoomParams(*this); }
......@@ -74,12 +75,14 @@ public:
bool isEncrypted() const;
bool isGroup() const;
bool isRealTimeText() const;
const std::string& getSubject() const;
void setChatRoomBackend(ChatRoomBackend backend);
void setChatRoomEncryptionBackend(ChatRoomEncryptionBackend backend);
void setEncrypted(bool encrypted);
void setGroup(bool group);
void setRealTimeText(bool rtt);
void setSubject(std::string subject);
protected:
~ChatRoomParams() = default;
......@@ -90,6 +93,7 @@ private:
bool mEncrypted = false;
bool mGroup = false; //one to one
bool mRtt = false; //Real Time Text
std::string mSubject;
};
LINPHONE_END_NAMESPACE
......
......@@ -58,8 +58,8 @@ LINPHONE_BEGIN_NAMESPACE
* If withGruu is true, returns the local address with its gruu parameter. FlexisipChat kind of chatroom (also refered as ClientGroupChatRoom)
* require a local address with gruu, unlike basic chatrooms.
*/
static IdentityAddress getDefaultLocalAddress(const shared_ptr<Core> &core, const IdentityAddress *peerAddress, bool withGruu) {
LinphoneCore *cCore = core->getCCore();
IdentityAddress CorePrivate::getDefaultLocalAddress(const IdentityAddress *peerAddress, bool withGruu) const {
LinphoneCore *cCore = getCCore();
LinphoneProxyConfig *proxy = nullptr;
if (peerAddress) {
......@@ -162,7 +162,7 @@ shared_ptr<AbstractChatRoom> CorePrivate::createClientGroupChatRoom (
#ifdef HAVE_ADVANCED_IM
L_Q();
shared_ptr<ChatRoomParams> params = ChatRoomParams::create(encrypted, true, ChatRoomParams::ChatRoomBackend::FlexisipChat);
shared_ptr<ChatRoomParams> params = ChatRoomParams::create(subject, encrypted, true, ChatRoomParams::ChatRoomBackend::FlexisipChat);
shared_ptr<ClientGroupChatRoom> clientGroupChatRoom(new ClientGroupChatRoom(
q->getSharedFromThis(),
conferenceId.getPeerAddress(),
......@@ -186,9 +186,9 @@ shared_ptr<AbstractChatRoom> CorePrivate::createClientGroupChatRoom (
shared_ptr<AbstractChatRoom> CorePrivate::createClientGroupChatRoom(const string &subject, bool fallback, bool encrypted) {
L_Q();
IdentityAddress defaultLocalAddress = getDefaultLocalAddress(q->getSharedFromThis(), nullptr, true);
IdentityAddress defaultLocalAddress = getDefaultLocalAddress(nullptr, true);
IdentityAddress conferenceFactoryUri(getConferenceFactoryUri(q->getSharedFromThis(), defaultLocalAddress));
shared_ptr<ChatRoomParams> params = ChatRoomParams::create(encrypted, !fallback, ChatRoomParams::ChatRoomBackend::FlexisipChat);
shared_ptr<ChatRoomParams> params = ChatRoomParams::create(subject, encrypted, !fallback, ChatRoomParams::ChatRoomBackend::FlexisipChat);
return createClientGroupChatRoom(subject, conferenceFactoryUri, ConferenceId(IdentityAddress(), defaultLocalAddress), Content(), ChatRoomParams::toCapabilities(params), params, fallback);
}
......@@ -230,8 +230,61 @@ shared_ptr<AbstractChatRoom> CorePrivate::createBasicChatRoom (
return chatRoom;
}
shared_ptr<AbstractChatRoom> CorePrivate::searchChatRoom (const shared_ptr<ChatRoomParams> &params, const IdentityAddress &localAddress, const std::list<IdentityAddress> &participants) const {
for (auto it = chatRoomsById.begin(); it != chatRoomsById.end(); it++) {
const auto &chatRoom = it->second;
const IdentityAddress &curLocalAddress = chatRoom->getLocalAddress();
ChatRoom::CapabilitiesMask capabilities = chatRoom->getCapabilities();