2020-09-02 23:49:15 +03:00
|
|
|
/*
|
2020-10-19 20:34:47 +03:00
|
|
|
Copyright (C) 2020 Sebastian J. Wolf and other contributors
|
2020-09-02 23:49:15 +03:00
|
|
|
|
|
|
|
This file is part of Fernschreiber.
|
|
|
|
|
|
|
|
Fernschreiber is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Fernschreiber is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2020-08-22 18:30:02 +03:00
|
|
|
#ifndef CHATMODEL_H
|
|
|
|
#define CHATMODEL_H
|
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
|
|
|
#include "tdlibwrapper.h"
|
|
|
|
|
|
|
|
class ChatModel : public QAbstractListModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2020-12-06 07:38:03 +03:00
|
|
|
Q_PROPERTY(qlonglong chatId READ getChatId NOTIFY chatIdChanged)
|
2020-11-15 07:11:10 +03:00
|
|
|
Q_PROPERTY(QVariantMap smallPhoto READ smallPhoto NOTIFY smallPhotoChanged)
|
|
|
|
|
2020-08-22 18:30:02 +03:00
|
|
|
public:
|
|
|
|
ChatModel(TDLibWrapper *tdLibWrapper);
|
|
|
|
~ChatModel() override;
|
|
|
|
|
2020-12-06 07:38:03 +03:00
|
|
|
virtual QHash<int,QByteArray> roleNames() const override;
|
2020-08-22 18:30:02 +03:00
|
|
|
virtual int rowCount(const QModelIndex&) const override;
|
|
|
|
virtual QVariant data(const QModelIndex &index, int role) const override;
|
|
|
|
|
2020-11-20 22:39:23 +03:00
|
|
|
Q_INVOKABLE void clear();
|
2020-08-29 22:39:57 +03:00
|
|
|
Q_INVOKABLE void initialize(const QVariantMap &chatInformation);
|
2020-08-26 23:52:06 +03:00
|
|
|
Q_INVOKABLE void triggerLoadMoreHistory();
|
2020-11-16 01:05:22 +03:00
|
|
|
Q_INVOKABLE void triggerLoadMoreFuture();
|
2020-09-16 21:43:36 +03:00
|
|
|
Q_INVOKABLE QVariantMap getChatInformation();
|
2020-11-15 07:11:10 +03:00
|
|
|
Q_INVOKABLE QVariantMap getMessage(int index);
|
2020-11-16 01:05:22 +03:00
|
|
|
Q_INVOKABLE int getLastReadMessageIndex();
|
2020-11-20 22:39:23 +03:00
|
|
|
|
2020-11-15 07:11:10 +03:00
|
|
|
QVariantMap smallPhoto() const;
|
2020-11-20 22:39:23 +03:00
|
|
|
qlonglong getChatId() const;
|
2020-08-22 22:43:20 +03:00
|
|
|
|
|
|
|
signals:
|
2020-11-15 07:11:10 +03:00
|
|
|
void messagesReceived(int modelIndex, int lastReadSentIndex, int totalCount);
|
|
|
|
void messagesIncrementalUpdate(int modelIndex, int lastReadSentIndex);
|
2020-09-22 21:32:35 +03:00
|
|
|
void newMessageReceived(const QVariantMap &message);
|
2020-11-15 07:11:10 +03:00
|
|
|
void unreadCountUpdated(int unreadCount, const QString &lastReadInboxMessageId);
|
|
|
|
void lastReadSentMessageUpdated(int lastReadSentIndex);
|
2020-09-16 21:43:36 +03:00
|
|
|
void notificationSettingsUpdated();
|
2020-11-15 07:11:10 +03:00
|
|
|
void messageUpdated(int modelIndex);
|
|
|
|
void smallPhotoChanged();
|
2020-12-06 07:38:03 +03:00
|
|
|
void chatIdChanged();
|
2020-11-17 14:18:46 +03:00
|
|
|
void pinnedMessageChanged();
|
2020-08-22 22:43:20 +03:00
|
|
|
|
2020-12-06 07:38:03 +03:00
|
|
|
private slots:
|
2020-11-15 07:11:10 +03:00
|
|
|
void handleMessagesReceived(const QVariantList &messages, int totalCount);
|
2020-12-06 07:38:03 +03:00
|
|
|
void handleNewMessageReceived(qlonglong chatId, const QVariantMap &message);
|
2020-11-15 07:11:10 +03:00
|
|
|
void handleChatReadInboxUpdated(const QString &chatId, const QString &lastReadInboxMessageId, int unreadCount);
|
2020-08-30 20:04:16 +03:00
|
|
|
void handleChatReadOutboxUpdated(const QString &chatId, const QString &lastReadOutboxMessageId);
|
2020-12-06 07:38:03 +03:00
|
|
|
void handleMessageSendSucceeded(qlonglong messageId, qlonglong oldMessageId, const QVariantMap &message);
|
2020-09-16 21:43:36 +03:00
|
|
|
void handleChatNotificationSettingsUpdated(const QString &chatId, const QVariantMap &chatNotificationSettings);
|
2020-11-15 07:11:10 +03:00
|
|
|
void handleChatPhotoUpdated(qlonglong chatId, const QVariantMap &photo);
|
2020-11-17 14:18:46 +03:00
|
|
|
void handleChatPinnedMessageUpdated(qlonglong chatId, qlonglong pinnedMessageId);
|
2020-12-06 07:38:03 +03:00
|
|
|
void handleMessageContentUpdated(qlonglong chatId, qlonglong messageId, const QVariantMap &newContent);
|
|
|
|
void handleMessagesDeleted(qlonglong chatId, const QList<qlonglong> &messageIds);
|
|
|
|
|
|
|
|
private:
|
|
|
|
class MessageData;
|
|
|
|
void removeRange(int firstDeleted, int lastDeleted);
|
|
|
|
void insertMessages(const QList<MessageData*> newMessages);
|
|
|
|
void appendMessages(const QList<MessageData*> newMessages);
|
|
|
|
void prependMessages(const QList<MessageData*> newMessages);
|
|
|
|
QVariantMap enhanceMessage(const QVariantMap &message);
|
|
|
|
int calculateLastKnownMessageId();
|
|
|
|
int calculateLastReadSentMessageId();
|
|
|
|
bool isMostRecentMessageLoaded();
|
2020-08-22 22:43:20 +03:00
|
|
|
|
2020-08-22 18:30:02 +03:00
|
|
|
private:
|
|
|
|
TDLibWrapper *tdLibWrapper;
|
2020-12-06 07:38:03 +03:00
|
|
|
QList<MessageData*> messages;
|
|
|
|
QHash<qlonglong,int> messageIndexMap;
|
2020-08-29 22:39:57 +03:00
|
|
|
QVariantMap chatInformation;
|
2020-11-15 07:11:10 +03:00
|
|
|
qlonglong chatId;
|
2020-08-22 22:43:20 +03:00
|
|
|
bool inReload;
|
2020-08-26 23:52:06 +03:00
|
|
|
bool inIncrementalUpdate;
|
2020-08-22 18:30:02 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CHATMODEL_H
|