mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-18 11:38:08 +00:00
feat(ChatMessage): use L_DECLARE_ENUM for state
This commit is contained in:
parent
c4121b438d
commit
779646a38b
4 changed files with 47 additions and 23 deletions
|
|
@ -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
|
||||
)
|
||||
|
|
|
|||
34
include/linphone/enums/chat-message-enums.h
Normal file
34
include/linphone/enums/chat-message-enums.h
Normal file
|
|
@ -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 <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 {
|
|||
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));
|
||||
|
|
|
|||
|
|
@ -20,11 +20,9 @@
|
|||
#define _CHAT_MESSAGE_H_
|
||||
|
||||
#include <list>
|
||||
#include <memory>
|
||||
|
||||
#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<ChatRoom> &room);
|
||||
virtual ~ChatMessage() = default;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue