Support some message types in chat list

This commit is contained in:
Sebastian J. Wolf 2020-08-20 23:56:21 +02:00
parent 13ce878b05
commit 588fbd11a8
10 changed files with 101 additions and 2 deletions

View file

@ -17,13 +17,27 @@
along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>.
*/
function getUserName(userInformation) {
return userInformation.first_name + " " + userInformation.last_name;
var firstName = typeof userInformation.first_name !== "undefined" ? userInformation.first_name : "";
var lastName = typeof userInformation.last_name !== "undefined" ? userInformation.last_name : "";
return (firstName + " " + lastName).trim();
}
function getSimpleMessageText(message) {
if (message.content['@type'] === 'messageText') {
return message.content.text.text;
}
if (message.content['@type'] === 'messagePhoto') {
return (typeof message.content.caption) ? qsTr("Picture: %1").arg(message.content.caption.text) : qsTr("Picture");
}
if (message.content['@type'] === 'messageVideo') {
return (typeof message.content.caption) ? qsTr("Video: %1").arg(message.content.caption.text) : qsTr("Video");
}
if (message.content['@type'] === 'messageContactRegistered') {
return qsTr("has registered with Telegram");
}
if (message.content['@type'] === 'messageChatJoinByLink') {
return qsTr("joined this chat by link.");
}
return "?";
}

View file

@ -62,7 +62,7 @@ Page {
onTriggered: {
overviewPage.chatListCreated = true;
chatListModel.enableDeltaUpdates();
// Sometimes delta updates are not properly displayed, enforce list redraw every minute
// Sometimes delta updates are not properly displayed, enforce list redraw from time to time
synchronizeChangesTimer.start();
}
}

View file

@ -8,6 +8,7 @@ ChatListModel::ChatListModel(TDLibWrapper *tdLibWrapper)
connect(this->tdLibWrapper, SIGNAL(newChatDiscovered(QString, QVariantMap)), this, SLOT(handleChatDiscovered(QString, QVariantMap)));
connect(this->tdLibWrapper, SIGNAL(chatLastMessageUpdated(QString, QString, QVariantMap)), this, SLOT(handleChatLastMessageUpdated(QString, QString, QVariantMap)));
connect(this->tdLibWrapper, SIGNAL(chatOrderUpdated(QString, QString)), this, SLOT(handleChatOrderUpdated(QString, QString)));
connect(this->tdLibWrapper, SIGNAL(chatReadInboxUpdated(QString, int)), this, SLOT(handleChatReadInboxUpdated(QString, int)));
}
ChatListModel::~ChatListModel()
@ -103,6 +104,18 @@ void ChatListModel::handleChatOrderUpdated(const QString &chatId, const QString
this->chatListMutex.unlock();
}
void ChatListModel::handleChatReadInboxUpdated(const QString &chatId, const int &unreadCount)
{
this->chatListMutex.lock();
qDebug() << "[ChatListModel] Updating chat unread count for " << chatId << " unread messages " << unreadCount;
int chatIndex = this->chatIndexMap.value(chatId).toInt();
QVariantMap currentChat = this->chatList.at(chatIndex).toMap();
currentChat.insert("unread_count", unreadCount);
this->chatList.replace(chatIndex, currentChat);
emit dataChanged(this->index(chatIndex), this->index(chatIndex));
this->chatListMutex.unlock();
}
void ChatListModel::updateChatOrder(const int &currentChatIndex, const QVariantMap &updatedChat)
{
// Finding the new position manually as information is needed by beginMoveRows()

View file

@ -23,6 +23,7 @@ public slots:
void handleChatDiscovered(const QString &chatId, const QVariantMap &chatInformation);
void handleChatLastMessageUpdated(const QString &chatId, const QString &order, const QVariantMap &lastMessage);
void handleChatOrderUpdated(const QString &chatId, const QString &order);
void handleChatReadInboxUpdated(const QString &chatId, const int &unreadCount);
private:
TDLibWrapper *tdLibWrapper;

View file

@ -64,6 +64,7 @@ void TDLibReceiver::processReceivedDocument(const QJsonDocument &receivedJsonDoc
if (objectTypeName == "updateUnreadChatCount") { this->processUpdateUnreadChatCount(receivedInformation); }
if (objectTypeName == "updateChatLastMessage") { this->processUpdateChatLastMessage(receivedInformation); }
if (objectTypeName == "updateChatOrder") { this->processUpdateChatOrder(receivedInformation); }
if (objectTypeName == "updateChatReadInbox") { this->processUpdateChatReadInbox(receivedInformation); }
}
void TDLibReceiver::processUpdateOption(const QVariantMap &receivedInformation)
@ -150,3 +151,9 @@ void TDLibReceiver::processUpdateChatOrder(const QVariantMap &receivedInformatio
qDebug() << "[TDLibReceiver] Chat order updated for ID " << receivedInformation.value("chat_id").toString() << " new order: " << receivedInformation.value("order").toString();
emit chatOrderUpdated(receivedInformation.value("chat_id").toString(), receivedInformation.value("order").toString());
}
void TDLibReceiver::processUpdateChatReadInbox(const QVariantMap &receivedInformation)
{
qDebug() << "[TDLibReceiver] Chat read information updated for " << receivedInformation.value("chat_id").toString() << " unread count: " << receivedInformation.value("unread_count").toString();
emit chatReadInboxUpdated(receivedInformation.value("chat_id").toString(), receivedInformation.value("unread_count").toInt());
}

View file

@ -47,6 +47,7 @@ signals:
void unreadChatCountUpdated(const QVariantMap &chatCountInformation);
void chatLastMessageUpdated(const QString &chatId, const QString &order, const QVariantMap &lastMessage);
void chatOrderUpdated(const QString &chatId, const QString &order);
void chatReadInboxUpdated(const QString &chatId, const int &unreadCount);
private:
void *tdLibClient;
@ -64,6 +65,7 @@ private:
void processUpdateUnreadChatCount(const QVariantMap &receivedInformation);
void processUpdateChatLastMessage(const QVariantMap &receivedInformation);
void processUpdateChatOrder(const QVariantMap &receivedInformation);
void processUpdateChatReadInbox(const QVariantMap &receivedInformation);
};
#endif // TDLIBRECEIVER_H

View file

@ -47,6 +47,7 @@ TDLibWrapper::TDLibWrapper(QObject *parent) : QObject(parent)
connect(this->tdLibReceiver, SIGNAL(unreadChatCountUpdated(QVariantMap)), this, SLOT(handleUnreadChatCountUpdated(QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(chatLastMessageUpdated(QString, QString, QVariantMap)), this, SLOT(handleChatLastMessageUpdated(QString, QString, QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(chatOrderUpdated(QString, QString)), this, SLOT(handleChatOrderUpdated(QString, QString)));
connect(this->tdLibReceiver, SIGNAL(chatReadInboxUpdated(QString, int)), this, SLOT(handleChatReadInboxUpdated(QString, int)));
this->tdLibReceiver->start();
@ -287,6 +288,11 @@ void TDLibWrapper::handleChatOrderUpdated(const QString &chatId, const QString &
emit chatOrderUpdated(chatId, order);
}
void TDLibWrapper::handleChatReadInboxUpdated(const QString &chatId, const int &unreadCount)
{
emit chatReadInboxUpdated(chatId, unreadCount);
}
void TDLibWrapper::setInitialParameters()
{
qDebug() << "[TDLibWrapper] Sending initial parameters to TD Lib";

View file

@ -85,6 +85,7 @@ signals:
void unreadChatCountUpdated(const QVariantMap &chatCountInformation);
void chatLastMessageUpdated(const QString &chatId, const QString &order, const QVariantMap &lastMessage);
void chatOrderUpdated(const QString &chatId, const QString &order);
void chatReadInboxUpdated(const QString &chatId, const int &unreadCount);
public slots:
void handleVersionDetected(const QString &version);
@ -98,6 +99,7 @@ public slots:
void handleUnreadChatCountUpdated(const QVariantMap &chatCountInformation);
void handleChatLastMessageUpdated(const QString &chatId, const QString &order, const QVariantMap &lastMessage);
void handleChatOrderUpdated(const QString &chatId, const QString &order);
void handleChatReadInboxUpdated(const QString &chatId, const int &unreadCount);
private:
void *tdLibClient;
TDLibReceiver *tdLibReceiver;

View file

@ -197,4 +197,31 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>functions</name>
<message>
<source>Video: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Video</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>has registered with Telegram</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Picture: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>joined this chat by link.</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View file

@ -197,4 +197,31 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>functions</name>
<message>
<source>Video: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Video</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>has registered with Telegram</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Picture: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>joined this chat by link.</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>