forked from mirrors/linphone-iphone
Added new chat room callback to let app decides whether or not store chat message in database
This commit is contained in:
parent
997496ffa9
commit
b5b6ef4545
6 changed files with 42 additions and 26 deletions
|
|
@ -249,6 +249,13 @@ typedef void (*LinphoneChatRoomCbsParticipantDeviceFetchedCb) (LinphoneChatRoom
|
|||
*/
|
||||
typedef void (*LinphoneChatRoomCbsParticipantsCapabilitiesCheckedCb) (LinphoneChatRoom *cr, const LinphoneAddress *deviceAddr, const bctbx_list_t *participantsAddr);
|
||||
|
||||
/**
|
||||
* Callback used to tell the core whether or not to store the incoming message in db or not using linphone_chat_message_set_to_be_stored().
|
||||
* @param[in] cr #LinphoneChatRoom object
|
||||
* @param[in] msg The #LinphoneChatMessage that is being received
|
||||
*/
|
||||
typedef void (*LinphoneChatRoomCbsShouldChatMessageBeStoredCb) (LinphoneChatRoom *cr, LinphoneChatMessage *msg);
|
||||
|
||||
/**
|
||||
* @}
|
||||
**/
|
||||
|
|
|
|||
|
|
@ -271,6 +271,19 @@ LINPHONE_PUBLIC LinphoneChatRoomCbsParticipantsCapabilitiesCheckedCb linphone_ch
|
|||
*/
|
||||
LINPHONE_PUBLIC void linphone_chat_room_cbs_set_participants_capabilities_checked (LinphoneChatRoomCbs *cbs, LinphoneChatRoomCbsParticipantsCapabilitiesCheckedCb cb);
|
||||
|
||||
/**
|
||||
* Get the message should be stored callback.
|
||||
* @param[in] cbs LinphoneChatRoomCbs object
|
||||
* @return The message should be stored getting callback
|
||||
*/
|
||||
LINPHONE_PUBLIC LinphoneChatRoomCbsShouldChatMessageBeStoredCb linphone_chat_room_cbs_get_chat_message_should_be_stored( LinphoneChatRoomCbs *cbs);
|
||||
/**
|
||||
* Set the message should be stored callback.
|
||||
* @param[in] cbs LinphoneChatRoomCbs object
|
||||
* @param[in] cb The message should be stored callback to be used
|
||||
*/
|
||||
LINPHONE_PUBLIC void linphone_chat_room_cbs_set_chat_message_should_be_stored( LinphoneChatRoomCbs *cbs, LinphoneChatRoomCbsShouldChatMessageBeStoredCb cb);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ struct _LinphoneChatRoomCbs {
|
|||
LinphoneChatRoomCbsConferenceAddressGenerationCb conferenceAddressGenerationCb;
|
||||
LinphoneChatRoomCbsParticipantDeviceFetchedCb participantDeviceFetchedCb;
|
||||
LinphoneChatRoomCbsParticipantsCapabilitiesCheckedCb participantsCapabilitiesChecked;
|
||||
LinphoneChatRoomCbsShouldChatMessageBeStoredCb shouldMessageBeStoredCb;
|
||||
};
|
||||
|
||||
BELLE_SIP_DECLARE_VPTR_NO_EXPORT(LinphoneChatRoomCbs);
|
||||
|
|
@ -196,3 +197,11 @@ LinphoneChatRoomCbsParticipantsCapabilitiesCheckedCb linphone_chat_room_cbs_get_
|
|||
void linphone_chat_room_cbs_set_participants_capabilities_checked (LinphoneChatRoomCbs *cbs, LinphoneChatRoomCbsParticipantsCapabilitiesCheckedCb cb) {
|
||||
cbs->participantsCapabilitiesChecked = cb;
|
||||
}
|
||||
|
||||
LinphoneChatRoomCbsShouldChatMessageBeStoredCb linphone_chat_room_cbs_get_chat_message_should_be_stored( LinphoneChatRoomCbs *cbs) {
|
||||
return cbs->shouldMessageBeStoredCb;
|
||||
}
|
||||
|
||||
void linphone_chat_room_cbs_set_chat_message_should_be_stored( LinphoneChatRoomCbs *cbs, LinphoneChatRoomCbsShouldChatMessageBeStoredCb cb) {
|
||||
cbs->shouldMessageBeStoredCb = cb;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -401,18 +401,23 @@ void ChatMessagePrivate::notifyReceiving () {
|
|||
|
||||
LinphoneChatRoom *chatRoom = L_GET_C_BACK_PTR(q->getChatRoom());
|
||||
LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(chatRoom);
|
||||
LinphoneChatRoomCbsParticipantAddedCb cb = linphone_chat_room_cbs_get_chat_message_received(cbs);
|
||||
shared_ptr<ConferenceChatMessageEvent> event = make_shared<ConferenceChatMessageEvent>(
|
||||
::time(nullptr), q->getSharedFromThis()
|
||||
);
|
||||
if (cb)
|
||||
cb(chatRoom, L_GET_C_BACK_PTR(event));
|
||||
// Legacy
|
||||
q->getChatRoom()->getPrivate()->notifyChatMessageReceived(q->getSharedFromThis());
|
||||
|
||||
LinphoneChatRoomCbsShouldChatMessageBeStoredCb shouldMessageBeStoredCb = linphone_chat_room_cbs_get_chat_message_should_be_stored(cbs);
|
||||
if (shouldMessageBeStoredCb)
|
||||
shouldMessageBeStoredCb(chatRoom, L_GET_C_BACK_PTR(q->getSharedFromThis()));
|
||||
|
||||
if (toBeStored)
|
||||
storeInDb();
|
||||
|
||||
shared_ptr<ConferenceChatMessageEvent> event = make_shared<ConferenceChatMessageEvent>(
|
||||
::time(nullptr), q->getSharedFromThis()
|
||||
);
|
||||
LinphoneChatRoomCbsChatMessageReceivedCb messageReceivedCb = linphone_chat_room_cbs_get_chat_message_received(cbs);
|
||||
if (messageReceivedCb)
|
||||
messageReceivedCb(chatRoom, L_GET_C_BACK_PTR(event));
|
||||
// Legacy
|
||||
q->getChatRoom()->getPrivate()->notifyChatMessageReceived(q->getSharedFromThis());
|
||||
|
||||
q->sendDeliveryNotification(LinphoneReasonNone);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -78,7 +78,6 @@ private:
|
|||
time_t creationTime = std::time(nullptr);
|
||||
time_t lastUpdateTime = std::time(nullptr);
|
||||
|
||||
std::shared_ptr<ChatMessage> pendingMessage;
|
||||
std::unique_ptr<IsComposing> isComposingHandler;
|
||||
|
||||
bool isComposing = false;
|
||||
|
|
|
|||
|
|
@ -189,7 +189,6 @@ void ChatRoomPrivate::notifyUndecryptableChatMessageReceived (const shared_ptr<C
|
|||
LinphoneReason ChatRoomPrivate::onSipMessageReceived (SalOp *op, const SalMessage *message) {
|
||||
L_Q();
|
||||
|
||||
bool increaseMsgCount = true;
|
||||
LinphoneReason reason = LinphoneReasonNone;
|
||||
shared_ptr<ChatMessage> msg;
|
||||
|
||||
|
|
@ -224,29 +223,18 @@ LinphoneReason ChatRoomPrivate::onSipMessageReceived (SalOp *op, const SalMessag
|
|||
|
||||
if (msg->getPrivate()->getContentType() == ContentType::ImIsComposing) {
|
||||
onIsComposingReceived(msg->getFromAddress(), msg->getPrivate()->getText());
|
||||
increaseMsgCount = FALSE;
|
||||
if (lp_config_get_int(linphone_core_get_config(cCore), "sip", "deliver_imdn", 0) != 1) {
|
||||
goto end;
|
||||
}
|
||||
} else if (msg->getPrivate()->getContentType() == ContentType::Imdn) {
|
||||
onImdnReceived(msg->getPrivate()->getText());
|
||||
increaseMsgCount = FALSE;
|
||||
if (lp_config_get_int(linphone_core_get_config(cCore), "sip", "deliver_imdn", 0) != 1) {
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
if (increaseMsgCount) {
|
||||
/* Mark the message as pending so that if ChatRoom::markAsRead() is called in the
|
||||
* ChatRoomPrivate::chatMessageReceived() callback, it will effectively be marked as
|
||||
* being read before being stored. */
|
||||
pendingMessage = msg;
|
||||
}
|
||||
|
||||
onChatMessageReceived(msg);
|
||||
|
||||
pendingMessage = nullptr;
|
||||
|
||||
end:
|
||||
return reason;
|
||||
}
|
||||
|
|
@ -438,11 +426,6 @@ void ChatRoom::markAsRead () {
|
|||
chatMessage->sendDisplayNotification();
|
||||
|
||||
dCore->mainDb->markChatMessagesAsRead(d->chatRoomId);
|
||||
|
||||
if (d->pendingMessage) {
|
||||
d->pendingMessage->updateState(ChatMessage::State::Displayed);
|
||||
d->pendingMessage->sendDisplayNotification();
|
||||
}
|
||||
}
|
||||
|
||||
LINPHONE_END_NAMESPACE
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue