mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-05-07 05:53:06 +00:00
fix(ChatMessage): remove ugly send method on chatroom!!!
This commit is contained in:
parent
b9c4d7dcdf
commit
6310bfb10b
12 changed files with 62 additions and 68 deletions
|
|
@ -265,11 +265,11 @@ void linphone_chat_message_cancel_file_transfer(LinphoneChatMessage *msg) {
|
|||
}
|
||||
|
||||
void linphone_chat_message_resend(LinphoneChatMessage *msg) {
|
||||
L_GET_CPP_PTR_FROM_C_OBJECT(msg)->reSend();
|
||||
L_GET_CPP_PTR_FROM_C_OBJECT(msg)->send();
|
||||
}
|
||||
|
||||
void linphone_chat_message_resend_2(LinphoneChatMessage *msg) {
|
||||
L_GET_CPP_PTR_FROM_C_OBJECT(msg)->reSend();
|
||||
L_GET_CPP_PTR_FROM_C_OBJECT(msg)->send();
|
||||
}
|
||||
|
||||
void linphone_chat_message_update_state(LinphoneChatMessage *msg, LinphoneChatMessageState new_state) {
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ void linphone_chat_room_remove_transient_message (LinphoneChatRoom *cr, Linphone
|
|||
}
|
||||
|
||||
void linphone_chat_room_send_message (LinphoneChatRoom *cr, const char *msg) {
|
||||
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->sendMessage(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->createMessage(msg));
|
||||
L_GET_PRIVATE_FROM_C_OBJECT(cr)->sendMessage(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->createMessage(msg));
|
||||
}
|
||||
|
||||
bool_t linphone_chat_room_is_remote_composing (const LinphoneChatRoom *cr) {
|
||||
|
|
@ -136,16 +136,16 @@ void linphone_chat_room_send_message2 (
|
|||
) {
|
||||
linphone_chat_message_set_message_state_changed_cb(msg, status_cb);
|
||||
linphone_chat_message_set_message_state_changed_cb_user_data(msg, ud);
|
||||
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->sendMessage(L_GET_CPP_PTR_FROM_C_OBJECT(msg));
|
||||
L_GET_PRIVATE_FROM_C_OBJECT(cr)->sendMessage(L_GET_CPP_PTR_FROM_C_OBJECT(msg));
|
||||
}
|
||||
|
||||
void linphone_chat_room_send_chat_message_2 (LinphoneChatRoom *cr, LinphoneChatMessage *msg) {
|
||||
linphone_chat_message_ref(msg);
|
||||
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->sendMessage(L_GET_CPP_PTR_FROM_C_OBJECT(msg));
|
||||
L_GET_PRIVATE_FROM_C_OBJECT(cr)->sendMessage(L_GET_CPP_PTR_FROM_C_OBJECT(msg));
|
||||
}
|
||||
|
||||
void linphone_chat_room_send_chat_message (LinphoneChatRoom *cr, LinphoneChatMessage *msg) {
|
||||
L_GET_CPP_PTR_FROM_C_OBJECT(cr)->sendMessage(L_GET_CPP_PTR_FROM_C_OBJECT(msg));
|
||||
L_GET_PRIVATE_FROM_C_OBJECT(cr)->sendMessage(L_GET_CPP_PTR_FROM_C_OBJECT(msg));
|
||||
}
|
||||
|
||||
uint32_t linphone_chat_room_get_char (const LinphoneChatRoom *cr) {
|
||||
|
|
|
|||
|
|
@ -1420,7 +1420,7 @@ void ChatMessage::updateState(State state) {
|
|||
d->chatRoom->getPrivate()->moveTransientMessageToWeakMessages(getSharedFromThis());
|
||||
}
|
||||
|
||||
void ChatMessage::reSend() {
|
||||
void ChatMessage::send () {
|
||||
L_D();
|
||||
|
||||
if (d->state != State::NotDelivered) {
|
||||
|
|
@ -1428,7 +1428,7 @@ void ChatMessage::reSend() {
|
|||
return;
|
||||
}
|
||||
|
||||
d->chatRoom->sendMessage(getSharedFromThis());
|
||||
d->chatRoom->getPrivate()->sendMessage(getSharedFromThis());
|
||||
}
|
||||
|
||||
void ChatMessage::sendDeliveryNotification(LinphoneReason reason) {
|
||||
|
|
|
|||
|
|
@ -61,18 +61,18 @@ public:
|
|||
void cancelFileTransfer ();
|
||||
int putCharacter (uint32_t character);
|
||||
void updateState (State state);
|
||||
void reSend ();
|
||||
void sendDeliveryNotification (LinphoneReason reason);
|
||||
void sendDisplayNotification ();
|
||||
void setImdnMessageId (const std::string &imdnMessageId);
|
||||
void setIsSecured (bool isSecured);
|
||||
void setFromAddress (Address from);
|
||||
void setToAddress (Address to);
|
||||
void store ();
|
||||
// ----- TODO: Remove me.
|
||||
|
||||
std::shared_ptr<ChatRoom> getChatRoom () const;
|
||||
|
||||
void store ();
|
||||
void send ();
|
||||
|
||||
time_t getTime () const;
|
||||
|
||||
|
|
|
|||
|
|
@ -45,13 +45,13 @@ private:
|
|||
static int createChatMessageFromDb (void *data, int argc, char **argv, char **colName);
|
||||
|
||||
public:
|
||||
void addTransientMessage (std::shared_ptr<ChatMessage> msg);
|
||||
void addWeakMessage (std::shared_ptr<ChatMessage> msg);
|
||||
void addTransientMessage (const std::shared_ptr<ChatMessage> &msg);
|
||||
void addWeakMessage (const std::shared_ptr<ChatMessage> &msg);
|
||||
std::list<std::shared_ptr<ChatMessage> > getTransientMessages () const {
|
||||
return transientMessages;
|
||||
}
|
||||
void moveTransientMessageToWeakMessages (std::shared_ptr<ChatMessage> msg);
|
||||
void removeTransientMessage (std::shared_ptr<ChatMessage> msg);
|
||||
void moveTransientMessageToWeakMessages (const std::shared_ptr<ChatMessage> &msg);
|
||||
void removeTransientMessage (const std::shared_ptr<ChatMessage> &msg);
|
||||
|
||||
void release ();
|
||||
void sendImdn (const std::string &content, LinphoneReason reason);
|
||||
|
|
@ -59,6 +59,8 @@ public:
|
|||
int getMessagesCount (bool unreadOnly);
|
||||
void setState (ChatRoom::State newState);
|
||||
|
||||
virtual void sendMessage (const std::shared_ptr<ChatMessage> &msg);
|
||||
|
||||
protected:
|
||||
void sendIsComposingNotification ();
|
||||
|
||||
|
|
@ -68,21 +70,21 @@ protected:
|
|||
int sqlRequest (sqlite3 *db, const std::string &stmt);
|
||||
void sqlRequestMessage (sqlite3 *db, const std::string &stmt);
|
||||
std::list<std::shared_ptr<ChatMessage> > findMessages (const std::string &messageId);
|
||||
void storeOrUpdateMessage (std::shared_ptr<ChatMessage> msg);
|
||||
void storeOrUpdateMessage (const std::shared_ptr<ChatMessage> &msg);
|
||||
|
||||
public:
|
||||
LinphoneReason messageReceived (SalOp *op, const SalMessage *msg);
|
||||
void realtimeTextReceived (uint32_t character, LinphoneCall *call);
|
||||
|
||||
protected:
|
||||
void chatMessageReceived (std::shared_ptr<ChatMessage> msg);
|
||||
void chatMessageReceived (const std::shared_ptr<ChatMessage> &msg);
|
||||
void imdnReceived (const std::string &text);
|
||||
void isComposingReceived (const std::string &text);
|
||||
|
||||
private:
|
||||
void notifyChatMessageReceived (std::shared_ptr<ChatMessage> msg);
|
||||
void notifyChatMessageReceived (const std::shared_ptr<ChatMessage> &msg);
|
||||
void notifyStateChanged ();
|
||||
void notifyUndecryptableMessageReceived (std::shared_ptr<ChatMessage> msg);
|
||||
void notifyUndecryptableMessageReceived (const std::shared_ptr<ChatMessage> &msg);
|
||||
|
||||
private:
|
||||
/* IsComposingListener */
|
||||
|
|
|
|||
|
|
@ -51,18 +51,18 @@ int ChatRoomPrivate::createChatMessageFromDb (void *data, int argc, char **argv,
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void ChatRoomPrivate::addTransientMessage (shared_ptr<ChatMessage> msg) {
|
||||
void ChatRoomPrivate::addTransientMessage (const shared_ptr<ChatMessage> &msg) {
|
||||
auto iter = find(transientMessages.begin(), transientMessages.end(), msg);
|
||||
if (iter == transientMessages.end())
|
||||
transientMessages.push_back(msg);
|
||||
}
|
||||
|
||||
void ChatRoomPrivate::addWeakMessage (shared_ptr<ChatMessage> msg) {
|
||||
void ChatRoomPrivate::addWeakMessage (const shared_ptr<ChatMessage> &msg) {
|
||||
weak_ptr<ChatMessage> weakptr(msg);
|
||||
weakMessages.push_back(weakptr);
|
||||
}
|
||||
|
||||
void ChatRoomPrivate::moveTransientMessageToWeakMessages (shared_ptr<ChatMessage> msg) {
|
||||
void ChatRoomPrivate::moveTransientMessageToWeakMessages (const shared_ptr<ChatMessage> &msg) {
|
||||
auto iter = find(transientMessages.begin(), transientMessages.end(), msg);
|
||||
if (iter != transientMessages.end()) {
|
||||
/* msg is not transient anymore, we can remove it from our transient list and unref it */
|
||||
|
|
@ -73,7 +73,7 @@ void ChatRoomPrivate::moveTransientMessageToWeakMessages (shared_ptr<ChatMessage
|
|||
}
|
||||
}
|
||||
|
||||
void ChatRoomPrivate::removeTransientMessage (shared_ptr<ChatMessage> msg) {
|
||||
void ChatRoomPrivate::removeTransientMessage (const shared_ptr<ChatMessage> &msg) {
|
||||
auto iter = find(transientMessages.begin(), transientMessages.end(), msg);
|
||||
if (iter != transientMessages.end()) {
|
||||
transientMessages.erase(iter);
|
||||
|
|
@ -378,10 +378,27 @@ list<shared_ptr<ChatMessage> > ChatRoomPrivate::findMessages (const string &mess
|
|||
return result;
|
||||
}
|
||||
|
||||
void ChatRoomPrivate::storeOrUpdateMessage (shared_ptr<ChatMessage> msg) {
|
||||
void ChatRoomPrivate::storeOrUpdateMessage (const shared_ptr<ChatMessage> &msg) {
|
||||
msg->store();
|
||||
}
|
||||
|
||||
void ChatRoomPrivate::sendMessage (const shared_ptr<ChatMessage> &msg) {
|
||||
msg->getPrivate()->setDirection(ChatMessage::Direction::Outgoing);
|
||||
|
||||
/* Add to transient list */
|
||||
addTransientMessage(msg);
|
||||
|
||||
msg->getPrivate()->setTime(ms_time(0));
|
||||
msg->getPrivate()->send();
|
||||
|
||||
storeOrUpdateMessage(msg);
|
||||
|
||||
if (isComposing)
|
||||
isComposing = false;
|
||||
isComposingHandler.stopIdleTimer();
|
||||
isComposingHandler.stopRefreshTimer();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
LinphoneReason ChatRoomPrivate::messageReceived (SalOp *op, const SalMessage *salMsg) {
|
||||
|
|
@ -460,7 +477,7 @@ end:
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void ChatRoomPrivate::chatMessageReceived (shared_ptr<ChatMessage> msg) {
|
||||
void ChatRoomPrivate::chatMessageReceived (const shared_ptr<ChatMessage> &msg) {
|
||||
L_Q();
|
||||
if ((msg->getPrivate()->getContentType() != ContentType::Imdn) && (msg->getPrivate()->getContentType() != ContentType::ImIsComposing)) {
|
||||
notifyChatMessageReceived(msg);
|
||||
|
|
@ -481,7 +498,7 @@ void ChatRoomPrivate::isComposingReceived (const string &text) {
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void ChatRoomPrivate::notifyChatMessageReceived (shared_ptr<ChatMessage> msg) {
|
||||
void ChatRoomPrivate::notifyChatMessageReceived (const shared_ptr<ChatMessage> &msg) {
|
||||
L_Q();
|
||||
LinphoneChatRoom *cr = L_GET_C_BACK_PTR(q);
|
||||
if (!msg->getPrivate()->getText().empty()) {
|
||||
|
|
@ -504,7 +521,7 @@ void ChatRoomPrivate::notifyStateChanged () {
|
|||
cb(cr, (LinphoneChatRoomState)state);
|
||||
}
|
||||
|
||||
void ChatRoomPrivate::notifyUndecryptableMessageReceived (shared_ptr<ChatMessage> msg) {
|
||||
void ChatRoomPrivate::notifyUndecryptableMessageReceived (const shared_ptr<ChatMessage> &msg) {
|
||||
L_Q();
|
||||
LinphoneChatRoom *cr = L_GET_C_BACK_PTR(q);
|
||||
LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr);
|
||||
|
|
@ -598,7 +615,7 @@ void ChatRoom::deleteHistory () {
|
|||
if (d->unreadCount > 0) d->unreadCount = 0;
|
||||
}
|
||||
|
||||
void ChatRoom::deleteMessage (shared_ptr<ChatMessage> msg) {
|
||||
void ChatRoom::deleteMessage (const shared_ptr<ChatMessage> &msg) {
|
||||
L_D();
|
||||
if (!d->core->db) return;
|
||||
char *buf = sqlite3_mprintf("DELETE FROM history WHERE id = %u;", msg->getPrivate()->getStorageId());
|
||||
|
|
@ -734,25 +751,6 @@ void ChatRoom::markAsRead () {
|
|||
d->unreadCount = 0;
|
||||
}
|
||||
|
||||
void ChatRoom::sendMessage (shared_ptr<ChatMessage> msg) {
|
||||
L_D();
|
||||
|
||||
msg->getPrivate()->setDirection(ChatMessage::Direction::Outgoing);
|
||||
|
||||
/* Add to transient list */
|
||||
d->addTransientMessage(msg);
|
||||
|
||||
msg->getPrivate()->setTime(ms_time(0));
|
||||
msg->getPrivate()->send();
|
||||
|
||||
d->storeOrUpdateMessage(msg);
|
||||
|
||||
if (d->isComposing)
|
||||
d->isComposing = false;
|
||||
d->isComposingHandler.stopIdleTimer();
|
||||
d->isComposingHandler.stopRefreshTimer();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
LinphoneCore *ChatRoom::getCore () const {
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public:
|
|||
std::shared_ptr<ChatMessage> createMessage (const std::string &msg);
|
||||
std::shared_ptr<ChatMessage> createMessage ();
|
||||
void deleteHistory ();
|
||||
void deleteMessage (std::shared_ptr<ChatMessage> msg);
|
||||
void deleteMessage (const std::shared_ptr<ChatMessage> &msg);
|
||||
std::shared_ptr<ChatMessage> findMessage (const std::string& messageId);
|
||||
std::shared_ptr<ChatMessage> findMessageWithDirection (const std::string &messageId, ChatMessage::Direction direction);
|
||||
std::list<std::shared_ptr<ChatMessage> > getHistory (int nbMessages);
|
||||
|
|
@ -64,7 +64,6 @@ public:
|
|||
int getUnreadMessagesCount ();
|
||||
bool isRemoteComposing () const;
|
||||
void markAsRead ();
|
||||
virtual void sendMessage (std::shared_ptr<ChatMessage> msg);
|
||||
|
||||
LinphoneCore *getCore () const;
|
||||
|
||||
|
|
|
|||
|
|
@ -37,10 +37,10 @@ public:
|
|||
|
||||
public:
|
||||
void setCall (LinphoneCall *call) { this->call = call; }
|
||||
|
||||
public:
|
||||
void realtimeTextReceived (uint32_t character, LinphoneCall *call);
|
||||
|
||||
void sendMessage (const std::shared_ptr<ChatMessage> &msg) override;
|
||||
|
||||
public:
|
||||
LinphoneCall *call = nullptr;
|
||||
std::list<LinphoneChatMessageCharacter *> receivedRttCharacters;
|
||||
|
|
|
|||
|
|
@ -100,20 +100,17 @@ void RealTimeTextChatRoomPrivate::realtimeTextReceived (uint32_t character, Linp
|
|||
}
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
|
||||
RealTimeTextChatRoom::RealTimeTextChatRoom (LinphoneCore *core, const Address &peerAddress) : ChatRoom(*new RealTimeTextChatRoomPrivate(core, peerAddress)) {}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void RealTimeTextChatRoom::sendMessage (std::shared_ptr<ChatMessage> msg) {
|
||||
L_D();
|
||||
if (d->call && linphone_call_params_realtime_text_enabled(linphone_call_get_current_params(d->call))) {
|
||||
void RealTimeTextChatRoomPrivate::sendMessage (const std::shared_ptr<ChatMessage> &msg) {
|
||||
if (call && linphone_call_params_realtime_text_enabled(linphone_call_get_current_params(call))) {
|
||||
uint32_t new_line = 0x2028;
|
||||
msg->putCharacter(new_line);
|
||||
}
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
|
||||
RealTimeTextChatRoom::RealTimeTextChatRoom (LinphoneCore *core, const Address &peerAddress) : ChatRoom(*new RealTimeTextChatRoomPrivate(core, peerAddress)) {}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
uint32_t RealTimeTextChatRoom::getChar () const {
|
||||
|
|
|
|||
|
|
@ -38,8 +38,6 @@ public:
|
|||
RealTimeTextChatRoom (LinphoneCore *core, const Address &peerAddress);
|
||||
virtual ~RealTimeTextChatRoom () = default;
|
||||
|
||||
void sendMessage (std::shared_ptr<ChatMessage> msg) override;
|
||||
|
||||
uint32_t getChar () const;
|
||||
LinphoneCall *getCall () const;
|
||||
|
||||
|
|
|
|||
|
|
@ -257,7 +257,7 @@ static void parse_rfc_example () {
|
|||
|
||||
const string str2 = message->asString();
|
||||
BC_ASSERT_STRING_EQUAL(str2.c_str(), str.c_str());
|
||||
|
||||
|
||||
string content = message->getContent();
|
||||
BC_ASSERT_STRING_EQUAL(content.c_str(), body.c_str());
|
||||
}
|
||||
|
|
@ -283,7 +283,7 @@ static void parse_message_with_generic_header_parameters () {
|
|||
|
||||
const string str2 = message->asString();
|
||||
BC_ASSERT_STRING_EQUAL(str2.c_str(), str.c_str());
|
||||
|
||||
|
||||
string content = message->getContent();
|
||||
BC_ASSERT_STRING_EQUAL(content.c_str(), body.c_str());
|
||||
}
|
||||
|
|
@ -346,7 +346,7 @@ static void build_message () {
|
|||
if (!BC_ASSERT_TRUE(contentTypeHeader.setName("Content-Type"))) return;
|
||||
if (!BC_ASSERT_TRUE( contentTypeHeader.setValue("text/xml; charset=utf-8"))) return;
|
||||
if (!BC_ASSERT_TRUE(message.addContentHeader(contentTypeHeader))) return;
|
||||
|
||||
|
||||
Cpim::GenericHeader contentIdHeader;
|
||||
if (!BC_ASSERT_TRUE(contentIdHeader.setName("Content-ID"))) return;
|
||||
if (!BC_ASSERT_TRUE( contentIdHeader.setValue("<1234567890@foo.com>"))) return;
|
||||
|
|
@ -398,11 +398,11 @@ static void cpim_chat_message_modifier_base(bool_t use_multipart) {
|
|||
content.setBody("Hello Part 2");
|
||||
marieMessage->addContent(content);
|
||||
}
|
||||
marieRoom->sendMessage(marieMessage);
|
||||
marieMessage->send();
|
||||
|
||||
BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneMessageReceived,1));
|
||||
BC_ASSERT_TRUE(marieMessage->getInternalContent().getContentType() == ContentType::Cpim);
|
||||
|
||||
|
||||
BC_ASSERT_PTR_NOT_NULL(pauline->stat.last_received_chat_message);
|
||||
if (pauline->stat.last_received_chat_message != NULL) {
|
||||
BC_ASSERT_STRING_EQUAL(linphone_chat_message_get_text(pauline->stat.last_received_chat_message), "Hello CPIM");
|
||||
|
|
|
|||
|
|
@ -51,11 +51,11 @@ static void chat_message_multipart_modifier_base(bool first_file_transfer, bool
|
|||
content.setBody("Hello Part 2");
|
||||
marieMessage->addContent(content);
|
||||
}
|
||||
marieRoom->sendMessage(marieMessage);
|
||||
marieMessage->send();
|
||||
|
||||
BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneMessageReceived,1));
|
||||
BC_ASSERT_STRING_EQUAL(marieMessage->getInternalContent().getContentType().asString().c_str(), "multipart/mixed");
|
||||
|
||||
|
||||
BC_ASSERT_PTR_NOT_NULL(pauline->stat.last_received_chat_message);
|
||||
//TODO
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue