Compare commits

...

3 commits

Author SHA1 Message Date
Sebastian Wolf
7046d1dc0b
Merge branch 'master' into reviveContactSync 2021-09-28 21:33:03 +02:00
Sebastian Wolf
078a509183
Contact synchronization also via settings 2021-09-01 00:37:15 +02:00
Sebastian Wolf
3b387afa01
Synchronize contacts with Nemomobile QML API 2021-08-31 12:15:05 +02:00
21 changed files with 351 additions and 11 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 \
@ -201,8 +202,11 @@ fernschreiber.desktop.files = harbour-fernschreiber.desktop
database.files = db
database.path = /usr/share/$${TARGET}
mapplauncher.path = /usr/share/mapplauncherd/privileges.d
mapplauncher.files = privileges/harbour-fernschreiber.privileges
INSTALLS += telegram 86.png 108.png 128.png 172.png 256.png \
fernschreiber.desktop gui images database
fernschreiber.desktop gui images database mapplauncher
HEADERS += \
src/appsettings.h \

View file

@ -0,0 +1 @@
/usr/bin/harbour-fernschreiber,p

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

@ -29,6 +29,7 @@ Page {
property bool isLoading: true;
property bool syncSupported: false;
property bool nemoSync: false;
function resetFocus() {
contactsSearchField.focus = false;
@ -56,15 +57,29 @@ Page {
}
Component.onCompleted: {
// With Sailfish OS 4 we can't get up-to-date contacts andmore. 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
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 {
Debug.log("Sailfish OS version 4.x - contact sync no longer supported...")
newChatPage.syncSupported = false;
}
}
Connections {
target: contactSyncLoader.item
onSyncError: {
newChatPage.isLoading = false;
}
}
Loader {
id: contactSyncLoader
source: "../components/ContactSync.qml"
active: true
onLoaded: {
newChatPage.nemoSync = true;
}
}
@ -74,13 +89,18 @@ Page {
anchors.fill: parent
PullDownMenu {
visible: contactsModel.canSynchronizeContacts() && newChatPage.syncSupported
enabled: newChatPage.syncSupported || newChatPage.nemoSync
MenuItem {
onClicked: {
newChatPage.isLoading = true;
if (!contactsModel.synchronizeContacts()) {
reloadContacts();
appNotification.show(qsTr("Could not synchronize your contacts with Telegram."));
if (newChatPage.nemoSync) {
contactSyncLoader.item.synchronize();
}
if (newChatPage.syncSupported) {
if (!contactsModel.synchronizeContacts()) {
reloadContacts();
appNotification.show(qsTr("Could not synchronize your contacts with Telegram."));
}
}
// Success message is not fired before TDLib returned "Contacts imported" (see above)
}

View file

@ -19,6 +19,7 @@ URL: http://werkwolf.eu/
Source0: %{name}-%{version}.tar.bz2
Source100: harbour-fernschreiber.yaml
Requires: sailfishsilica-qt5 >= 0.10.9
Requires: nemo-qml-plugin-contacts-qt5
BuildRequires: pkgconfig(sailfishapp) >= 1.0.2
BuildRequires: pkgconfig(Qt5Core)
BuildRequires: pkgconfig(Qt5Qml)
@ -70,5 +71,6 @@ desktop-file-install --delete-original \
%{_datadir}/%{name}
%{_datadir}/applications/%{name}.desktop
%{_datadir}/icons/hicolor/*/apps/%{name}.png
%{_datadir}/mapplauncherd/privileges.d/harbour-fernschreiber.privileges
# >> files
# << files

View file

@ -36,6 +36,7 @@ PkgConfigBR:
# Runtime dependencies which are not automatically detected
Requires:
- sailfishsilica-qt5 >= 0.10.9
- nemo-qml-plugin-contacts-qt5
# All installed files
Files:
@ -43,6 +44,7 @@ Files:
- '%{_datadir}/%{name}'
- '%{_datadir}/applications/%{name}.desktop'
- '%{_datadir}/icons/hicolor/*/apps/%{name}.png'
- '%{_datadir}/mapplauncherd/privileges.d/harbour-fernschreiber.privileges'
# For more information about yaml and what's supported in Sailfish OS
# build system, please see https://wiki.merproject.org/wiki/Spectacle

View file

@ -153,7 +153,7 @@ void ContactsModel::hydrateContacts()
bool ContactsModel::synchronizeContacts()
{
LOG("Synchronizing device contacts");
QVariantList deviceContacts;
deviceContacts.clear();
QSqlQuery databaseQuery(this->deviceContactsDatabase);
databaseQuery.prepare("select distinct c.contactId, c.firstName, c.lastName, n.phoneNumber from Contacts as c inner join PhoneNumbers as n on c.contactId = n.contactId where n.phoneNumber is not null and ( c.firstName is not null or c.lastName is not null );");
if (databaseQuery.exec()) {
@ -182,3 +182,32 @@ bool ContactsModel::canSynchronizeContacts()
{
return this->canUseDeviceContacts;
}
void ContactsModel::startImportingContacts()
{
this->deviceContacts.clear();
}
void ContactsModel::stopImportingContacts()
{
if (!deviceContacts.isEmpty()) {
LOG("Importing found contacts" << deviceContacts.size());
this->tdLibWrapper->importContacts(deviceContacts);
}
}
void ContactsModel::importContact(const QVariantMap &singlePerson)
{
QString firstName = singlePerson.value("firstName").toString();
QVariantList phoneNumbers = singlePerson.value("phoneNumbers").toList();
if (!firstName.isEmpty() && !phoneNumbers.isEmpty()) {
for (QVariant phoneNumber : phoneNumbers) {
QVariantMap singleContact;
singleContact.insert("first_name", firstName);
singleContact.insert("last_name", singlePerson.value("lastName").toString());
singleContact.insert("phone_number", phoneNumber.toString());
deviceContacts.append(singleContact);
LOG("Found contact" << singleContact.value("first_name").toString() << singleContact.value("last_name").toString() << singleContact.value("phone_number").toString());
}
}
}

View file

@ -52,6 +52,9 @@ public:
Q_INVOKABLE void hydrateContacts();
Q_INVOKABLE bool synchronizeContacts();
Q_INVOKABLE bool canSynchronizeContacts();
Q_INVOKABLE void startImportingContacts();
Q_INVOKABLE void stopImportingContacts();
Q_INVOKABLE void importContact(const QVariantMap &singlePerson);
public slots:
void handleUsersReceived(const QString &extra, const QVariantList &userIds, int totalUsers);
@ -63,6 +66,7 @@ private:
QString filter;
QSqlDatabase deviceContactsDatabase;
bool canUseDeviceContacts;
QVariantList deviceContacts;
};
#endif // CONTACTSMODEL_H

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>