mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-05-07 14:44:01 +00:00
feat(src/components/chat/ChatModel): mark messages as read when it is necessary
This commit is contained in:
parent
ec2b354573
commit
ff733ab306
2 changed files with 15 additions and 4 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue