Commit 6aabd89f authored by Ronan's avatar Ronan
Browse files

fix(chat): fix partially previous merge

parent 4315f674
......@@ -79,39 +79,6 @@ LinphoneChatRoom *linphone_core_create_client_group_chat_room (LinphoneCore *lc,
return L_GET_C_BACK_PTR(lc->cppCore->createClientGroupChatRoom(L_C_TO_STRING(subject)));
}
static LinphoneChatRoom *_linphone_core_get_or_create_chat_room(LinphoneCore *lc, const char *to) {
LinphoneAddress *to_addr = linphone_core_interpret_url(lc, to);
LinphoneChatRoom *ret;
if (to_addr == NULL) {
ms_error("linphone_core_get_or_create_chat_room(): Cannot make a valid address with %s", to);
return NULL;
}
ret = _linphone_core_get_chat_room(lc, to_addr);
linphone_address_unref(to_addr);
if (!ret) {
ret = _linphone_core_create_chat_room_from_url(lc, to);
}
return ret;
}
LinphoneChatRoom *linphone_core_get_chat_room(LinphoneCore *lc, const LinphoneAddress *addr) {
LinphoneChatRoom *ret = _linphone_core_get_chat_room(lc, addr);
if (!ret) {
ret = _linphone_core_create_chat_room(lc, addr);
}
return ret;
}
LinphoneChatRoom * linphone_core_create_client_group_chat_room(LinphoneCore *lc, const char *subject) {
const char *factoryUri = linphone_core_get_conference_factory_uri(lc);
if (!factoryUri)
return nullptr;
LinphoneChatRoom *cr = _linphone_client_group_chat_room_new(lc, factoryUri, subject);
lc->chatrooms = bctbx_list_append(lc->chatrooms, cr);
return cr;
}
LinphoneChatRoom *_linphone_core_join_client_group_chat_room (LinphoneCore *lc, const LinphonePrivate::Address &addr) {
LinphoneChatRoom *cr = _linphone_client_group_chat_room_new(lc, addr.asString().c_str(), nullptr);
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->join();
......@@ -126,14 +93,8 @@ LinphoneChatRoom *_linphone_core_create_server_group_chat_room (LinphoneCore *lc
return cr;
}
void linphone_core_delete_chat_room(LinphoneCore *lc, LinphoneChatRoom *cr) {
if (bctbx_list_find(lc->chatrooms, cr)) {
lc->chatrooms = bctbx_list_remove(lc->chatrooms, cr);
linphone_chat_room_delete_history(cr);
linphone_chat_room_unref(cr);
} else {
ms_error("linphone_core_delete_chat_room(): chatroom [%p] isn't part of LinphoneCore.", cr);
}
void linphone_core_delete_chat_room (LinphoneCore *, LinphoneChatRoom *cr) {
LinphonePrivate::Core::deleteChatRoom(L_GET_CPP_PTR_FROM_C_OBJECT(cr));
}
LinphoneChatRoom *linphone_core_get_chat_room_from_uri(LinphoneCore *lc, const char *to) {
......@@ -142,8 +103,9 @@ LinphoneChatRoom *linphone_core_get_chat_room_from_uri(LinphoneCore *lc, const c
int linphone_core_message_received(LinphoneCore *lc, LinphonePrivate::SalOp *op, const SalMessage *sal_msg) {
LinphoneReason reason = LinphoneReasonNotAcceptable;
LinphoneChatRoom *cr = _linphone_core_find_group_chat_room(lc,
linphone_core_conference_server_enabled(lc) ? op->get_to() : op->get_from());
const char *peerAddress = linphone_core_conference_server_enabled(lc) ? op->get_to() : op->get_from();
LinphoneChatRoom *cr = L_GET_C_BACK_PTR(lc->cppCore->findChatRoom(LinphonePrivate::Address(peerAddress)));
if (cr)
reason = L_GET_PRIVATE_FROM_C_OBJECT(cr)->messageReceived(op, sal_msg);
else {
......
......@@ -7198,33 +7198,6 @@ void _linphone_core_remove_group_chat_room(LinphoneCore *lc, LinphoneChatRoom *c
bctbx_iterator_cchar_delete(it);
}
LinphoneChatRoom *_linphone_core_find_group_chat_room(const LinphoneCore *lc, const char *id) {
LinphoneChatRoom *result = nullptr;
Address cleanedAddr(id);
cleanedAddr.clean();
cleanedAddr.setPort(0);
bctbx_iterator_t *it = bctbx_map_cchar_find_key(lc->group_chat_rooms, cleanedAddr.asStringUriOnly().c_str());
bctbx_iterator_t *endit = bctbx_map_cchar_end(lc->group_chat_rooms);
if (!bctbx_iterator_cchar_equals(it, endit)) {
result = reinterpret_cast<LinphoneChatRoom *>(bctbx_pair_cchar_get_second(bctbx_iterator_cchar_get_pair(it)));
} else {
bctbx_iterator_cchar_delete(it);
Address backupAddress(cleanedAddr);
Address factoryAddress(linphone_core_get_conference_factory_uri(lc));
backupAddress.setDomain(factoryAddress.getDomain());
lWarning() << "We don't found the chat room with address " << id << " as a temporary workaround, searching with " << backupAddress.asString();
it = bctbx_map_cchar_find_key(lc->group_chat_rooms, backupAddress.asStringUriOnly().c_str());
if (!bctbx_iterator_cchar_equals(it, endit)) {
result = reinterpret_cast<LinphoneChatRoom *>(bctbx_pair_cchar_get_second(bctbx_iterator_cchar_get_pair(it)));
}
if (!result) lWarning() << "Chatroom " << id << " or " << backupAddress.asString() << " not found!";
}
bctbx_iterator_cchar_delete(endit);
bctbx_iterator_cchar_delete(it);
return result;
}
void linphone_core_enable_conference_server (LinphoneCore *lc, bool_t enable) {
lp_config_set_int(linphone_core_get_config(lc), "misc", "conference_server_enabled", enable);
}
......
......@@ -20,10 +20,9 @@
// TODO: Remove me later.
#include "linphone/chat.h"
#include "linphone/wrapper_utils.h"
#include "linphone/api/c-chat-room.h"
#include "linphone/wrapper_utils.h"
#include "event-log/event-log.h"
#include "c-wrapper/c-wrapper.h"
#include "chat/chat-room/basic-chat-room.h"
#include "chat/chat-room/client-group-chat-room.h"
......
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