Commit ff733ab3 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(src/components/chat/ChatModel): mark messages as read when it is necessary

parent ec2b3545
...@@ -14,13 +14,13 @@ using namespace std; ...@@ -14,13 +14,13 @@ using namespace std;
// ============================================================================= // =============================================================================
class ChatModel::MessageHandlers : public linphone::ChatMessageListener { class ChatModel::MessageHandlers : public linphone::ChatMessageListener {
friend class ChatModel;
public: public:
MessageHandlers (ChatModel *chat_model) : m_chat_model(chat_model) {} MessageHandlers (ChatModel *chat_model) : m_chat_model(chat_model) {}
~MessageHandlers () = default; ~MessageHandlers () = default;
private:
void onFileTransferRecv ( void onFileTransferRecv (
const shared_ptr<linphone::ChatMessage> &message, const shared_ptr<linphone::ChatMessage> &message,
const shared_ptr<linphone::Content> &content, const shared_ptr<linphone::Content> &content,
...@@ -48,6 +48,9 @@ private: ...@@ -48,6 +48,9 @@ private:
} }
void onMsgStateChanged (const shared_ptr<linphone::ChatMessage> &message, linphone::ChatMessageState state) override { void onMsgStateChanged (const shared_ptr<linphone::ChatMessage> &message, linphone::ChatMessageState state) override {
if (!m_chat_model)
return;
ChatModel &chat = *m_chat_model; ChatModel &chat = *m_chat_model;
auto it = find_if(chat.m_entries.begin(), chat.m_entries.end(), [&message](const ChatEntryData &pair) { auto it = find_if(chat.m_entries.begin(), chat.m_entries.end(), [&message](const ChatEntryData &pair) {
...@@ -62,6 +65,7 @@ private: ...@@ -62,6 +65,7 @@ private:
emit chat.dataChanged(chat.index(row, 0), chat.index(row, 0)); emit chat.dataChanged(chat.index(row, 0), chat.index(row, 0));
} }
private:
ChatModel *m_chat_model; ChatModel *m_chat_model;
}; };
...@@ -82,12 +86,18 @@ ChatModel::ChatModel (QObject *parent) : QAbstractListModel(parent) { ...@@ -82,12 +86,18 @@ ChatModel::ChatModel (QObject *parent) : QAbstractListModel(parent) {
const shared_ptr<linphone::ChatRoom> &room, const shared_ptr<linphone::ChatRoom> &room,
const shared_ptr<linphone::ChatMessage> &message const shared_ptr<linphone::ChatMessage> &message
) { ) {
if (m_chat_room == room) if (m_chat_room == room) {
insertMessageAtEnd(message); insertMessageAtEnd(message);
m_chat_room->markAsRead();
}
} }
); );
} }
ChatModel::~ChatModel () {
m_message_handlers->m_chat_model = nullptr;
}
QHash<int, QByteArray> ChatModel::roleNames () const { QHash<int, QByteArray> ChatModel::roleNames () const {
QHash<int, QByteArray> roles; QHash<int, QByteArray> roles;
roles[Roles::ChatEntry] = "$chatEntry"; roles[Roles::ChatEntry] = "$chatEntry";
...@@ -162,6 +172,7 @@ void ChatModel::setSipAddress (const QString &sip_address) { ...@@ -162,6 +172,7 @@ void ChatModel::setSipAddress (const QString &sip_address) {
string std_sip_address = ::Utils::qStringToLinphoneString(sip_address); string std_sip_address = ::Utils::qStringToLinphoneString(sip_address);
m_chat_room = core->getChatRoomFromUri(std_sip_address); m_chat_room = core->getChatRoomFromUri(std_sip_address);
m_chat_room->markAsRead();
// Get messages. // Get messages.
for (auto &message : m_chat_room->getHistory(0)) { for (auto &message : m_chat_room->getHistory(0)) {
......
...@@ -50,7 +50,7 @@ public: ...@@ -50,7 +50,7 @@ public:
Q_ENUM(MessageStatus); Q_ENUM(MessageStatus);
ChatModel (QObject *parent = Q_NULLPTR); ChatModel (QObject *parent = Q_NULLPTR);
~ChatModel () = default; ~ChatModel ();
int rowCount (const QModelIndex &index = QModelIndex()) const override; int rowCount (const QModelIndex &index = QModelIndex()) const override;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment