Display chat status (members/online)
This commit is contained in:
parent
b42a8e4181
commit
2f5d725f7b
9 changed files with 292 additions and 12 deletions
|
@ -40,11 +40,14 @@ function getSimpleMessageText(message) {
|
|||
return qsTr("has registered with Telegram");
|
||||
}
|
||||
if (message.content['@type'] === 'messageChatJoinByLink') {
|
||||
return qsTr("joined this chat by link.");
|
||||
return qsTr("joined this chat.");
|
||||
}
|
||||
if (message.content['@type'] === 'messageChatAddMembers') {
|
||||
return qsTr("was added to this chat.");
|
||||
}
|
||||
if (message.content['@type'] === 'messageChatDeleteMember') {
|
||||
return qsTr("left this chat.");
|
||||
}
|
||||
return "?";
|
||||
}
|
||||
|
||||
|
|
|
@ -31,9 +31,76 @@ Page {
|
|||
|
||||
property bool loading: true;
|
||||
property variant chatInformation;
|
||||
property bool isPrivateChat: false;
|
||||
property bool isBasicGroup: false;
|
||||
property bool isSuperGroup: false;
|
||||
property bool isChannel: false;
|
||||
property variant chatPartnerInformation;
|
||||
property variant chatGroupInformation;
|
||||
property int chatOnlineMemberCount: 0;
|
||||
|
||||
function getShortenedCount(count) {
|
||||
if (count >= 1000000) {
|
||||
return qsTr("%1M").arg((count / 1000000).toLocaleString(Qt.locale(), 'f', 0));
|
||||
} else if (count >= 1000 ) {
|
||||
return qsTr("%1K").arg((count / 1000).toLocaleString(Qt.locale(), 'f', 0));
|
||||
} else {
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
function updateChatPartnerStatusText() {
|
||||
if (chatPartnerInformation.status['@type'] === "userStatusEmpty" ) {
|
||||
chatStatusText.text = qsTr("was never online");
|
||||
}
|
||||
if (chatPartnerInformation.status['@type'] === "userStatusLastMonth" ) {
|
||||
chatStatusText.text = qsTr("offline, last online: last month");
|
||||
}
|
||||
if (chatPartnerInformation.status['@type'] === "userStatusLastWeek" ) {
|
||||
chatStatusText.text = qsTr("offline, last online: last week");
|
||||
}
|
||||
if (chatPartnerInformation.status['@type'] === "userStatusOffline" ) {
|
||||
chatStatusText.text = qsTr("offline, last online: %1").arg(Functions.getDateTimeElapsed(chatPartnerInformation.status.was_online));
|
||||
}
|
||||
if (chatPartnerInformation.status['@type'] === "userStatusOnline" ) {
|
||||
chatStatusText.text = qsTr("online");
|
||||
}
|
||||
if (chatPartnerInformation.status['@type'] === "userStatusRecently" ) {
|
||||
chatStatusText.text = qsTr("offline, was recently online");
|
||||
}
|
||||
}
|
||||
|
||||
function updateGroupStatusText() {
|
||||
if (chatOnlineMemberCount > 0) {
|
||||
chatStatusText.text = qsTr("%1 members, %2 online").arg(getShortenedCount(chatGroupInformation.member_count)).arg(getShortenedCount(chatOnlineMemberCount));
|
||||
} else {
|
||||
if (isChannel) {
|
||||
chatStatusText.text = qsTr("%1 subscribers").arg(getShortenedCount(chatGroupInformation.member_count));
|
||||
} else {
|
||||
chatStatusText.text = qsTr("%1 members").arg(getShortenedCount(chatGroupInformation.member_count));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function initializePage() {
|
||||
tdLibWrapper.openChat(chatInformation.id);
|
||||
var chatType = chatInformation.type['@type'];
|
||||
isPrivateChat = ( chatType === "chatTypePrivate" );
|
||||
isBasicGroup = ( chatType === "chatTypeBasicGroup" );
|
||||
isSuperGroup = ( chatType === "chatTypeSupergroup" );
|
||||
if (isPrivateChat) {
|
||||
chatPartnerInformation = tdLibWrapper.getUserInformation(chatInformation.type.user_id);
|
||||
updateChatPartnerStatusText();
|
||||
}
|
||||
if (isBasicGroup) {
|
||||
chatGroupInformation = tdLibWrapper.getBasicGroup(chatInformation.type.basic_group_id);
|
||||
updateGroupStatusText();
|
||||
}
|
||||
if (isSuperGroup) {
|
||||
chatGroupInformation = tdLibWrapper.getSuperGroup(chatInformation.type.supergroup_id);
|
||||
isChannel = chatGroupInformation.is_channel;
|
||||
updateGroupStatusText();
|
||||
}
|
||||
chatPage.loading = false;
|
||||
}
|
||||
|
||||
|
@ -47,6 +114,45 @@ Page {
|
|||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: tdLibWrapper
|
||||
onUserUpdated: {
|
||||
if (isPrivateChat && chatPartnerInformation.id.toString() === userId ) {
|
||||
chatPartnerInformation = userInformation;
|
||||
updateChatPartnerStatusText();
|
||||
}
|
||||
}
|
||||
onBasicGroupUpdated: {
|
||||
if (isBasicGroup && chatGroupInformation.id.toString() === groupId ) {
|
||||
chatGroupInformation = groupInformation;
|
||||
updateGroupStatusText();
|
||||
}
|
||||
}
|
||||
onSuperGroupUpdated: {
|
||||
if (isSuperGroup && chatGroupInformation.id.toString() === groupId ) {
|
||||
chatGroupInformation = groupInformation;
|
||||
updateGroupStatusText();
|
||||
}
|
||||
}
|
||||
onChatOnlineMemberCountUpdated: {
|
||||
console.log(isSuperGroup + "/" + isBasicGroup + "/" + chatInformation.id.toString() + "/" + chatId);
|
||||
if ((isSuperGroup || isBasicGroup) && chatInformation.id.toString() === chatId) {
|
||||
chatOnlineMemberCount = onlineMemberCount;
|
||||
updateGroupStatusText();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: chatContactTimeUpdater
|
||||
interval: 60000
|
||||
running: true
|
||||
repeat: true
|
||||
onTriggered: {
|
||||
updateChatPartnerStatusText();
|
||||
}
|
||||
}
|
||||
|
||||
SilicaFlickable {
|
||||
id: chatContainer
|
||||
contentHeight: parent.height
|
||||
|
@ -101,9 +207,9 @@ Page {
|
|||
}
|
||||
Text {
|
||||
id: chatStatusText
|
||||
text: "This will become a status bar..."
|
||||
text: ""
|
||||
textFormat: Text.StyledText
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
font.pixelSize: Theme.fontSizeExtraSmall
|
||||
font.family: Theme.fontFamilyHeading
|
||||
color: Theme.secondaryColor
|
||||
elide: Text.ElideRight
|
||||
|
|
|
@ -39,7 +39,7 @@ Page {
|
|||
|
||||
onStatusChanged: {
|
||||
console.log("[OverviewPage] Status changed: " + status + ", initialization completed: " + initializationCompleted);
|
||||
if (status === PageStatus.Active && initializationCompleted) {
|
||||
if (status === PageStatus.Active && initializationCompleted && !chatListCreated) {
|
||||
updateContent();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,6 +65,9 @@ void TDLibReceiver::processReceivedDocument(const QJsonDocument &receivedJsonDoc
|
|||
if (objectTypeName == "updateChatLastMessage") { this->processUpdateChatLastMessage(receivedInformation); }
|
||||
if (objectTypeName == "updateChatOrder") { this->processUpdateChatOrder(receivedInformation); }
|
||||
if (objectTypeName == "updateChatReadInbox") { this->processUpdateChatReadInbox(receivedInformation); }
|
||||
if (objectTypeName == "updateBasicGroup") { this->processUpdateBasicGroup(receivedInformation); }
|
||||
if (objectTypeName == "updateSupergroup") { this->processUpdateSuperGroup(receivedInformation); }
|
||||
if (objectTypeName == "updateChatOnlineMemberCount") { this->processChatOnlineMemberCountUpdated(receivedInformation); }
|
||||
}
|
||||
|
||||
void TDLibReceiver::processUpdateOption(const QVariantMap &receivedInformation)
|
||||
|
@ -157,3 +160,24 @@ void TDLibReceiver::processUpdateChatReadInbox(const QVariantMap &receivedInform
|
|||
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());
|
||||
}
|
||||
|
||||
void TDLibReceiver::processUpdateBasicGroup(const QVariantMap &receivedInformation)
|
||||
{
|
||||
QString basicGroupId = receivedInformation.value("basic_group").toMap().value("id").toString();
|
||||
qDebug() << "[TDLibReceiver] Basic group information updated for " << basicGroupId;
|
||||
emit basicGroupUpdated(basicGroupId, receivedInformation.value("basic_group").toMap());
|
||||
}
|
||||
|
||||
void TDLibReceiver::processUpdateSuperGroup(const QVariantMap &receivedInformation)
|
||||
{
|
||||
QString superGroupId = receivedInformation.value("supergroup").toMap().value("id").toString();
|
||||
qDebug() << "[TDLibReceiver] Super group information updated for " << superGroupId;
|
||||
emit superGroupUpdated(superGroupId, receivedInformation.value("supergroup").toMap());
|
||||
}
|
||||
|
||||
void TDLibReceiver::processChatOnlineMemberCountUpdated(const QVariantMap &receivedInformation)
|
||||
{
|
||||
QString chatId = receivedInformation.value("chat_id").toString();
|
||||
qDebug() << "[TDLibReceiver] Online member count updated for chat " << chatId;
|
||||
emit chatOnlineMemberCountUpdated(chatId, receivedInformation.value("online_member_count").toInt());
|
||||
}
|
||||
|
|
|
@ -48,6 +48,9 @@ signals:
|
|||
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);
|
||||
void basicGroupUpdated(const QString &groupId, const QVariantMap &groupInformation);
|
||||
void superGroupUpdated(const QString &groupId, const QVariantMap &groupInformation);
|
||||
void chatOnlineMemberCountUpdated(const QString &chatId, const int &onlineMemberCount);
|
||||
|
||||
private:
|
||||
void *tdLibClient;
|
||||
|
@ -66,6 +69,9 @@ private:
|
|||
void processUpdateChatLastMessage(const QVariantMap &receivedInformation);
|
||||
void processUpdateChatOrder(const QVariantMap &receivedInformation);
|
||||
void processUpdateChatReadInbox(const QVariantMap &receivedInformation);
|
||||
void processUpdateBasicGroup(const QVariantMap &receivedInformation);
|
||||
void processUpdateSuperGroup(const QVariantMap &receivedInformation);
|
||||
void processChatOnlineMemberCountUpdated(const QVariantMap &receivedInformation);
|
||||
};
|
||||
|
||||
#endif // TDLIBRECEIVER_H
|
||||
|
|
|
@ -48,6 +48,9 @@ TDLibWrapper::TDLibWrapper(QObject *parent) : QObject(parent)
|
|||
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)));
|
||||
connect(this->tdLibReceiver, SIGNAL(basicGroupUpdated(QString, QVariantMap)), this, SLOT(handleBasicGroupUpdated(QString, QVariantMap)));
|
||||
connect(this->tdLibReceiver, SIGNAL(superGroupUpdated(QString, QVariantMap)), this, SLOT(handleSuperGroupUpdated(QString, QVariantMap)));
|
||||
connect(this->tdLibReceiver, SIGNAL(chatOnlineMemberCountUpdated(QString, int)), this, SLOT(handleChatOnlineMemberCountUpdated(QString, int)));
|
||||
|
||||
this->tdLibReceiver->start();
|
||||
|
||||
|
@ -169,6 +172,18 @@ QVariantMap TDLibWrapper::getUnreadChatInformation()
|
|||
return this->unreadChatInformation;
|
||||
}
|
||||
|
||||
QVariantMap TDLibWrapper::getBasicGroup(const QString &groupId)
|
||||
{
|
||||
qDebug() << "[TDLibWrapper] Returning basic group information for ID " << groupId;
|
||||
return this->basicGroups.value(groupId).toMap();
|
||||
}
|
||||
|
||||
QVariantMap TDLibWrapper::getSuperGroup(const QString &groupId)
|
||||
{
|
||||
qDebug() << "[TDLibWrapper] Returning super group information for ID " << groupId;
|
||||
return this->superGroups.value(groupId).toMap();
|
||||
}
|
||||
|
||||
void TDLibWrapper::handleVersionDetected(const QString &version)
|
||||
{
|
||||
this->version = version;
|
||||
|
@ -266,6 +281,7 @@ void TDLibWrapper::handleUserUpdated(const QVariantMap &userInformation)
|
|||
}
|
||||
qDebug() << "[TDLibWrapper] User information updated: " << userInformation.value("username").toString() << userInformation.value("first_name").toString() << userInformation.value("last_name").toString();
|
||||
this->allUsers.insert(updatedUserId, userInformation);
|
||||
emit userUpdated(updatedUserId, userInformation);
|
||||
}
|
||||
|
||||
void TDLibWrapper::handleFileUpdated(const QVariantMap &fileInformation)
|
||||
|
@ -311,6 +327,23 @@ void TDLibWrapper::handleChatReadInboxUpdated(const QString &chatId, const int &
|
|||
emit chatReadInboxUpdated(chatId, unreadCount);
|
||||
}
|
||||
|
||||
void TDLibWrapper::handleBasicGroupUpdated(const QString &groupId, const QVariantMap &groupInformation)
|
||||
{
|
||||
this->basicGroups.insert(groupId, groupInformation);
|
||||
emit basicGroupUpdated(groupId, groupInformation);
|
||||
}
|
||||
|
||||
void TDLibWrapper::handleSuperGroupUpdated(const QString &groupId, const QVariantMap &groupInformation)
|
||||
{
|
||||
this->superGroups.insert(groupId, groupInformation);
|
||||
emit superGroupUpdated(groupId, groupInformation);
|
||||
}
|
||||
|
||||
void TDLibWrapper::handleChatOnlineMemberCountUpdated(const QString &chatId, const int &onlineMemberCount)
|
||||
{
|
||||
emit chatOnlineMemberCountUpdated(chatId, onlineMemberCount);
|
||||
}
|
||||
|
||||
void TDLibWrapper::setInitialParameters()
|
||||
{
|
||||
qDebug() << "[TDLibWrapper] Sending initial parameters to TD Lib";
|
||||
|
|
|
@ -65,6 +65,8 @@ public:
|
|||
Q_INVOKABLE QVariantMap getUserInformation(const QString &userId);
|
||||
Q_INVOKABLE QVariantMap getUnreadMessageInformation();
|
||||
Q_INVOKABLE QVariantMap getUnreadChatInformation();
|
||||
Q_INVOKABLE QVariantMap getBasicGroup(const QString &groupId);
|
||||
Q_INVOKABLE QVariantMap getSuperGroup(const QString &groupId);
|
||||
|
||||
// Direct TDLib functions
|
||||
Q_INVOKABLE void sendRequest(const QVariantMap &requestObject);
|
||||
|
@ -88,6 +90,10 @@ signals:
|
|||
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);
|
||||
void userUpdated(const QString &userId, const QVariantMap &userInformation);
|
||||
void basicGroupUpdated(const QString &groupId, const QVariantMap &groupInformation);
|
||||
void superGroupUpdated(const QString &groupId, const QVariantMap &groupInformation);
|
||||
void chatOnlineMemberCountUpdated(const QString &chatId, const int &onlineMemberCount);
|
||||
|
||||
public slots:
|
||||
void handleVersionDetected(const QString &version);
|
||||
|
@ -102,6 +108,10 @@ public slots:
|
|||
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);
|
||||
void handleBasicGroupUpdated(const QString &groupId, const QVariantMap &groupInformation);
|
||||
void handleSuperGroupUpdated(const QString &groupId, const QVariantMap &groupInformation);
|
||||
void handleChatOnlineMemberCountUpdated(const QString &chatId, const int &onlineMemberCount);
|
||||
|
||||
private:
|
||||
void *tdLibClient;
|
||||
TDLibReceiver *tdLibReceiver;
|
||||
|
@ -114,6 +124,8 @@ private:
|
|||
QVariantMap chats;
|
||||
QVariantMap unreadMessageInformation;
|
||||
QVariantMap unreadChatInformation;
|
||||
QVariantMap basicGroups;
|
||||
QVariantMap superGroups;
|
||||
|
||||
void setInitialParameters();
|
||||
void setEncryptionKey();
|
||||
|
|
|
@ -86,6 +86,50 @@
|
|||
<source>Your message</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>was never online</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>offline, last online: last month</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>offline, last online: last week</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>offline, last online: %1</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>online</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>offline, was recently online</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>%1 members, %2 online</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>%1 members</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>%1M</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>%1K</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>%1 subscribers</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>CoverPage</name>
|
||||
|
@ -230,10 +274,6 @@
|
|||
<source>Picture</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>joined this chat by link.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Sticker: %1</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
@ -242,5 +282,13 @@
|
|||
<source>was added to this chat.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>joined this chat.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>left this chat.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
|
|
@ -86,6 +86,50 @@
|
|||
<source>Your message</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>was never online</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>offline, last online: last month</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>offline, last online: last week</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>offline, last online: %1</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>online</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>offline, was recently online</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>%1 members, %2 online</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>%1 members</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>%1M</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>%1K</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>%1 subscribers</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>CoverPage</name>
|
||||
|
@ -230,10 +274,6 @@
|
|||
<source>Picture</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>joined this chat by link.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Sticker: %1</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
@ -242,5 +282,13 @@
|
|||
<source>was added to this chat.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>joined this chat.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>left this chat.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
|
Loading…
Reference in a new issue