Commit c67b913d authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Moved send code from ChatMessage to ChatRoom

parent fc12fb1e
......@@ -45,6 +45,8 @@ public:
void setTime(time_t time);
void setIsReadOnly(bool readOnly);
unsigned int getStorageId() const;
void setStorageId(unsigned int id);
......
......@@ -27,8 +27,6 @@
#include "chat-message-p.h"
#include "content/content.h"
#include "modifier/multipart-chat-message-modifier.h"
#include "modifier/cpim-chat-message-modifier.h"
#include "chat-room-p.h"
#include "real-time-text-chat-room.h"
......@@ -65,6 +63,10 @@ void ChatMessagePrivate::setTime(time_t t) {
time = t;
}
void ChatMessagePrivate::setIsReadOnly(bool readOnly) {
isReadOnly = readOnly;
}
void ChatMessagePrivate::setState(ChatMessage::State s) {
L_Q();
......@@ -1107,24 +1109,6 @@ void ChatMessage::updateState(State state) {
}
}
void ChatMessage::send () {
L_D();
if (d->contents.size() > 1) {
MultipartChatMessageModifier mcmm;
mcmm.encode(d);
}
LinphoneCore *lc = getChatRoom()->getCore();
LpConfig *lpc = linphone_core_get_config(lc);
if (lp_config_get_int(lpc, "sip", "use_cpim", 0) == 1) {
CpimChatMessageModifier ccmm;
ccmm.encode(d);
}
d->isReadOnly = true;
}
void ChatMessage::reSend() {
L_D();
......
......@@ -61,59 +61,66 @@ public:
Displayed
};
ChatMessage (const std::shared_ptr<ChatRoom> &room);
virtual ~ChatMessage () = default;
ChatMessage(const std::shared_ptr<ChatRoom> &room);
virtual ~ChatMessage() = default;
LinphoneChatMessage * getBackPtr();
std::shared_ptr<ChatRoom> getChatRoom () const;
std::shared_ptr<ChatRoom> getChatRoom() const;
// -----------------------------------------------------------------------------
// Methods
// -----------------------------------------------------------------------------
void store();
void updateState(State state);
void send();
void reSend();
void sendDeliveryNotification(LinphoneReason reason);
void sendDisplayNotification();
int uploadFile();
int downloadFile();
void cancelFileTransfer();
int putCharacter(uint32_t character);
// -----------------------------------------------------------------------------
// Getters & setters
// -----------------------------------------------------------------------------
Direction getDirection () const;
bool isOutgoing () const;
bool isIncoming () const;
Direction getDirection() const;
bool isOutgoing() const;
bool isIncoming() const;
const std::string& getExternalBodyUrl() const;
void setExternalBodyUrl(const std::string &url);
time_t getTime () const;
time_t getTime() const;
bool isSecured () const;
bool isSecured() const;
void setIsSecured(bool isSecured);
State getState() const;
const std::string& getId () const;
void setId (const std::string&);
const std::string& getId() const;
void setId(const std::string&);
bool isRead() const;
const std::string& getAppdata () const;
void setAppdata (const std::string &appData);
const std::string& getAppdata() const;
void setAppdata(const std::string &appData);
const Address& getFromAddress () const;
const Address& getFromAddress() const;
void setFromAddress(Address from);
void setFromAddress(const std::string& from);
const Address& getToAddress () const;
const Address& getToAddress() const;
void setToAddress(Address to);
void setToAddress(const std::string& to);
......@@ -123,20 +130,20 @@ public:
bool isToBeStored() const;
void setIsToBeStored(bool store);
const LinphoneErrorInfo * getErrorInfo () const;
const LinphoneErrorInfo * getErrorInfo() const;
bool isReadOnly () const;
bool isReadOnly() const;
std::list<std::shared_ptr<const Content> > getContents () const;
void addContent (const std::shared_ptr<Content> &content);
void removeContent (const std::shared_ptr<const Content> &content);
std::list<std::shared_ptr<const Content> > getContents() const;
void addContent(const std::shared_ptr<Content> &content);
void removeContent(const std::shared_ptr<const Content> &content);
std::string getCustomHeaderValue (const std::string &headerName) const;
void addCustomHeader (const std::string &headerName, const std::string &headerValue);
void removeCustomHeader (const std::string &headerName);
std::string getCustomHeaderValue(const std::string &headerName) const;
void addCustomHeader(const std::string &headerName, const std::string &headerValue);
void removeCustomHeader(const std::string &headerName);
protected:
explicit ChatMessage (ChatMessagePrivate &p);
explicit ChatMessage(ChatMessagePrivate &p);
private:
L_DECLARE_PRIVATE(ChatMessage);
......
......@@ -23,6 +23,8 @@
#include "c-wrapper/c-wrapper.h"
#include "chat-room-p.h"
#include "modifier/multipart-chat-message-modifier.h"
#include "modifier/cpim-chat-message-modifier.h"
#include "imdn.h"
#include "content/content.h"
#include "chat-message-p.h"
......@@ -810,6 +812,10 @@ void ChatRoom::sendMessage (shared_ptr<ChatMessage> msg) {
}
}
msg->setFromAddress(identity);
// ---------------------------------------
// Start of message modification
// ---------------------------------------
int retval = -1;
LinphoneImEncryptionEngine *imee = d->core->im_encryption_engine;
......@@ -824,6 +830,20 @@ void ChatRoom::sendMessage (shared_ptr<ChatMessage> msg) {
}
}
if (msg->getContents().size() > 1) {
MultipartChatMessageModifier mcmm;
mcmm.encode(msg->getPrivate());
}
if (lp_config_get_int(d->core->config, "sip", "use_cpim", 0) == 1) {
CpimChatMessageModifier ccmm;
ccmm.encode(msg->getPrivate());
}
// ---------------------------------------
// End of message modification
// ---------------------------------------
if (!op) {
/* Sending out of call */
msg->getPrivate()->setSalOp(op = new SalMessageOp(d->core->sal));
......@@ -843,7 +863,7 @@ void ChatRoom::sendMessage (shared_ptr<ChatMessage> msg) {
}
if (!msg->getExternalBodyUrl().empty()) {
char *content_type = ms_strdup_printf("message/external-body; access-type=URL; URL=\"%s\"",msg->getExternalBodyUrl().empty());
char *content_type = ms_strdup_printf("message/external-body; access-type=URL; URL=\"%s\"", msg->getExternalBodyUrl().c_str());
auto msgOp = dynamic_cast<SalMessageOpInterface *>(op);
msgOp->send_message(identity.c_str(), d->peerAddress.asString().c_str(), content_type, nullptr, nullptr);
ms_free(content_type);
......@@ -864,7 +884,7 @@ void ChatRoom::sendMessage (shared_ptr<ChatMessage> msg) {
/* We replace the encrypted content type by the original one */
msg->getPrivate()->setContentType(clearTextContentType);
}
msg->setId(op->get_call_id()); /* must be known at that time */
msg->setId(op->get_call_id()); /* must be known at that time */
d->storeOrUpdateMessage(msg);
if (d->isComposing)
......@@ -890,6 +910,7 @@ void ChatRoom::sendMessage (shared_ptr<ChatMessage> msg) {
/* If operation failed, we should not change message state */
if (msg->isOutgoing()) {
msg->getPrivate()->setIsReadOnly(true);
msg->getPrivate()->setState(ChatMessage::State::InProgress);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment