Introduce online-only mode as non-default option, fixes #77

This commit is contained in:
Sebastian Wolf 2021-01-10 13:35:34 +01:00
parent 90a3d8ad2b
commit d4935a4968
No known key found for this signature in database
GPG key ID: CEA9522B5F38A90A
20 changed files with 169 additions and 9 deletions

View file

@ -67,7 +67,7 @@ CoverBackground {
coverPage.authenticated = (tdLibWrapper.getAuthorizationState() === TelegramAPI.AuthorizationReady);
coverPage.connectionState = tdLibWrapper.getConnectionState();
coverPage.unreadMessages = tdLibWrapper.getUnreadMessageInformation().unread_count || 0;
coverPage.unreadChats = tdLibWrapper.getUnreadChatInformation().unread_count;
coverPage.unreadChats = tdLibWrapper.getUnreadChatInformation().unread_count || 0;
setUnreadInfoText();
}
@ -91,6 +91,15 @@ CoverBackground {
}
}
Connections {
target: chatListModel
onUnreadStateChanged: {
coverPage.unreadMessages = unreadMessagesCount;
coverPage.unreadChats = unreadChatsCount;
setUnreadInfoText();
}
}
BackgroundImage {
id: backgroundImage
width: parent.height - Theme.paddingLarge

View file

@ -87,6 +87,7 @@ Page {
id: updateSecondaryContentTimer
interval: 600
onTriggered: {
chatListModel.calculateUnreadState();
tdLibWrapper.getRecentStickers();
tdLibWrapper.getInstalledStickerSets();
tdLibWrapper.getContacts();
@ -192,11 +193,15 @@ Page {
onChatLastMessageUpdated: {
if (!overviewPage.chatListCreated) {
chatListCreatedTimer.restart();
} else {
chatListModel.calculateUnreadState();
}
}
onChatOrderUpdated: {
if (!overviewPage.chatListCreated) {
chatListCreatedTimer.restart();
} else {
chatListModel.calculateUnreadState();
}
}
onChatsReceived: {

View file

@ -172,6 +172,16 @@ Page {
}
}
TextSwitch {
checked: appSettings.onlineOnlyMode
text: qsTr("Enable online-only mode")
description: qsTr("Disables offline caching. Certain features may be limited or missing in this mode. Changes require a restart of Fernschreiber to take effect.")
automaticCheck: false
onClicked: {
appSettings.onlineOnlyMode = !checked
}
}
Item {
width: 1
height: Theme.paddingLarge // Some space at the bottom

View file

@ -30,6 +30,7 @@ namespace {
const QString KEY_NOTIFICATION_FEEDBACK("notificationFeedback");
const QString KEY_STORAGE_OPTIMIZER("storageOptimizer");
const QString KEY_REMAINING_INTERACTION_HINTS("remainingInteractionHints");
const QString KEY_ONLINE_ONLY_MODE("onlineOnlyMode");
}
AppSettings::AppSettings(QObject *parent) : QObject(parent), settings("harbour-fernschreiber", "settings")
@ -161,3 +162,17 @@ void AppSettings::setRemainingInteractionHints(int remainingHints)
emit remainingInteractionHintsChanged();
}
}
bool AppSettings::onlineOnlyMode() const
{
return settings.value(KEY_ONLINE_ONLY_MODE, false).toBool();
}
void AppSettings::setOnlineOnlyMode(bool enable)
{
if (onlineOnlyMode() != enable) {
LOG(KEY_ONLINE_ONLY_MODE << enable);
settings.setValue(KEY_ONLINE_ONLY_MODE, enable);
emit onlineOnlyModeChanged();
}
}

View file

@ -32,6 +32,7 @@ class AppSettings : public QObject {
Q_PROPERTY(NotificationFeedback notificationFeedback READ notificationFeedback WRITE setNotificationFeedback NOTIFY notificationFeedbackChanged)
Q_PROPERTY(bool storageOptimizer READ storageOptimizer WRITE setStorageOptimizer NOTIFY storageOptimizerChanged)
Q_PROPERTY(int remainingInteractionHints READ remainingInteractionHints WRITE setRemainingInteractionHints NOTIFY remainingInteractionHintsChanged)
Q_PROPERTY(bool onlineOnlyMode READ onlineOnlyMode WRITE setOnlineOnlyMode NOTIFY onlineOnlyModeChanged)
public:
enum NotificationFeedback {
@ -71,6 +72,9 @@ public:
int remainingInteractionHints() const;
void setRemainingInteractionHints(int remainingHints);
bool onlineOnlyMode() const;
void setOnlineOnlyMode(bool enable);
signals:
void sendByEnterChanged();
void focusTextAreaAfterSendChanged();
@ -81,6 +85,7 @@ signals:
void notificationFeedbackChanged();
void storageOptimizerChanged();
void remainingInteractionHintsChanged();
void onlineOnlyModeChanged();
private:
QSettings settings;

View file

@ -19,6 +19,7 @@
#include "chatlistmodel.h"
#include "fernschreiberutils.h"
#include <QListIterator>
#define DEBUG_MODULE ChatListModel
#include "debuglog.h"
@ -353,9 +354,10 @@ QVector<int> ChatListModel::ChatData::updateSecretChat(const QVariantMap &secret
return changedRoles;
}
ChatListModel::ChatListModel(TDLibWrapper *tdLibWrapper) : showHiddenChats(false)
ChatListModel::ChatListModel(TDLibWrapper *tdLibWrapper, AppSettings *appSettings) : showHiddenChats(false)
{
this->tdLibWrapper = tdLibWrapper;
this->appSettings = appSettings;
connect(tdLibWrapper, SIGNAL(newChatDiscovered(QString, QVariantMap)), this, SLOT(handleChatDiscovered(QString, QVariantMap)));
connect(tdLibWrapper, SIGNAL(chatLastMessageUpdated(QString, QString, QVariantMap)), this, SLOT(handleChatLastMessageUpdated(QString, QString, QVariantMap)));
connect(tdLibWrapper, SIGNAL(chatOrderUpdated(QString, QString)), this, SLOT(handleChatOrderUpdated(QString, QString)));
@ -519,6 +521,26 @@ int ChatListModel::updateChatOrder(int chatIndex)
return newIndex;
}
void ChatListModel::calculateUnreadState()
{
if (this->appSettings->onlineOnlyMode()) {
LOG("Online-only mode: Calculating unread state on my own...");
int unreadMessages = 0;
int unreadChats = 0;
QListIterator<ChatData*> chatIterator(this->chatList);
while (chatIterator.hasNext()) {
ChatData *currentChat = chatIterator.next();
int unreadCount = currentChat->unreadCount();
if (unreadCount > 0) {
unreadChats++;
unreadMessages += unreadCount;
}
}
LOG("Online-only mode: New unread state:" << unreadMessages << unreadChats);
emit unreadStateChanged(unreadMessages, unreadChats);
}
}
void ChatListModel::addVisibleChat(ChatData *chat)
{
const int n = chatList.size();
@ -719,6 +741,7 @@ void ChatListModel::handleChatReadInboxUpdated(const QString &id, const QString
}
const QModelIndex modelIndex(index(chatIndex));
emit dataChanged(modelIndex, modelIndex, changedRoles);
this->calculateUnreadState();
} else {
ChatData *chat = hiddenChats.value(chatId);
if (chat) {

View file

@ -22,6 +22,7 @@
#include <QAbstractListModel>
#include "tdlibwrapper.h"
#include "appsettings.h"
class ChatListModel : public QAbstractListModel
{
@ -53,7 +54,7 @@ public:
RoleDraftMessageDate
};
ChatListModel(TDLibWrapper *tdLibWrapper);
ChatListModel(TDLibWrapper *tdLibWrapper, AppSettings *appSettings);
~ChatListModel() override;
virtual QHash<int,QByteArray> roleNames() const override;
@ -63,6 +64,7 @@ public:
Q_INVOKABLE void redrawModel();
Q_INVOKABLE QVariantMap get(int row);
Q_INVOKABLE QVariantMap getById(qlonglong chatId);
Q_INVOKABLE void calculateUnreadState();
bool showAllChats() const;
void setShowAllChats(bool showAll);
@ -89,6 +91,7 @@ signals:
void showAllChatsChanged();
void chatChanged(const qlonglong &changedChatId);
void chatJoined(const qlonglong &chatId, const QString &chatTitle);
void unreadStateChanged(int unreadMessagesCount, int unreadChatsCount);
private:
class ChatData;
@ -99,6 +102,7 @@ private:
private:
TDLibWrapper *tdLibWrapper;
AppSettings *appSettings;
QTimer *relativeTimeRefreshTimer;
QList<ChatData*> chatList;
QHash<qlonglong,int> chatIndexMap;

View file

@ -87,7 +87,7 @@ int main(int argc, char *argv[])
DBusAdaptor *dBusAdaptor = tdLibWrapper->getDBusAdaptor();
context->setContextProperty("dBusAdaptor", dBusAdaptor);
ChatListModel chatListModel(tdLibWrapper);
ChatListModel chatListModel(tdLibWrapper, appSettings);
context->setContextProperty("chatListModel", &chatListModel);
QSortFilterProxyModel chatListProxyModel(view.data());
chatListProxyModel.setSourceModel(&chatListModel);

View file

@ -1476,9 +1476,10 @@ void TDLibWrapper::setInitialParameters()
initialParameters.insert("api_id", TDLIB_API_ID);
initialParameters.insert("api_hash", TDLIB_API_HASH);
initialParameters.insert("database_directory", QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/tdlib");
initialParameters.insert("use_file_database", true);
initialParameters.insert("use_chat_info_database", true);
initialParameters.insert("use_message_database", true);
bool onlineOnlyMode = this->appSettings->onlineOnlyMode();
initialParameters.insert("use_file_database", !onlineOnlyMode);
initialParameters.insert("use_chat_info_database", !onlineOnlyMode);
initialParameters.insert("use_message_database", !onlineOnlyMode);
initialParameters.insert("use_secret_chats", true);
initialParameters.insert("system_language_code", QLocale::system().name());
QSettings hardwareSettings("/etc/hw-release", QSettings::NativeFormat);

View file

@ -1433,6 +1433,14 @@
<source>Focus the text input area after sending a message</source>
<translation>Fokussiert die Texteingabe nach Senden einer Nachricht</translation>
</message>
<message>
<source>Enable online-only mode</source>
<translation>Nur-Online-Modus einschalten</translation>
</message>
<message>
<source>Disables offline caching. Certain features may be limited or missing in this mode. Changes require a restart of Fernschreiber to take effect.</source>
<translation>Schaltet das Offline-Caching aus. Bestimmte Features können in diesem Modus eingeschränkt sein oder fehlen. Änderungen erfordern einen Neustart von Fernschreiber, um in Kraft zu treten.</translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -177,11 +177,11 @@
</message>
<message>
<source>Unmute Chat</source>
<translation type="unfinished">Unmute Chat</translation>
<translation>Unmute Chat</translation>
</message>
<message>
<source>Mute Chat</source>
<translation type="unfinished">Mute Chat</translation>
<translation>Mute Chat</translation>
</message>
</context>
<context>
@ -1433,6 +1433,14 @@
<source>Focus the text input area after sending a message</source>
<translation>Focus the text input area after sending a message</translation>
</message>
<message>
<source>Enable online-only mode</source>
<translation>Enable online-only mode</translation>
</message>
<message>
<source>Disables offline caching. Certain features may be limited or missing in this mode. Changes require a restart of Fernschreiber to take effect.</source>
<translation>Disables offline caching. Certain features may be limited or missing in this mode. Changes require a restart of Fernschreiber to take effect.</translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -1412,6 +1412,14 @@
<source>Focus the text input area after sending a message</source>
<translation>Enfoca el área de entrada de texto después de enviar un mensaje</translation>
</message>
<message>
<source>Enable online-only mode</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Disables offline caching. Certain features may be limited or missing in this mode. Changes require a restart of Fernschreiber to take effect.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -1434,6 +1434,14 @@
<source>Focus the text input area after sending a message</source>
<translation>Kohdista tekstinsyöttökenttä viestin lähetyksen jälkeen</translation>
</message>
<message>
<source>Enable online-only mode</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Disables offline caching. Certain features may be limited or missing in this mode. Changes require a restart of Fernschreiber to take effect.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -1412,6 +1412,14 @@
<source>Focus the text input area after sending a message</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enable online-only mode</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Disables offline caching. Certain features may be limited or missing in this mode. Changes require a restart of Fernschreiber to take effect.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -1433,6 +1433,14 @@
<source>Focus the text input area after sending a message</source>
<translation>Mantieni la tastiera in primo piano dopo aver inviato un messaggio</translation>
</message>
<message>
<source>Enable online-only mode</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Disables offline caching. Certain features may be limited or missing in this mode. Changes require a restart of Fernschreiber to take effect.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -1454,6 +1454,14 @@
<source>Focus the text input area after sending a message</source>
<translation>Po wysłaniu wiadomości zaznacz pole wprowadzania tekstu</translation>
</message>
<message>
<source>Enable online-only mode</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Disables offline caching. Certain features may be limited or missing in this mode. Changes require a restart of Fernschreiber to take effect.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -1454,6 +1454,14 @@
<source>Focus the text input area after sending a message</source>
<translation>Сфокусироваться на поле ввода текста после отправки сообщения</translation>
</message>
<message>
<source>Enable online-only mode</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Disables offline caching. Certain features may be limited or missing in this mode. Changes require a restart of Fernschreiber to take effect.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -1433,6 +1433,14 @@
<source>Focus the text input area after sending a message</source>
<translation>Fokusera textinmatningsfältet efter att ett meddelande skickats</translation>
</message>
<message>
<source>Enable online-only mode</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Disables offline caching. Certain features may be limited or missing in this mode. Changes require a restart of Fernschreiber to take effect.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -1413,6 +1413,14 @@
<source>Focus the text input area after sending a message</source>
<translation></translation>
</message>
<message>
<source>Enable online-only mode</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Disables offline caching. Certain features may be limited or missing in this mode. Changes require a restart of Fernschreiber to take effect.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -1433,6 +1433,14 @@
<source>Focus the text input area after sending a message</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enable online-only mode</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Disables offline caching. Certain features may be limited or missing in this mode. Changes require a restart of Fernschreiber to take effect.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerPicker</name>