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;
// =============================================================================
class ChatModel::MessageHandlers : public linphone::ChatMessageListener {
friend class ChatModel;
public:
MessageHandlers (ChatModel *chat_model) : m_chat_model(chat_model) {}
~MessageHandlers () = default;
private:
void onFileTransferRecv (
const shared_ptr<linphone::ChatMessage> &message,
const shared_ptr<linphone::Content> &content,
......@@ -48,6 +48,9 @@ private:
}
void onMsgStateChanged (const shared_ptr<linphone::ChatMessage> &message, linphone::ChatMessageState state) override {
if (!m_chat_model)
return;
ChatModel &chat = *m_chat_model;
auto it = find_if(chat.m_entries.begin(), chat.m_entries.end(), [&message](const ChatEntryData &pair) {
......@@ -62,6 +65,7 @@ private:
emit chat.dataChanged(chat.index(row, 0), chat.index(row, 0));
}
private:
ChatModel *m_chat_model;
};
......@@ -82,12 +86,18 @@ ChatModel::ChatModel (QObject *parent) : QAbstractListModel(parent) {
const shared_ptr<linphone::ChatRoom> &room,
const shared_ptr<linphone::ChatMessage> &message
) {
if (m_chat_room == room)
if (m_chat_room == room) {
insertMessageAtEnd(message);
m_chat_room->markAsRead();
}
}
);
}
ChatModel::~ChatModel () {
m_message_handlers->m_chat_model = nullptr;
}
QHash<int, QByteArray> ChatModel::roleNames () const {
QHash<int, QByteArray> roles;
roles[Roles::ChatEntry] = "$chatEntry";
......@@ -162,6 +172,7 @@ void ChatModel::setSipAddress (const QString &sip_address) {
string std_sip_address = ::Utils::qStringToLinphoneString(sip_address);
m_chat_room = core->getChatRoomFromUri(std_sip_address);
m_chat_room->markAsRead();
// Get messages.
for (auto &message : m_chat_room->getHistory(0)) {
......
......@@ -50,7 +50,7 @@ public:
Q_ENUM(MessageStatus);
ChatModel (QObject *parent = Q_NULLPTR);
~ChatModel () = default;
~ChatModel ();
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