Commit 223bd817 authored by Ronan's avatar Ronan

feat(core): break completely old message storage api impl

parent 8e05e6a2
......@@ -87,7 +87,6 @@ set(LINPHONE_SOURCE_FILES_C
lpc2xml.c
lpconfig.c
lsd.c
message_storage.c
misc.c
nat_policy.c
offeranswer.c
......
......@@ -6106,9 +6106,6 @@ static void linphone_core_uninit(LinphoneCore *lc)
if(lc->rec_file!=NULL){
ms_free(lc->rec_file);
}
if (lc->chat_db_file){
ms_free(lc->chat_db_file);
}
if (lc->logs_db_file) {
ms_free(lc->logs_db_file);
}
......@@ -6127,7 +6124,6 @@ static void linphone_core_uninit(LinphoneCore *lc)
linphone_core_free_payload_types(lc);
if (lc->supported_formats) ms_free((void *)lc->supported_formats);
linphone_core_message_storage_close(lc);
linphone_core_call_log_storage_close(lc);
linphone_core_friends_storage_close(lc);
linphone_core_zrtp_cache_close(lc);
......@@ -6508,6 +6504,90 @@ void linphone_core_remove_iterate_hook(LinphoneCore *lc, LinphoneCoreIterateHook
}
// =============================================================================
// TODO: Remove me later, code found in message_storage.c.
// =============================================================================
#ifdef SQLITE_STORAGE_ENABLED
#ifndef _WIN32
#if !defined(__QNXNTO__) && !defined(__ANDROID__)
#include <ctype.h>
#include <langinfo.h>
#include <locale.h>
#include <iconv.h>
#include <string.h>
#endif
#else
#include <Windows.h>
#endif
#define MAX_DB_PATH_SIZE 1024
static char *utf8_convert(const char *filename){
char db_file_utf8[MAX_DB_PATH_SIZE] = "";
#if defined(_WIN32)
wchar_t db_file_utf16[MAX_DB_PATH_SIZE]={0};
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, filename, -1, db_file_utf16, MAX_DB_PATH_SIZE);
WideCharToMultiByte(CP_UTF8, 0, db_file_utf16, -1, db_file_utf8, sizeof(db_file_utf8), NULL, NULL);
#elif defined(__QNXNTO__) || defined(__ANDROID__)
strncpy(db_file_utf8, filename, MAX_DB_PATH_SIZE - 1);
#else
char db_file_locale[MAX_DB_PATH_SIZE] = {'\0'};
char *inbuf=db_file_locale, *outbuf=db_file_utf8;
size_t inbyteleft = MAX_DB_PATH_SIZE, outbyteleft = MAX_DB_PATH_SIZE;
iconv_t cb;
if (strcasecmp("UTF-8", nl_langinfo(CODESET)) == 0) {
strncpy(db_file_utf8, filename, MAX_DB_PATH_SIZE - 1);
} else {
strncpy(db_file_locale, filename, MAX_DB_PATH_SIZE-1);
cb = iconv_open("UTF-8", nl_langinfo(CODESET));
if (cb != (iconv_t)-1) {
int ret;
ret = static_cast<int>(iconv(cb, &inbuf, &inbyteleft, &outbuf, &outbyteleft));
if(ret == -1) db_file_utf8[0] = '\0';
iconv_close(cb);
}
}
#endif
return ms_strdup(db_file_utf8);
}
int _linphone_sqlite3_open(const char *db_file, sqlite3 **db) {
char* errmsg = NULL;
int ret;
int flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
#if TARGET_OS_IPHONE
/* the secured filesystem of the iPHone doesn't allow writing while the app is in background mode, which is problematic.
* We workaround by asking that the open is made with no protection*/
flags |= SQLITE_OPEN_FILEPROTECTION_NONE;
#endif
/*since we plug our vfs into sqlite, we convert to UTF-8.
* On Windows, the filename has to be converted back to windows native charset.*/
char *utf8_filename = utf8_convert(db_file);
ret = sqlite3_open_v2(utf8_filename, db, flags, LINPHONE_SQLITE3_VFS);
ms_free(utf8_filename);
if (ret != SQLITE_OK) return ret;
// Some platforms do not provide a way to create temporary files which are needed
// for transactions... so we work in memory only
// see http ://www.sqlite.org/compile.html#temp_store
ret = sqlite3_exec(*db, "PRAGMA temp_store=MEMORY", NULL, NULL, &errmsg);
if (ret != SQLITE_OK) {
ms_error("Cannot set sqlite3 temporary store to memory: %s.", errmsg);
sqlite3_free(errmsg);
}
return ret;
}
#endif
// =============================================================================
void linphone_core_set_zrtp_secrets_file(LinphoneCore *lc, const char* file){
LinphoneProxyConfig *proxy = linphone_core_get_default_proxy_config(lc);
if (lc->zrtp_secrets_cache != NULL) {
......@@ -6821,19 +6901,13 @@ int linphone_core_get_video_dscp(const LinphoneCore *lc){
return lp_config_get_int(lc->config,"rtp","video_dscp",0);
}
void linphone_core_set_chat_database_path(LinphoneCore *lc, const char *path){
if (lc->chat_db_file){
ms_free(lc->chat_db_file);
lc->chat_db_file=NULL;
}
if (path) {
lc->chat_db_file=ms_strdup(path);
linphone_core_message_storage_init(lc);
}
void linphone_core_set_chat_database_path (LinphoneCore *, const char *) {
lError() << "Do not use `linphone_core_set_chat_database_path`. Not necessary.";
}
const char* linphone_core_get_chat_database_path(const LinphoneCore *lc) {
return lc->chat_db_file;
const char *linphone_core_get_chat_database_path (const LinphoneCore *) {
lError() << "Do not use `linphone_core_get_chat_database_path`. Not necessary.";
return "";
}
void linphone_core_enable_sdp_200_ack(LinphoneCore *lc, bool_t enable) {
......
This diff is collapsed.
......@@ -906,12 +906,10 @@ struct _LinphoneCore
int max_calls;
LinphoneTunnel *tunnel;
char* device_id;
char *chat_db_file;
char *logs_db_file;
char *friends_db_file;
#ifdef SQLITE_STORAGE_ENABLED
sqlite3 *zrtp_cache_db; /**< zrtp sqlite cache, used by both zrtp and lime */
sqlite3 *db;
sqlite3 *logs_db;
sqlite3 *friends_db;
bool_t debug_storage;
......@@ -1092,15 +1090,7 @@ void linphone_upnp_destroy(LinphoneCore *lc);
#ifdef SQLITE_STORAGE_ENABLED
int _linphone_sqlite3_open(const char *db_file, sqlite3 **db);
sqlite3 * linphone_message_storage_init(void);
void linphone_message_storage_init_chat_rooms(LinphoneCore *lc);
#endif
void linphone_chat_message_store_update(LinphoneChatMessage *msg);
void linphone_chat_message_store_state(LinphoneChatMessage *msg);
void linphone_chat_message_store_appdata(LinphoneChatMessage* msg);
void linphone_core_message_storage_init(LinphoneCore *lc);
void linphone_core_message_storage_close(LinphoneCore *lc);
void linphone_core_message_storage_set_debug(LinphoneCore *lc, bool_t debug);
void linphone_chat_message_set_time(LinphoneChatMessage* msg, time_t time);
void linphone_chat_message_set_incoming(LinphoneChatMessage *msg);
......
......@@ -36,10 +36,6 @@ void linphone_core_enable_send_call_stats_periodical_updates(LinphoneCore *lc, b
lc->send_call_stats_periodical_updates = enabled;
}
sqlite3 *linphone_core_get_sqlite_database(const LinphoneCore *lc) {
return lc->db;
}
void linphone_core_set_zrtp_cache_db(LinphoneCore *lc, sqlite3 *cache_db) {
lc->zrtp_cache_db = cache_db;
}
......
......@@ -60,7 +60,6 @@ LINPHONE_PUBLIC int linphone_run_stun_tests(LinphoneCore *lc, int audioPort, int
char *audioCandidateAddr, int *audioCandidatePort, char *videoCandidateAddr, int *videoCandidatePort, char *textCandidateAddr, int *textCandidatePort);
LINPHONE_PUBLIC void linphone_core_enable_short_turn_refresh(LinphoneCore *lc, bool_t enable);
LINPHONE_PUBLIC sqlite3 *linphone_core_get_sqlite_database(const LinphoneCore *lc);
LINPHONE_PUBLIC void linphone_core_set_zrtp_cache_db(LinphoneCore *lc, sqlite3 *cache_db);
LINPHONE_PUBLIC LinphoneCoreCbs *linphone_core_get_first_callbacks(const LinphoneCore *lc);
......
......@@ -82,6 +82,7 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES
content/content-manager.h
content/content-type.h
content/content.h
core/core-accessor.h
core/core-p.h
core/core.h
core/paths/paths.h
......@@ -178,6 +179,7 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES
content/content-manager.cpp
content/content-type.cpp
content/content.cpp
core/core-accessor.cpp
core/core-chat-room.cpp
core/core.cpp
core/paths/paths.cpp
......
......@@ -89,7 +89,7 @@ LinphoneCore *linphone_chat_room_get_lc (const LinphoneChatRoom *cr) {
}
LinphoneCore *linphone_chat_room_get_core (const LinphoneChatRoom *cr) {
return L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getCore();
return L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getCore()->getCCore();
}
const LinphoneAddress *linphone_chat_room_get_peer_address (LinphoneChatRoom *cr) {
......@@ -181,7 +181,7 @@ void linphone_chat_room_mark_as_read (LinphoneChatRoom *cr) {
}
int linphone_chat_room_get_unread_messages_count (LinphoneChatRoom *cr) {
return L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getUnreadMessagesCount();
return L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getUnreadChatMessagesCount();
}
int linphone_chat_room_get_history_size (LinphoneChatRoom *cr) {
......@@ -206,7 +206,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()->cppCore)->mainDb->getHistory(
L_GET_PRIVATE(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getCore())->mainDb->getHistory(
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getPeerAddress().asStringUriOnly(),
nb_events
)
......@@ -215,7 +215,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()->cppCore)->mainDb->getHistory(
L_GET_PRIVATE(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getCore())->mainDb->getHistory(
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getPeerAddress().asStringUriOnly(),
begin,
end
......@@ -348,14 +348,19 @@ LinphoneChatRoom *_linphone_client_group_chat_room_new (LinphoneCore *core, cons
from = linphone_core_get_primary_contact(core);
LinphonePrivate::Address me(from);
LinphoneChatRoom *cr = L_INIT(ChatRoom);
L_SET_CPP_PTR_FROM_C_OBJECT(cr, LinphonePrivate::ObjectFactory::create<LinphonePrivate::ClientGroupChatRoom>(core, me, L_C_TO_STRING(uri), L_C_TO_STRING(subject)));
L_SET_CPP_PTR_FROM_C_OBJECT(cr, LinphonePrivate::ObjectFactory::create<LinphonePrivate::ClientGroupChatRoom>(
core->cppCore, me, L_C_TO_STRING(uri), L_C_TO_STRING(subject))
);
L_GET_PRIVATE_FROM_C_OBJECT(cr)->setState(LinphonePrivate::ChatRoom::State::Instantiated);
return cr;
}
LinphoneChatRoom *_linphone_server_group_chat_room_new (LinphoneCore *core, LinphonePrivate::SalCallOp *op) {
LinphoneChatRoom *cr = L_INIT(ChatRoom);
L_SET_CPP_PTR_FROM_C_OBJECT(cr, LinphonePrivate::ObjectFactory::create<LinphonePrivate::ServerGroupChatRoom>(core, op));
L_SET_CPP_PTR_FROM_C_OBJECT(cr, LinphonePrivate::ObjectFactory::create<LinphonePrivate::ServerGroupChatRoom>(
core->cppCore,
op
));
L_GET_PRIVATE_FROM_C_OBJECT(cr)->setState(LinphonePrivate::ChatRoom::State::Instantiated);
L_GET_PRIVATE_FROM_C_OBJECT(cr, ServerGroupChatRoom)->confirmCreation();
return cr;
......
......@@ -47,8 +47,8 @@ public:
Cpim = 1 << 4
};
ChatMessagePrivate (const std::shared_ptr<ChatRoom> &room);
virtual ~ChatMessagePrivate ();
ChatMessagePrivate ();
~ChatMessagePrivate ();
void setChatRoom (std::shared_ptr<ChatRoom> chatRoom);
......@@ -119,7 +119,10 @@ public:
void send();
private:
std::shared_ptr<ChatRoom> chatRoom;
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;
......@@ -157,9 +160,13 @@ private:
void fileUploadEndBackgroundTask();
void fileUploadBeginBackgroundTask();
bool isFileTransferInProgressAndValid();
int startHttpTransfer(std::string url, std::string action, belle_http_request_listener_callbacks_t *cbs);
int startHttpTransfer(
const std::string &url,
const std::string &action,
belle_http_request_listener_callbacks_t *cbs
);
void releaseHttpRequest();
void createFileTransferInformationsFromVndGsmaRcsFtHttpXml(std::string body);
void createFileTransferInformationsFromVndGsmaRcsFtHttpXml(const std::string &body);
L_DECLARE_PUBLIC(ChatMessage);
};
......
This diff is collapsed.
......@@ -25,6 +25,7 @@
#include "linphone/api/c-types.h"
#include "linphone/enums/chat-message-enums.h"
#include "core/core-accessor.h"
#include "object/object.h"
// =============================================================================
......@@ -36,7 +37,7 @@ class ChatRoom;
class Content;
class ChatMessagePrivate;
class LINPHONE_PUBLIC ChatMessage : public Object {
class LINPHONE_PUBLIC ChatMessage : public Object, public CoreAccessor {
friend class ChatRoom;
friend class ChatRoomPrivate;
friend class CpimChatMessageModifier;
......@@ -49,6 +50,7 @@ public:
L_DECLARE_ENUM(State, L_ENUM_VALUES_CHAT_MESSAGE_STATE);
L_DECLARE_ENUM(Direction, L_ENUM_VALUES_CHAT_MESSAGE_DIRECTION);
// TODO: Make me private.
ChatMessage (const std::shared_ptr<ChatRoom> &chatRoom);
// ----- TODO: Remove me.
......
......@@ -29,8 +29,7 @@ LINPHONE_BEGIN_NAMESPACE
class BasicChatRoomPrivate : public ChatRoomPrivate {
public:
BasicChatRoomPrivate (LinphoneCore *core, const Address &peerAddress);
virtual ~BasicChatRoomPrivate () = default;
BasicChatRoomPrivate () = default;
private:
std::string subject;
......
......@@ -29,14 +29,8 @@ using namespace std;
LINPHONE_BEGIN_NAMESPACE
BasicChatRoomPrivate::BasicChatRoomPrivate (LinphoneCore *core, const Address &peerAddress) : ChatRoomPrivate(core) {
this->peerAddress = peerAddress;
}
// =============================================================================
BasicChatRoom::BasicChatRoom (LinphoneCore *core, const Address &peerAddress) :
ChatRoom(*new BasicChatRoomPrivate(core, peerAddress)) {}
BasicChatRoom::BasicChatRoom (const shared_ptr<Core> &core, const Address &peerAddress) :
ChatRoom(*new BasicChatRoomPrivate, core, peerAddress) {}
// -----------------------------------------------------------------------------
......
......@@ -30,8 +30,7 @@ class BasicChatRoomPrivate;
class LINPHONE_PUBLIC BasicChatRoom : public ChatRoom {
public:
BasicChatRoom (LinphoneCore *core, const Address &peerAddress);
virtual ~BasicChatRoom () = default;
BasicChatRoom (const std::shared_ptr<Core> &core, const Address &peerAddress);
CapabilitiesMask getCapabilities () const override;
......
......@@ -34,8 +34,7 @@ class ChatRoomPrivate : public ObjectPrivate, public IsComposingListener {
friend class ChatMessagePrivate;
public:
ChatRoomPrivate (LinphoneCore *core);
virtual ~ChatRoomPrivate ();
ChatRoomPrivate () = default;
private:
static int createChatMessageFromDb (void *data, int argc, char **argv, char **colName);
......@@ -53,7 +52,6 @@ public:
void release ();
void sendImdn (const std::string &content, LinphoneReason reason);
int getMessagesCount (bool unreadOnly);
void setState (ChatRoom::State newState);
virtual void sendMessage (const std::shared_ptr<ChatMessage> &msg);
......@@ -64,8 +62,6 @@ protected:
int createChatMessageFromDb (int argc, char **argv, char **colName);
std::shared_ptr<ChatMessage> getTransientMessage (unsigned int storageId) const;
std::shared_ptr<ChatMessage> getWeakMessage (unsigned int storageId) const;
int sqlRequest (sqlite3 *db, const std::string &stmt);
void sqlRequestMessage (sqlite3 *db, const std::string &stmt);
std::list<std::shared_ptr<ChatMessage>> findMessages (const std::string &messageId);
virtual void storeOrUpdateMessage (const std::shared_ptr<ChatMessage> &msg);
......@@ -91,18 +87,20 @@ private:
void onIsComposingRefreshNeeded () override;
public:
LinphoneCore *core = nullptr;
LinphoneCall *call = nullptr;
ChatRoom::State state = ChatRoom::State::None;
Address peerAddress;
int unreadCount = -1;
bool isComposing = false;
std::unordered_set<std::string> remoteIsComposing;
std::list<std::shared_ptr<ChatMessage>> messages;
std::list<std::shared_ptr<ChatMessage>> transientMessages;
std::list<std::weak_ptr<ChatMessage>> weakMessages;
// TODO: Remove me. Must be present only in rtt chat room.
std::shared_ptr<ChatMessage> pendingMessage;
IsComposing isComposingHandler;
// TODO: Use CoreAccessor on IsComposing. And avoid pointer if possible.
std::unique_ptr<IsComposing> isComposingHandler;
private:
L_DECLARE_PUBLIC(ChatRoom);
......
This diff is collapsed.
......@@ -22,6 +22,7 @@
#include "chat/chat-message/chat-message.h"
#include "conference/conference-interface.h"
#include "core/core-accessor.h"
// =============================================================================
......@@ -29,7 +30,7 @@ LINPHONE_BEGIN_NAMESPACE
class ChatRoomPrivate;
class LINPHONE_PUBLIC ChatRoom : public Object, public ConferenceInterface {
class LINPHONE_PUBLIC ChatRoom : public Object, public CoreAccessor, public ConferenceInterface {
friend class Core;
friend class CorePrivate;
friend class ChatMessage;
......@@ -58,18 +59,18 @@ public:
std::list<std::shared_ptr<ChatMessage>> getHistory (int nbMessages);
int getHistorySize ();
std::list<std::shared_ptr<ChatMessage>> getHistoryRange (int startm, int endm);
int getUnreadMessagesCount ();
int getUnreadChatMessagesCount ();
bool isRemoteComposing () const;
void markAsRead ();
LinphoneCore *getCore () const;
virtual void markAsRead ();
const Address &getPeerAddress () const;
State getState () const;
protected:
explicit ChatRoom (ChatRoomPrivate &p, const std::shared_ptr<Core> &core, const Address &address);
virtual void onChatMessageReceived (const std::shared_ptr<ChatMessage> &msg) = 0;
explicit ChatRoom (ChatRoomPrivate &p);
private:
L_DECLARE_PRIVATE(ChatRoom);
......
......@@ -29,8 +29,7 @@ LINPHONE_BEGIN_NAMESPACE
class ClientGroupChatRoomPrivate : public ChatRoomPrivate {
public:
ClientGroupChatRoomPrivate (LinphoneCore *core);
virtual ~ClientGroupChatRoomPrivate () = default;
ClientGroupChatRoomPrivate () = default;
std::shared_ptr<CallSession> createSession ();
void notifyReceived (std::string body);
......
......@@ -37,8 +37,6 @@ using namespace std;
LINPHONE_BEGIN_NAMESPACE
ClientGroupChatRoomPrivate::ClientGroupChatRoomPrivate (LinphoneCore *core) : ChatRoomPrivate(core) {}
// -----------------------------------------------------------------------------
shared_ptr<CallSession> ClientGroupChatRoomPrivate::createSession () {
......@@ -68,11 +66,11 @@ void ClientGroupChatRoomPrivate::notifyReceived (string body) {
// =============================================================================
ClientGroupChatRoom::ClientGroupChatRoom (
LinphoneCore *core,
const std::shared_ptr<Core> &core,
const Address &me,
const string &uri,
const string &subject
) : ChatRoom(*new ClientGroupChatRoomPrivate(core)), RemoteConference(core, me, nullptr) {
const std::string &uri,
const std::string &subject
) : ChatRoom(*new ClientGroupChatRoomPrivate, core, me), RemoteConference(core->getCCore(), me, nullptr) {
L_D_T(RemoteConference, dConference);
dConference->focus = ObjectFactory::create<Participant>(Address(uri));
RemoteConference::setSubject(subject);
......@@ -178,10 +176,11 @@ void ClientGroupChatRoom::leave () {
}
void ClientGroupChatRoom::removeParticipant (const shared_ptr<const Participant> &participant) {
L_D();
SalReferOp *referOp = new SalReferOp(d->core->sal);
LinphoneCore *cCore = CoreAccessor::getCore()->getCCore();
SalReferOp *referOp = new SalReferOp(cCore->sal);
LinphoneAddress *lAddr = linphone_address_new(getConferenceAddress().asString().c_str());
linphone_configure_op(d->core, referOp, lAddr, nullptr, false);
linphone_configure_op(cCore, referOp, lAddr, nullptr, false);
linphone_address_unref(lAddr);
Address referToAddr = participant->getAddress();
referToAddr.setParam("text");
......@@ -197,8 +196,6 @@ void ClientGroupChatRoom::removeParticipants (const list<shared_ptr<Participant>
}
void ClientGroupChatRoom::setParticipantAdminStatus (shared_ptr<Participant> &participant, bool isAdmin) {
L_D();
if (isAdmin == participant->isAdmin())
return;
......@@ -207,9 +204,11 @@ void ClientGroupChatRoom::setParticipantAdminStatus (shared_ptr<Participant> &pa
return;
}
SalReferOp *referOp = new SalReferOp(d->core->sal);
LinphoneCore *cCore = CoreAccessor::getCore()->getCCore();
SalReferOp *referOp = new SalReferOp(cCore->sal);
LinphoneAddress *lAddr = linphone_address_new(getConferenceAddress().asString().c_str());
linphone_configure_op(d->core, referOp, lAddr, nullptr, false);
linphone_configure_op(cCore, referOp, lAddr, nullptr, false);
linphone_address_unref(lAddr);
Address referToAddr = participant->getAddress();
referToAddr.setParam("text");
......@@ -246,7 +245,7 @@ void ClientGroupChatRoom::setSubject (const string &subject) {
// -----------------------------------------------------------------------------
void ClientGroupChatRoom::onChatMessageReceived (const shared_ptr<ChatMessage> &msg) {
}
void ClientGroupChatRoom::onConferenceCreated (const Address &addr) {
......@@ -254,9 +253,9 @@ void ClientGroupChatRoom::onConferenceCreated (const Address &addr) {
L_D_T(RemoteConference, dConference);
dConference->conferenceAddress = addr;
d->peerAddress = addr;
d->core->cppCore->getPrivate()->insertChatRoom(getSharedFromThis());
CoreAccessor::getCore()->getPrivate()->insertChatRoom(getSharedFromThis());
d->setState(ChatRoom::State::Created);
d->core->cppCore->getPrivate()->insertChatRoomWithDb(getSharedFromThis());
CoreAccessor::getCore()->getPrivate()->insertChatRoomWithDb(getSharedFromThis());
}
void ClientGroupChatRoom::onConferenceTerminated (const Address &addr) {
......
......@@ -31,8 +31,13 @@ class ClientGroupChatRoomPrivate;
class LINPHONE_PUBLIC ClientGroupChatRoom : public ChatRoom, public RemoteConference {
public:
ClientGroupChatRoom (LinphoneCore *core, const Address &me, const std::string &uri, const std::string &subject);
virtual ~ClientGroupChatRoom () = default;
// TODO: Make me private.
ClientGroupChatRoom (
const std::shared_ptr<Core> &core,
const Address &me,
const std::string &uri,
const std::string &subject
);
CapabilitiesMask getCapabilities () const override;
......@@ -52,7 +57,7 @@ public:
void setParticipantAdminStatus (std::shared_ptr<Participant> &participant, bool isAdmin) override;
void setSubject (const std::string &subject) override;
private:
protected:
void onChatMessageReceived (const std::shared_ptr<ChatMessage> &msg) override;
private:
......
......@@ -29,8 +29,8 @@ LINPHONE_BEGIN_NAMESPACE
class RealTimeTextChatRoomPrivate : public ChatRoomPrivate {
public:
RealTimeTextChatRoomPrivate (LinphoneCore *core, const Address &peerAddress);
virtual ~RealTimeTextChatRoomPrivate ();
RealTimeTextChatRoomPrivate () = default;
~RealTimeTextChatRoomPrivate ();
public:
void setCall (LinphoneCall *call) {
......
......@@ -20,6 +20,7 @@
#include "c-wrapper/c-wrapper.h"
#include "chat/chat-message/chat-message-p.h"
#include "conference/participant.h"
#include "core/core.h"
#include "logger/logger.h"
#include "real-time-text-chat-room-p.h"
......@@ -29,11 +30,6 @@ using namespace std;
LINPHONE_BEGIN_NAMESPACE
RealTimeTextChatRoomPrivate::RealTimeTextChatRoomPrivate (LinphoneCore *core, const Address &peerAddress)
: ChatRoomPrivate(core) {
this->peerAddress = peerAddress;
}
RealTimeTextChatRoomPrivate::~RealTimeTextChatRoomPrivate () {
if (!receivedRttCharacters.empty()) {
for (auto &rttChars : receivedRttCharacters)
......@@ -49,6 +45,9 @@ void RealTimeTextChatRoomPrivate::realtimeTextReceived (uint32_t character, Linp
const uint32_t crlf = 0x0D0A;
const uint32_t lf = 0x0A;
shared_ptr<Core> core = q->getCore();
LinphoneCore *cCore = core->getCCore();
if (call && linphone_call_params_realtime_text_enabled(linphone_call_get_current_params(call))) {
LinphoneChatMessageCharacter *cmc = bctbx_new0(LinphoneChatMessageCharacter, 1);
......@@ -60,7 +59,7 @@ void RealTimeTextChatRoomPrivate::realtimeTextReceived (uint32_t character, Linp
receivedRttCharacters.push_back(cmc);
remoteIsComposing.insert(peerAddress.asStringUriOnly());
linphone_core_notify_is_composing_received(core, L_GET_C_BACK_PTR(q));
linphone_core_notify_is_composing_received(cCore, L_GET_C_BACK_PTR(q));
if ((character == new_line) || (character == crlf) || (character == lf)) {
/* End of message */
......@@ -70,18 +69,15 @@ void RealTimeTextChatRoomPrivate::realtimeTextReceived (uint32_t character, Linp
Address(
linphone_call_get_dest_proxy(call)
? linphone_address_as_string(linphone_call_get_dest_proxy(call)->identity_address)
: linphone_core_get_identity(core)
: linphone_core_get_identity(cCore)
)
);
pendingMessage->getPrivate()->setState(ChatMessage::State::Delivered);
pendingMessage->getPrivate()->setDirection(ChatMessage::Direction::Incoming);
if (lp_config_get_int(core->config, "misc", "store_rtt_messages", 1) == 1)
if (lp_config_get_int(cCore->config, "misc", "store_rtt_messages", 1) == 1)
storeOrUpdateMessage(pendingMessage);
if (unreadCount < 0) unreadCount = 1;
else unreadCount++;
chatMessageReceived(pendingMessage);
pendingMessage = nullptr;
for (auto &rttChars : receivedRttCharacters)
......@@ -106,8 +102,8 @@ void RealTimeTextChatRoomPrivate::sendMessage (const std::shared_ptr<ChatMessage
// =============================================================================
RealTimeTextChatRoom::RealTimeTextChatRoom (LinphoneCore *core, const Address &peerAddress) :
ChatRoom(*new RealTimeTextChatRoomPrivate(core, peerAddress)) {}
RealTimeTextChatRoom::RealTimeTextChatRoom (const shared_ptr<Core> &core, const Address &peerAddress) :
ChatRoom(*new RealTimeTextChatRoomPrivate, core, peerAddress) {}
int RealTimeTextChatRoom::getCapabilities () const {
return static_cast<int>(Capabilities::Basic) | static_cast<int>(Capabilities::RealTimeText);
......@@ -133,6 +129,15 @@ LinphoneCall *RealTimeTextChatRoom::getCall () const {
return d->call;
}
void RealTimeTextChatRoom::markAsRead () {
L_D();
ChatRoom::markAsRead();
if (d->pendingMessage) {
d->pendingMessage->updateState(ChatMessage::State::Displayed);
d->pendingMessage->sendDisplayNotification();
}
}
// -----------------------------------------------------------------------------
void RealTimeTextChatRoom::onChatMessageReceived(const shared_ptr<ChatMessage> &msg) {}
......
......@@ -30,14 +30,16 @@ class RealTimeTextChatRoomPrivate;
class LINPHONE_PUBLIC RealTimeTextChatRoom : public ChatRoom {
public:
RealTimeTextChatRoom (LinphoneCore *core, const Address &peerAddress);
virtual ~RealTimeTextChatRoom () = default;
// TODO: Make me private.
RealTimeTextChatRoom (const std::shared_ptr<Core> &core, const Address &peerAddress);
CapabilitiesMask getCapabilities () const override;
uint32_t getChar () const;
LinphoneCall *getCall () const;
void markAsRead () override;
void onChatMessageReceived (const std::shared_ptr<ChatMessage> &msg) override;
/* ConferenceInterface */
void addParticipant (const Address &addr, const CallSessionParams *params, bool hasMedia) override;
......
......@@ -35,8 +35,7 @@ class Participant;
class ServerGroupChatRoomPrivate : public ChatRoomPrivate {
public:
ServerGroupChatRoomPrivate (LinphoneCore *core);
virtual ~ServerGroupChatRoomPrivate () = default;