Commit 72bc4fec authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Moved most of exisiting code from LinphoneChatMessage* to shared_ptr<ChatMessage>

parent e7f7abd7
......@@ -29,5 +29,5 @@
#include "chat/chat-room.h"
LinphoneChatMessage *linphone_chat_room_create_file_transfer_message(LinphoneChatRoom *cr, const LinphoneContent *initial_content) {
return L_GET_CPP_PTR_FROM_C_OBJECT(cr)->createFileTransferMessage(initial_content);
return L_GET_C_BACK_PTR(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->createFileTransferMessage(initial_content));
}
......@@ -126,7 +126,7 @@ LINPHONE_PUBLIC const LinphoneAddress* linphone_chat_message_get_to_address(Linp
* @param[in] message LinphoneChatMessage object
* @return The content type of the chat message
*/
LINPHONE_PUBLIC const char * linphone_chat_message_get_content_type(const LinphoneChatMessage *msg);
LINPHONE_PUBLIC const char * linphone_chat_message_get_content_type(LinphoneChatMessage *msg);
/**
* Set the content type of a chat message.
......@@ -140,7 +140,7 @@ LINPHONE_PUBLIC void linphone_chat_message_set_content_type(LinphoneChatMessage
* Get text part of this message
* @return text or NULL if no text.
*/
LINPHONE_PUBLIC const char* linphone_chat_message_get_text(const LinphoneChatMessage* msg);
LINPHONE_PUBLIC const char* linphone_chat_message_get_text(LinphoneChatMessage* msg);
/**
* Returns the id used to identify this message in the storage database
......@@ -235,14 +235,14 @@ LINPHONE_PUBLIC LinphoneContent* linphone_chat_message_get_file_transfer_informa
* @param[in] message LinphoneChatMessage object
* @return Whether or not the message is a file tranfer
*/
LINPHONE_PUBLIC bool_t linphone_chat_message_is_file_transfer(const LinphoneChatMessage *message);
LINPHONE_PUBLIC bool_t linphone_chat_message_is_file_transfer(LinphoneChatMessage *message);
/**
* Return whether or not a chat message is a text.
* @param[in] message LinphoneChatMessage object
* @return Whether or not the message is a text
*/
LINPHONE_PUBLIC bool_t linphone_chat_message_is_text(const LinphoneChatMessage *message);
LINPHONE_PUBLIC bool_t linphone_chat_message_is_text(LinphoneChatMessage *message);
/**
* Get if a chat message is to be stored.
......
......@@ -173,26 +173,28 @@ void linphone_chat_message_set_appdata(LinphoneChatMessage *msg, const char *dat
}
void linphone_chat_message_set_from_address(LinphoneChatMessage *msg, const LinphoneAddress *from) {
if (!from) L_GET_CPP_PTR_FROM_C_OBJECT(msg)->setFromAddress(nullptr);
else L_GET_CPP_PTR_FROM_C_OBJECT(msg)->setFromAddress(make_shared<LinphonePrivate::Address>(linphone_address_as_string(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_from_address(LinphoneChatMessage *msg) {
if (msg->from)
linphone_address_unref(msg->from);
msg->from = linphone_address_new(L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getFromAddress()->asString().c_str());
msg->from = linphone_address_new(L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getFromAddress().asString().c_str());
return msg->from;
}
void linphone_chat_message_set_to_address(LinphoneChatMessage *msg, const LinphoneAddress *to) {
if (!to) L_GET_CPP_PTR_FROM_C_OBJECT(msg)->setToAddress(nullptr);
else L_GET_CPP_PTR_FROM_C_OBJECT(msg)->setToAddress(make_shared<LinphonePrivate::Address>(linphone_address_as_string(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 LinphoneAddress *linphone_chat_message_get_to_address(LinphoneChatMessage *msg) {
if (msg->to)
linphone_address_unref(msg->to);
msg->to = linphone_address_new(L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getToAddress()->asString().c_str());
msg->to = linphone_address_new(L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getToAddress().asString().c_str());
return msg->to;
}
......@@ -325,7 +327,7 @@ void * linphone_chat_message_get_message_state_changed_cb_user_data(LinphoneChat
// Structure has changed, hard to keep the behavior
// =============================================================================
const char * linphone_chat_message_get_content_type(const LinphoneChatMessage *msg) {
const char * linphone_chat_message_get_content_type(LinphoneChatMessage *msg) {
return L_STRING_TO_C(L_GET_PRIVATE_FROM_C_OBJECT(msg)->getContentType());
}
......@@ -333,7 +335,7 @@ void linphone_chat_message_set_content_type(LinphoneChatMessage *msg, const char
L_GET_PRIVATE_FROM_C_OBJECT(msg)->setContentType(L_C_TO_STRING(content_type));
}
const char *linphone_chat_message_get_text(const LinphoneChatMessage *msg) {
const char *linphone_chat_message_get_text(LinphoneChatMessage *msg) {
return L_STRING_TO_C(L_GET_PRIVATE_FROM_C_OBJECT(msg)->getText());
}
......@@ -369,11 +371,11 @@ LinphoneReason linphone_chat_message_get_reason(LinphoneChatMessage *msg) {
return linphone_error_info_get_reason(linphone_chat_message_get_error_info(msg));
}
bool_t linphone_chat_message_is_file_transfer(const LinphoneChatMessage *msg) {
bool_t linphone_chat_message_is_file_transfer(LinphoneChatMessage *msg) {
return LinphonePrivate::ContentType::isFileTransfer(linphone_chat_message_get_content_type(msg));
}
bool_t linphone_chat_message_is_text(const LinphoneChatMessage *msg) {
bool_t linphone_chat_message_is_text(LinphoneChatMessage *msg) {
return LinphonePrivate::ContentType::isText(linphone_chat_message_get_content_type(msg));
}
......
......@@ -68,12 +68,11 @@ void linphone_chat_room_release (LinphoneChatRoom *cr) {
}
void linphone_chat_room_remove_transient_message (LinphoneChatRoom *cr, LinphoneChatMessage *msg) {
L_GET_PRIVATE_FROM_C_OBJECT(cr)->removeTransientMessage(msg);
L_GET_PRIVATE_FROM_C_OBJECT(cr)->removeTransientMessage(L_GET_CPP_PTR_FROM_C_OBJECT(msg));
}
void linphone_chat_room_send_message (LinphoneChatRoom *cr, const char *msg) {
LinphoneChatMessage *message = L_GET_CPP_PTR_FROM_C_OBJECT(cr)->createMessage(msg);
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->sendMessage(message);
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->sendMessage(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->createMessage(msg));
}
bool_t linphone_chat_room_is_remote_composing (const LinphoneChatRoom *cr) {
......@@ -97,7 +96,7 @@ const LinphoneAddress *linphone_chat_room_get_peer_address (LinphoneChatRoom *cr
}
LinphoneChatMessage *linphone_chat_room_create_message (LinphoneChatRoom *cr, const char *message) {
return L_GET_CPP_PTR_FROM_C_OBJECT(cr)->createMessage(L_C_TO_STRING(message));
return L_GET_C_BACK_PTR(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->createMessage(L_C_TO_STRING(message)));
}
LinphoneChatMessage *linphone_chat_room_create_message_2 (
......@@ -135,16 +134,16 @@ void linphone_chat_room_send_message2 (
) {
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_CPP_PTR_FROM_C_OBJECT(cr)->sendMessage(msg);
L_GET_CPP_PTR_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_CPP_PTR_FROM_C_OBJECT(cr)->sendMessage(msg);
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->sendMessage(L_GET_CPP_PTR_FROM_C_OBJECT(msg));
}
void linphone_chat_room_send_chat_message (LinphoneChatRoom *cr, LinphoneChatMessage *msg) {
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->sendMessage(msg);
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->sendMessage(L_GET_CPP_PTR_FROM_C_OBJECT(msg));
}
uint32_t linphone_chat_room_get_char (const LinphoneChatRoom *cr) {
......@@ -169,7 +168,7 @@ void linphone_chat_room_set_call (LinphoneChatRoom *cr, LinphoneCall *call) {
}
bctbx_list_t *linphone_chat_room_get_transient_messages (const LinphoneChatRoom *cr) {
return L_GET_C_LIST_FROM_CPP_LIST(L_GET_PRIVATE_FROM_C_OBJECT(cr)->getTransientMessages());
return L_GET_RESOLVED_C_LIST_FROM_CPP_LIST(L_GET_PRIVATE_FROM_C_OBJECT(cr)->getTransientMessages());
}
void linphone_chat_room_mark_as_read (LinphoneChatRoom *cr) {
......@@ -185,7 +184,7 @@ int linphone_chat_room_get_history_size (LinphoneChatRoom *cr) {
}
void linphone_chat_room_delete_message (LinphoneChatRoom *cr, LinphoneChatMessage *msg) {
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->deleteMessage(msg);
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->deleteMessage(L_GET_CPP_PTR_FROM_C_OBJECT(msg));
}
void linphone_chat_room_delete_history (LinphoneChatRoom *cr) {
......@@ -193,15 +192,15 @@ void linphone_chat_room_delete_history (LinphoneChatRoom *cr) {
}
bctbx_list_t *linphone_chat_room_get_history_range (LinphoneChatRoom *cr, int startm, int endm) {
return L_GET_C_LIST_FROM_CPP_LIST(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getHistoryRange(startm, endm));
return L_GET_RESOLVED_C_LIST_FROM_CPP_LIST(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getHistoryRange(startm, endm));
}
bctbx_list_t *linphone_chat_room_get_history (LinphoneChatRoom *cr, int nb_message) {
return L_GET_C_LIST_FROM_CPP_LIST(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getHistory(nb_message));
return L_GET_RESOLVED_C_LIST_FROM_CPP_LIST(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getHistory(nb_message));
}
LinphoneChatMessage *linphone_chat_room_find_message (LinphoneChatRoom *cr, const char *message_id) {
return 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)->findMessage(message_id));
}
LinphoneChatRoomCbs *linphone_chat_room_get_callbacks (const LinphoneChatRoom *cr) {
......
......@@ -65,10 +65,10 @@ public:
// Methods only used for C wrapper
// -----------------------------------------------------------------------------
const std::string& getContentType() const;
const std::string& getContentType();
void setContentType(const std::string& contentType);
const std::string& getText() const;
const std::string& getText();
void setText(const std::string& text);
LinphoneContent * getFileTransferInformation() const;
......@@ -98,11 +98,11 @@ public:
private:
std::shared_ptr<ChatRoom> chatRoom;
ChatMessage::Direction direction = ChatMessage::Incoming;
ChatMessage::State state = ChatMessage::Idle;
ChatMessage::Direction direction = ChatMessage::Direction::Incoming;
ChatMessage::State state = ChatMessage::State::Idle;
unsigned int storageId = 0;
std::shared_ptr<Address> from;
std::shared_ptr<Address> to;
Address from;
Address to;
time_t time = 0;
std::string id = "";
std::string appData = "";
......@@ -122,9 +122,10 @@ private:
SalOp *salOp = NULL;
SalCustomHeader *salCustomHeaders = NULL;
unsigned long backgroundTaskId;
// Used for compatibility with previous C API
// Cache for returned values, used for compatibility with previous C API
std::string cContentType = "";
std::string cText = "";
// Used for compatibility with previous C API
LinphoneContent *cFileTransferInformation = NULL;
// -----------------------------------------------------------------------------
......
......@@ -22,11 +22,11 @@
#include "linphone/core.h"
#include "linphone/lpconfig.h"
#include "c-wrapper/c-wrapper.h"
#include "address/address.h"
#include "chat-message-p.h"
#include "chat-message.h"
#include "content/content.h"
#include "content/content.h"
#include "modifier/multipart-chat-message-modifier.h"
#include "modifier/cpim-chat-message-modifier.h"
#include "chat-room-p.h"
......@@ -133,20 +133,33 @@ string ChatMessagePrivate::getSalCustomHeaderValue(const string& name) {
// -----------------------------------------------------------------------------
const string& ChatMessagePrivate::getContentType() const {
const string& ChatMessagePrivate::getContentType() {
if (internalContent) {
ContentType contentType = internalContent->getContentType();
cContentType = contentType.asString();
}
return cContentType;
}
void ChatMessagePrivate::setContentType(const string& contentType) {
cContentType = contentType;
if (!internalContent) {
internalContent = make_shared<Content>();
}
internalContent->setContentType(contentType);
}
const string& ChatMessagePrivate::getText() const {
const string& ChatMessagePrivate::getText() {
if (internalContent) {
cText = internalContent->getBodyAsString();
}
return cText;
}
void ChatMessagePrivate::setText(const string& text) {
cText = text;
if (!internalContent) {
internalContent = make_shared<Content>();
}
internalContent->setBody(text);
}
LinphoneContent * ChatMessagePrivate::getFileTransferInformation() const {
......@@ -464,7 +477,7 @@ void ChatMessagePrivate::onRecvBody(belle_sip_user_body_handler_t *bh, belle_sip
}
} else {
ms_warning("File transfer decrypt failed with code %d", (int)retval);
setState(ChatMessage::FileTransferError);
setState(ChatMessage::State::FileTransferError);
}
return;
......@@ -654,22 +667,22 @@ void ChatMessagePrivate::processResponseFromPostFile(const belle_http_response_e
}
xmlFreeDoc(xmlMessageBody);
} else { // no encryption key, transfer in plain, just copy the msg sent by server
cText = ms_strdup(body);
setText(body);
}
cContentType = "application/vnd.gsma.rcs-ft-http+xml";
q->updateState(ChatMessage::FileTransferDone);
setContentType("application/vnd.gsma.rcs-ft-http+xml");
q->updateState(ChatMessage::State::FileTransferDone);
releaseHttpRequest();
chatRoom->sendMessage(L_GET_C_BACK_PTR(q));
//TODO chatRoom->sendMessage(q);
fileUploadEndBackgroundTask();
} else {
ms_warning("Received empty response from server, file transfer failed");
q->updateState(ChatMessage::NotDelivered);
q->updateState(ChatMessage::State::NotDelivered);
releaseHttpRequest();
fileUploadEndBackgroundTask();
}
} else {
ms_warning("Unhandled HTTP code response %d for file transfer", code);
q->updateState(ChatMessage::NotDelivered);
q->updateState(ChatMessage::State::NotDelivered);
releaseHttpRequest();
fileUploadEndBackgroundTask();
}
......@@ -755,7 +768,7 @@ void ChatMessagePrivate::processAuthRequestedDownload(const belle_sip_auth_event
L_Q();
ms_error("Error during file download : auth requested for msg [%p]", this);
q->updateState(ChatMessage::FileTransferError);
q->updateState(ChatMessage::State::FileTransferError);
releaseHttpRequest();
}
......@@ -767,9 +780,9 @@ static void _chat_message_process_io_error_upload(void *data, const belle_sip_io
void ChatMessagePrivate::processIoErrorUpload(const belle_sip_io_error_event_t *event) {
L_Q();
ms_error("I/O Error during file upload of msg [%p]", this);
q->updateState(ChatMessage::NotDelivered);
q->updateState(ChatMessage::State::NotDelivered);
releaseHttpRequest();
chatRoom->getPrivate()->removeTransientMessage(L_GET_C_BACK_PTR(q));
//TODO chatRoom->getPrivate()->removeTransientMessage(q);
}
static void _chat_message_process_auth_requested_upload(void *data, belle_sip_auth_event *event) {
......@@ -780,9 +793,9 @@ static void _chat_message_process_auth_requested_upload(void *data, belle_sip_au
void ChatMessagePrivate::processAuthRequestedUpload(const belle_sip_auth_event *event) {
L_Q();
ms_error("Error during file upload: auth requested for msg [%p]", this);
q->updateState(ChatMessage::NotDelivered);
q->updateState(ChatMessage::State::NotDelivered);
releaseHttpRequest();
chatRoom->getPrivate()->removeTransientMessage(L_GET_C_BACK_PTR(q));
//TODO chatRoom->getPrivate()->removeTransientMessage(q);
}
static void _chat_message_process_io_error_download(void *data, const belle_sip_io_error_event_t *event) {
......@@ -794,7 +807,7 @@ void ChatMessagePrivate::processIoErrorDownload(const belle_sip_io_error_event_t
L_Q();
ms_error("I/O Error during file download msg [%p]", this);
q->updateState(ChatMessage::FileTransferError);
q->updateState(ChatMessage::State::FileTransferError);
releaseHttpRequest();
}
......@@ -809,7 +822,7 @@ void ChatMessagePrivate::processResponseFromGetFile(const belle_http_response_ev
int code = belle_http_response_get_status_code(event->response);
if (code >= 400 && code < 500) {
ms_warning("File transfer failed with code %d", code);
setState(ChatMessage::FileTransferError);
setState(ChatMessage::State::FileTransferError);
} else if (code != 200) {
ms_warning("Unhandled HTTP code response %d for file transfer", code);
}
......@@ -959,26 +972,36 @@ void ChatMessage::setAppdata (const string &appData) {
linphone_chat_message_store_appdata(L_GET_C_BACK_PTR(this));
}
shared_ptr<Address> ChatMessage::getFromAddress () const {
const Address& ChatMessage::getFromAddress () const {
L_D();
return d->from;
}
void ChatMessage::setFromAddress(shared_ptr<Address> from) {
void ChatMessage::setFromAddress(Address from) {
L_D();
d->from = from;
}
shared_ptr<Address> ChatMessage::getToAddress () const {
void ChatMessage::setFromAddress(const string& from) {
L_D();
d->from = Address(from);
}
const Address& ChatMessage::getToAddress () const {
L_D();
return d->to;
}
void ChatMessage::setToAddress(shared_ptr<Address> to) {
void ChatMessage::setToAddress(Address to) {
L_D();
d->to = to;
}
void ChatMessage::setToAddress(const string& to) {
L_D();
d->to = Address(to);
}
const string& ChatMessage::getFileTransferFilepath() const {
L_D();
return d->fileTransferFilePath;
......@@ -1061,6 +1084,18 @@ void ChatMessage::removeCustomHeader (const string &headerName) {
// -----------------------------------------------------------------------------
void ChatMessage::store() {
L_D();
if (d->storageId != 0) {
/* The message has already been stored (probably because of file transfer), update it */
linphone_chat_message_store_update(L_GET_C_BACK_PTR(this));
} else {
/* Store the new message */
linphone_chat_message_store(L_GET_C_BACK_PTR(this));
}
}
void ChatMessage::updateState(State state) {
L_D();
......@@ -1068,7 +1103,7 @@ void ChatMessage::updateState(State state) {
linphone_chat_message_store_state(L_GET_C_BACK_PTR(this));
if (state == Delivered || state == NotDelivered) {
d->chatRoom->getPrivate()->moveTransientMessageToWeakMessages(L_GET_C_BACK_PTR(this));
d->chatRoom->getPrivate()->moveTransientMessageToWeakMessages(static_pointer_cast<ChatMessage>(shared_from_this()));
}
}
......@@ -1098,7 +1133,7 @@ void ChatMessage::reSend() {
return;
}
d->chatRoom->sendMessage(L_GET_C_BACK_PTR(this));
d->chatRoom->sendMessage(static_pointer_cast<ChatMessage>(shared_from_this()));
}
void ChatMessage::sendDeliveryNotification(LinphoneReason reason) {
......@@ -1201,7 +1236,7 @@ int ChatMessage::putCharacter(uint32_t character) {
d->setTime(ms_time(0));
d->state = Displayed;
d->direction = Outgoing;
setFromAddress(make_shared<LinphonePrivate::Address>(linphone_address_as_string(linphone_address_new(linphone_core_get_identity(lc)))));
setFromAddress(LinphonePrivate::Address(linphone_address_as_string(linphone_address_new(linphone_core_get_identity(lc)))));
linphone_chat_message_store(L_GET_C_BACK_PTR(this));
d->rttMessage = "";
}
......
......@@ -22,7 +22,7 @@
#include <list>
#include <memory>
#include "imdn.h"
#include "enums.h"
#include "linphone/api/c-types.h"
#include "linphone/api/c-chat-message.h"
......@@ -34,19 +34,22 @@ LINPHONE_BEGIN_NAMESPACE
class Address;
class ChatRoom;
class ChatRoomPrivate;
class Content;
class ErrorInfo;
class ChatMessagePrivate;
class LINPHONE_PUBLIC ChatMessage : public Object {
friend class ChatRoom;
friend class ChatRoomPrivate;
friend class RealTimeTextChatRoomPrivate;
public:
public:
enum Direction {
Incoming,
Outgoing
};
enum State {
Idle,
InProgress,
......@@ -69,6 +72,7 @@ public:
// Methods
// -----------------------------------------------------------------------------
void store();
void updateState(State state);
void send();
void reSend();
......@@ -105,11 +109,13 @@ public:
const std::string& getAppdata () const;
void setAppdata (const std::string &appData);
std::shared_ptr<Address> getFromAddress () const;
void setFromAddress(std::shared_ptr<Address> from);
const Address& getFromAddress () const;
void setFromAddress(Address from);
void setFromAddress(const std::string& from);
std::shared_ptr<Address> getToAddress () const;
void setToAddress(std::shared_ptr<Address> to);
const Address& getToAddress () const;
void setToAddress(Address to);
void setToAddress(const std::string& to);
const std::string& getFileTransferFilepath() const;
void setFileTransferFilepath(const std::string &path);
......
......@@ -41,16 +41,15 @@ public:
private:
static int createChatMessageFromDb (void *data, int argc, char **argv, char **colName);
static void onWeakMessageDestroyed (void *obj, belle_sip_object_t *messageBeingDestroyed);
public:
void addTransientMessage (LinphoneChatMessage *msg);
void addWeakMessage (LinphoneChatMessage *msg);
std::list<LinphoneChatMessage *> getTransientMessages () const {
void addTransientMessage (std::shared_ptr<ChatMessage> msg);
void addWeakMessage (std::shared_ptr<ChatMessage> msg);
std::list<std::shared_ptr<ChatMessage> > getTransientMessages () const {
return transientMessages;
}
void moveTransientMessageToWeakMessages (LinphoneChatMessage *msg);
void removeTransientMessage (LinphoneChatMessage *msg);
void moveTransientMessageToWeakMessages (std::shared_ptr<ChatMessage> msg);
void removeTransientMessage (std::shared_ptr<ChatMessage> msg);
void release ();
void sendImdn (const std::string &content, LinphoneReason reason);
......@@ -62,27 +61,26 @@ protected:
void sendIsComposingNotification ();
int createChatMessageFromDb (int argc, char **argv, char **colName);
void onWeakMessageDestroyed (LinphoneChatMessage *messageBeingDestroyed);
LinphoneChatMessage *getTransientMessage (unsigned int storageId) const;
LinphoneChatMessage *getWeakMessage (unsigned int storageId) const;
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<LinphoneChatMessage *> findMessages (const std::string &messageId);
void storeOrUpdateMessage (LinphoneChatMessage *msg);
std::list<std::shared_ptr<ChatMessage> > findMessages (const std::string &messageId);
void storeOrUpdateMessage (std::shared_ptr<ChatMessage> msg);
public:
LinphoneReason messageReceived (SalOp *op, const SalMessage *msg);
void realtimeTextReceived (uint32_t character, LinphoneCall *call);
protected:
void chatMessageReceived (LinphoneChatMessage *msg);
void chatMessageReceived (std::shared_ptr<ChatMessage> msg);
void imdnReceived (const std::string &text);
void isComposingReceived (const std::string &text);
private:
void notifyChatMessageReceived (LinphoneChatMessage *msg);
void notifyChatMessageReceived (std::shared_ptr<ChatMessage> msg);
void notifyStateChanged ();
void notifyUndecryptableMessageReceived (LinphoneChatMessage *msg);
void notifyUndecryptableMessageReceived (std::shared_ptr<ChatMessage> msg);
private:
/* IsComposingListener */
......@@ -98,11 +96,11 @@ public:
int unreadCount = -1;
bool isComposing = false;
bool remoteIsComposing = false;
std::list<LinphoneChatMessage *> messages;
std::list<LinphoneChatMessage *> transientMessages;
std::list<LinphoneChatMessage *> weakMessages;
std::list<std::shared_ptr<ChatMessage> > messages;
std::list<std::shared_ptr<ChatMessage> > transientMessages;
std::list<std::weak_ptr<ChatMessage> > weakMessages;
std::list<LinphoneChatMessageCharacter *> receivedRttCharacters;
LinphoneChatMessage *pendingMessage = nullptr;
std::shared_ptr<ChatMessage> pendingMessage = nullptr;
IsComposing isComposingHandler;
private:
......
This diff is collapsed.
......@@ -28,6 +28,8 @@
#include "object/object.h"
#include "conference/conference-interface.h"
#include "chat-message.h"
#include "linphone/types.h"
// =============================================================================
......@@ -47,19 +49,20 @@ public:
virtual ~ChatRoom () = default;
void compose ();
LinphoneChatMessage *createFileTransferMessage (const LinphoneContent *initialContent);
LinphoneChatMessage *createMessage (const std::string &msg);
std::shared_ptr<ChatMessage> createFileTransferMessage (const LinphoneContent *initialContent);
std::shared_ptr<ChatMessage> createMessage (const std::string &msg);
std::shared_ptr<ChatMessage> createMessage ();
void deleteHistory ();
void deleteMessage (LinphoneChatMessage *msg);
LinphoneChatMessage * findMessage (const std::string& messageId);
LinphoneChatMessage * findMessageWithDirection (const std::string &messageId, LinphoneChatMessageDir direction);
std::list<LinphoneChatMessage *> getHistory (int nbMessages);
void deleteMessage (std::shared_ptr<ChatMessage> msg);
std::shared_ptr<ChatMessage> findMessage (const std::string& messageId);
std::shared_ptr<ChatMessage> findMessageWithDirection (const std::string &messageId, ChatMessage::Direction direction);
std::list<std::shared_ptr<ChatMessage> > getHistory (int nbMessages);
int getHistorySize ();
std::list<LinphoneChatMessage *> getHistoryRange (int startm, int endm);
std::list<std::shared_ptr<ChatMessage> > getHistoryRange (int startm, int endm);
int getUnreadMessagesCount ();
bool isRemoteComposing () const;
void markAsRead ();
virtual void sendMessage (LinphoneChatMessage *msg);
virtual void sendMessage (std::shared_ptr<ChatMessage> msg);
LinphoneCore *getCore () const;
......
......@@ -19,6 +19,8 @@
#include "logger/logger.h"
#include "imdn.h"
#include "chat/chat-room.h"
#include "chat/chat-message.h"
// =============================================================================
......@@ -59,7 +61,7 @@ void Imdn::parse (ChatRoom &cr, xmlparsing_context_t *xmlCtx) {
}
if (messageIdStr && datetimeStr) {
LinphoneChatMessage *cm = cr.findMessageWithDirection(messageIdStr, LinphoneChatMessageOutgoing);
shared_ptr<ChatMessage> cm = cr.findMessageWithDirection(messageIdStr, ChatMessage::Direction::Outgoing);
if (!cm) {
lWarning() << "Received IMDN for unknown message " << messageIdStr;
} else {
......@@ -73,9 +75,9 @@ void Imdn::parse (ChatRoom &cr, xmlparsing_context_t *xmlCtx) {
xmlNodePtr node = deliveryStatusObject->nodesetval->nodeTab[0];
if (node->children && node->children->name) {
if (strcmp((const char *)node->children->name, "delivered") == 0) {
linphone_chat_message_update_state(cm, LinphoneChatMessageStateDeliveredToUser);
cm->updateState(ChatMessage::State::DeliveredToUser);
} else if (strcmp((const char *)node->children->name, "error") == 0) {
linphone_chat_message_update_state(cm, LinphoneChatMessageStateNotDelivered);
cm->updateState(ChatMessage::State::NotDelivered);
}
}
}
......@@ -86,13 +88,12 @@ void Imdn::parse (ChatRoom &cr, xmlparsing_context_t *xmlCtx) {
xmlNodePtr node = displayStatusObject->nodesetval->nodeTab[0];
if (node->children && node->children->name) {
if (strcmp((const char *)node->children->name, "displayed") == 0) {
linphone_chat_message_update_state(cm, LinphoneChatMessageStateDisplayed);
cm->updateState(ChatMessage::State::Displayed);
}
}
}
xmlXPathFreeObject(displayStatusObject);
}
linphone_chat_message_unref(cm);
}
}
if (messageIdStr)
......
......@@ -21,14 +21,14 @@
#include "linphone/utils/general.h"
#include "chat-room.h"
#include "private.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
class ChatRoom;
class Imdn {
public:
static void parse (ChatRoom &cr, const std::string &content);
......
......@@ -21,6 +21,8 @@
#include "linphone/utils/general.h"
#include "private.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
......
......@@ -16,12 +16,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "chat/chat-message-p.h"
#include "cpim-chat-message-modifier.h"
#include "chat/cpim/cpim.h"
#include "content/content-type.h"
#include "content/content.h"
#include "cpim-chat-message-modifier.h"
#include "address/address.h"
#include "chat/chat-message-p.h"
// =============================================================================
......
......@@ -16,8 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "chat/chat-message-p.h"
#include "multipart-chat-message-modifier.h"