mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-01-17 11:28:07 +00:00
Fix message order and remove local timestamp received.
This commit is contained in:
parent
b240ccda9a
commit
b8d3e0d382
7 changed files with 53 additions and 50 deletions
|
|
@ -72,8 +72,17 @@ void ChatMessageModel::connectTo(ChatMessageListener * listener){
|
|||
}
|
||||
// =============================================================================
|
||||
|
||||
ChatMessageModel::ChatMessageModel ( std::shared_ptr<linphone::ChatMessage> chatMessage, QObject * parent) : ChatEvent(ChatRoomModel::EntryType::MessageEntry, parent) {
|
||||
ChatMessageModel::ChatMessageModel (const std::shared_ptr<linphone::ChatMessage>& chatMessage, const std::shared_ptr<const linphone::EventLog>& chatMessageLog, QObject * parent) : ChatEvent(ChatRoomModel::EntryType::MessageEntry, parent) {
|
||||
App::getInstance()->getEngine()->setObjectOwnership(this, QQmlEngine::CppOwnership);// Avoid QML to destroy it
|
||||
init(chatMessage, chatMessageLog);
|
||||
}
|
||||
|
||||
ChatMessageModel::~ChatMessageModel(){
|
||||
if(mChatMessage)
|
||||
mChatMessage->removeListener(mChatMessageListener);
|
||||
}
|
||||
|
||||
void ChatMessageModel::init(const std::shared_ptr<linphone::ChatMessage>& chatMessage, const std::shared_ptr<const linphone::EventLog>& chatMessageLog){
|
||||
if(chatMessage){
|
||||
mParticipantImdnStateListModel = QSharedPointer<ParticipantImdnStateListModel>::create(chatMessage);
|
||||
mChatMessageListener = std::make_shared<ChatMessageListener>();
|
||||
|
|
@ -83,7 +92,7 @@ ChatMessageModel::ChatMessageModel ( std::shared_ptr<linphone::ChatMessage> chat
|
|||
if( mChatMessage->isReply()){
|
||||
auto replyMessage = mChatMessage->getReplyMessage();
|
||||
if( replyMessage)// Reply message could be inexistant (for example : when locally deleted)
|
||||
mReplyChatMessageModel = create(replyMessage, parent);
|
||||
mReplyChatMessageModel = create(replyMessage, this->parent());
|
||||
}
|
||||
std::list<std::shared_ptr<linphone::Content>> contents = chatMessage->getContents();
|
||||
QString txt;
|
||||
|
|
@ -94,7 +103,10 @@ ChatMessageModel::ChatMessageModel ( std::shared_ptr<linphone::ChatMessage> chat
|
|||
mContent = txt;
|
||||
|
||||
mTimestamp = QDateTime::fromMSecsSinceEpoch(chatMessage->getTime() * 1000);
|
||||
mReceivedTimestamp = ChatMessageModel::initReceivedTimestamp(chatMessage, false);
|
||||
if(chatMessageLog)
|
||||
mReceivedTimestamp = QDateTime::fromMSecsSinceEpoch(chatMessageLog->getCreationTime() * 1000);
|
||||
else
|
||||
mReceivedTimestamp = mTimestamp;
|
||||
}
|
||||
mWasDownloaded = false;
|
||||
|
||||
|
|
@ -102,12 +114,13 @@ ChatMessageModel::ChatMessageModel ( std::shared_ptr<linphone::ChatMessage> chat
|
|||
mChatReactionListModel = QSharedPointer<ChatReactionListModel>::create(this);
|
||||
}
|
||||
|
||||
ChatMessageModel::~ChatMessageModel(){
|
||||
if(mChatMessage)
|
||||
mChatMessage->removeListener(mChatMessageListener);
|
||||
QSharedPointer<ChatMessageModel> ChatMessageModel::create(const std::shared_ptr<const linphone::EventLog>& chatMessageLog, QObject * parent){
|
||||
auto model = QSharedPointer<ChatMessageModel>::create(chatMessageLog->getChatMessage(), chatMessageLog, parent);
|
||||
return model;
|
||||
}
|
||||
QSharedPointer<ChatMessageModel> ChatMessageModel::create(std::shared_ptr<linphone::ChatMessage> chatMessage, QObject * parent){
|
||||
auto model = QSharedPointer<ChatMessageModel>::create(chatMessage, parent);
|
||||
|
||||
QSharedPointer<ChatMessageModel> ChatMessageModel::create(const std::shared_ptr<linphone::ChatMessage>& chatMessage, QObject * parent){
|
||||
auto model = QSharedPointer<ChatMessageModel>::create(chatMessage, nullptr, parent);
|
||||
return model;
|
||||
}
|
||||
|
||||
|
|
@ -288,16 +301,6 @@ void ChatMessageModel::updateFileTransferInformation(){
|
|||
mContentListModel->updateContents(this);
|
||||
}
|
||||
|
||||
QDateTime ChatMessageModel::initReceivedTimestamp(const std::shared_ptr<linphone::ChatMessage> &message, bool isNew, bool force){
|
||||
auto appdata = ChatEvent::AppDataManager(QString::fromStdString(message->getAppdata()));
|
||||
if(force || !appdata.mData.contains("receivedTime")){// If already set : Do not overwrite.
|
||||
appdata.mData["receivedTime"] = QString::number(isNew ? QDateTime::currentMSecsSinceEpoch() : message->getTime()*1000);
|
||||
qDebug() << (isNew ? "New" : "Old") << " message received at " << QDateTime::fromMSecsSinceEpoch(appdata.mData["receivedTime"].toLongLong()).toString("yyyy/MM/dd hh:mm:ss.zzz") << QDateTime::fromMSecsSinceEpoch(message->getTime()*1000).toString("yyyy/MM/dd hh:mm:ss.zzz");
|
||||
message->setAppdata(Utils::appStringToCoreString(appdata.toString()));
|
||||
}
|
||||
return QDateTime::fromMSecsSinceEpoch(appdata.mData["receivedTime"].toLongLong());
|
||||
}
|
||||
|
||||
void ChatMessageModel::onFileTransferRecv(const std::shared_ptr<linphone::ChatMessage> & message, const std::shared_ptr<linphone::Content> & content, const std::shared_ptr<const linphone::Buffer> & buffer){
|
||||
}
|
||||
void ChatMessageModel::onFileTransferSendChunk(const std::shared_ptr<linphone::ChatMessage> & message, const std::shared_ptr<linphone::Content> & content, size_t offset, size_t size, const std::shared_ptr<linphone::Buffer> & buffer) {
|
||||
|
|
|
|||
|
|
@ -44,10 +44,13 @@ class ContentProxyModel;
|
|||
class ChatMessageModel : public ChatEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
static QSharedPointer<ChatMessageModel> create(std::shared_ptr<linphone::ChatMessage> chatMessage, QObject * parent = nullptr);// Call it instead constructor
|
||||
ChatMessageModel (std::shared_ptr<linphone::ChatMessage> chatMessage, QObject * parent = nullptr);
|
||||
static QSharedPointer<ChatMessageModel> create(const std::shared_ptr<const linphone::EventLog>& chatMessageLog, QObject * parent = nullptr);// Call it instead constructor
|
||||
static QSharedPointer<ChatMessageModel> create(const std::shared_ptr<linphone::ChatMessage>& chatMessage, QObject * parent = nullptr);// Call it instead constructor
|
||||
ChatMessageModel (const std::shared_ptr<linphone::ChatMessage>& chatMessage, const std::shared_ptr<const linphone::EventLog>& chatMessageLog, QObject * parent = nullptr);
|
||||
virtual ~ChatMessageModel();
|
||||
|
||||
void init(const std::shared_ptr<linphone::ChatMessage>& chatMessage, const std::shared_ptr<const linphone::EventLog>& chatMessageLog);
|
||||
|
||||
Q_PROPERTY(QString fromDisplayName READ getFromDisplayName CONSTANT)
|
||||
Q_PROPERTY(QString fromDisplayNameReplyMessage READ getFromDisplayNameReplyMessage CONSTANT)
|
||||
Q_PROPERTY(QString fromSipAddress READ getFromSipAddress CONSTANT)
|
||||
|
|
@ -119,7 +122,6 @@ public:
|
|||
|
||||
virtual void deleteEvent() override;
|
||||
void updateFileTransferInformation();
|
||||
static QDateTime initReceivedTimestamp(const std::shared_ptr<linphone::ChatMessage> &message, bool isNew, bool force = false); // return received timestamp
|
||||
|
||||
// Linphone callbacks
|
||||
void onFileTransferRecv(const std::shared_ptr<linphone::ChatMessage> & message, const std::shared_ptr<linphone::Content> & content, const std::shared_ptr<const linphone::Buffer> & buffer) ;
|
||||
|
|
|
|||
|
|
@ -785,7 +785,7 @@ public:
|
|||
itEntries = entries.begin();
|
||||
for(; itEntries != entries.end() ; ++itEntries){
|
||||
if( (*itEntries).mType== ChatRoomModel::EntryType::MessageEntry)
|
||||
*resultEntries << ChatMessageModel::create(std::dynamic_pointer_cast<linphone::ChatMessage>(itEntries->mObject));
|
||||
*resultEntries << ChatMessageModel::create(std::dynamic_pointer_cast<linphone::EventLog>(itEntries->mObject));
|
||||
else if( (*itEntries).mType == ChatRoomModel::EntryType::CallEntry) {
|
||||
auto entry = ChatCallModel::create(std::dynamic_pointer_cast<linphone::CallLog>(itEntries->mObject), true);
|
||||
if(entry) {
|
||||
|
|
@ -817,10 +817,11 @@ void ChatRoomModel::updateNewMessageNotice(const int& count){
|
|||
QDateTime lastReceivedMessage = lastUnreadMessage;
|
||||
enableMarkAsRead(false);
|
||||
// Get chat messages
|
||||
for (auto &message : mChatRoom->getHistory(mLastEntriesStep)) {
|
||||
if( !message->isRead()) {
|
||||
for (auto &messageLog : mChatRoom->getHistoryMessageEvents(mLastEntriesStep)) {
|
||||
auto message = messageLog->getChatMessage();
|
||||
if( message && !message->isRead()) {
|
||||
lastUnreadMessage = min(lastUnreadMessage, QDateTime::fromMSecsSinceEpoch(message->getTime() * 1000 - 1 )); //-1 to be sure that event will be before the message
|
||||
lastReceivedMessage = min(lastReceivedMessage, ChatMessageModel::initReceivedTimestamp(message, false).addMSecs(-1));
|
||||
lastReceivedMessage = min(lastReceivedMessage, QDateTime::fromMSecsSinceEpoch(messageLog->getCreationTime() * 1000 - 1));
|
||||
}
|
||||
}
|
||||
mUnreadMessageNotice = ChatNoticeModel::create(ChatNoticeModel::NoticeType::NoticeUnreadMessages, lastUnreadMessage,lastReceivedMessage, QString::number(count));
|
||||
|
|
@ -936,8 +937,8 @@ void ChatRoomModel::initEntries(){
|
|||
QList<QSharedPointer<ChatEvent> > entries;
|
||||
QList<EntrySorterHelper> prepareEntries;
|
||||
// Get chat messages
|
||||
for (auto &message : mChatRoom->getHistory(mFirstLastEntriesStep)) {
|
||||
prepareEntries << EntrySorterHelper(ChatMessageModel::initReceivedTimestamp(message, false).toTime_t() ,MessageEntry, message);
|
||||
for (auto &messageLog : mChatRoom->getHistoryMessageEvents(mFirstLastEntriesStep)) {
|
||||
prepareEntries << EntrySorterHelper(messageLog->getCreationTime() ,MessageEntry, messageLog);
|
||||
}
|
||||
// Get events
|
||||
for(auto &eventLog : mChatRoom->getHistoryEvents(mFirstLastEntriesStep))
|
||||
|
|
@ -994,7 +995,8 @@ int ChatRoomModel::loadMoreEntries(){
|
|||
}
|
||||
|
||||
// Messages
|
||||
for (auto &message : mChatRoom->getHistoryRange(entriesCounts[0], entriesCounts[0]+mLastEntriesStep)){
|
||||
for (auto &messageLog : mChatRoom->getHistoryRangeMessageEvents(entriesCounts[0], entriesCounts[0]+mLastEntriesStep)){
|
||||
auto message = messageLog->getChatMessage();
|
||||
auto itEntries = mList.begin();
|
||||
bool haveEntry = false;
|
||||
while(!haveEntry && itEntries != mList.end()){
|
||||
|
|
@ -1003,7 +1005,7 @@ int ChatRoomModel::loadMoreEntries(){
|
|||
++itEntries;
|
||||
}
|
||||
if(!haveEntry)
|
||||
prepareEntries << EntrySorterHelper(ChatMessageModel::initReceivedTimestamp(message, false).toTime_t() ,MessageEntry, message);
|
||||
prepareEntries << EntrySorterHelper(messageLog->getCreationTime() ,MessageEntry, messageLog);
|
||||
}
|
||||
|
||||
// Notices
|
||||
|
|
@ -1052,12 +1054,12 @@ void ChatRoomModel::onCallEnded(std::shared_ptr<linphone::Call> call){
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
QSharedPointer<ChatMessageModel> ChatRoomModel::insertMessageAtEnd (const std::shared_ptr<linphone::ChatMessage> &message) {
|
||||
QSharedPointer<ChatMessageModel> ChatRoomModel::insertMessageAtEnd (const std::shared_ptr<const linphone::EventLog> &messageLog) {
|
||||
QSharedPointer<ChatMessageModel> model;
|
||||
if(mIsInitialized && !exists(message)){
|
||||
model = ChatMessageModel::create(message);
|
||||
if(mIsInitialized && !exists(messageLog->getChatMessage())){
|
||||
model = ChatMessageModel::create(messageLog);
|
||||
if(model){
|
||||
qDebug() << "Adding at end" << model->getReceivedTimestamp().toString("hh:mm:ss.zzz") << model->getTimestamp().toString("hh:mm:ss.zzz") << QString(message->getUtf8Text().c_str()).left(5);
|
||||
qDebug() << "Adding at end" << model->getReceivedTimestamp().toString("hh:mm:ss.zzz") << model->getTimestamp().toString("hh:mm:ss.zzz") << QString(messageLog->getChatMessage()->getUtf8Text().c_str()).left(5);
|
||||
connect(model.get(), &ChatMessageModel::remove, this, &ChatRoomModel::removeEntry);
|
||||
emit unreadMessagesCountChanged();
|
||||
add(model);
|
||||
|
|
@ -1066,11 +1068,11 @@ QSharedPointer<ChatMessageModel> ChatRoomModel::insertMessageAtEnd (const std::s
|
|||
return model;
|
||||
}
|
||||
|
||||
void ChatRoomModel::insertMessages (const QList<std::shared_ptr<linphone::ChatMessage> > &messages) {
|
||||
void ChatRoomModel::insertMessages (const QList<std::shared_ptr<const linphone::EventLog> > &messageLogs) {
|
||||
if(mIsInitialized){
|
||||
QList<QSharedPointer<QObject> > entries;
|
||||
for(auto message : messages) {
|
||||
QSharedPointer<ChatMessageModel> model = ChatMessageModel::create(message);
|
||||
for(auto messageLog : messageLogs) {
|
||||
QSharedPointer<ChatMessageModel> model = ChatMessageModel::create(messageLog);
|
||||
if(model){
|
||||
connect(model.get(), &ChatMessageModel::remove, this, &ChatRoomModel::removeEntry);
|
||||
entries << model;
|
||||
|
|
@ -1169,14 +1171,11 @@ void ChatRoomModel::onIsComposingReceived(const std::shared_ptr<linphone::ChatRo
|
|||
}
|
||||
|
||||
void ChatRoomModel::onMessageReceived(const std::shared_ptr<linphone::ChatRoom> & chatRoom, const std::shared_ptr<linphone::ChatMessage> & message){
|
||||
if(message) ChatMessageModel::initReceivedTimestamp(message, true);
|
||||
emit unreadMessagesCountChanged();
|
||||
updateLastUpdateTime();
|
||||
}
|
||||
|
||||
void ChatRoomModel::onMessagesReceived(const std::shared_ptr<linphone::ChatRoom> & chatRoom, const std::list<std::shared_ptr<linphone::ChatMessage>> & messages){
|
||||
for(auto message : messages)
|
||||
if(message) ChatMessageModel::initReceivedTimestamp(message, true);
|
||||
emit unreadMessagesCountChanged();
|
||||
updateLastUpdateTime();
|
||||
}
|
||||
|
|
@ -1206,8 +1205,7 @@ void ChatRoomModel::onNewEvents(const std::shared_ptr<linphone::ChatRoom> & chat
|
|||
void ChatRoomModel::onChatMessageReceived(const std::shared_ptr<linphone::ChatRoom> & chatRoom, const std::shared_ptr<const linphone::EventLog> & eventLog) {
|
||||
auto message = eventLog->getChatMessage();
|
||||
if(message){
|
||||
ChatMessageModel::initReceivedTimestamp(message, true);
|
||||
insertMessageAtEnd(message);
|
||||
insertMessageAtEnd(eventLog);
|
||||
updateLastUpdateTime();
|
||||
emit messageReceived(message);
|
||||
}
|
||||
|
|
@ -1217,8 +1215,7 @@ void ChatRoomModel::onChatMessagesReceived(const std::shared_ptr<linphone::ChatR
|
|||
for(auto eventLog : eventLogs){
|
||||
auto message = eventLog->getChatMessage();
|
||||
if(message){
|
||||
ChatMessageModel::initReceivedTimestamp(message, true);
|
||||
insertMessageAtEnd(message);
|
||||
insertMessageAtEnd(eventLog);
|
||||
updateLastUpdateTime();
|
||||
emit messageReceived(message);
|
||||
}
|
||||
|
|
@ -1228,8 +1225,7 @@ void ChatRoomModel::onChatMessagesReceived(const std::shared_ptr<linphone::ChatR
|
|||
void ChatRoomModel::onChatMessageSending(const std::shared_ptr<linphone::ChatRoom> & chatRoom, const std::shared_ptr<const linphone::EventLog> & eventLog){
|
||||
auto message = eventLog->getChatMessage();
|
||||
if(message){
|
||||
ChatMessageModel::initReceivedTimestamp(message, true, true);
|
||||
insertMessageAtEnd(message);
|
||||
insertMessageAtEnd(eventLog);
|
||||
updateLastUpdateTime();
|
||||
emit messageReceived(message);
|
||||
}
|
||||
|
|
@ -1237,7 +1233,6 @@ void ChatRoomModel::onChatMessageSending(const std::shared_ptr<linphone::ChatRoo
|
|||
|
||||
void ChatRoomModel::onChatMessageSent(const std::shared_ptr<linphone::ChatRoom> & chatRoom, const std::shared_ptr<const linphone::EventLog> & eventLog){
|
||||
auto message = eventLog->getChatMessage();
|
||||
if(message) ChatMessageModel::initReceivedTimestamp(message, true); // Just in case
|
||||
updateLastUpdateTime();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -202,8 +202,8 @@ public:
|
|||
bool mMarkAsReadEnabled = true;
|
||||
bool mEntriesLoading = false;
|
||||
|
||||
QSharedPointer<ChatMessageModel> insertMessageAtEnd (const std::shared_ptr<linphone::ChatMessage> &message);
|
||||
void insertMessages (const QList<std::shared_ptr<linphone::ChatMessage> > &messages);
|
||||
QSharedPointer<ChatMessageModel> insertMessageAtEnd (const std::shared_ptr<const linphone::EventLog> &messageLog);
|
||||
void insertMessages (const QList<std::shared_ptr<const linphone::EventLog> > &messageLogs);
|
||||
void insertNotice (const std::shared_ptr<linphone::EventLog> &enventLog);
|
||||
void insertNotices (const QList<std::shared_ptr<linphone::EventLog>> &eventLogs);
|
||||
|
||||
|
|
|
|||
|
|
@ -272,7 +272,6 @@ void CoreHandlers::onMessagesReceived (
|
|||
|
||||
appSettings.beginGroup("chatrooms");
|
||||
for(auto message : messages){
|
||||
if(message) ChatMessageModel::initReceivedTimestamp(message, true);
|
||||
if( !message || message->isOutgoing() )
|
||||
continue;
|
||||
// 1. Do not notify if chat is not activated.
|
||||
|
|
|
|||
|
|
@ -20,6 +20,9 @@
|
|||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#cmakedefine APPLICATION_DESCRIPTION "${APPLICATION_DESCRIPTION}"
|
||||
#cmakedefine APPLICATION_ID "${APPLICATION_ID}"
|
||||
#cmakedefine APPLICATION_NAME "${APPLICATION_NAME}"
|
||||
|
|
@ -36,3 +39,4 @@
|
|||
#cmakedefine QTKEYCHAIN_TARGET_NAME ${QTKEYCHAIN_TARGET_NAME}
|
||||
#cmakedefine PDF_ENABLED
|
||||
|
||||
#endif
|
||||
|
|
@ -1 +1 @@
|
|||
Subproject commit 12fc0869e41db12362fd3e7617712e2069882696
|
||||
Subproject commit 521a001ab21f1127682333efce8d4a292099203c
|
||||
Loading…
Add table
Reference in a new issue