Commit 9258c5f1 authored by Ronan's avatar Ronan

feat(ChatRoom): provide an abstract chat room for chat room migration proxy

parent 91196256
......@@ -87,7 +87,7 @@ static void call_received(SalCallOp *h) {
linphone_address_unref(fromAddr);
return;
} else if (sal_address_has_param(h->get_remote_contact_address(), "text")) {
shared_ptr<ChatRoom> chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findChatRoom(
shared_ptr<AbstractChatRoom> chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findChatRoom(
ChatRoomId(IdentityAddress(h->get_to()), IdentityAddress(h->get_to()))
);
if (chatRoom) {
......@@ -681,7 +681,7 @@ 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
shared_ptr<ChatRoom> chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findChatRoom(
shared_ptr<AbstractChatRoom> chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findChatRoom(
ChatRoomId(IdentityAddress(op->get_to()), IdentityAddress(op->get_to()))
);
if (chatRoom) {
......
......@@ -137,18 +137,18 @@ int linphone_core_message_received(LinphoneCore *lc, LinphonePrivate::SalOp *op,
localAddress = op->get_to();
}
shared_ptr<LinphonePrivate::ChatRoom> chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findChatRoom(
shared_ptr<LinphonePrivate::AbstractChatRoom> chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findChatRoom(
LinphonePrivate::ChatRoomId(LinphonePrivate::IdentityAddress(peerAddress), LinphonePrivate::IdentityAddress(localAddress))
);
if (chatRoom)
reason = L_GET_PRIVATE(chatRoom)->messageReceived(op, sal_msg);
reason = L_GET_PRIVATE(chatRoom)->onSipMessageReceived(op, sal_msg);
else {
LinphoneAddress *addr = linphone_address_new(sal_msg->from);
linphone_address_clean(addr);
LinphoneChatRoom *cr = linphone_core_get_chat_room(lc, addr);
if (cr)
reason = L_GET_PRIVATE_FROM_C_OBJECT(cr)->messageReceived(op, sal_msg);
reason = L_GET_PRIVATE_FROM_C_OBJECT(cr)->onSipMessageReceived(op, sal_msg);
linphone_address_unref(addr);
}
return reason;
......
......@@ -2134,7 +2134,7 @@ static void linphone_core_internal_notify_received(LinphoneCore *lc, LinphoneEve
const LinphoneAddress *resource = linphone_event_get_resource(lev);
const LinphoneAddress *from = linphone_event_get_from(lev);
shared_ptr<ChatRoom> chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findChatRoom(LinphonePrivate::ChatRoomId(
shared_ptr<AbstractChatRoom> chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findChatRoom(LinphonePrivate::ChatRoomId(
IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(resource)),
IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(from))
));
......@@ -2164,7 +2164,7 @@ static void _linphone_core_conference_subscription_state_changed(LinphoneCore *l
state == LinphoneSubscriptionIncomingReceived
) {
const LinphoneAddress *resource = linphone_event_get_resource(lev);
shared_ptr<ChatRoom> chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findChatRoom(LinphonePrivate::ChatRoomId(
shared_ptr<AbstractChatRoom> chatRoom = L_GET_CPP_PTR_FROM_C_OBJECT(lc)->findChatRoom(LinphonePrivate::ChatRoomId(
IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(resource)),
IdentityAddress(*L_GET_CPP_PTR_FROM_C_OBJECT(resource))
));
......
......@@ -274,7 +274,6 @@ void _linphone_proxy_config_release_ops(LinphoneProxyConfig *obj);
/*chat*/
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);
void linphone_chat_room_set_call(LinphoneChatRoom *cr, LinphoneCall *call);
LinphoneChatRoomCbs * linphone_chat_room_cbs_new (void);
/**/
......
......@@ -116,19 +116,6 @@ LINPHONE_PUBLIC const LinphoneAddress* linphone_chat_room_get_local_address(Linp
*/
LINPHONE_PUBLIC LINPHONE_DEPRECATED void linphone_chat_room_send_message(LinphoneChatRoom *cr, const char *msg);
/**
* Send a message to peer member of this chat room.
* @param cr #LinphoneChatRoom object
* @param msg #LinphoneChatMessage message to be sent
* @param status_cb LinphoneChatMessageStateChangeCb status callback invoked when message is delivered or could not be delivered. May be NULL
* @param ud user data for the status cb.
* @deprecated Use linphone_chat_message_send() instead.
* @note The LinphoneChatMessage must not be destroyed until the the callback is called.
* The LinphoneChatMessage reference is transfered to the function and thus doesn't need to be unref'd by the application.
* @donotwrap
*/
LINPHONE_PUBLIC LINPHONE_DEPRECATED void linphone_chat_room_send_message2(LinphoneChatRoom *cr, LinphoneChatMessage* msg,LinphoneChatMessageStateChangedCb status_cb,void* ud);
/**
* Send a message to peer member of this chat room.
* @param[in] cr LinphoneChatRoom object
......
......@@ -36,8 +36,11 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES
call/remote-conference-call.h
chat/chat-message/chat-message-p.h
chat/chat-message/chat-message.h
chat/chat-room/abstract-chat-room-p.h
chat/chat-room/abstract-chat-room.h
chat/chat-room/basic-chat-room-p.h
chat/chat-room/basic-chat-room.h
chat/chat-room/basic-to-client-group-chat-room.h
chat/chat-room/chat-room-id.h
chat/chat-room/chat-room-p.h
chat/chat-room/chat-room.h
......@@ -168,7 +171,9 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES
call/local-conference-call.cpp
call/remote-conference-call.cpp
chat/chat-message/chat-message.cpp
chat/chat-room/abstract-chat-room.cpp
chat/chat-room/basic-chat-room.cpp
chat/chat-room/basic-to-client-group-chat-room.cpp
chat/chat-room/chat-room-id.cpp
chat/chat-room/chat-room.cpp
chat/chat-room/client-group-chat-room.cpp
......
......@@ -68,12 +68,8 @@ static void _linphone_chat_room_destructor (LinphoneChatRoom *cr) {
// Public functions.
// =============================================================================
void linphone_chat_room_release (LinphoneChatRoom *cr) {
L_GET_PRIVATE_FROM_C_OBJECT(cr)->release();
}
void linphone_chat_room_send_message (LinphoneChatRoom *cr, const char *msg) {
L_GET_PRIVATE_FROM_C_OBJECT(cr)->sendMessage(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->createMessage(msg));
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->createChatMessage(msg)->send();
}
bool_t linphone_chat_room_is_remote_composing (const LinphoneChatRoom *cr) {
......@@ -107,7 +103,7 @@ const LinphoneAddress *linphone_chat_room_get_local_address (LinphoneChatRoom *c
}
LinphoneChatMessage *linphone_chat_room_create_message (LinphoneChatRoom *cr, const char *message) {
shared_ptr<LinphonePrivate::ChatMessage> cppPtr = L_GET_CPP_PTR_FROM_C_OBJECT(cr)->createMessage(L_C_TO_STRING(message));
shared_ptr<LinphonePrivate::ChatMessage> cppPtr = L_GET_CPP_PTR_FROM_C_OBJECT(cr)->createChatMessage(L_C_TO_STRING(message));
LinphoneChatMessage *object = L_INIT(ChatMessage);
L_SET_CPP_PTR_FROM_C_OBJECT(object, cppPtr);
return object;
......@@ -130,24 +126,13 @@ LinphoneChatMessage *linphone_chat_room_create_message_2 (
return msg;
}
void linphone_chat_room_send_message2 (
LinphoneChatRoom *cr,
LinphoneChatMessage *msg,
LinphoneChatMessageStateChangedCb status_cb,
void *ud
) {
linphone_chat_message_set_message_state_changed_cb(msg, status_cb);
linphone_chat_message_set_message_state_changed_cb_user_data(msg, ud);
L_GET_PRIVATE_FROM_C_OBJECT(cr)->sendMessage(L_GET_CPP_PTR_FROM_C_OBJECT(msg));
}
void linphone_chat_room_send_chat_message_2 (LinphoneChatRoom *cr, LinphoneChatMessage *msg) {
linphone_chat_message_ref(msg);
L_GET_PRIVATE_FROM_C_OBJECT(cr)->sendMessage(L_GET_CPP_PTR_FROM_C_OBJECT(msg));
L_GET_CPP_PTR_FROM_C_OBJECT(msg)->send();
}
void linphone_chat_room_send_chat_message (LinphoneChatRoom *cr, LinphoneChatMessage *msg) {
L_GET_PRIVATE_FROM_C_OBJECT(cr)->sendMessage(L_GET_CPP_PTR_FROM_C_OBJECT(msg));
L_GET_CPP_PTR_FROM_C_OBJECT(msg)->send();
}
void linphone_chat_room_receive_chat_message (LinphoneChatRoom *cr, LinphoneChatMessage *msg) {
......@@ -235,7 +220,7 @@ LinphoneChatMessage *linphone_chat_room_get_last_message_in_history(LinphoneChat
}
LinphoneChatMessage *linphone_chat_room_find_message (LinphoneChatRoom *cr, const char *message_id) {
return L_GET_C_BACK_PTR(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->findMessage(message_id));
return L_GET_C_BACK_PTR(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->findChatMessage(message_id));
}
LinphoneChatRoomCbs *linphone_chat_room_get_callbacks (const LinphoneChatRoom *cr) {
......@@ -323,8 +308,10 @@ void linphone_chat_room_set_subject (LinphoneChatRoom *cr, const char *subject)
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->setSubject(L_C_TO_STRING(subject));
}
const bctbx_list_t * linphone_chat_room_get_composing_addresses(LinphoneChatRoom *cr) {
return L_GET_RESOLVED_C_LIST_FROM_CPP_LIST(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getComposingAddresses());
const bctbx_list_t *linphone_chat_room_get_composing_addresses (LinphoneChatRoom *cr) {
// FIXME
// return L_GET_RESOLVED_C_LIST_FROM_CPP_LIST(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getComposingAddresses());
return nullptr;
}
LinphoneChatMessage *linphone_chat_room_create_file_transfer_message(LinphoneChatRoom *cr, const LinphoneContent *initial_content) {
......@@ -389,7 +376,7 @@ LinphoneChatRoom *_linphone_client_group_chat_room_new (LinphoneCore *core, cons
L_SET_CPP_PTR_FROM_C_OBJECT(cr, make_shared<LinphonePrivate::ClientGroupChatRoom>(
L_GET_CPP_PTR_FROM_C_OBJECT(core), L_C_TO_STRING(uri), me, L_C_TO_STRING(subject))
);
L_GET_PRIVATE_FROM_C_OBJECT(cr)->setState(LinphonePrivate::ChatRoom::State::Instantiated);
L_GET_PRIVATE_FROM_C_OBJECT(cr, ChatRoom)->setState(LinphonePrivate::ChatRoom::State::Instantiated);
return cr;
}
......
......@@ -35,7 +35,7 @@
F(Address, Address) \
F(Call, Call) \
F(ChatMessage, ChatMessage) \
F(ChatRoom, ChatRoom) \
F(AbstractChatRoom, ChatRoom) \
F(Core, Core) \
F(DialPlan, DialPlan) \
F(EventLog, EventLog) \
......@@ -43,12 +43,14 @@
F(Participant, Participant)
#define L_REGISTER_SUBTYPES(F) \
F(AbstractChatRoom, BasicChatRoom) \
F(AbstractChatRoom, BasicToClientGroupChatRoom) \
F(AbstractChatRoom, ChatRoom) \
F(AbstractChatRoom, ClientGroupChatRoom) \
F(AbstractChatRoom, RealTimeTextChatRoom) \
F(AbstractChatRoom, ServerGroupChatRoom) \
F(Call, LocalConferenceCall) \
F(Call, RemoteConferenceCall) \
F(ChatRoom, BasicChatRoom) \
F(ChatRoom, ClientGroupChatRoom) \
F(ChatRoom, RealTimeTextChatRoom) \
F(ChatRoom, ServerGroupChatRoom) \
F(EventLog, ConferenceCallEvent) \
F(EventLog, ConferenceChatMessageEvent) \
F(EventLog, ConferenceEvent) \
......
......@@ -156,7 +156,7 @@ public:
mutable MainDbChatMessageKey dbKey;
private:
std::weak_ptr<ChatRoom> chatRoom;
std::weak_ptr<AbstractChatRoom> chatRoom;
ChatRoomId chatRoomId;
IdentityAddress fromAddress;
IdentityAddress toAddress;
......
......@@ -67,7 +67,7 @@ void ChatMessagePrivate::setState (ChatMessage::State s, bool force) {
if (force)
state = s;
if (s == state || !q->getChatRoom())
if (s == state)
return;
if (
......@@ -316,7 +316,7 @@ void ChatMessagePrivate::loadFileTransferUrlFromBodyToContent() {
void ChatMessagePrivate::sendImdn (Imdn::Type imdnType, LinphoneReason reason) {
L_Q();
shared_ptr<ChatMessage> msg = q->getChatRoom()->createMessage();
shared_ptr<ChatMessage> msg = q->getChatRoom()->createChatMessage();
Content *content = new Content();
content->setContentType("message/imdn+xml");
......@@ -332,7 +332,7 @@ LinphoneReason ChatMessagePrivate::receive () {
LinphoneReason reason = LinphoneReasonNone;
shared_ptr<Core> core = q->getCore();
shared_ptr<ChatRoom> chatRoom = q->getChatRoom();
shared_ptr<AbstractChatRoom> chatRoom = q->getChatRoom();
setState(ChatMessage::State::Delivered);
......@@ -357,8 +357,7 @@ LinphoneReason ChatMessagePrivate::receive () {
ChatMessageModifier::Result result = ecmm.decode(q->getSharedFromThis(), errorCode);
if (result == ChatMessageModifier::Result::Error) {
/* Unable to decrypt message */
if (chatRoom)
chatRoom->getPrivate()->notifyUndecryptableMessageReceived(q->getSharedFromThis());
chatRoom->getPrivate()->notifyUndecryptableMessageReceived(q->getSharedFromThis());
reason = linphone_error_code_to_reason(errorCode);
q->sendDeliveryNotification(reason);
return reason;
......@@ -416,7 +415,7 @@ LinphoneReason ChatMessagePrivate::receive () {
setDirection(ChatMessage::Direction::Outgoing);
// Check if this is a duplicate message.
if (chatRoom && chatRoom->findMessageWithDirection(imdnId, direction))
if (chatRoom->findChatMessage(imdnId, direction))
return core->getCCore()->chat_deny_code;
if (errorCode > 0) {
......@@ -632,9 +631,8 @@ void ChatMessagePrivate::store() {
// -----------------------------------------------------------------------------
ChatMessage::ChatMessage (const shared_ptr<ChatRoom> &chatRoom, ChatMessage::Direction direction) :
ChatMessage::ChatMessage (const shared_ptr<AbstractChatRoom> &chatRoom, ChatMessage::Direction direction) :
Object(*new ChatMessagePrivate), CoreAccessor(chatRoom->getCore()) {
L_ASSERT(chatRoom);
L_D();
d->chatRoom = chatRoom;
......@@ -658,12 +656,17 @@ ChatMessage::~ChatMessage () {
d->salOp->release();
}
shared_ptr<ChatRoom> ChatMessage::getChatRoom () const {
shared_ptr<AbstractChatRoom> ChatMessage::getChatRoom () const {
L_D();
shared_ptr<ChatRoom> chatRoom = d->chatRoom.lock();
if (!chatRoom)
shared_ptr<AbstractChatRoom> chatRoom = d->chatRoom.lock();
if (!chatRoom) {
chatRoom = getCore()->getOrCreateBasicChatRoom(d->chatRoomId);
if (!chatRoom) {
lError() << "Unable to get valid chat room instance.";
throw logic_error("Unable to get chat room of chat message.");
}
}
return chatRoom;
}
......@@ -813,9 +816,7 @@ void ChatMessage::send () {
return;
}
shared_ptr<ChatRoom> chatRoom = getChatRoom();
if (chatRoom)
chatRoom->getPrivate()->sendMessage(getSharedFromThis());
getChatRoom()->getPrivate()->sendChatMessage(getSharedFromThis());
}
void ChatMessage::sendDeliveryNotification (LinphoneReason reason) {
......@@ -860,9 +861,7 @@ int ChatMessage::putCharacter (uint32_t character) {
static const uint32_t crlf = 0x0D0A;
static const uint32_t lf = 0x0A;
shared_ptr<ChatRoom> chatRoom = getChatRoom();
if (!chatRoom)
return -1;
shared_ptr<AbstractChatRoom> chatRoom = getChatRoom();
shared_ptr<LinphonePrivate::RealTimeTextChatRoom> rttcr =
static_pointer_cast<LinphonePrivate::RealTimeTextChatRoom>(chatRoom);
......
......@@ -35,7 +35,7 @@
LINPHONE_BEGIN_NAMESPACE
class ChatRoom;
class AbstractChatRoom;
class Content;
class FileTransferContent;
class ChatMessagePrivate;
......@@ -67,7 +67,7 @@ public:
void setIsSecured (bool isSecured);
// ----- TODO: Remove me.
std::shared_ptr<ChatRoom> getChatRoom () const;
std::shared_ptr<AbstractChatRoom> getChatRoom () const;
void send ();
......@@ -102,7 +102,7 @@ public:
bool downloadFile (FileTransferContent &content);
private:
ChatMessage (const std::shared_ptr<ChatRoom> &chatRoom, ChatMessage::Direction direction);
ChatMessage (const std::shared_ptr<AbstractChatRoom> &chatRoom, ChatMessage::Direction direction);
L_DECLARE_PRIVATE(ChatMessage);
L_DISABLE_COPY(ChatMessage);
......
/*
* abstract-chat-room-p.h
* Copyright (C) 2010-2017 Belledonne Communications SARL
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _ABSTRACT_CHAT_ROOM_P_H_
#define _ABSTRACT_CHAT_ROOM_P_H_
#include "abstract-chat-room.h"
#include "object/object-p.h"
// =============================================================================
L_DECL_C_STRUCT_PREFIX_LESS(SalMessage);
LINPHONE_BEGIN_NAMESPACE
class SalOp;
class AbstractChatRoomPrivate : public ObjectPrivate {
public:
virtual void setCreationTime (time_t creationTime) = 0;
virtual void setLastUpdateTime (time_t lastUpdateTime) = 0;
virtual void setState (AbstractChatRoom::State state) = 0;
virtual void sendChatMessage (const std::shared_ptr<ChatMessage> &chatMessage) = 0;
virtual void addTransientEvent (const std::shared_ptr<EventLog> &eventLog) = 0;
virtual void removeTransientEvent (const std::shared_ptr<EventLog> &eventLog) = 0;
virtual void notifyUndecryptableMessageReceived (const std::shared_ptr<ChatMessage> &chatMessage) = 0;
virtual void onChatMessageReceived (const std::shared_ptr<ChatMessage> &chatMessage) = 0;
virtual LinphoneReason onSipMessageReceived (SalOp *op, const SalMessage *message) = 0;
};
LINPHONE_END_NAMESPACE
#endif // ifndef _ABSTRACT_CHAT_ROOM_P_H_
/*
* abstract-chat-room.cpp
* Copyright (C) 2010-2017 Belledonne Communications SARL
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "abstract-chat-room-p.h"
// =============================================================================
using namespace std;
LINPHONE_BEGIN_NAMESPACE
// -----------------------------------------------------------------------------
AbstractChatRoom::AbstractChatRoom (
AbstractChatRoomPrivate &p,
const shared_ptr<Core> &core
) : Object(p), CoreAccessor(core) {}
LINPHONE_END_NAMESPACE
/*
* abstract-chat-room.h
* Copyright (C) 2010-2017 Belledonne Communications SARL
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _ABSTRACT_CHAT_ROOM_H_
#define _ABSTRACT_CHAT_ROOM_H_
#include "chat/chat-message/chat-message.h"
#include "conference/conference-interface.h"
#include "core/core-accessor.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
class AbstractChatRoomPrivate;
class ChatRoomId;
class EventLog;
class LINPHONE_PUBLIC AbstractChatRoom : public Object, public CoreAccessor, public ConferenceInterface {
friend class ChatMessage;
friend class ChatMessagePrivate;
friend class CorePrivate;
friend class MainDb;
public:
L_DECLARE_ENUM(Capabilities, L_ENUM_VALUES_CHAT_ROOM_CAPABILITIES);
L_DECLARE_ENUM(State, L_ENUM_VALUES_CHAT_ROOM_STATE);
typedef int CapabilitiesMask;
virtual const ChatRoomId &getChatRoomId () const = 0;
virtual const IdentityAddress &getPeerAddress () const = 0;
virtual const IdentityAddress &getLocalAddress () const = 0;
virtual time_t getCreationTime () const = 0;
virtual time_t getLastUpdateTime () const = 0;
virtual CapabilitiesMask getCapabilities () const = 0;
virtual State getState () const = 0;
virtual bool hasBeenLeft () const = 0;
virtual std::list<std::shared_ptr<EventLog>> getHistory (int nLast) const = 0;
virtual std::list<std::shared_ptr<EventLog>> getHistoryRange (int begin, int end) const = 0;
virtual int getHistorySize () const = 0;
virtual void deleteHistory () = 0;
virtual std::shared_ptr<ChatMessage> getLastChatMessageInHistory () const = 0;
virtual int getChatMessageCount () const = 0;
virtual int getUnreadChatMessageCount () const = 0;
virtual void compose () = 0;
virtual bool isRemoteComposing () const = 0;
virtual std::list<IdentityAddress> getComposingAddresses () const = 0;
virtual std::shared_ptr<ChatMessage> createChatMessage () = 0;
virtual std::shared_ptr<ChatMessage> createChatMessage (const std::string &text) = 0;
// TODO: Remove LinphoneContent by LinphonePrivate::Content.
virtual std::shared_ptr<ChatMessage> createFileTransferMessage (const LinphoneContent *initialContent) = 0;
virtual std::shared_ptr<ChatMessage> findChatMessage (const std::string &messageId) const = 0;
virtual std::shared_ptr<ChatMessage> findChatMessage (
const std::string &messageId,
ChatMessage::Direction direction
) const = 0;
virtual void markAsRead () = 0;
protected:
explicit AbstractChatRoom (AbstractChatRoomPrivate &p, const std::shared_ptr<Core> &core);
private:
L_DECLARE_PRIVATE(AbstractChatRoom);
L_DISABLE_COPY(AbstractChatRoom);
};
LINPHONE_END_NAMESPACE
#endif // ifndef _ABSTRACT_CHAT_ROOM_H_
......@@ -32,8 +32,6 @@ public:
BasicChatRoomPrivate () = default;
private:
void onChatMessageReceived (const std::shared_ptr<ChatMessage> &chatMessage) override;
std::string subject;
std::list<std::shared_ptr<Participant>> participants;
......
......@@ -31,10 +31,6 @@ LINPHONE_BEGIN_NAMESPACE
// -----------------------------------------------------------------------------
void BasicChatRoomPrivate::onChatMessageReceived (const shared_ptr<ChatMessage> &) {}
// -----------------------------------------------------------------------------
BasicChatRoom::BasicChatRoom (const shared_ptr<Core> &core, const ChatRoomId &chatRoomId) :
ChatRoom(*new BasicChatRoomPrivate, core, chatRoomId) {}
......
......@@ -20,46 +20,50 @@
#ifndef _CHAT_ROOM_P_H_
#define _CHAT_ROOM_P_H_
#include <unordered_set>
#include "chat/notification/is-composing.h"
#include "abstract-chat-room-p.h"
#include "chat-room-id.h"
#include "chat-room.h"
#include "object/object-p.h"
#include "chat/notification/is-composing.h"
#include "event-log/event-log.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
// TODO: clean and order methods!
class ChatRoomPrivate : public ObjectPrivate, public IsComposingListener {
class ChatRoomPrivate : public AbstractChatRoomPrivate, public IsComposingListener {
public:
ChatRoomPrivate () = default;
void setCreationTime (time_t creationTime) override {
this->creationTime = creationTime;
}
void setLastUpdateTime (time_t lastUpdateTime) override {
this->lastUpdateTime = lastUpdateTime;
}
void setState (ChatRoom::State state) override;
void addTransientEvent (const std::shared_ptr<EventLog> &log);
void removeTransientEvent (const std::shared_ptr<EventLog> &log);
void sendChatMessage (const std::shared_ptr<ChatMessage> &chatMessage) override;
void release ();
void addTransientEvent (const std::shared_ptr<EventLog> &eventLog) override;
void removeTransientEvent (const std::shared_ptr<EventLog> &eventLog) override;
void setState (ChatRoom::State newState);
void notifyUndecryptableMessageReceived (const std::shared_ptr<ChatMessage> &chatMessage) override;
virtual void sendMessage (const std::shared_ptr<ChatMessage> &msg);
void onChatMessageReceived (const std::shared_ptr<ChatMessage> &chatMessage) override;
LinphoneReason onSipMessageReceived (SalOp *op, const SalMessage *message) override;
// TODO: After this point clean and order methods (AND set members private if possible)!!!
void sendIsComposingNotification ();
std::list<std::shared_ptr<ChatMessage>> findMessages (const std::string &messageId) const;
virtual LinphoneReason messageReceived (SalOp *op, const SalMessage *msg);
void realtimeTextReceived (uint32_t character, LinphoneCall *call);
void chatMessageReceived (const std::shared_ptr<ChatMessage> &msg);
void imdnReceived (const std::string &text);
void isComposingReceived (const Address &remoteAddr, const std::string &text);
void notifyChatMessageReceived (const std::shared_ptr<ChatMessage> &msg);
void notifyIsComposingReceived (const Address &remoteAddr, bool isComposing);
void notifyStateChanged ();
void notifyUndecryptableMessageReceived (const std::shared_ptr<ChatMessage> &msg);
/* IsComposingListener */
void onIsComposingStateChanged (bool isComposing) override;
......@@ -70,7 +74,7 @@ public:
LinphoneCall *call = nullptr;
bool isComposing = false;
std::list<Address> remoteIsComposing;
std::list<IdentityAddress> remoteIsComposing;
std::list<std::shared_ptr<EventLog>> transientEvents;
// TODO: Remove me. Must be present only in rtt chat room.
......@@ -83,9 +87,6 @@ public:
ChatRoom::State state = ChatRoom::State::None;
public:
virtual void onChatMessageReceived (const std::shared_ptr<ChatMessage> &chatMessage) = 0;
ChatRoomId chatRoomId;
time_t creationTime = std::time(nullptr);
......
......@@ -50,12 +50,6 @@ void ChatRoomPrivate::removeTransientEvent (const shared_ptr<EventLog> &log) {
// -----------------------------------------------------------------------------
void ChatRoomPrivate::release () {
isComposingHandler->stopTimers();
}
// -----------------------------------------------------------------------------
void ChatRoomPrivate::setState (ChatRoom::State newState) {
if (newState != state) {
state = newState;
......@@ -93,7 +87,7 @@ list<shared_ptr<ChatMessage> > ChatRoomPrivate::findMessages (const string &mess
return q->getCore()->getPrivate()->mainDb->findChatMessages(q->getChatRoomId(), messageId);
}
void ChatRoomPrivate::sendMessage (const shared_ptr<ChatMessage> &msg) {
void ChatRoomPrivate::sendChatMessage (const shared_ptr<ChatMessage> &msg) {
L_Q();
// TODO: Check direction.
......@@ -125,7 +119,7 @@ void ChatRoomPrivate::sendMessage (const shared_ptr<ChatMessage> &msg) {
// -----------------------------------------------------------------------------
LinphoneReason ChatRoomPrivate::messageReceived (SalOp *op, const SalMessage *salMsg) {
LinphoneReason ChatRoomPrivate::onSipMessageReceived (SalOp *op, const SalMessage *message) {
L_Q();
bool increaseMsgCount = true;
......@@ -142,11 +136,11 @@ LinphoneReason ChatRoomPrivate::messageReceived (SalOp *op, const SalMessage *sa
);
Content content;
content.setContentType(salMsg->content_type);
content.setBody(salMsg->text ? salMsg->text : "");
content.setContentType(message->content_type);
content.setBody(message->text ? message->text : "");
msg->setInternalContent(content);
msg->getPrivate()->setTime(salMsg->time);
msg->getPrivate()->setTime(message->time);
msg->getPrivate()->setImdnMessageId(op->get_call_id());
const SalCustomHeader *ch = op->get_recv_custom_header();
......@@ -182,7 +176,7 @@ LinphoneReason ChatRoomPrivate::messageReceived (SalOp *op, const SalMessage *sa
pendingMessage = msg;
}
chatMessageReceived(msg);
onChatMessageReceived(msg);
pendingMessage = nullptr;
......@@ -192,7 +186,7 @@ end:
// -----------------------------------------------------------------------------
void ChatRoomPrivate::chatMessageReceived (const shared_ptr<ChatMessage> &msg) {