diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index adf89688f..c4141b33f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -35,7 +35,9 @@ 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-message/is-composing-message.h chat/chat-message/notification-message.h + chat/chat-message/notification-message-p.h chat/chat-room/abstract-chat-room-p.h chat/chat-room/abstract-chat-room.h chat/chat-room/basic-chat-room-p.h @@ -191,6 +193,7 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES call/local-conference-call.cpp call/remote-conference-call.cpp chat/chat-message/chat-message.cpp + chat/chat-message/is-composing-message.cpp chat/chat-message/notification-message.cpp chat/chat-room/abstract-chat-room.cpp chat/chat-room/basic-chat-room.cpp diff --git a/src/chat/chat-message/is-composing-message.cpp b/src/chat/chat-message/is-composing-message.cpp new file mode 100644 index 000000000..13177e92e --- /dev/null +++ b/src/chat/chat-message/is-composing-message.cpp @@ -0,0 +1,46 @@ +/* + * is-composing-message.cpp + * Copyright (C) 2010-2018 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 "chat/chat-message/notification-message-p.h" +#include "chat/chat-message/is-composing-message.h" +#include "sip-tools/sip-headers.h" + +// ============================================================================= + +using namespace std; + +LINPHONE_BEGIN_NAMESPACE + +// ----------------------------------------------------------------------------- + +IsComposingMessage::IsComposingMessage ( + const shared_ptr &chatRoom, + IsComposing &isComposingHandler, + bool isComposing +) : NotificationMessage(*new NotificationMessagePrivate(chatRoom, ChatMessage::Direction::Outgoing)) { + L_D(); + Content *content = new Content(); + content->setContentType(ContentType::ImIsComposing); + content->setBody(isComposingHandler.marshal(isComposing)); + addContent(content); + d->addSalCustomHeader(PriorityHeader::HeaderName, PriorityHeader::NonUrgent); + d->addSalCustomHeader("Expires", "0"); +} + +LINPHONE_END_NAMESPACE diff --git a/src/chat/chat-message/is-composing-message.h b/src/chat/chat-message/is-composing-message.h new file mode 100644 index 000000000..41f2a8c7f --- /dev/null +++ b/src/chat/chat-message/is-composing-message.h @@ -0,0 +1,51 @@ +/* + * is-composing-message.h + * Copyright (C) 2010-2018 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 _L_IS_COMPOSING_MESSAGE_H_ +#define _L_IS_COMPOSING_MESSAGE_H_ + +#include "chat/chat-message/notification-message.h" +#include "chat/notification/is-composing.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class LINPHONE_PUBLIC IsComposingMessage : public NotificationMessage { +public: + friend class ChatRoomPrivate; + + L_OVERRIDE_SHARED_FROM_THIS(IsComposingMessage); + + virtual ~IsComposingMessage () = default; + +private: + IsComposingMessage ( + const std::shared_ptr &chatRoom, + IsComposing &isComposingHandler, + bool isComposing + ); + + L_DECLARE_PRIVATE(NotificationMessage); + L_DISABLE_COPY(IsComposingMessage); +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _L_IS_COMPOSING_MESSAGE_H_ diff --git a/src/chat/chat-message/notification-message-p.h b/src/chat/chat-message/notification-message-p.h new file mode 100644 index 000000000..122086529 --- /dev/null +++ b/src/chat/chat-message/notification-message-p.h @@ -0,0 +1,46 @@ +/* + * notification-message-p.h + * Copyright (C) 2010-2018 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 _L_NOTIFICATION_MESSAGE_P_H_ +#define _L_NOTIFICATION_MESSAGE_P_H_ + +#include "chat/chat-message/chat-message-p.h" +#include "chat/chat-message/notification-message.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class NotificationMessagePrivate : public ChatMessagePrivate { + friend class IsComposingMessage; + +private: + NotificationMessagePrivate(const std::shared_ptr &cr, ChatMessage::Direction dir) + : ChatMessagePrivate(cr, dir) {} + + void setDisplayNotificationRequired (bool value) override {} + void setNegativeDeliveryNotificationRequired (bool value) override {} + void setPositiveDeliveryNotificationRequired (bool value) override {} + + L_DECLARE_PUBLIC(NotificationMessage); +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _L_NOTIFICATION_MESSAGE_P_H_ diff --git a/src/chat/chat-message/notification-message.cpp b/src/chat/chat-message/notification-message.cpp index 8471c1484..eefcdaf20 100644 --- a/src/chat/chat-message/notification-message.cpp +++ b/src/chat/chat-message/notification-message.cpp @@ -17,8 +17,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "chat/chat-message/chat-message-p.h" -#include "chat/chat-message/notification-message.h" +#include "chat/chat-message/notification-message-p.h" // ============================================================================= @@ -26,22 +25,13 @@ using namespace std; LINPHONE_BEGIN_NAMESPACE -class NotificationMessagePrivate : public ChatMessagePrivate { -private: - NotificationMessagePrivate(const std::shared_ptr &cr, ChatMessage::Direction dir) - : ChatMessagePrivate(cr, dir) {} - - void setDisplayNotificationRequired (bool value) override {} - void setNegativeDeliveryNotificationRequired (bool value) override {} - void setPositiveDeliveryNotificationRequired (bool value) override {} - - L_DECLARE_PUBLIC(NotificationMessage); -}; - // ----------------------------------------------------------------------------- NotificationMessage::NotificationMessage (const shared_ptr &chatRoom, ChatMessage::Direction direction) : - ChatMessage(*new NotificationMessagePrivate(chatRoom, direction)) { + NotificationMessage(*new NotificationMessagePrivate(chatRoom, direction)) { +} + +NotificationMessage::NotificationMessage (NotificationMessagePrivate &p) : ChatMessage(p) { L_D(); d->displayNotificationRequired = false; d->negativeDeliveryNotificationRequired = false; diff --git a/src/chat/chat-message/notification-message.h b/src/chat/chat-message/notification-message.h index 4870788c1..f818a009f 100644 --- a/src/chat/chat-message/notification-message.h +++ b/src/chat/chat-message/notification-message.h @@ -38,6 +38,9 @@ public: void setToBeStored (bool value) override; +protected: + explicit NotificationMessage (NotificationMessagePrivate &p); + private: NotificationMessage (const std::shared_ptr &chatRoom, ChatMessage::Direction direction); diff --git a/src/chat/chat-room/chat-room-p.h b/src/chat/chat-room/chat-room-p.h index 0da5cc137..c884ffda6 100644 --- a/src/chat/chat-room/chat-room-p.h +++ b/src/chat/chat-room/chat-room-p.h @@ -54,6 +54,7 @@ public: void removeTransientEvent (const std::shared_ptr &eventLog) override; std::shared_ptr createChatMessage (ChatMessage::Direction direction); + std::shared_ptr createIsComposingMessage (); std::shared_ptr createNotificationMessage (ChatMessage::Direction direction); std::list> findChatMessages (const std::string &messageId) const; diff --git a/src/chat/chat-room/chat-room.cpp b/src/chat/chat-room/chat-room.cpp index e57bef564..dcacd666e 100644 --- a/src/chat/chat-room/chat-room.cpp +++ b/src/chat/chat-room/chat-room.cpp @@ -23,10 +23,10 @@ #include "c-wrapper/c-wrapper.h" #include "chat/chat-message/chat-message-p.h" +#include "chat/chat-message/is-composing-message.h" #include "chat/chat-message/notification-message.h" #include "chat/chat-room/chat-room-p.h" #include "core/core-p.h" -#include "sip-tools/sip-headers.h" #include "logger/logger.h" // ============================================================================= @@ -77,20 +77,8 @@ void ChatRoomPrivate::sendIsComposingNotification () { if (!linphone_im_notif_policy_get_send_is_composing(policy)) return; - string payload = isComposingHandler->marshal(isComposing); - if (payload.empty()) - return; - - Content *content = new Content(); - content->setContentType(ContentType::ImIsComposing); - content->setBody(payload); - - shared_ptr chatMessage = createNotificationMessage(ChatMessage::Direction::Outgoing); - chatMessage->addContent(content); - chatMessage->getPrivate()->addSalCustomHeader(PriorityHeader::HeaderName, PriorityHeader::NonUrgent); - chatMessage->getPrivate()->addSalCustomHeader("Expires", "0"); - - chatMessage->getPrivate()->send(); + auto isComposingMsg = createIsComposingMessage(); + isComposingMsg->getPrivate()->send(); } // ----------------------------------------------------------------------------- @@ -121,6 +109,11 @@ shared_ptr ChatRoomPrivate::createChatMessage (ChatMessage::Directi return shared_ptr(new ChatMessage(q->getSharedFromThis(), direction)); } +shared_ptr ChatRoomPrivate::createIsComposingMessage () { + L_Q(); + return shared_ptr(new IsComposingMessage(q->getSharedFromThis(), *isComposingHandler.get(), isComposing)); +} + shared_ptr ChatRoomPrivate::createNotificationMessage (ChatMessage::Direction direction) { L_Q(); return shared_ptr(new NotificationMessage(q->getSharedFromThis(), direction));