From 87ca435ad7522aa02be180022a48c52d7a8f4482 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Tue, 12 Dec 2017 15:15:58 +0100 Subject: [PATCH] fix(ChatRoom): clean code (again) --- src/chat/chat-room/chat-room.cpp | 40 ++++++++++++-------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/src/chat/chat-room/chat-room.cpp b/src/chat/chat-room/chat-room.cpp index 97f783499..24ccccac7 100644 --- a/src/chat/chat-room/chat-room.cpp +++ b/src/chat/chat-room/chat-room.cpp @@ -244,22 +244,22 @@ end: void ChatRoomPrivate::onChatMessageReceived (const shared_ptr &chatMessage) { L_Q(); - if ((chatMessage->getPrivate()->getContentType() != ContentType::Imdn) && (chatMessage->getPrivate()->getContentType() != ContentType::ImIsComposing)) { + ContentType contentType = chatMessage->getPrivate()->getContentType(); + if (contentType != ContentType::Imdn && contentType != ContentType::ImIsComposing) { onChatMessageReceived(chatMessage); - LinphoneChatRoom *cr = L_GET_C_BACK_PTR(q); - LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr); + LinphoneChatRoom *chatRoom = L_GET_C_BACK_PTR(q); + LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(chatRoom); LinphoneChatRoomCbsParticipantAddedCb cb = linphone_chat_room_cbs_get_chat_message_received(cbs); shared_ptr event = make_shared(time(nullptr), chatMessage); - if (cb) { - cb(cr, L_GET_C_BACK_PTR(event)); - } + if (cb) + cb(chatRoom, L_GET_C_BACK_PTR(event)); // Legacy notifyChatMessageReceived(chatMessage); - const string fromAddress = chatMessage->getFromAddress().asString(); - isComposingHandler->stopRemoteRefreshTimer(fromAddress); - notifyIsComposingReceived(chatMessage->getFromAddress(), false); + const IdentityAddress &fromAddress = chatMessage->getFromAddress(); + isComposingHandler->stopRemoteRefreshTimer(fromAddress.asString()); + notifyIsComposingReceived(fromAddress, false); chatMessage->sendDeliveryNotification(LinphoneReasonNone); } } @@ -410,25 +410,16 @@ shared_ptr ChatRoom::createFileTransferMessage (const LinphoneConte shared_ptr ChatRoom::findChatMessage (const string &messageId) const { L_D(); - shared_ptr cm = nullptr; - list > l = d->findChatMessages(messageId); - if (!l.empty()) { - cm = l.front(); - } - return cm; + list> chatMessages = d->findChatMessages(messageId); + return chatMessages.empty() ? nullptr : chatMessages.front(); } shared_ptr ChatRoom::findChatMessage (const string &messageId, ChatMessage::Direction direction) const { L_D(); - shared_ptr ret = nullptr; - list > l = d->findChatMessages(messageId); - for (auto &message : l) { - if (message->getDirection() == direction) { - ret = message; - break; - } - } - return ret; + for (auto &chatMessage : d->findChatMessages(messageId)) + if (chatMessage->getDirection() == direction) + return chatMessage; + return nullptr; } void ChatRoom::markAsRead () { @@ -438,7 +429,6 @@ void ChatRoom::markAsRead () { return; CorePrivate *dCore = getCore()->getPrivate(); - const string peerAddress = getPeerAddress().asString(); for (auto &chatMessage : dCore->mainDb->getUnreadChatMessages(d->chatRoomId)) chatMessage->sendDisplayNotification();