Commit 105e63f2 authored by Ronan's avatar Ronan

feat(core): provide a local address on chat room (the core is dead now)

parent 54ed6798
......@@ -48,6 +48,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "conference/session/media-session.h"
#include "core/core-p.h"
using namespace std;
using namespace LinphonePrivate;
static void register_failure(SalOp *op);
......@@ -126,13 +128,12 @@ static void call_received(SalCallOp *h) {
} else if (sal_address_has_param(h->get_remote_contact_address(), "text")) {
linphone_address_unref(toAddr);
linphone_address_unref(fromAddr);
LinphonePrivate::Address addr(h->get_to());
if (addr.isValid()) {
LinphoneChatRoom *cr = L_GET_C_BACK_PTR(lc->cppCore->findChatRoom(addr));
if (cr) {
L_GET_PRIVATE_FROM_C_OBJECT(cr, ServerGroupChatRoom)->confirmJoining(h);
return;
}
shared_ptr<ChatRoom> chatRoom = lc->cppCore->findChatRoom(
ChatRoomId(SimpleAddress(h->get_to()), SimpleAddress(h->get_from()))
);
if (chatRoom) {
L_GET_PRIVATE(static_pointer_cast<ServerGroupChatRoom>(chatRoom))->confirmJoining(h);
return;
}
} else {
// TODO: handle media conference joining if the "text" feature tag is not present
......@@ -751,26 +752,25 @@ static void refer_received(SalOp *op, const SalAddress *refer_to){
if (addr.hasUriParam("method") && (addr.getUriParamValue("method") == "BYE")) {
if (linphone_core_conference_server_enabled(lc)) {
// Removal of a participant at the server side
LinphoneChatRoom *cr = L_GET_C_BACK_PTR(
lc->cppCore->findChatRoom(Address(op->get_to()))
shared_ptr<ChatRoom> chatRoom = lc->cppCore->findChatRoom(
ChatRoomId(SimpleAddress(op->get_to()), SimpleAddress(op->get_from()))
);
if (cr) {
Address fromAddr(op->get_from());
std::shared_ptr<Participant> participant = L_GET_CPP_PTR_FROM_C_OBJECT(cr)->findParticipant(fromAddr);
if (chatRoom) {
std::shared_ptr<Participant> participant = chatRoom->findParticipant(chatRoom->getLocalAddress());
if (!participant || !participant->isAdmin()) {
static_cast<SalReferOp *>(op)->reply(SalReasonDeclined);
return;
}
participant = L_GET_CPP_PTR_FROM_C_OBJECT(cr)->findParticipant(addr);
participant = chatRoom->findParticipant(addr);
if (participant)
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->removeParticipant(participant);
chatRoom->removeParticipant(participant);
static_cast<SalReferOp *>(op)->reply(SalReasonNone);
return;
}
} else {
// The server asks a participant to leave a chat room
LinphoneChatRoom *cr = L_GET_C_BACK_PTR(
lc->cppCore->findChatRoom(addr)
lc->cppCore->findChatRoom(ChatRoomId(addr, SimpleAddress(op->get_from())))
);
if (cr) {
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->leave();
......@@ -780,7 +780,9 @@ static void refer_received(SalOp *op, const SalAddress *refer_to){
static_cast<SalReferOp *>(op)->reply(SalReasonDeclined);
}
} else if (addr.hasParam("admin")) {
LinphoneChatRoom *cr = L_GET_C_BACK_PTR(lc->cppCore->findChatRoom(Address(op->get_to())));
LinphoneChatRoom *cr = L_GET_C_BACK_PTR(lc->cppCore->findChatRoom(
ChatRoomId(SimpleAddress(op->get_to()), SimpleAddress(op->get_from()))
));
if (cr) {
Address fromAddr(op->get_from());
std::shared_ptr<Participant> participant = L_GET_CPP_PTR_FROM_C_OBJECT(cr)->findParticipant(fromAddr);
......@@ -797,16 +799,12 @@ static void refer_received(SalOp *op, const SalAddress *refer_to){
return;
}
} else {
LinphoneChatRoom *cr = L_GET_C_BACK_PTR(lc->cppCore->findChatRoom(addr));
LinphoneChatRoom *cr = L_GET_C_BACK_PTR(lc->cppCore->findChatRoom(
ChatRoomId(addr, SimpleAddress(op->get_from()))
));
if (!cr)
cr = _linphone_client_group_chat_room_new(lc, addr.asString().c_str(), nullptr);
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->join();
/* The following causes a crash because chat room hasn't yet a peer address.
The above call to join() will create a CallSession which will call onConferenceCreated when it'll reach the Connected state.
onConferenceCreated will then call the following commented lines, no need for them here. */
/*L_GET_PRIVATE(lc->cppCore)->insertChatRoom(L_GET_CPP_PTR_FROM_C_OBJECT(cr));
L_GET_PRIVATE_FROM_C_OBJECT(cr)->setState(LinphonePrivate::ChatRoom::State::Created);
L_GET_PRIVATE(lc->cppCore)->insertChatRoomWithDb(L_GET_CPP_PTR_FROM_C_OBJECT(cr));*/
static_cast<SalReferOp *>(op)->reply(SalReasonNone);
return;
}
......
......@@ -64,6 +64,13 @@ 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(core->cppCore->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)));
......@@ -99,20 +106,24 @@ void linphone_core_delete_chat_room (LinphoneCore *, LinphoneChatRoom *cr) {
}
LinphoneChatRoom *linphone_core_get_chat_room_from_uri(LinphoneCore *lc, const char *to) {
return L_GET_C_BACK_PTR(lc->cppCore->getOrCreateBasicChatRoom(L_C_TO_STRING(to)));
return L_GET_C_BACK_PTR(lc->cppCore->getOrCreateBasicChatRoomFromUri(L_C_TO_STRING(to)));
}
int linphone_core_message_received(LinphoneCore *lc, LinphonePrivate::SalOp *op, const SalMessage *sal_msg) {
LinphoneReason reason = LinphoneReasonNotAcceptable;
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);
// TODO: Use local address.
list<shared_ptr<LinphonePrivate::ChatRoom>> chatRooms = lc->cppCore->findChatRooms(
LinphonePrivate::SimpleAddress(peerAddress)
);
if (!chatRooms.empty())
reason = L_GET_PRIVATE(chatRooms.front())->messageReceived(op, sal_msg);
else {
LinphoneAddress *addr = linphone_address_new(sal_msg->from);
linphone_address_clean(addr);
cr = linphone_core_get_chat_room(lc, addr);
LinphoneChatRoom *cr = linphone_core_get_chat_room(lc, addr);
if (cr)
reason = L_GET_PRIVATE_FROM_C_OBJECT(cr)->messageReceived(op, sal_msg);
linphone_address_unref(addr);
......
......@@ -148,6 +148,8 @@ static void toggle_video_preview(LinphoneCore *lc, bool_t val);
#define HOLD_MUSIC_WAV "toy-mono.wav"
#define HOLD_MUSIC_MKV "dont_wait_too_long.mkv"
using namespace std;
using namespace LinphonePrivate;
extern Sal::Callbacks linphone_sal_callbacks;
......@@ -2133,9 +2135,16 @@ static void linphone_core_internal_notify_received(LinphoneCore *lc, LinphoneEve
}
} else if (strcmp(notified_event, "conference") == 0) {
const LinphoneAddress *resource = linphone_event_get_resource(lev);
LinphoneChatRoom *cr = L_GET_C_BACK_PTR(lc->cppCore->findChatRoom(*L_GET_CPP_PTR_FROM_C_OBJECT(resource)));
if (cr)
L_GET_PRIVATE_FROM_C_OBJECT(cr, ClientGroupChatRoom)->notifyReceived(linphone_content_get_string_buffer(body));
// TODO: Ensure it is the good solution.
list<shared_ptr<ChatRoom>> chatRooms = lc->cppCore->findChatRooms(
SimpleAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(resource))
);
if (!chatRooms.empty())
L_GET_PRIVATE(static_pointer_cast<ClientGroupChatRoom>(chatRooms.front()))->notifyReceived(
linphone_content_get_string_buffer(body)
);
}
}
......@@ -2145,10 +2154,15 @@ static void _linphone_core_conference_subscription_state_changed(LinphoneCore *l
state == LinphoneSubscriptionIncomingReceived
) {
const LinphoneAddress *resource = linphone_event_get_resource(lev);
LinphoneChatRoom *cr = L_GET_C_BACK_PTR(lc->cppCore->findChatRoom(*L_GET_CPP_PTR_FROM_C_OBJECT(resource)));
if (cr) {
// TODO: Ensure it is the good solution.
list<shared_ptr<ChatRoom>> chatRooms = lc->cppCore->findChatRooms(
SimpleAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(resource))
);
if (!chatRooms.empty()) {
linphone_event_accept_subscription(lev);
L_GET_PRIVATE_FROM_C_OBJECT(cr, ServerGroupChatRoom)->subscribeReceived(lev);
L_GET_PRIVATE(static_pointer_cast<ServerGroupChatRoom>(chatRooms.front()))->subscribeReceived(lev);
} else
linphone_event_deny_subscription(lev, LinphoneReasonDeclined);
}
......
......@@ -472,7 +472,6 @@ void _linphone_proxy_config_unregister(LinphoneProxyConfig *obj);
void _linphone_proxy_config_release_ops(LinphoneProxyConfig *obj);
/*chat*/
LinphoneChatRoom * linphone_chat_room_new(LinphoneCore *core, const LinphoneAddress *addr);
LinphoneChatRoom *_linphone_client_group_chat_room_new (LinphoneCore *core, const char *uri, const char *subject);
LinphoneChatRoom *_linphone_server_group_chat_room_new (LinphoneCore *core, LinphonePrivate::SalCallOp *op);
void linphone_chat_room_release(LinphoneChatRoom *cr);
......
......@@ -24,6 +24,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "core/core.h"
#include "c-wrapper/c-wrapper.h"
using namespace std;
using namespace LinphonePrivate;
LinphoneVcardContext *linphone_core_get_vcard_context(const LinphoneCore *lc) {
return lc->vcard_context;
}
......@@ -53,11 +57,13 @@ bctbx_list_t **linphone_core_get_call_logs_attribute(LinphoneCore *lc) {
}
LinphoneChatRoom * linphone_core_find_chat_room (const LinphoneCore *lc, const LinphoneAddress *addr) {
const LinphonePrivate::Address *cppAddr = L_GET_CPP_PTR_FROM_C_OBJECT(addr);
std::shared_ptr<LinphonePrivate::ChatRoom> cr = lc->cppCore->findChatRoom(*cppAddr);
if (!cr)
return nullptr;
return L_GET_C_BACK_PTR(cr);
list<shared_ptr<ChatRoom>> chatRooms = lc->cppCore->findChatRooms(
SimpleAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(addr))
);
if (!chatRooms.empty())
return L_GET_C_BACK_PTR(chatRooms.front());
return nullptr;
}
void linphone_core_cbs_set_auth_info_requested(LinphoneCoreCbs *cbs, LinphoneCoreAuthInfoRequestedCb cb) {
......
......@@ -96,13 +96,6 @@ LINPHONE_PUBLIC bool_t linphone_chat_message_is_outgoing(LinphoneChatMessage* ms
*/
LINPHONE_PUBLIC const LinphoneAddress* linphone_chat_message_get_from_address(LinphoneChatMessage* msg);
/**
* Set origin of the message
* @param[in] message #LinphoneChatMessage obj
* @param[in] from #LinphoneAddress origin of this message (copied)
*/
LINPHONE_PUBLIC void linphone_chat_message_set_from_address(LinphoneChatMessage* msg, const LinphoneAddress* from);
/**
* Get destination of the message
* @param[in] message #LinphoneChatMessage obj
......@@ -110,13 +103,6 @@ LINPHONE_PUBLIC void linphone_chat_message_set_from_address(LinphoneChatMessage*
*/
LINPHONE_PUBLIC const LinphoneAddress* linphone_chat_message_get_to_address(LinphoneChatMessage* msg);
/**
* Set destination of the message
* @param[in] message #LinphoneChatMessage obj
* @param[in] addr #LinphoneAddress destination of this message (copied)
*/
LINPHONE_PUBLIC void linphone_chat_message_set_to_address(LinphoneChatMessage* msg, const LinphoneAddress* addr);
/**
* Get the content type of a chat message.
* @param[in] message LinphoneChatMessage object
......
......@@ -78,6 +78,7 @@ LINPHONE_PUBLIC LinphoneChatMessage* linphone_chat_room_create_message(LinphoneC
* @param is_read TRUE if the message should be flagged as read, FALSE otherwise.
* @param is_incoming TRUE if the message has been received, FALSE otherwise.
* @return a new #LinphoneChatMessage
* @deprecated Use #linphone_chat_room_create_message() instead. Deprecated since 2017-11-14.
* @donotwrap
*/
LINPHONE_PUBLIC LinphoneChatMessage* linphone_chat_room_create_message_2(LinphoneChatRoom *cr, const char* message, const char* external_body_url, LinphoneChatMessageState state, time_t time, bool_t is_read, bool_t is_incoming);
......
......@@ -102,7 +102,7 @@ const char *linphone_chat_message_get_external_body_url(const LinphoneChatMessag
}
void linphone_chat_message_set_external_body_url(LinphoneChatMessage *msg, const char *url) {
}
time_t linphone_chat_message_get_time(const LinphoneChatMessage *msg) {
......@@ -180,12 +180,6 @@ const LinphoneAddress *linphone_chat_message_get_from_address(LinphoneChatMessag
return msg->from;
}
void linphone_chat_message_set_from_address(LinphoneChatMessage *msg, const LinphoneAddress *from) {
LinphonePrivate::Address addr;
if (from) addr = LinphonePrivate::Address(linphone_address_as_string(from));
else L_GET_CPP_PTR_FROM_C_OBJECT(msg)->setFromAddress(addr);
}
const LinphoneAddress *linphone_chat_message_get_to_address(LinphoneChatMessage *msg) {
if (msg->to)
linphone_address_unref(msg->to);
......@@ -193,12 +187,6 @@ const LinphoneAddress *linphone_chat_message_get_to_address(LinphoneChatMessage
return msg->to;
}
void linphone_chat_message_set_to_address(LinphoneChatMessage *msg, const LinphoneAddress *to) {
LinphonePrivate::Address addr;
if (to) addr = LinphonePrivate::Address(linphone_address_as_string(to));
else L_GET_CPP_PTR_FROM_C_OBJECT(msg)->setToAddress(addr);
}
const char *linphone_chat_message_get_file_transfer_filepath(LinphoneChatMessage *msg) {
return L_STRING_TO_C(L_GET_PRIVATE_FROM_C_OBJECT(msg)->getFileTransferFilepath());
}
......@@ -278,7 +266,6 @@ void linphone_chat_message_update_state(LinphoneChatMessage *msg, LinphoneChatMe
void linphone_chat_message_deactivate(LinphoneChatMessage *msg){
L_GET_CPP_PTR_FROM_C_OBJECT(msg)->cancelFileTransfer();
L_GET_PRIVATE_FROM_C_OBJECT(msg)->setChatRoom(nullptr);
}
void linphone_chat_message_send_delivery_notification(LinphoneChatMessage *msg, LinphoneReason reason) {
......@@ -298,7 +285,7 @@ void linphone_chat_message_add_text_content(LinphoneChatMessage *msg, const char
LinphonePrivate::ContentType contentType = LinphonePrivate::ContentType::PlainText;
content->setContentType(contentType);
content->setBody(L_C_TO_STRING(c_content));
L_GET_CPP_PTR_FROM_C_OBJECT(msg)->addContent(content);
L_GET_CPP_PTR_FROM_C_OBJECT(msg)->addContent(*content);
}
bool_t linphone_chat_message_has_text_content(const LinphoneChatMessage *msg) {
......
......@@ -117,20 +117,10 @@ LinphoneChatMessage *linphone_chat_room_create_message_2 (
bool_t is_incoming
) {
LinphoneChatMessage *msg = linphone_chat_room_create_message(cr, message);
LinphoneCore *lc = linphone_chat_room_get_core(cr);
linphone_chat_message_set_external_body_url(msg, external_body_url ? ms_strdup(external_body_url) : NULL);
linphone_chat_message_set_time(msg, time);
linphone_chat_message_set_is_secured(msg, FALSE);
linphone_chat_message_set_state(msg, state);
if (is_incoming) {
linphone_chat_message_set_incoming(msg);
linphone_chat_message_set_from_address(msg, linphone_chat_room_get_peer_address(cr));
linphone_chat_message_set_to_address(msg, linphone_address_new(linphone_core_get_identity(lc)));
} else {
linphone_chat_message_set_outgoing(msg);
linphone_chat_message_set_to_address(msg, linphone_chat_room_get_peer_address(cr));
linphone_chat_message_set_from_address(msg, linphone_address_new(linphone_core_get_identity(lc)));
}
return msg;
}
......@@ -172,7 +162,7 @@ LinphoneCall *linphone_chat_room_get_call (const LinphoneChatRoom *cr) {
void linphone_chat_room_set_call (LinphoneChatRoom *cr, LinphoneCall *call) {
if (linphone_core_realtime_text_enabled(linphone_chat_room_get_core(cr)))
L_GET_PRIVATE_FROM_C_OBJECT(cr, RealTimeTextChatRoom)->setCall(call);
L_GET_PRIVATE_FROM_C_OBJECT(cr, RealTimeTextChatRoom)->call = call;
}
bctbx_list_t *linphone_chat_room_get_transient_messages (const LinphoneChatRoom *cr) {
......@@ -210,7 +200,7 @@ bctbx_list_t *linphone_chat_room_get_history (LinphoneChatRoom *cr, int nb_messa
bctbx_list_t *linphone_chat_room_get_history_events (LinphoneChatRoom *cr, int nb_events) {
return L_GET_RESOLVED_C_LIST_FROM_CPP_LIST(
L_GET_PRIVATE(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getCore())->mainDb->getHistory(
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getPeerAddress().asStringUriOnly(),
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getChatRoomId(),
nb_events
)
);
......@@ -219,7 +209,7 @@ bctbx_list_t *linphone_chat_room_get_history_events (LinphoneChatRoom *cr, int n
bctbx_list_t *linphone_chat_room_get_history_range_events (LinphoneChatRoom *cr, int begin, int end) {
return L_GET_RESOLVED_C_LIST_FROM_CPP_LIST(
L_GET_PRIVATE(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getCore())->mainDb->getHistory(
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getPeerAddress().asStringUriOnly(),
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getChatRoomId(),
begin,
end
)
......@@ -344,13 +334,6 @@ void linphone_chat_room_set_user_data (LinphoneChatRoom *cr, void *ud) {
// Constructor and destructor functions.
// =============================================================================
LinphoneChatRoom *linphone_chat_room_new (LinphoneCore *core, const LinphoneAddress *addr) {
return L_GET_C_BACK_PTR(core->cppCore->getOrCreateBasicChatRoom(
*L_GET_CPP_PTR_FROM_C_OBJECT(addr),
linphone_core_realtime_text_enabled(core)
));
}
LinphoneChatRoom *_linphone_client_group_chat_room_new (LinphoneCore *core, const char *uri, const char *subject) {
LinphoneAddress *addr = linphone_address_new(uri);
LinphoneProxyConfig *proxy = linphone_core_lookup_known_proxy(core, addr);
......@@ -363,7 +346,7 @@ LinphoneChatRoom *_linphone_client_group_chat_room_new (LinphoneCore *core, cons
LinphonePrivate::Address me(from);
LinphoneChatRoom *cr = L_INIT(ChatRoom);
L_SET_CPP_PTR_FROM_C_OBJECT(cr, make_shared<LinphonePrivate::ClientGroupChatRoom>(
core->cppCore, me, L_C_TO_STRING(uri), L_C_TO_STRING(subject))
core->cppCore, L_C_TO_STRING(uri), me, L_C_TO_STRING(subject))
);
L_GET_PRIVATE_FROM_C_OBJECT(cr)->setState(LinphonePrivate::ChatRoom::State::Instantiated);
return cr;
......
......@@ -23,12 +23,13 @@
#include <belle-sip/types.h>
#include "chat/chat-message/chat-message.h"
#include "chat/chat-room/chat-room-id.h"
#include "chat/modifier/file-transfer-chat-message-modifier.h"
#include "chat/notification/imdn.h"
#include "content/content-type.h"
#include "content/content.h"
#include "content/file-content.h"
#include "content/file-transfer-content.h"
#include "chat/modifier/file-transfer-chat-message-modifier.h"
#include "content/content-type.h"
#include "object/object-p.h"
#include "sal/sal.h"
......@@ -50,12 +51,7 @@ public:
Cpim = 1 << 4
};
ChatMessagePrivate ();
~ChatMessagePrivate ();
void setChatRoom (std::shared_ptr<ChatRoom> chatRoom);
// -----------------------------------------------------------------------------
ChatMessagePrivate () = default;
void setApplyModifiers (bool value) { applyModifiers = value; }
......@@ -67,6 +63,10 @@ public:
void setIsReadOnly(bool readOnly);
inline void forceFromAddress (const SimpleAddress &fromAddress) {
this->fromAddress = fromAddress;
}
unsigned int getStorageId() const;
void setStorageId(unsigned int id);
......@@ -110,7 +110,7 @@ public:
LinphoneContent *getFileTransferInformation() const;
void setFileTransferInformation(const LinphoneContent *content);
int downloadFile ();
bool downloadFile ();
void sendImdn(Imdn::Type imdnType, LinphoneReason reason);
......@@ -118,16 +118,9 @@ public:
void send();
private:
std::weak_ptr<ChatRoom> chatRoom;
Address peerAddress;
// TODO: Clean attributes.
ChatMessage::Direction direction = ChatMessage::Direction::Incoming;
ChatMessage::State state = ChatMessage::State::Idle;
unsigned int storageId = 0;
Address from;
Address to;
time_t time = 0;
time_t time = ::ms_time(0); // TODO: Change me in all files.
std::string id;
std::string rttMessage;
bool isSecured = false;
......@@ -148,10 +141,18 @@ private:
ContentType cContentType;
std::string cText;
// -----------------------------------------------------------------------------
std::string createImdnXml(Imdn::Type imdnType, LinphoneReason reason);
// TODO: Remove my comment. VARIABLES OK.
// Do not expose.
std::weak_ptr<ChatRoom> chatRoom;
ChatRoomId chatRoomId;
SimpleAddress fromAddress;
ChatMessage::State state = ChatMessage::State::Idle;
ChatMessage::Direction direction = ChatMessage::Direction::Incoming;
L_DECLARE_PUBLIC(ChatMessage);
};
......
This diff is collapsed.
......@@ -25,6 +25,9 @@
#include "linphone/api/c-types.h"
#include "linphone/enums/chat-message-enums.h"
// TODO: Remove me later?
#include "address/simple-address.h"
#include "core/core-accessor.h"
#include "object/object.h"
......@@ -32,7 +35,6 @@
LINPHONE_BEGIN_NAMESPACE
class Address;
class ChatRoom;
class Content;
class FileTransferContent;
......@@ -54,8 +56,15 @@ public:
L_DECLARE_ENUM(Direction, L_ENUM_VALUES_CHAT_MESSAGE_DIRECTION);
// TODO: Make me private.
// Build an outgoing message.
ChatMessage (const std::shared_ptr<ChatRoom> &chatRoom);
// Build and incoming message.
ChatMessage (const std::shared_ptr<ChatRoom> &chatRoom, const SimpleAddress &fromAddress);
~ChatMessage ();
// ----- TODO: Remove me.
void cancelFileTransfer ();
int putCharacter (uint32_t character);
......@@ -64,8 +73,6 @@ public:
void sendDisplayNotification ();
void setImdnMessageId (const std::string &imdnMessageId);
void setIsSecured (bool isSecured);
void setFromAddress (Address from);
void setToAddress (Address to);
void store ();
// ----- TODO: Remove me.
......@@ -81,19 +88,21 @@ public:
const std::string &getImdnMessageId () const;
const Address &getFromAddress () const;
const Address &getToAddress () const;
const Address &getLocalAddress () const;
const Address &getRemoteAddress () const;
const SimpleAddress &getFromAddress () const;
const SimpleAddress &getToAddress () const;
const SimpleAddress &getLocalAddress () const;
const SimpleAddress &getRemoteAddress () const;
// TODO: Return a cpp reference.
const LinphoneErrorInfo *getErrorInfo () const;
bool isRead () const;
bool isReadOnly () const;
const std::list<Content *> &getContents () const;
void addContent (Content *content);
void removeContent (Content *content);
void addContent (Content &content);
void removeContent (const Content &content);
const Content &getInternalContent () const;
void setInternalContent (const Content &content);
......@@ -102,7 +111,7 @@ public:
void addCustomHeader (const std::string &headerName, const std::string &headerValue);
void removeCustomHeader (const std::string &headerName);
int downloadFile (FileTransferContent *content);
bool downloadFile (FileTransferContent &content);
private:
L_DECLARE_PRIVATE(ChatMessage);
......
......@@ -29,43 +29,51 @@ using namespace std;
LINPHONE_BEGIN_NAMESPACE
BasicChatRoom::BasicChatRoom (const shared_ptr<Core> &core, const Address &peerAddress) :
ChatRoom(*new BasicChatRoomPrivate, core, peerAddress) {}
BasicChatRoom::BasicChatRoom (const shared_ptr<Core> &core, const ChatRoomId &chatRoomId) :
ChatRoom(*new BasicChatRoomPrivate, core, chatRoomId) {}
// -----------------------------------------------------------------------------
BasicChatRoom::BasicChatRoom (
BasicChatRoomPrivate &p,
const std::shared_ptr<Core> &core,
const ChatRoomId &chatRoomId
) : ChatRoom(p, core, chatRoomId) {}
void BasicChatRoom::onChatMessageReceived (const shared_ptr<ChatMessage> &msg) {
BasicChatRoom::CapabilitiesMask BasicChatRoom::getCapabilities () const {
return static_cast<CapabilitiesMask>(Capabilities::Basic);
}
bool BasicChatRoom::canHandleParticipants () const {
return false;
}
int BasicChatRoom::getCapabilities () const {
return static_cast<int>(Capabilities::Basic);
const Address &BasicChatRoom::getConferenceAddress () const {
lError() << "a BasicChatRoom does not have a conference address";
return Utils::getEmptyConstRefObject<Address>();
}
void BasicChatRoom::addParticipant (const Address &addr, const CallSessionParams *params, bool hasMedia) {
void BasicChatRoom::addParticipant (const Address &, const CallSessionParams *, bool) {
lError() << "addParticipant() is not allowed on a BasicChatRoom";
}
void BasicChatRoom::addParticipants (const list<Address> &addresses, const CallSessionParams *params, bool hasMedia) {
void BasicChatRoom::addParticipants (const list<Address> &, const CallSessionParams *, bool) {
lError() << "addParticipants() is not allowed on a BasicChatRoom";
}
bool BasicChatRoom::canHandleParticipants () const {
return false;
void BasicChatRoom::removeParticipant (const shared_ptr<const Participant> &) {
lError() << "removeParticipant() is not allowed on a BasicChatRoom";
}
shared_ptr<Participant> BasicChatRoom::findParticipant (const Address &addr) const {
lError() << "findParticipant() is not allowed on a BasicChatRoom";
return nullptr;
void BasicChatRoom::removeParticipants (const list<shared_ptr<Participant>> &) {
lError() << "removeParticipants() is not allowed on a BasicChatRoom";
}
const Address &BasicChatRoom::getConferenceAddress () const {
lError() << "a BasicChatRoom does not have a conference address";
return Utils::getEmptyConstRefObject<Address>();
shared_ptr<Participant> BasicChatRoom::findParticipant (const Address &) const {
lError() << "findParticipant() is not allowed on a BasicChatRoom";
return nullptr;
}
shared_ptr<Participant> BasicChatRoom::getMe () const {
lError() << "a BasicChatRoom does not handle participants";
lError() << "getMe() is not allowed on a BasicChatRoom";
return nullptr;
}
......@@ -74,10 +82,11 @@ int BasicChatRoom::getNbParticipants () const {
}
list<shared_ptr<Participant>> BasicChatRoom::getParticipants () const {
L_D();
list<shared_ptr<Participant>> l;
l.push_back(make_shared<Participant>(d->peerAddress));
return l;
return { make_shared<Participant>(getPeerAddress()) };
}
void BasicChatRoom::setParticipantAdminStatus (shared_ptr<Participant> &, bool) {
lError() << "setParticipantAdminStatus() is not allowed on a BasicChatRoom";
}
const string &BasicChatRoom::getSubject () const {
......@@ -85,6 +94,11 @@ const string &BasicChatRoom::getSubject () const {
return d->subject;
}
void BasicChatRoom::setSubject (const string &subject) {
L_D();
d->subject = subject;
}
void BasicChatRoom::join () {
lError() << "join() is not allowed on a BasicChatRoom";
}
......@@ -93,21 +107,7 @@ void BasicChatRoom::leave () {
lError() << "leave() is not allowed on a BasicChatRoom";
}
void BasicChatRoom::removeParticipant (const shared_ptr<const Participant> &participant) {
lError() << "removeParticipant() is not allowed on a BasicChatRoom";
}
void BasicChatRoom::removeParticipants (const list<shared_ptr<Participant>> &participants) {
lError() << "removeParticipants() is not allowed on a BasicChatRoom";
}
void BasicChatRoom::setParticipantAdminStatus (shared_ptr<Participant> &participant, bool isAdmin) {
lError() << "setParticipantAdminStatus() is not allowed on a BasicChatRoom";
}
void BasicChatRoom::setSubject (const string &subject) {
L_D();
d->subject = subject;
}
// TODO: Move me in BasicChatRoomPrivate.
void BasicChatRoom::onChatMessageReceived (const shared_ptr<ChatMessage> &) {}
LINPHONE_END_NAMESPACE
......@@ -29,30 +29,44 @@ LINPHONE_BEGIN_NAMESPACE
class BasicChatRoomPrivate;
class LINPHONE_PUBLIC BasicChatRoom : public ChatRoom {
public:
BasicChatRoom (const std::shared_ptr<Core> &core, const Address &peerAddress);
friend class CorePrivate;
public:
CapabilitiesMask getCapabilities () const override;
void onChatMessageReceived (const std::shared_ptr<ChatMessage> &msg) override;
/* ConferenceInterface. */
const Address &getConferenceAddress () const override;
bool canHandleParticipants () const override;
void addParticipant (const Address &addr, const CallSessionParams *params, bool hasMedia) override;
void addParticipants (const std::list<Address> &addresses, const CallSessionParams *params, bool hasMedia) override;
bool canHandleParticipants () const override;
void removeParticipant (const std::shared_ptr<const Participant> &participant) override;
void removeParticipants (const std::list<std::shared_ptr<Participant>> &participants) override;
std::shared_ptr<Participant> findParticipant (const Address &addr) const override;
const Address &getConferenceAddress () const override;
std::shared_ptr<Participant> getMe () const override;
int getNbParticipants () const override;
std::list<std::shared_ptr<Participant>> getParticipants () const override;
void setParticipantAdminStatus (std::shared_ptr<Participant> &participant, bool isAdmin) override;
const std::string &getSubject () const override;
void setSubject (const std::string &subject) override;
void join () override;