Contact synchronization also via settings

This commit is contained in:
Sebastian Wolf 2021-09-01 00:37:15 +02:00
parent 3b387afa01
commit 078a509183
No known key found for this signature in database
GPG key ID: CEA9522B5F38A90A
16 changed files with 298 additions and 20 deletions

View file

@ -44,6 +44,7 @@ DISTFILES += qml/harbour-fernschreiber.qml \
qml/components/AudioPreview.qml \
qml/components/BackgroundImage.qml \
qml/components/ChatListViewItem.qml \
qml/components/ContactSync.qml \
qml/components/DocumentPreview.qml \
qml/components/GamePreview.qml \
qml/components/ImagePreview.qml \

View file

@ -0,0 +1,45 @@
/*
Copyright (C) 2021 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.0
import org.nemomobile.contacts 1.0
Item {
signal syncError();
function synchronize() {
if (peopleModel.count === 0) {
appNotification.show(qsTr("Could not synchronize your contacts with Telegram."));
syncError();
} else {
contactsModel.startImportingContacts();
for (var i = 0; i < peopleModel.count; i++ ) {
contactsModel.importContact(peopleModel.get(i));
}
contactsModel.stopImportingContacts();
}
}
PeopleModel {
id: peopleModel
filterType: PeopleModel.FilterAll
requiredProperty: PeopleModel.PhoneNumberRequired
}
}

View file

@ -34,6 +34,7 @@ AccordionItem {
readonly property var userInformation: tdLibWrapper.getUserInformation()
property bool uploadInProgress: false
property bool contactSyncEnabled: false
Component.onCompleted: {
tdLibWrapper.getUserProfilePhotos(userInformation.id, 100, 0);
@ -152,6 +153,49 @@ AccordionItem {
}
Column {
id: contactSyncItem
width: parent.width
height: syncInProgress ? ( syncContactsBusyIndicator.height + Theme.paddingMedium ) : ( syncContactsButton.height + Theme.paddingMedium )
visible: accordionContent.contactSyncEnabled
property bool syncInProgress: false
Connections {
target: contactSyncLoader.item
onSyncError: {
contactSyncItem.syncInProgress = false;
}
}
Connections {
target: tdLibWrapper
onContactsImported: {
appNotification.show(qsTr("Contacts successfully synchronized with Telegram."));
}
}
Button {
id: syncContactsButton
text: qsTr("Synchronize Contacts with Telegram")
visible: !contactSyncItem.syncInProgress
anchors {
horizontalCenter: parent.horizontalCenter
}
onClicked: {
contactSyncLoader.item.synchronize();
}
}
BusyIndicator {
id: syncContactsBusyIndicator
anchors.horizontalCenter: parent.horizontalCenter
running: contactSyncItem.syncInProgress
size: BusyIndicatorSize.Small
visible: running
}
}
SectionHeader {
horizontalAlignment: Text.AlignLeft
text: qsTr("Profile Pictures")
@ -246,6 +290,15 @@ AccordionItem {
}
Loader {
id: contactSyncLoader
source: "../ContactSync.qml"
active: true
onLoaded: {
accordionContent.contactSyncEnabled = true;
}
}
Component {
id: imagePickerPage
ImagePickerPage {

View file

@ -18,7 +18,6 @@
*/
import QtQuick 2.6
import Sailfish.Silica 1.0
import org.nemomobile.contacts 1.0
import "../components"
import "../js/twemoji.js" as Emoji
import "../js/functions.js" as Functions
@ -59,21 +58,29 @@ Page {
Component.onCompleted: {
var sailfishOSVersion = fernschreiberUtils.getSailfishOSVersion().split(".");
// With Sailfish OS 4 we can't get up-to-date contacts with the standard database anymore. We might need to enter Sailjail eventually...
// Details see https://forum.sailfishos.org/t/4-0-1-45-non-jailed-contacts-sqlite-database-no-longer-updated/4724
// We try it with the inofficial Nemo Contact API via a loader...
if (parseInt(sailfishOSVersion[0]) < 4) {
Debug.log("Sailfish OS version 3.x - contact sync should still be possible...")
newChatPage.syncSupported = true;
} else {
// With Sailfish OS 4 we can't get up-to-date contacts with the standard database anymore. We might need to enter Sailjail eventually...
// Details see https://forum.sailfishos.org/t/4-0-1-45-non-jailed-contacts-sqlite-database-no-longer-updated/4724
// We try it with the inofficial Nemo Contact API...
newChatPage.nemoSync = true;
}
}
PeopleModel {
id: peopleModel
filterType: PeopleModel.FilterAll
requiredProperty: PeopleModel.PhoneNumberRequired
Connections {
target: contactSyncLoader.item
onSyncError: {
newChatPage.isLoading = false;
}
}
Loader {
id: contactSyncLoader
source: "../components/ContactSync.qml"
active: true
onLoaded: {
newChatPage.nemoSync = true;
}
}
SilicaFlickable {
@ -82,20 +89,12 @@ Page {
anchors.fill: parent
PullDownMenu {
enabled: newChatPage.syncSupported || newChatPage.nemoSync
MenuItem {
onClicked: {
newChatPage.isLoading = true;
if (newChatPage.nemoSync) {
if (peopleModel.count === 0) {
appNotification.show(qsTr("Could not synchronize your contacts with Telegram."));
newChatPage.isLoading = false;
} else {
contactsModel.startImportingContacts();
for (var i = 0; i < peopleModel.count; i++ ) {
contactsModel.importContact(peopleModel.get(i));
}
contactsModel.stopImportingContacts();
}
contactSyncLoader.item.synchronize();
}
if (newChatPage.syncSupported) {
if (!contactsModel.synchronizeContacts()) {

View file

@ -534,6 +534,13 @@
<translation>Sie haben noch keine Chats.</translation>
</message>
</context>
<context>
<name>ContactSync</name>
<message>
<source>Could not synchronize your contacts with Telegram.</source>
<translation>Konnte Ihre Kontakte nicht mit Telegram synchronisieren.</translation>
</message>
</context>
<context>
<name>CoverPage</name>
<message>
@ -1756,6 +1763,14 @@
<source>Uploading...</source>
<translation>Lade hoch...</translation>
</message>
<message>
<source>Synchronize Contacts with Telegram</source>
<translation>Kontakte mit Telegram synchronisieren</translation>
</message>
<message>
<source>Contacts successfully synchronized with Telegram.</source>
<translation>Die Kontakte wurden erfolgreich mit Telegram synchronisiert.</translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -534,6 +534,13 @@
<translation>You don&apos;t have any chats yet.</translation>
</message>
</context>
<context>
<name>ContactSync</name>
<message>
<source>Could not synchronize your contacts with Telegram.</source>
<translation type="unfinished">Could not synchronize your contacts with Telegram.</translation>
</message>
</context>
<context>
<name>CoverPage</name>
<message>
@ -1758,6 +1765,14 @@ messages</numerusform>
<source>Uploading...</source>
<translation>Uploading...</translation>
</message>
<message>
<source>Synchronize Contacts with Telegram</source>
<translation type="unfinished">Synchronize Contacts with Telegram</translation>
</message>
<message>
<source>Contacts successfully synchronized with Telegram.</source>
<translation type="unfinished">Contacts successfully synchronized with Telegram.</translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -534,6 +534,13 @@
<translation>No hay todavía conversaciones.</translation>
</message>
</context>
<context>
<name>ContactSync</name>
<message>
<source>Could not synchronize your contacts with Telegram.</source>
<translation type="unfinished">No se pudieron sincronizar los contactos con Telegram.</translation>
</message>
</context>
<context>
<name>CoverPage</name>
<message>
@ -1756,6 +1763,14 @@
<source>Uploading...</source>
<translation>Subiendo...</translation>
</message>
<message>
<source>Synchronize Contacts with Telegram</source>
<translation type="unfinished">Sincronizar con Telegram</translation>
</message>
<message>
<source>Contacts successfully synchronized with Telegram.</source>
<translation type="unfinished">Contactos sincronizados con éxito con Telegram.</translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -534,6 +534,13 @@
<translation>Sinulla ei ole vielä keskusteluja.</translation>
</message>
</context>
<context>
<name>ContactSync</name>
<message>
<source>Could not synchronize your contacts with Telegram.</source>
<translation type="unfinished">Yhteystietojasi ei voitu synkronoida Telegramin kanssa.</translation>
</message>
</context>
<context>
<name>CoverPage</name>
<message>
@ -1757,6 +1764,14 @@
<source>Uploading...</source>
<translation>Lähetetään...</translation>
</message>
<message>
<source>Synchronize Contacts with Telegram</source>
<translation type="unfinished">Synkronoi yhteystiedot Telegramin kanssa</translation>
</message>
<message>
<source>Contacts successfully synchronized with Telegram.</source>
<translation type="unfinished">Yhteystietojen synkronointi Telegramin kanssa onnistui.</translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -524,6 +524,13 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ContactSync</name>
<message>
<source>Could not synchronize your contacts with Telegram.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>CoverPage</name>
<message>
@ -1729,6 +1736,14 @@
<source>Uploading...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Synchronize Contacts with Telegram</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Contacts successfully synchronized with Telegram.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -534,6 +534,13 @@
<translation>Nessuna chat presente</translation>
</message>
</context>
<context>
<name>ContactSync</name>
<message>
<source>Could not synchronize your contacts with Telegram.</source>
<translation type="unfinished">Sincronizzazione contatti con Telegram non riuscita</translation>
</message>
</context>
<context>
<name>CoverPage</name>
<message>
@ -1756,6 +1763,14 @@
<source>Uploading...</source>
<translation>Carica...</translation>
</message>
<message>
<source>Synchronize Contacts with Telegram</source>
<translation type="unfinished">Sincronizza contatti con Telegram</translation>
</message>
<message>
<source>Contacts successfully synchronized with Telegram.</source>
<translation type="unfinished">Sincronizzazione contatti con Telegram completata</translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -544,6 +544,13 @@
<translation>Nie masz jeszcze żadnych czatów.</translation>
</message>
</context>
<context>
<name>ContactSync</name>
<message>
<source>Could not synchronize your contacts with Telegram.</source>
<translation type="unfinished">Nie można zsynchonizaować kontaktów z Telegramem.</translation>
</message>
</context>
<context>
<name>CoverPage</name>
<message>
@ -1783,6 +1790,14 @@
<source>Uploading...</source>
<translation>Przesyłanie...</translation>
</message>
<message>
<source>Synchronize Contacts with Telegram</source>
<translation type="unfinished">Synchronizuj kontakty z Telegramem</translation>
</message>
<message>
<source>Contacts successfully synchronized with Telegram.</source>
<translation type="unfinished">Synchronizacja kontaktów z Telegramem zakończona sukcesem.</translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -544,6 +544,13 @@
<translation>Тут пока ничего нет</translation>
</message>
</context>
<context>
<name>ContactSync</name>
<message>
<source>Could not synchronize your contacts with Telegram.</source>
<translation type="unfinished">Невозможно синхронизировать ваши контакты с Телеграм.</translation>
</message>
</context>
<context>
<name>CoverPage</name>
<message>
@ -1786,6 +1793,14 @@
<source>Uploading...</source>
<translation>Отправка...</translation>
</message>
<message>
<source>Synchronize Contacts with Telegram</source>
<translation type="unfinished">Синхронизировать с Телеграм</translation>
</message>
<message>
<source>Contacts successfully synchronized with Telegram.</source>
<translation type="unfinished">Контакты успешно синхронизированы с Телеграм.</translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -544,6 +544,13 @@
<translation>Nemáte žiadne čety.</translation>
</message>
</context>
<context>
<name>ContactSync</name>
<message>
<source>Could not synchronize your contacts with Telegram.</source>
<translation type="unfinished">Nemožno synchonizovať kontakty s Telegramom.</translation>
</message>
</context>
<context>
<name>CoverPage</name>
<message>
@ -1783,6 +1790,14 @@
<source>Uploading...</source>
<translation>Zapisovanie...</translation>
</message>
<message>
<source>Synchronize Contacts with Telegram</source>
<translation type="unfinished">Synchronizovať kontakty s Telegramom</translation>
</message>
<message>
<source>Contacts successfully synchronized with Telegram.</source>
<translation type="unfinished">Kontakty boli úspešne synchronizované s Telegramom.</translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -534,6 +534,13 @@
<translation>Du har inga chattar än.</translation>
</message>
</context>
<context>
<name>ContactSync</name>
<message>
<source>Could not synchronize your contacts with Telegram.</source>
<translation type="unfinished">Kunde inte synkronisera dina kontakter med Telegram.</translation>
</message>
</context>
<context>
<name>CoverPage</name>
<message>
@ -1756,6 +1763,14 @@
<source>Uploading...</source>
<translation>Ladda upp...</translation>
</message>
<message>
<source>Synchronize Contacts with Telegram</source>
<translation type="unfinished">Synkronisera kontakter med Telegram</translation>
</message>
<message>
<source>Contacts successfully synchronized with Telegram.</source>
<translation type="unfinished">Kontakter synkroniserade med Telegram.</translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -524,6 +524,13 @@
<translation></translation>
</message>
</context>
<context>
<name>ContactSync</name>
<message>
<source>Could not synchronize your contacts with Telegram.</source>
<translation type="unfinished"> Telegram </translation>
</message>
</context>
<context>
<name>CoverPage</name>
<message>
@ -1730,6 +1737,14 @@
<source>Uploading...</source>
<translation></translation>
</message>
<message>
<source>Synchronize Contacts with Telegram</source>
<translation type="unfinished"> Telegram </translation>
</message>
<message>
<source>Contacts successfully synchronized with Telegram.</source>
<translation type="unfinished"> Telegram </translation>
</message>
</context>
<context>
<name>StickerPicker</name>

View file

@ -534,6 +534,13 @@
<translation>You don&apos;t have any chats yet.</translation>
</message>
</context>
<context>
<name>ContactSync</name>
<message>
<source>Could not synchronize your contacts with Telegram.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>CoverPage</name>
<message>
@ -1756,6 +1763,14 @@
<source>Uploading...</source>
<translation type="unfinished">Uploading...</translation>
</message>
<message>
<source>Synchronize Contacts with Telegram</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Contacts successfully synchronized with Telegram.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerPicker</name>