Commit 39437121 authored by Ghislain MARY's avatar Ghislain MARY

Some cleaning in chat room and chat message.

parent 5b139dc7
......@@ -1118,7 +1118,6 @@ void linphone_chat_room_remove_transient_message(LinphoneChatRoom *cr, LinphoneC
void linphone_chat_message_deactivate(LinphoneChatMessage *msg);
void linphone_chat_message_release(LinphoneChatMessage *msg);
void linphone_chat_message_fetch_content_from_database(sqlite3 *db, LinphoneChatMessage *message, int content_id);
void linphone_chat_message_send_imdn(LinphoneChatMessage *cm, ImdnType imdn_type, LinphoneReason reason);
void linphone_core_play_named_tone(LinphoneCore *lc, LinphoneToneID id);
bool_t linphone_core_tone_indications_enabled(LinphoneCore*lc);
......
......@@ -29,11 +29,6 @@
// =============================================================================
typedef enum _ImdnType {
ImdnTypeDelivery,
ImdnTypeDisplay
} ImdnType;
typedef enum _LinphoneChatMessageDir{
LinphoneChatMessageIncoming,
LinphoneChatMessageOutgoing
......
......@@ -28,9 +28,9 @@
#include "content/content.h"
#include "content/content-type.h"
#include "chat/chat-message/chat-message-p.h"
#include "chat/chat-message/chat-message.h"
#include "chat/chat-room/chat-room-p.h"
#include "chat/chat-room/real-time-text-chat-room-p.h"
#include "chat/imdn.h"
// =============================================================================
......@@ -275,9 +275,6 @@ void linphone_chat_message_resend_2(LinphoneChatMessage *msg) {
void linphone_chat_message_update_state(LinphoneChatMessage *msg, LinphoneChatMessageState new_state) {
L_GET_CPP_PTR_FROM_C_OBJECT(msg)->updateState((LinphonePrivate::ChatMessage::State) new_state);
}
void linphone_chat_message_send_imdn(LinphoneChatMessage *msg, ImdnType imdn_type, LinphoneReason reason) {
L_GET_PRIVATE_FROM_C_OBJECT(msg)->sendImdn(imdn_type, reason);
}
void linphone_chat_message_deactivate(LinphoneChatMessage *msg){
L_GET_CPP_PTR_FROM_C_OBJECT(msg)->cancelFileTransfer();
......
......@@ -20,10 +20,15 @@
#ifndef _CHAT_MESSAGE_P_H_
#define _CHAT_MESSAGE_P_H_
#include "chat-message.h"
#include <belle-sip/types.h>
#include "chat/chat-message/chat-message.h"
#include "chat/imdn.h"
#include "content/content.h"
#include "content/content-type.h"
#include "db/events-db.h"
#include "object/object-p.h"
#include "sal/sal.h"
// =============================================================================
......@@ -107,7 +112,7 @@ public:
// -----------------------------------------------------------------------------
void sendImdn(ImdnType imdnType, LinphoneReason reason);
void sendImdn(Imdn::Type imdnType, LinphoneReason reason);
LinphoneReason receive();
void send();
......@@ -146,7 +151,7 @@ private:
// -----------------------------------------------------------------------------
std::string createImdnXml(ImdnType imdnType, LinphoneReason reason);
std::string createImdnXml(Imdn::Type imdnType, LinphoneReason reason);
void fileUploadEndBackgroundTask();
void fileUploadBeginBackgroundTask();
......
......@@ -74,7 +74,6 @@ void ChatMessagePrivate::setIsReadOnly(bool readOnly) {
void ChatMessagePrivate::setState(ChatMessage::State s) {
L_Q();
if (s != state && chatRoom) {
if (((state == ChatMessage::State::Displayed) || (state == ChatMessage::State::DeliveredToUser))
&& ((s == ChatMessage::State::DeliveredToUser) || (s == ChatMessage::State::Delivered) || (s == ChatMessage::State::NotDelivered))) {
......@@ -204,7 +203,7 @@ void ChatMessagePrivate::setFileTransferInformation(LinphoneContent *content) {
// -----------------------------------------------------------------------------
string ChatMessagePrivate::createImdnXml(ImdnType imdnType, LinphoneReason reason) {
string ChatMessagePrivate::createImdnXml(Imdn::Type imdnType, LinphoneReason reason) {
xmlBufferPtr buf;
xmlTextWriterPtr writer;
int err;
......@@ -241,7 +240,7 @@ string ChatMessagePrivate::createImdnXml(ImdnType imdnType, LinphoneReason reaso
err = xmlTextWriterWriteElement(writer, (const xmlChar *)"datetime", (const xmlChar *)datetime);
}
if (err >= 0) {
if (imdnType == ImdnTypeDelivery) {
if (imdnType == Imdn::Type::Delivery) {
err = xmlTextWriterStartElement(writer, (const xmlChar *)"delivery-notification");
} else {
err = xmlTextWriterStartElement(writer, (const xmlChar *)"display-notification");
......@@ -252,7 +251,7 @@ string ChatMessagePrivate::createImdnXml(ImdnType imdnType, LinphoneReason reaso
}
if (err >= 0) {
if (reason == LinphoneReasonNone) {
if (imdnType == ImdnTypeDelivery) {
if (imdnType == Imdn::Type::Delivery) {
err = xmlTextWriterStartElement(writer, (const xmlChar *)"delivered");
} else {
err = xmlTextWriterStartElement(writer, (const xmlChar *)"displayed");
......@@ -304,7 +303,7 @@ string ChatMessagePrivate::createImdnXml(ImdnType imdnType, LinphoneReason reaso
return content;
}
void ChatMessagePrivate::sendImdn(ImdnType imdnType, LinphoneReason reason) {
void ChatMessagePrivate::sendImdn(Imdn::Type imdnType, LinphoneReason reason) {
string content = createImdnXml(imdnType, reason);
chatRoom->getPrivate()->sendImdn(content, reason);
}
......@@ -1082,7 +1081,7 @@ void ChatMessagePrivate::send() {
}
if (lp_config_get_int(chatRoom->getCore()->config, "sip", "chat_use_call_dialogs", 0) != 0) {
call = linphone_core_get_call_by_remote_address(chatRoom->getCore(), chatRoom->getPeerAddress().asString().c_str());
call = linphone_core_get_call_by_remote_address(chatRoom->getCore(), to.asString().c_str());
if (call) {
if (linphone_call_get_state(call) == LinphoneCallConnected || linphone_call_get_state(call) == LinphoneCallStreamsRunning ||
linphone_call_get_state(call) == LinphoneCallPaused || linphone_call_get_state(call) == LinphoneCallPausing ||
......@@ -1091,7 +1090,7 @@ void ChatMessagePrivate::send() {
op = linphone_call_get_op(call);
string identity = linphone_core_find_best_identity(chatRoom->getCore(), linphone_call_get_remote_address(call));
if (identity.empty()) {
LinphoneAddress *addr = linphone_address_new(chatRoom->getPeerAddress().asString().c_str());
LinphoneAddress *addr = linphone_address_new(to.asString().c_str());
LinphoneProxyConfig *proxy = linphone_core_lookup_known_proxy(chatRoom->getCore(), addr);
if (proxy) {
identity = L_GET_CPP_PTR_FROM_C_OBJECT(linphone_proxy_config_get_identity_address(proxy))->asString();
......@@ -1106,7 +1105,7 @@ void ChatMessagePrivate::send() {
}
if (!op) {
LinphoneAddress *peer = linphone_address_new(chatRoom->getPeerAddress().asString().c_str());
LinphoneAddress *peer = linphone_address_new(to.asString().c_str());
/* Sending out of call */
salOp = op = new SalMessageOp(chatRoom->getCore()->sal);
linphone_configure_op(
......@@ -1181,14 +1180,14 @@ void ChatMessagePrivate::send() {
if (!externalBodyUrl.empty()) {
char *content_type = ms_strdup_printf("message/external-body; access-type=URL; URL=\"%s\"", externalBodyUrl.c_str());
auto msgOp = dynamic_cast<SalMessageOpInterface *>(op);
msgOp->send_message(from.asString().c_str(), chatRoom->getPeerAddress().asString().c_str(), content_type, nullptr, nullptr);
msgOp->send_message(from.asString().c_str(), to.asString().c_str(), content_type, nullptr, nullptr);
ms_free(content_type);
} else {
auto msgOp = dynamic_cast<SalMessageOpInterface *>(op);
if (internalContent.getContentType().isValid()) {
msgOp->send_message(from.asString().c_str(), chatRoom->getPeerAddress().asString().c_str(), internalContent.getContentType().asString().c_str(), internalContent.getBodyAsString().c_str(), chatRoom->getPeerAddress().asStringUriOnly().c_str());
msgOp->send_message(from.asString().c_str(), to.asString().c_str(), internalContent.getContentType().asString().c_str(), internalContent.getBodyAsString().c_str(), to.asStringUriOnly().c_str());
} else {
msgOp->send_message(from.asString().c_str(), chatRoom->getPeerAddress().asString().c_str(), internalContent.getBodyAsString().c_str());
msgOp->send_message(from.asString().c_str(), to.asString().c_str(), internalContent.getBodyAsString().c_str());
}
}
......@@ -1436,7 +1435,7 @@ void ChatMessage::sendDeliveryNotification(LinphoneReason reason) {
LinphoneCore *lc = d->chatRoom->getCore();
LinphoneImNotifPolicy *policy = linphone_core_get_im_notif_policy(lc);
if (linphone_im_notif_policy_get_send_imdn_delivered(policy)) {
d->sendImdn(ImdnTypeDelivery, reason);
d->sendImdn(Imdn::Type::Delivery, reason);
}
}
......@@ -1445,7 +1444,7 @@ void ChatMessage::sendDisplayNotification() {
LinphoneCore *lc = d->chatRoom->getCore();
LinphoneImNotifPolicy *policy = linphone_core_get_im_notif_policy(lc);
if (linphone_im_notif_policy_get_send_imdn_displayed(policy)) {
d->sendImdn(ImdnTypeDisplay, LinphoneReasonNone);
d->sendImdn(Imdn::Type::Display, LinphoneReasonNone);
}
}
......
......@@ -187,46 +187,15 @@ void ChatRoomPrivate::sendIsComposingNotification () {
L_Q();
LinphoneImNotifPolicy *policy = linphone_core_get_im_notif_policy(core);
if (linphone_im_notif_policy_get_send_is_composing(policy)) {
LinphoneAddress *peer = linphone_address_new(peerAddress.asString().c_str());
LinphoneProxyConfig *proxy = linphone_core_lookup_known_proxy(core, peer);
const char *identity = nullptr;
if (proxy)
identity = linphone_address_as_string(linphone_proxy_config_get_identity_address(proxy));
else
identity = linphone_core_get_primary_contact(core);
/* Sending out of call */
SalMessageOp *op = new SalMessageOp(core->sal);
linphone_configure_op(core, op, peer, nullptr, !!lp_config_get_int(core->config, "sip", "chat_msg_with_contact", 0));
string payload = isComposingHandler.marshal(isComposing);
if (!payload.empty()) {
int retval = -1;
shared_ptr<ChatMessage> msg = q->createMessage();
msg->setFromAddress(Address(identity));
msg->setToAddress(peerAddress);
Content content;
content.setContentType("application/im-iscomposing+xml");
content.setBody(payload);
msg->addContent(content);
LinphoneImEncryptionEngine *imee = linphone_core_get_im_encryption_engine(core);
if (imee) {
LinphoneImEncryptionEngineCbs *imeeCbs = linphone_im_encryption_engine_get_callbacks(imee);
LinphoneImEncryptionEngineCbsOutgoingMessageCb cbProcessOutgoingMessage = linphone_im_encryption_engine_cbs_get_process_outgoing_message(imeeCbs);
if (cbProcessOutgoingMessage) {
retval = cbProcessOutgoingMessage(imee, L_GET_C_BACK_PTR(q), L_GET_C_BACK_PTR(msg));
}
}
if (retval <= 0) {
op->send_message(identity, peerAddress.asString().c_str(), msg->getPrivate()->getContentType().asString().c_str(), msg->getPrivate()->getText().c_str(), nullptr);
}
op->unref();
msg->getPrivate()->send();
}
linphone_address_unref(peer);
}
}
......@@ -561,7 +530,6 @@ void ChatRoom::compose () {
}
shared_ptr<ChatMessage> ChatRoom::createFileTransferMessage (const LinphoneContent *initialContent) {
L_D();
shared_ptr<ChatMessage> chatMessage = createMessage();
/* TODO
......@@ -570,31 +538,25 @@ shared_ptr<ChatMessage> ChatRoom::createFileTransferMessage (const LinphoneConte
content.setBody(linphone_content_get_string_buffer(initialContent));
chatMessage->addContent(content);*/
chatMessage->setToAddress(d->peerAddress);
chatMessage->setFromAddress(Address(linphone_core_get_identity(d->core)));
chatMessage->getPrivate()->setDirection(ChatMessage::Direction::Outgoing);
chatMessage->getPrivate()->setFileTransferInformation(linphone_content_copy(initialContent));
return chatMessage;
}
shared_ptr<ChatMessage> ChatRoom::createMessage (const string &message) {
L_D();
shared_ptr<ChatMessage> chatMessage = createMessage();
Content content;
content.setContentType(ContentType::PlainText);
content.setBody(message);
chatMessage->addContent(content);
chatMessage->setToAddress(d->peerAddress);
chatMessage->setFromAddress(Address(linphone_core_get_identity(d->core)));
return chatMessage;
}
shared_ptr<ChatMessage> ChatRoom::createMessage () {
L_D();
shared_ptr<ChatMessage> chatMessage = ObjectFactory::create<ChatMessage>(getSharedFromThis());
chatMessage->setToAddress(d->peerAddress);
chatMessage->setFromAddress(Address(linphone_core_get_identity(d->core)));
chatMessage->getPrivate()->setTime(ms_time(0));
return chatMessage;
}
......
......@@ -245,8 +245,8 @@ void ClientGroupChatRoom::setSubject (const string &subject) {
void ClientGroupChatRoom::onConferenceCreated (const Address &addr) {
L_D();
L_D_T(RemoteConference, dConference);
dConference->conferenceAddress = addr;
d->peerAddress = addr;
d->setState(ChatRoom::State::Created);
_linphone_core_add_group_chat_room(d->core, addr, L_GET_C_BACK_PTR(this));
}
......
......@@ -23,6 +23,7 @@
#include "logger/logger.h"
#include "chat/cpim/parser/cpim-parser.h"
#include "content/content-type.h"
#include "object/object-p.h"
#include "cpim-message.h"
......@@ -137,7 +138,7 @@ bool Cpim::Message::isValid () const {
return find_if(d->cpimHeaders->cbegin(), d->cpimHeaders->cend(),
[](const shared_ptr<const Header> &header) {
return Utils::iequals(header->getName(), "content-type") && header->getValue() == "Message/CPIM";
return Utils::iequals(header->getName(), "content-type") && (ContentType(header->getValue()) == ContentType::Cpim);
}) != d->cpimHeaders->cend();
}
......
......@@ -23,6 +23,7 @@
#include "linphone/utils/utils.h"
#include "cpim-grammar.h"
#include "content/content-type.h"
#include "logger/logger.h"
#include "object/object-p.h"
......@@ -172,7 +173,7 @@ namespace Cpim {
if (find_if(cpimHeaders->cbegin(), cpimHeaders->cend(),
[](const shared_ptr<const HeaderNode> &headerNode) {
return Utils::iequals(headerNode->getName(), "content-type") && headerNode->getValue() == "Message/CPIM";
return Utils::iequals(headerNode->getName(), "content-type") && (ContentType(headerNode->getValue()) == ContentType::Cpim);
}) == cpimHeaders->cend()) {
lWarning() << "No MIME `Content-Type` found!";
return nullptr;
......
......@@ -32,6 +32,11 @@ class ChatRoom;
class Imdn {
public:
enum class Type {
Delivery,
Display
};
static void parse (ChatRoom &cr, const std::string &content);
private:
......
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