diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
index 8877fd6a9..aaf4510a3 100644
--- a/include/CMakeLists.txt
+++ b/include/CMakeLists.txt
@@ -90,6 +90,7 @@ set(C_API_HEADER_FILES
)
set(ENUMS_HEADER_FILES
+ chat-message-enums.h
chat-room-enums.h
event-log-enums.h
)
diff --git a/include/linphone/enums/chat-message-enums.h b/include/linphone/enums/chat-message-enums.h
new file mode 100644
index 000000000..a069b6989
--- /dev/null
+++ b/include/linphone/enums/chat-message-enums.h
@@ -0,0 +1,34 @@
+/*
+ * 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 .
+ */
+
+#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_
diff --git a/src/chat/chat-message.cpp b/src/chat/chat-message.cpp
index e72f89d6f..89ef2534e 100644
--- a/src/chat/chat-message.cpp
+++ b/src/chat/chat-message.cpp
@@ -1221,9 +1221,9 @@ bool ChatMessage::isRead() const {
L_D();
LinphoneCore *lc = d->chatRoom->getCore();
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_delivered(policy) && (d->state == DeliveredToUser || d->state == Displayed)) return true;
- return d->state == Delivered || d->state == Displayed || d->state == DeliveredToUser;
+ 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 == State::DeliveredToUser || d->state == State::Displayed)) return true;
+ return d->state == State::Delivered || d->state == State::Displayed || d->state == State::DeliveredToUser;
}
const string& ChatMessage::getAppdata () const {
@@ -1354,14 +1354,14 @@ void ChatMessage::updateState(State state) {
d->setState(state);
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());
}
void ChatMessage::reSend() {
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);
return;
}
@@ -1402,7 +1402,7 @@ int ChatMessage::uploadFile() {
int err = d->startHttpTransfer(linphone_core_get_file_transfer_server(d->chatRoom->getCore()), "POST", &cbs);
if (err == -1) {
- d->setState(NotDelivered);
+ d->setState(State::NotDelivered);
}
return err;
}
@@ -1424,15 +1424,15 @@ int ChatMessage::downloadFile() {
if (err == -1) return -1;
// start the download, status is In Progress
- d->setState(InProgress);
+ d->setState(State::InProgress);
return 0;
}
void ChatMessage::cancelFileTransfer() {
L_D();
if (d->httpRequest) {
- if (d->state == InProgress) {
- d->setState(NotDelivered);
+ if (d->state == State::InProgress) {
+ d->setState(State::NotDelivered);
}
if (!belle_http_request_is_cancelled(d->httpRequest)) {
if (d->chatRoom) {
@@ -1467,7 +1467,7 @@ int ChatMessage::putCharacter(uint32_t character) {
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();
d->setTime(ms_time(0));
- d->state = Displayed;
+ d->state = State::Displayed;
d->direction = Outgoing;
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));
diff --git a/src/chat/chat-message.h b/src/chat/chat-message.h
index 8344fe11e..14af85871 100644
--- a/src/chat/chat-message.h
+++ b/src/chat/chat-message.h
@@ -20,11 +20,9 @@
#define _CHAT_MESSAGE_H_
#include
-#include
-#include "enums.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"
@@ -52,16 +50,7 @@ public:
Outgoing
};
- enum State {
- Idle,
- InProgress,
- Delivered,
- NotDelivered,
- FileTransferError,
- FileTransferDone,
- DeliveredToUser,
- Displayed
- };
+ L_DECLARE_ENUM(State, L_ENUM_VALUES_CHAT_MESSAGE_STATE);
ChatMessage(const std::shared_ptr &room);
virtual ~ChatMessage() = default;