Commit 779646a3 authored by Ronan's avatar Ronan
Browse files

feat(ChatMessage): use L_DECLARE_ENUM for state

parent c4121b43
...@@ -90,6 +90,7 @@ set(C_API_HEADER_FILES ...@@ -90,6 +90,7 @@ set(C_API_HEADER_FILES
) )
set(ENUMS_HEADER_FILES set(ENUMS_HEADER_FILES
chat-message-enums.h
chat-room-enums.h chat-room-enums.h
event-log-enums.h event-log-enums.h
) )
......
/*
* chat-room-enums.h
* Copyright (C) 2017 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef _CHAT_MESSAGE_ENUMS_H_
#define _CHAT_MESSAGE_ENUMS_H_
// =============================================================================
#define L_ENUM_VALUES_CHAT_MESSAGE_STATE(F) \
F(Idle) \
F(InProgress) \
F(Delivered) \
F(NotDelivered) \
F(FileTransferError) \
F(FileTransferDone) \
F(DeliveredToUser) \
F(Displayed)
#endif // ifndef _CHAT_MESSAGE_ENUMS_H_
...@@ -1221,9 +1221,9 @@ bool ChatMessage::isRead() const { ...@@ -1221,9 +1221,9 @@ bool ChatMessage::isRead() const {
L_D(); L_D();
LinphoneCore *lc = d->chatRoom->getCore(); LinphoneCore *lc = d->chatRoom->getCore();
LinphoneImNotifPolicy *policy = linphone_core_get_im_notif_policy(lc); LinphoneImNotifPolicy *policy = linphone_core_get_im_notif_policy(lc);
if (linphone_im_notif_policy_get_recv_imdn_displayed(policy) && d->state == Displayed) return true; if (linphone_im_notif_policy_get_recv_imdn_displayed(policy) && d->state == State::Displayed) return true;
if (linphone_im_notif_policy_get_recv_imdn_delivered(policy) && (d->state == DeliveredToUser || d->state == Displayed)) return true; if (linphone_im_notif_policy_get_recv_imdn_delivered(policy) && (d->state == State::DeliveredToUser || d->state == State::Displayed)) return true;
return d->state == Delivered || d->state == Displayed || d->state == DeliveredToUser; return d->state == State::Delivered || d->state == State::Displayed || d->state == State::DeliveredToUser;
} }
const string& ChatMessage::getAppdata () const { const string& ChatMessage::getAppdata () const {
...@@ -1354,14 +1354,14 @@ void ChatMessage::updateState(State state) { ...@@ -1354,14 +1354,14 @@ void ChatMessage::updateState(State state) {
d->setState(state); d->setState(state);
linphone_chat_message_store_state(L_GET_C_BACK_PTR(this)); linphone_chat_message_store_state(L_GET_C_BACK_PTR(this));
if (state == Delivered || state == NotDelivered) if (state == State::Delivered || state == State::NotDelivered)
d->chatRoom->getPrivate()->moveTransientMessageToWeakMessages(getSharedFromThis()); d->chatRoom->getPrivate()->moveTransientMessageToWeakMessages(getSharedFromThis());
} }
void ChatMessage::reSend() { void ChatMessage::reSend() {
L_D(); L_D();
if (d->state != NotDelivered) { if (d->state != State::NotDelivered) {
lWarning() << "Cannot resend chat message in state " << linphone_chat_message_state_to_string((LinphoneChatMessageState)d->state); lWarning() << "Cannot resend chat message in state " << linphone_chat_message_state_to_string((LinphoneChatMessageState)d->state);
return; return;
} }
...@@ -1402,7 +1402,7 @@ int ChatMessage::uploadFile() { ...@@ -1402,7 +1402,7 @@ int ChatMessage::uploadFile() {
int err = d->startHttpTransfer(linphone_core_get_file_transfer_server(d->chatRoom->getCore()), "POST", &cbs); int err = d->startHttpTransfer(linphone_core_get_file_transfer_server(d->chatRoom->getCore()), "POST", &cbs);
if (err == -1) { if (err == -1) {
d->setState(NotDelivered); d->setState(State::NotDelivered);
} }
return err; return err;
} }
...@@ -1424,15 +1424,15 @@ int ChatMessage::downloadFile() { ...@@ -1424,15 +1424,15 @@ int ChatMessage::downloadFile() {
if (err == -1) return -1; if (err == -1) return -1;
// start the download, status is In Progress // start the download, status is In Progress
d->setState(InProgress); d->setState(State::InProgress);
return 0; return 0;
} }
void ChatMessage::cancelFileTransfer() { void ChatMessage::cancelFileTransfer() {
L_D(); L_D();
if (d->httpRequest) { if (d->httpRequest) {
if (d->state == InProgress) { if (d->state == State::InProgress) {
d->setState(NotDelivered); d->setState(State::NotDelivered);
} }
if (!belle_http_request_is_cancelled(d->httpRequest)) { if (!belle_http_request_is_cancelled(d->httpRequest)) {
if (d->chatRoom) { if (d->chatRoom) {
...@@ -1467,7 +1467,7 @@ int ChatMessage::putCharacter(uint32_t character) { ...@@ -1467,7 +1467,7 @@ int ChatMessage::putCharacter(uint32_t character) {
if (lc && lp_config_get_int(lc->config, "misc", "store_rtt_messages", 1) == 1) { if (lc && lp_config_get_int(lc->config, "misc", "store_rtt_messages", 1) == 1) {
lDebug() << "New line sent, forge a message with content " << d->rttMessage.c_str(); lDebug() << "New line sent, forge a message with content " << d->rttMessage.c_str();
d->setTime(ms_time(0)); d->setTime(ms_time(0));
d->state = Displayed; d->state = State::Displayed;
d->direction = Outgoing; d->direction = Outgoing;
setFromAddress(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)); linphone_chat_message_store(L_GET_C_BACK_PTR(this));
......
...@@ -20,11 +20,9 @@ ...@@ -20,11 +20,9 @@
#define _CHAT_MESSAGE_H_ #define _CHAT_MESSAGE_H_
#include <list> #include <list>
#include <memory>
#include "enums.h"
#include "linphone/api/c-types.h" #include "linphone/api/c-types.h"
#include "linphone/api/c-chat-message.h" #include "linphone/enums/chat-message-enums.h"
#include "object/object.h" #include "object/object.h"
...@@ -52,16 +50,7 @@ public: ...@@ -52,16 +50,7 @@ public:
Outgoing Outgoing
}; };
enum State { L_DECLARE_ENUM(State, L_ENUM_VALUES_CHAT_MESSAGE_STATE);
Idle,
InProgress,
Delivered,
NotDelivered,
FileTransferError,
FileTransferDone,
DeliveredToUser,
Displayed
};
ChatMessage(const std::shared_ptr<ChatRoom> &room); ChatMessage(const std::shared_ptr<ChatRoom> &room);
virtual ~ChatMessage() = default; virtual ~ChatMessage() = default;
......
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