Support for managing Telegram sessions

This commit is contained in:
Sebastian Wolf 2021-02-20 00:14:43 +01:00
parent b2f2ee5453
commit aef9fd8391
No known key found for this signature in database
GPG key ID: CEA9522B5F38A90A
20 changed files with 719 additions and 3 deletions

View file

@ -110,6 +110,7 @@ DISTFILES += qml/harbour-fernschreiber.qml \
qml/components/messageContent/WebPagePreview.qml \
qml/js/debug.js \
qml/js/functions.js \
qml/pages/ActiveSessionsPage.qml \
qml/pages/ChatInformationPage.qml \
qml/pages/ChatPage.qml \
qml/pages/ChatSelectionPage.qml \

View file

@ -219,6 +219,10 @@ function getDateTimeTranslated(timestamp) {
return new Date(timestamp * 1000).toLocaleString();
}
function getDateTimeTimepoint(timestamp) {
return Silica.Format.formatDate(new Date(timestamp * 1000), Silica.Formatter.TimepointRelative);
}
function handleHtmlEntity(messageText, messageInsertions, originalString, replacementString) {
var nextIndex = -1;
while ((nextIndex = messageText.indexOf(originalString, nextIndex + 1)) > -1) {

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 2020 Sebastian J. Wolf and other contributors
Copyright (C) 2020-21 Sebastian J. Wolf and other contributors
This file is part of Fernschreiber.
@ -232,7 +232,17 @@ Page {
}
Button {
id: flickrTosButton
id: activeSessionsButton
text: qsTr("Active Sessions")
anchors {
horizontalCenter: parent.horizontalCenter
}
onClicked: {
pageStack.push(Qt.resolvedUrl("ActiveSessionsPage.qml"));
}
}
Button {
text: qsTr("Terms of Service")
anchors {
horizontalCenter: parent.horizontalCenter
@ -243,7 +253,6 @@ Page {
}
Button {
id: flickrPrivacyButton
text: qsTr("Privacy Policy")
anchors {
horizontalCenter: parent.horizontalCenter

View file

@ -0,0 +1,203 @@
/*
Copyright (C) 2020-21 Sebastian J. Wolf and other contributors
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/>.
*/
import QtQuick 2.6
import Sailfish.Silica 1.0
import "../components"
import "../js/twemoji.js" as Emoji
import "../js/functions.js" as Functions
Page {
id: activeSessionsPage
allowedOrientations: Orientation.All
property variant activeSessions;
property bool loaded : false;
Component.onCompleted: {
if (!activeSessions) {
tdLibWrapper.getActiveSessions();
} else {
activeSessionsPage.loaded = true;
}
}
Connections {
target: tdLibWrapper
onSessionsReceived: {
activeSessionsPage.activeSessions = sessions;
activeSessionsPage.loaded = true;
}
onOkReceived: {
if (request === "terminateSession") {
appNotification.show(qsTr("Session was terminated"));
activeSessionsPage.loaded = false;
tdLibWrapper.getActiveSessions();
}
}
}
SilicaFlickable {
id: activeSessionsFlickable
anchors.fill: parent
Column {
anchors.fill: parent
PageHeader {
id: activeSessionsHeader
title: qsTr("Active Sessions")
}
SilicaListView {
id: activeSessionsListView
width: parent.width
height: parent.height - activeSessionsHeader.height
clip: true
model: activeSessionsPage.activeSessions
delegate: ListItem {
id: activeSessionListItem
width: parent.width
contentHeight: activeSessionColumn.height + ( 2 * Theme.paddingMedium )
menu: ContextMenu {
hasContent: !modelData.is_current
MenuItem {
onClicked: {
var sessionId = modelData.id;
Remorse.itemAction(activeSessionListItem, qsTr("Terminating session"), function() { tdLibWrapper.terminateSession(sessionId); });
}
text: qsTr("Terminate Session")
}
}
Column {
id: activeSessionColumn
width: parent.width - ( 2 * Theme.horizontalPageMargin )
spacing: Theme.paddingSmall
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
Label {
width: parent.width
text: qsTr("This app")
font.pixelSize: Theme.fontSizeMedium
font.bold: true
visible: modelData.is_current
color: Theme.highlightColor
anchors {
horizontalCenter: parent.horizontalCenter
}
}
Label {
width: parent.width
text: modelData.application_name + " " + modelData.application_version
font.pixelSize: Theme.fontSizeMedium
font.bold: true
color: Theme.primaryColor
maximumLineCount: 1
elide: Text.ElideRight
anchors {
horizontalCenter: parent.horizontalCenter
}
}
Label {
width: parent.width
text: modelData.device_model + ", " + (modelData.platform + " " + modelData.system_version).trim()
font.pixelSize: Theme.fontSizeSmall
color: Theme.primaryColor
maximumLineCount: 1
truncationMode: TruncationMode.Fade
anchors {
horizontalCenter: parent.horizontalCenter
}
}
Label {
width: parent.width
text: qsTr("IP address: %1, origin: %2").arg(modelData.ip).arg(modelData.country)
font.pixelSize: Theme.fontSizeExtraSmall
color: Theme.secondaryColor
maximumLineCount: 1
truncationMode: TruncationMode.Fade
anchors {
horizontalCenter: parent.horizontalCenter
}
}
Label {
width: parent.width
text: qsTr("Active since: %1, last online: %2").arg(Functions.getDateTimeTimepoint(modelData.log_in_date)).arg(Functions.getDateTimeElapsed(modelData.last_active_date))
font.pixelSize: Theme.fontSizeExtraSmall
color: Theme.primaryColor
maximumLineCount: 1
truncationMode: TruncationMode.Fade
anchors {
horizontalCenter: parent.horizontalCenter
}
}
}
Separator {
id: separator
anchors {
bottom: parent.bottom
}
width: parent.width
color: Theme.primaryColor
horizontalAlignment: Qt.AlignHCenter
}
}
VerticalScrollDecorator {}
}
}
Column {
opacity: visible ? 1 : 0
Behavior on opacity { FadeAnimation {} }
visible: !activeSessionsPage.loaded
width: parent.width
height: loadingLabel.height + loadingBusyIndicator.height + Theme.paddingMedium
spacing: Theme.paddingMedium
anchors.verticalCenter: parent.verticalCenter
InfoLabel {
id: loadingLabel
text: qsTr("Getting active sessions...")
}
BusyIndicator {
id: loadingBusyIndicator
anchors.horizontalCenter: parent.horizontalCenter
running: !activeSessionsPage.loaded
size: BusyIndicatorSize.Large
}
}
}
}

View file

@ -143,6 +143,7 @@ TDLibReceiver::TDLibReceiver(void *tdLibClient, QObject *parent) : QThread(paren
handlers.insert("userPrivacySettingRules", &TDLibReceiver::processUserPrivacySettingRules);
handlers.insert("updateUserPrivacySettingRules", &TDLibReceiver::processUpdateUserPrivacySettingRules);
handlers.insert("updateMessageInteractionInfo", &TDLibReceiver::processUpdateMessageInteractionInfo);
handlers.insert("sessions", &TDLibReceiver::processSessions);
}
void TDLibReceiver::setActive(bool active)
@ -638,3 +639,9 @@ void TDLibReceiver::processUpdateMessageInteractionInfo(const QVariantMap &recei
LOG("Message interaction info updated" << chatId << messageId);
emit messageInteractionInfoUpdated(chatId, messageId, receivedInformation.value(INTERACTION_INFO).toMap());
}
void TDLibReceiver::processSessions(const QVariantMap &receivedInformation)
{
QVariantList sessions = receivedInformation.value("sessions").toList();
emit sessionsReceived(sessions);
}

View file

@ -99,6 +99,7 @@ signals:
void userPrivacySettingRulesUpdated(const QVariantMap &updatedRules);
void messageInteractionInfoUpdated(qlonglong chatId, qlonglong messageId, const QVariantMap &updatedInfo);
void okReceived(const QString &request);
void sessionsReceived(const QVariantList &sessions);
private:
typedef void (TDLibReceiver::*Handler)(const QVariantMap &);
@ -171,6 +172,7 @@ private:
void processUserPrivacySettingRules(const QVariantMap &receivedInformation);
void processUpdateUserPrivacySettingRules(const QVariantMap &receivedInformation);
void processUpdateMessageInteractionInfo(const QVariantMap &receivedInformation);
void processSessions(const QVariantMap &receivedInformation);
};
#endif // TDLIBRECEIVER_H

View file

@ -162,6 +162,7 @@ void TDLibWrapper::initializeTDLibReciever() {
connect(this->tdLibReceiver, SIGNAL(userPrivacySettingRulesUpdated(QVariantMap)), this, SLOT(handleUpdatedUserPrivacySettingRules(QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(messageInteractionInfoUpdated(qlonglong, qlonglong, QVariantMap)), this, SIGNAL(messageInteractionInfoUpdated(qlonglong, qlonglong, QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(okReceived(QString)), this, SIGNAL(okReceived(QString)));
connect(this->tdLibReceiver, SIGNAL(sessionsReceived(QVariantList)), this, SIGNAL(sessionsReceived(QVariantList)));
this->tdLibReceiver->start();
}
@ -1339,6 +1340,24 @@ void TDLibWrapper::changeStickerSet(const QString &stickerSetId, bool isInstalle
this->sendRequest(requestObject);
}
void TDLibWrapper::getActiveSessions()
{
LOG("Get active sessions");
QVariantMap requestObject;
requestObject.insert(_TYPE, "getActiveSessions");
this->sendRequest(requestObject);
}
void TDLibWrapper::terminateSession(const QString &sessionId)
{
LOG("Terminate session" << sessionId);
QVariantMap requestObject;
requestObject.insert(_TYPE, "terminateSession");
requestObject.insert(_EXTRA, "terminateSession");
requestObject.insert("session_id", sessionId);
this->sendRequest(requestObject);
}
void TDLibWrapper::searchEmoji(const QString &queryString)
{
LOG("Searching emoji" << queryString);

View file

@ -222,6 +222,8 @@ public:
Q_INVOKABLE void setProfilePhoto(const QString &filePath);
Q_INVOKABLE void deleteProfilePhoto(const QString &profilePhotoId);
Q_INVOKABLE void changeStickerSet(const QString &stickerSetId, bool isInstalled);
Q_INVOKABLE void getActiveSessions();
Q_INVOKABLE void terminateSession(const QString &sessionId);
// Others (candidates for extraction ;))
Q_INVOKABLE void searchEmoji(const QString &queryString);
@ -300,6 +302,7 @@ signals:
void userPrivacySettingUpdated(UserPrivacySetting setting, UserPrivacySettingRule rule);
void messageInteractionInfoUpdated(qlonglong chatId, qlonglong messageId, const QVariantMap &updatedInfo);
void okReceived(const QString &request);
void sessionsReceived(const QVariantList &sessions);
public slots:
void handleVersionDetected(const QString &version);

View file

@ -91,6 +91,45 @@
<source>Logged out</source>
<translation>Abgemeldet</translation>
</message>
<message>
<source>Active Sessions</source>
<translation>Aktive Sitzungen</translation>
</message>
</context>
<context>
<name>ActiveSessionsPage</name>
<message>
<source>Getting active sessions...</source>
<translation>Erhalte aktive Sitzungen...</translation>
</message>
<message>
<source>Active Sessions</source>
<translation>Aktive Sitzungen</translation>
</message>
<message>
<source>Session was terminated</source>
<translation>Sitzung wurde beendet</translation>
</message>
<message>
<source>Terminate Session</source>
<translation>Sitzung beenden</translation>
</message>
<message>
<source>This app</source>
<translation>Diese App</translation>
</message>
<message>
<source>IP address: %1, origin: %2</source>
<translation>IP-Adresse: %1, Herkunft: %2</translation>
</message>
<message>
<source>Active since: %1, last online: %2</source>
<translation>Aktiv seit: %1, zuletzt online: %2</translation>
</message>
<message>
<source>Terminating session</source>
<translation>Beende Sitzung</translation>
</message>
</context>
<context>
<name>BackgroundProgressIndicator</name>

View file

@ -91,6 +91,45 @@
<source>Logged out</source>
<translation>Logged out</translation>
</message>
<message>
<source>Active Sessions</source>
<translation>Active Sessions</translation>
</message>
</context>
<context>
<name>ActiveSessionsPage</name>
<message>
<source>Getting active sessions...</source>
<translation>Getting active sessions...</translation>
</message>
<message>
<source>Active Sessions</source>
<translation>Active Sessions</translation>
</message>
<message>
<source>Session was terminated</source>
<translation>Session was terminated</translation>
</message>
<message>
<source>Terminate Session</source>
<translation>Terminate Session</translation>
</message>
<message>
<source>This app</source>
<translation>This app</translation>
</message>
<message>
<source>IP address: %1, origin: %2</source>
<translation>IP address: %1, origin: %2</translation>
</message>
<message>
<source>Active since: %1, last online: %2</source>
<translation>Active since: %1, last online: %2</translation>
</message>
<message>
<source>Terminating session</source>
<translation>Terminating session</translation>
</message>
</context>
<context>
<name>BackgroundProgressIndicator</name>

View file

@ -91,6 +91,45 @@
<source>Logged out</source>
<translation>Desconectado</translation>
</message>
<message>
<source>Active Sessions</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ActiveSessionsPage</name>
<message>
<source>Getting active sessions...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Active Sessions</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Session was terminated</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Terminate Session</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>This app</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>IP address: %1, origin: %2</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Active since: %1, last online: %2</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Terminating session</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>BackgroundProgressIndicator</name>

View file

@ -91,6 +91,45 @@
<source>Logged out</source>
<translation>Kirjattu ulos</translation>
</message>
<message>
<source>Active Sessions</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ActiveSessionsPage</name>
<message>
<source>Getting active sessions...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Active Sessions</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Session was terminated</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Terminate Session</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>This app</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>IP address: %1, origin: %2</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Active since: %1, last online: %2</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Terminating session</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>BackgroundProgressIndicator</name>

View file

@ -91,6 +91,45 @@
<source>Logged out</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Active Sessions</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ActiveSessionsPage</name>
<message>
<source>Getting active sessions...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Active Sessions</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Session was terminated</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Terminate Session</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>This app</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>IP address: %1, origin: %2</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Active since: %1, last online: %2</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Terminating session</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>BackgroundProgressIndicator</name>

View file

@ -91,6 +91,45 @@
<source>Logged out</source>
<translation>Disconnesso</translation>
</message>
<message>
<source>Active Sessions</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ActiveSessionsPage</name>
<message>
<source>Getting active sessions...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Active Sessions</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Session was terminated</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Terminate Session</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>This app</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>IP address: %1, origin: %2</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Active since: %1, last online: %2</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Terminating session</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>BackgroundProgressIndicator</name>

View file

@ -91,6 +91,45 @@
<source>Logged out</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Active Sessions</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ActiveSessionsPage</name>
<message>
<source>Getting active sessions...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Active Sessions</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Session was terminated</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Terminate Session</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>This app</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>IP address: %1, origin: %2</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Active since: %1, last online: %2</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Terminating session</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>BackgroundProgressIndicator</name>

View file

@ -91,6 +91,45 @@
<source>Logged out</source>
<translation>Выход из аккаунта</translation>
</message>
<message>
<source>Active Sessions</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ActiveSessionsPage</name>
<message>
<source>Getting active sessions...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Active Sessions</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Session was terminated</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Terminate Session</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>This app</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>IP address: %1, origin: %2</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Active since: %1, last online: %2</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Terminating session</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>BackgroundProgressIndicator</name>

View file

@ -91,6 +91,45 @@
<source>Logged out</source>
<translation>Odhlásený</translation>
</message>
<message>
<source>Active Sessions</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ActiveSessionsPage</name>
<message>
<source>Getting active sessions...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Active Sessions</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Session was terminated</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Terminate Session</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>This app</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>IP address: %1, origin: %2</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Active since: %1, last online: %2</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Terminating session</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>BackgroundProgressIndicator</name>

View file

@ -91,6 +91,45 @@
<source>Logged out</source>
<translation>Utloggad</translation>
</message>
<message>
<source>Active Sessions</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ActiveSessionsPage</name>
<message>
<source>Getting active sessions...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Active Sessions</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Session was terminated</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Terminate Session</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>This app</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>IP address: %1, origin: %2</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Active since: %1, last online: %2</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Terminating session</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>BackgroundProgressIndicator</name>

View file

@ -91,6 +91,45 @@
<source>Logged out</source>
<translation></translation>
</message>
<message>
<source>Active Sessions</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ActiveSessionsPage</name>
<message>
<source>Getting active sessions...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Active Sessions</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Session was terminated</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Terminate Session</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>This app</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>IP address: %1, origin: %2</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Active since: %1, last online: %2</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Terminating session</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>BackgroundProgressIndicator</name>

View file

@ -91,6 +91,45 @@
<source>Logged out</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Active Sessions</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ActiveSessionsPage</name>
<message>
<source>Getting active sessions...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Active Sessions</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Session was terminated</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Terminate Session</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>This app</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>IP address: %1, origin: %2</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Active since: %1, last online: %2</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Terminating session</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>BackgroundProgressIndicator</name>