Mute/unmute chats both from list and in chat
This commit is contained in:
parent
1a5aa9de3f
commit
9070caa2a3
14 changed files with 99 additions and 7 deletions
|
@ -223,6 +223,30 @@ Page {
|
|||
contentWidth: parent.width
|
||||
anchors.fill: parent
|
||||
|
||||
PullDownMenu {
|
||||
MenuItem {
|
||||
id: muteChatMenuItem
|
||||
onClicked: {
|
||||
var newNotificationSettings = chatInformation.notification_settings;
|
||||
if (newNotificationSettings.mute_for > 0) {
|
||||
newNotificationSettings.mute_for = 0;
|
||||
} else {
|
||||
newNotificationSettings.mute_for = 6666666;
|
||||
}
|
||||
tdLibWrapper.setChatNotificationSettings(chatInformation.id, newNotificationSettings);
|
||||
}
|
||||
text: chatInformation.notification_settings.mute_for > 0 ? qsTr("Unmute Chat") : qsTr("Mute Chat")
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: chatModel
|
||||
onNotificationSettingsUpdated: {
|
||||
chatInformation = chatModel.getChatInformation();
|
||||
muteChatMenuItem.text = chatInformation.notification_settings.mute_for > 0 ? qsTr("Unmute Chat") : qsTr("Mute Chat");
|
||||
}
|
||||
}
|
||||
|
||||
Column {
|
||||
id: chatColumn
|
||||
width: parent.width
|
||||
|
|
|
@ -230,7 +230,7 @@ Page {
|
|||
if (newNotificationSettings.mute_for > 0) {
|
||||
newNotificationSettings.mute_for = 0;
|
||||
} else {
|
||||
newNotificationSettings.mute_for = 666666;
|
||||
newNotificationSettings.mute_for = 6666666;
|
||||
}
|
||||
tdLibWrapper.setChatNotificationSettings(display.id, newNotificationSettings);
|
||||
}
|
||||
|
@ -246,7 +246,7 @@ Page {
|
|||
chatListPictureThumbnail.photoData = (typeof display.photo !== "undefined") ? display.photo.small : "";
|
||||
chatUnreadMessagesCountBackground.visible = display.unread_count > 0;
|
||||
chatUnreadMessagesCount.text = display.unread_count > 99 ? "99+" : display.unread_count;
|
||||
chatListNameText.text = display.title !== "" ? Emoji.emojify(display.title, Theme.fontSizeMedium) : qsTr("Unknown");
|
||||
chatListNameText.text = display.title !== "" ? Emoji.emojify(display.title, Theme.fontSizeMedium) + ( display.notification_settings.mute_for > 0 ? Emoji.emojify(" 🔇", Theme.fontSizeMedium) : "" ) : qsTr("Unknown")
|
||||
chatListLastMessageText.text = (typeof display.last_message !== "undefined") ? Emoji.emojify(Functions.getMessageText(display.last_message, true), Theme.fontSizeExtraSmall) : qsTr("Unknown");
|
||||
messageContactTimeElapsedText.text = (typeof display.last_message !== "undefined") ? Functions.getDateTimeElapsed(display.last_message.date) : qsTr("Unknown");
|
||||
}
|
||||
|
@ -318,7 +318,7 @@ Page {
|
|||
|
||||
Text {
|
||||
id: chatListNameText
|
||||
text: display.title !== "" ? Emoji.emojify(display.title, font.pixelSize) + ( display.notification_settings.mute_for > 0 ? Emoji.emojify(" 🔇", font.pixelSize) : "" ) : qsTr("Unknown")
|
||||
text: display.title !== "" ? Emoji.emojify(display.title, Theme.fontSizeMedium) + ( display.notification_settings.mute_for > 0 ? Emoji.emojify(" 🔇", Theme.fontSizeMedium) : "" ) : qsTr("Unknown")
|
||||
textFormat: Text.StyledText
|
||||
font.pixelSize: Theme.fontSizeMedium
|
||||
color: Theme.primaryColor
|
||||
|
|
|
@ -12,7 +12,7 @@ Name: harbour-fernschreiber
|
|||
|
||||
Summary: Fernschreiber is a Telegram client for Sailfish OS
|
||||
Version: 0.1
|
||||
Release: 4
|
||||
Release: 5
|
||||
Group: Qt/Qt
|
||||
License: LICENSE
|
||||
URL: http://werkwolf.eu/
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
Name: harbour-fernschreiber
|
||||
Summary: Fernschreiber is a Telegram client for Sailfish OS
|
||||
Version: 0.1
|
||||
Release: 4
|
||||
Release: 5
|
||||
# The contents of the Group field should be one of the groups listed here:
|
||||
# https://github.com/mer-tools/spectacle/blob/master/data/GROUPS
|
||||
Group: Qt/Qt
|
||||
|
|
|
@ -31,6 +31,7 @@ ChatListModel::ChatListModel(TDLibWrapper *tdLibWrapper)
|
|||
connect(this->tdLibWrapper, SIGNAL(chatReadInboxUpdated(QString, QString, int)), this, SLOT(handleChatReadInboxUpdated(QString, QString, int)));
|
||||
connect(this->tdLibWrapper, SIGNAL(chatReadOutboxUpdated(QString, QString)), this, SLOT(handleChatReadOutboxUpdated(QString, QString)));
|
||||
connect(this->tdLibWrapper, SIGNAL(messageSendSucceeded(QString, QString, QVariantMap)), this, SLOT(handleMessageSendSucceeded(QString, QString, QVariantMap)));
|
||||
connect(this->tdLibWrapper, SIGNAL(chatNotificationSettingsUpdated(QString, QVariantMap)), this, SLOT(handleChatNotificationSettingsUpdated(QString, QVariantMap)));
|
||||
}
|
||||
|
||||
ChatListModel::~ChatListModel()
|
||||
|
@ -170,6 +171,20 @@ void ChatListModel::handleMessageSendSucceeded(const QString &messageId, const Q
|
|||
this->chatListMutex.unlock();
|
||||
}
|
||||
|
||||
void ChatListModel::handleChatNotificationSettingsUpdated(const QString &chatId, const QVariantMap &chatNotificationSettings)
|
||||
{
|
||||
this->chatListMutex.lock();
|
||||
int chatIndex = this->chatIndexMap.value(chatId).toInt();
|
||||
qDebug() << "[ChatListModel] Updating notification settings for chat " << chatId << " at index " << chatIndex;
|
||||
QVariantMap currentChat = this->chatList.value(chatIndex).toMap();
|
||||
currentChat.insert("notification_settings", chatNotificationSettings);
|
||||
this->chatList.replace(chatIndex, currentChat);
|
||||
emit dataChanged(this->index(chatIndex), this->index(chatIndex));
|
||||
emit chatChanged(chatId);
|
||||
|
||||
this->chatListMutex.unlock();
|
||||
}
|
||||
|
||||
void ChatListModel::updateChatOrder(const int ¤tChatIndex, const QVariantMap &updatedChat)
|
||||
{
|
||||
// Finding the new position manually as information is needed by beginMoveRows()
|
||||
|
|
|
@ -48,6 +48,7 @@ public slots:
|
|||
void handleChatReadInboxUpdated(const QString &chatId, const QString &lastReadInboxMessageId, const int &unreadCount);
|
||||
void handleChatReadOutboxUpdated(const QString &chatId, const QString &lastReadOutboxMessageId);
|
||||
void handleMessageSendSucceeded(const QString &messageId, const QString &oldMessageId, const QVariantMap &message);
|
||||
void handleChatNotificationSettingsUpdated(const QString &chatId, const QVariantMap &chatNotificationSettings);
|
||||
|
||||
private:
|
||||
TDLibWrapper *tdLibWrapper;
|
||||
|
|
|
@ -33,6 +33,7 @@ ChatModel::ChatModel(TDLibWrapper *tdLibWrapper)
|
|||
connect(this->tdLibWrapper, SIGNAL(chatReadInboxUpdated(QString, QString, int)), this, SLOT(handleChatReadInboxUpdated(QString, QString, int)));
|
||||
connect(this->tdLibWrapper, SIGNAL(chatReadOutboxUpdated(QString, QString)), this, SLOT(handleChatReadOutboxUpdated(QString, QString)));
|
||||
connect(this->tdLibWrapper, SIGNAL(messageSendSucceeded(QString, QString, QVariantMap)), this, SLOT(handleMessageSendSucceeded(QString, QString, QVariantMap)));
|
||||
connect(this->tdLibWrapper, SIGNAL(chatNotificationSettingsUpdated(QString, QVariantMap)), this, SLOT(handleChatNotificationSettingsUpdated(QString, QVariantMap)));
|
||||
}
|
||||
|
||||
ChatModel::~ChatModel()
|
||||
|
@ -85,6 +86,11 @@ void ChatModel::triggerLoadMoreHistory()
|
|||
}
|
||||
}
|
||||
|
||||
QVariantMap ChatModel::getChatInformation()
|
||||
{
|
||||
return this->chatInformation;
|
||||
}
|
||||
|
||||
bool compareMessages(const QVariant &message1, const QVariant &message2)
|
||||
{
|
||||
QVariantMap messageMap1 = message1.toMap();
|
||||
|
@ -199,6 +205,15 @@ void ChatModel::handleMessageSendSucceeded(const QString &messageId, const QStri
|
|||
}
|
||||
}
|
||||
|
||||
void ChatModel::handleChatNotificationSettingsUpdated(const QString &chatId, const QVariantMap &chatNotificationSettings)
|
||||
{
|
||||
if (chatId == this->chatId) {
|
||||
this->chatInformation.insert("notification_settings", chatNotificationSettings);
|
||||
qDebug() << "[ChatModel] Notification settings updated";
|
||||
emit notificationSettingsUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
void ChatModel::insertMessages()
|
||||
{
|
||||
if (this->messages.isEmpty()) {
|
||||
|
|
|
@ -38,6 +38,7 @@ public:
|
|||
|
||||
Q_INVOKABLE void initialize(const QVariantMap &chatInformation);
|
||||
Q_INVOKABLE void triggerLoadMoreHistory();
|
||||
Q_INVOKABLE QVariantMap getChatInformation();
|
||||
|
||||
signals:
|
||||
void messagesReceived(const int &modelIndex, const int &lastReadSentIndex);
|
||||
|
@ -45,6 +46,7 @@ signals:
|
|||
void newMessageReceived();
|
||||
void unreadCountUpdated(const int &unreadCount, const QString &lastReadInboxMessageId);
|
||||
void lastReadSentMessageUpdated(const int &lastReadSentIndex);
|
||||
void notificationSettingsUpdated();
|
||||
|
||||
public slots:
|
||||
void handleMessagesReceived(const QVariantList &messages);
|
||||
|
@ -52,6 +54,7 @@ public slots:
|
|||
void handleChatReadInboxUpdated(const QString &chatId, const QString &lastReadInboxMessageId, const int &unreadCount);
|
||||
void handleChatReadOutboxUpdated(const QString &chatId, const QString &lastReadOutboxMessageId);
|
||||
void handleMessageSendSucceeded(const QString &messageId, const QString &oldMessageId, const QVariantMap &message);
|
||||
void handleChatNotificationSettingsUpdated(const QString &chatId, const QVariantMap &chatNotificationSettings);
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -77,6 +77,7 @@ void TDLibReceiver::processReceivedDocument(const QJsonDocument &receivedJsonDoc
|
|||
if (objectTypeName == "updateMessageSendSucceeded") { this->processMessageSendSucceeded(receivedInformation); }
|
||||
if (objectTypeName == "updateActiveNotifications") { this->processUpdateActiveNotifications(receivedInformation); }
|
||||
if (objectTypeName == "updateNotificationGroup") { this->processUpdateNotificationGroup(receivedInformation); }
|
||||
if (objectTypeName == "updateChatNotificationSettings") { this->processUpdateChatNotificationSettings(receivedInformation); }
|
||||
}
|
||||
|
||||
void TDLibReceiver::processUpdateOption(const QVariantMap &receivedInformation)
|
||||
|
@ -258,3 +259,10 @@ void TDLibReceiver::processUpdateNotification(const QVariantMap &receivedInforma
|
|||
qDebug() << "[TDLibReceiver] Received notification update";
|
||||
emit notificationUpdated(receivedInformation);
|
||||
}
|
||||
|
||||
void TDLibReceiver::processUpdateChatNotificationSettings(const QVariantMap &receivedInformation)
|
||||
{
|
||||
QString chatId = receivedInformation.value("chat_id").toString();
|
||||
qDebug() << "[TDLibReceiver] Received new notification settings for chat " << chatId;
|
||||
emit chatNotificationSettingsUpdated(chatId, receivedInformation.value("notification_settings").toMap());
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@ signals:
|
|||
void activeNotificationsUpdated(const QVariantList notificationGroups);
|
||||
void notificationGroupUpdated(const QVariantMap notificationGroupUpdate);
|
||||
void notificationUpdated(const QVariantMap updatedNotification);
|
||||
void chatNotificationSettingsUpdated(const QString &chatId, const QVariantMap updatedChatNotificationSettings);
|
||||
|
||||
private:
|
||||
void *tdLibClient;
|
||||
|
@ -91,6 +92,7 @@ private:
|
|||
void processUpdateActiveNotifications(const QVariantMap &receivedInformation);
|
||||
void processUpdateNotificationGroup(const QVariantMap &receivedInformation);
|
||||
void processUpdateNotification(const QVariantMap &receivedInformation);
|
||||
void processUpdateChatNotificationSettings(const QVariantMap &receivedInformation);
|
||||
};
|
||||
|
||||
#endif // TDLIBRECEIVER_H
|
||||
|
|
|
@ -69,6 +69,7 @@ TDLibWrapper::TDLibWrapper(QObject *parent) : QObject(parent)
|
|||
connect(this->tdLibReceiver, SIGNAL(activeNotificationsUpdated(QVariantList)), this, SLOT(handleUpdateActiveNotifications(QVariantList)));
|
||||
connect(this->tdLibReceiver, SIGNAL(notificationGroupUpdated(QVariantMap)), this, SLOT(handleUpdateNotificationGroup(QVariantMap)));
|
||||
connect(this->tdLibReceiver, SIGNAL(notificationUpdated(QVariantMap)), this, SLOT(handleUpdateNotification(QVariantMap)));
|
||||
connect(this->tdLibReceiver, SIGNAL(chatNotificationSettingsUpdated(QString, QVariantMap)), this, SLOT(handleChatNotificationSettingsUpdated(QString, QVariantMap)));
|
||||
|
||||
this->tdLibReceiver->start();
|
||||
|
||||
|
@ -550,6 +551,11 @@ void TDLibWrapper::handleUpdateNotification(const QVariantMap updatedNotificatio
|
|||
emit notificationUpdated(updatedNotification);
|
||||
}
|
||||
|
||||
void TDLibWrapper::handleChatNotificationSettingsUpdated(const QString &chatId, const QVariantMap &chatNotificationSettings)
|
||||
{
|
||||
emit chatNotificationSettingsUpdated(chatId, chatNotificationSettings);
|
||||
}
|
||||
|
||||
void TDLibWrapper::setInitialParameters()
|
||||
{
|
||||
qDebug() << "[TDLibWrapper] Sending initial parameters to TD Lib";
|
||||
|
|
|
@ -118,6 +118,7 @@ signals:
|
|||
void activeNotificationsUpdated(const QVariantList notificationGroups);
|
||||
void notificationGroupUpdated(const QVariantMap notificationGroupUpdate);
|
||||
void notificationUpdated(const QVariantMap updatedNotification);
|
||||
void chatNotificationSettingsUpdated(const QString &chatId, const QVariantMap chatNotificationSettings);
|
||||
|
||||
public slots:
|
||||
void handleVersionDetected(const QString &version);
|
||||
|
@ -144,6 +145,7 @@ public slots:
|
|||
void handleUpdateActiveNotifications(const QVariantList notificationGroups);
|
||||
void handleUpdateNotificationGroup(const QVariantMap notificationGroupUpdate);
|
||||
void handleUpdateNotification(const QVariantMap updatedNotification);
|
||||
void handleChatNotificationSettingsUpdated(const QString &chatId, const QVariantMap &chatNotificationSettings);
|
||||
|
||||
private:
|
||||
void *tdLibClient;
|
||||
|
|
|
@ -153,6 +153,14 @@
|
|||
<source>Loading messages...</source>
|
||||
<translation>Lade Nachrichten...</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Unmute Chat</source>
|
||||
<translation>Stummschaltung des Chats aufheben</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Mute Chat</source>
|
||||
<translation>Chat stummschalten</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>CoverPage</name>
|
||||
|
@ -360,11 +368,11 @@
|
|||
</message>
|
||||
<message>
|
||||
<source>Unmute Chat</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>Stummschaltung des Chats aufheben</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Mute Chat</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>Chat stummschalten</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
|
|
|
@ -153,6 +153,14 @@
|
|||
<source>Loading messages...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Unmute Chat</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Mute Chat</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>CoverPage</name>
|
||||
|
|
Loading…
Reference in a new issue