Add and delete profile pictures

This commit is contained in:
Sebastian Wolf 2021-01-26 23:26:40 +01:00
parent 5e6cd6f4b4
commit 9b820dad2b
No known key found for this signature in database
GPG key ID: CEA9522B5F38A90A
17 changed files with 201 additions and 64 deletions

View file

@ -23,6 +23,7 @@ Item {
id: profilePictureListItem
visible: imageContainer.thumbnailVisible && bigProfilePictureList.count > 0
property bool isActive: imageContainer.thumbnailActive
readonly property int currentPictureIndex: bigProfilePictureList.currentIndex
opacity: isActive ? 1.0 : 0.0
Behavior on opacity { FadeAnimation {} }
@ -57,14 +58,15 @@ Item {
Text {
visible: bigProfilePictureList.count > 1
width: parent.width
width: parent.width - Theme.paddingSmall
anchors {
bottomMargin: Theme.paddingSmall
bottom: parent.bottom
}
horizontalAlignment: Text.AlignHCenter
property var baseString: new Array(bigProfilePictureList.count+1).join(" ○ ")
text: baseString.substring(0,bigProfilePictureList.currentIndex*3) + " ● " + baseString.substring((bigProfilePictureList.currentIndex+1)*3)
text: (baseString.substring(0,bigProfilePictureList.currentIndex*3) + " ● " + baseString.substring((bigProfilePictureList.currentIndex+1)*3)).trim()
font.pixelSize: Theme.fontSizeTiny
color: Theme.primaryColor
style: Text.Raised
styleColor: Theme.highlightDimmerColor

View file

@ -18,6 +18,7 @@
*/
import QtQuick 2.6
import Sailfish.Silica 1.0
import Sailfish.Pickers 1.0
import WerkWolf.Fernschreiber 1.0
import "../components"
import "../js/functions.js" as Functions
@ -29,6 +30,7 @@ Page {
readonly property bool landscapeLayout: (width > height && Screen.sizeCategory > Screen.Small) || Screen.sizeCategory > Screen.Medium
readonly property var userInformation: tdLibWrapper.getUserInformation()
property bool uploadInProgress: false
onStatusChanged: {
if (status === PageStatus.Active) {
@ -48,6 +50,21 @@ Page {
imageContainer.thumbnailModel = photos;
}
}
onFileUpdated: {
if (uploadInProgress) {
profilePictureButtonColumn.visible = !fileInformation.remote.is_uploading_active;
uploadInProgress = fileInformation.remote.is_uploading_active;
if (!fileInformation.remote.is_uploading_active) {
uploadInProgress = false;
tdLibWrapper.getUserProfilePhotos(userInformation.id, 100, 0);
}
}
}
onOkReceived: {
if (request === "deleteProfilePhoto") {
tdLibWrapper.getUserProfilePhotos(userInformation.id, 100, 0);
}
}
}
SilicaFlickable {
@ -182,6 +199,7 @@ Page {
}
Column {
id: profilePictureButtonColumn
spacing: Theme.paddingSmall
width: parent.width / 2
@ -192,27 +210,62 @@ Page {
horizontalCenter: parent.horizontalCenter
}
onClicked: {
pageStack.push(imagePickerPage);
}
}
Button {
id: removeProfilePictureButton
text: qsTr("Remove Picture")
text: qsTr("Delete Picture")
anchors {
horizontalCenter: parent.horizontalCenter
}
onClicked: {
var pictureIdForDeletion = imageContainer.thumbnailModel[profilePictureLoader.item.currentPictureIndex].id;
Remorse.popupAction(settingsPage, qsTr("Deleting profile picture"), function() { tdLibWrapper.deleteProfilePhoto(pictureIdForDeletion) });
}
}
}
Column {
id: uploadStatusColumn
visible: !profilePictureButtonColumn.visible
spacing: Theme.paddingMedium
width: parent.width / 2
Text {
id: uploadingText
font.pixelSize: Theme.fontSizeSmall
text: qsTr("Uploading...")
horizontalAlignment: Text.AlignHCenter
color: Theme.secondaryColor
width: parent.width
}
BusyIndicator {
anchors.horizontalCenter: parent.horizontalCenter
running: uploadStatusColumn.visible
size: BusyIndicatorSize.Medium
}
}
}
Component {
id: imagePickerPage
ImagePickerPage {
onSelectedContentPropertiesChanged: {
profilePictureButtonColumn.visible = false;
uploadInProgress = true;
tdLibWrapper.setProfilePhoto(selectedContentProperties.filePath);
}
}
}
SectionHeader {
horizontalAlignment: Text.AlignLeft
text: qsTr("Privacy Options")
text: qsTr("Privacy")
}
Grid {

View file

@ -558,8 +558,12 @@ void TDLibReceiver::processError(const QVariantMap &receivedInformation)
emit errorReceived(receivedInformation.value("code").toInt(), receivedInformation.value(MESSAGE).toString(), receivedInformation.value(EXTRA).toString());
}
void TDLibReceiver::nop(const QVariantMap &)
void TDLibReceiver::nop(const QVariantMap &receivedInformation)
{
LOG("Received an OK");
if (receivedInformation.contains(EXTRA)) {
emit okReceived(receivedInformation.value(EXTRA).toString());
}
}
void TDLibReceiver::processSecretChat(const QVariantMap &receivedInformation)

View file

@ -97,6 +97,7 @@ signals:
void callbackQueryAnswer(const QString &text, bool alert, const QString &url);
void userPrivacySettingRules(const QVariantMap &rules);
void userPrivacySettingRulesUpdated(const QVariantMap &updatedRules);
void okReceived(const QString &request);
private:
typedef void (TDLibReceiver::*Handler)(const QVariantMap &);

View file

@ -160,6 +160,7 @@ void TDLibWrapper::initializeTDLibReciever() {
connect(this->tdLibReceiver, SIGNAL(callbackQueryAnswer(QString, bool, QString)), this, SIGNAL(callbackQueryAnswer(QString, bool, QString)));
connect(this->tdLibReceiver, SIGNAL(userPrivacySettingRules(QVariantMap)), this, SLOT(handleUserPrivacySettingRules(QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(userPrivacySettingRulesUpdated(QVariantMap)), this, SLOT(handleUpdatedUserPrivacySettingRules(QVariantMap)));
connect(this->tdLibReceiver, SIGNAL(okReceived(QString)), this, SIGNAL(okReceived(QString)));
this->tdLibReceiver->start();
}
@ -1294,6 +1295,35 @@ void TDLibWrapper::getUserPrivacySettingRules(TDLibWrapper::UserPrivacySetting s
this->sendRequest(requestObject);
}
void TDLibWrapper::setProfilePhoto(const QString &filePath)
{
LOG("Set a profile photo" << filePath);
QVariantMap requestObject;
requestObject.insert(_TYPE, "setProfilePhoto");
QVariantMap inputChatPhoto;
inputChatPhoto.insert(_TYPE, "inputChatPhotoStatic");
QVariantMap inputFile;
inputFile.insert(_TYPE, "inputFileLocal");
inputFile.insert("path", filePath);
inputChatPhoto.insert("photo", inputFile);
requestObject.insert("photo", inputChatPhoto);
this->sendRequest(requestObject);
}
void TDLibWrapper::deleteProfilePhoto(const QString &profilePhotoId)
{
LOG("Delete a profile photo" << profilePhotoId);
QVariantMap requestObject;
requestObject.insert(_TYPE, "deleteProfilePhoto");
requestObject.insert(_EXTRA, "deleteProfilePhoto");
requestObject.insert("profile_photo_id", profilePhotoId);
this->sendRequest(requestObject);
}
void TDLibWrapper::searchEmoji(const QString &queryString)
{
LOG("Searching emoji" << queryString);

View file

@ -219,6 +219,8 @@ public:
Q_INVOKABLE void setUsername(const QString &userName);
Q_INVOKABLE void setUserPrivacySettingRule(UserPrivacySetting setting, UserPrivacySettingRule rule);
Q_INVOKABLE void getUserPrivacySettingRules(UserPrivacySetting setting);
Q_INVOKABLE void setProfilePhoto(const QString &filePath);
Q_INVOKABLE void deleteProfilePhoto(const QString &profilePhotoId);
// Others (candidates for extraction ;))
Q_INVOKABLE void searchEmoji(const QString &queryString);
@ -295,6 +297,7 @@ signals:
void inlineQueryResults(const QString &inlineQueryId, const QString &nextOffset, const QVariantList &results, const QString &switchPmText, const QString &switchPmParameter, const QString &extra);
void callbackQueryAnswer(const QString &text, bool alert, const QString &url);
void userPrivacySettingUpdated(UserPrivacySetting setting, UserPrivacySettingRule rule);
void okReceived(const QString &request);
public slots:
void handleVersionDetected(const QString &version);

View file

@ -1620,17 +1620,21 @@
<source>Add Picture</source>
<translation>Bild hinzufügen</translation>
</message>
<message>
<source>Remove Picture</source>
<translation>Bild löschen</translation>
</message>
<message>
<source>Profile Pictures</source>
<translation>Profilbilder</translation>
</message>
<message>
<source>Privacy Options</source>
<translation>Optionen zur Privatsphäre</translation>
<source>Delete Picture</source>
<translation>Bild löschen</translation>
</message>
<message>
<source>Uploading...</source>
<translation>Lade hoch...</translation>
</message>
<message>
<source>Deleting profile picture</source>
<translation>Lösche Profilbild</translation>
</message>
</context>
<context>

View file

@ -1620,17 +1620,21 @@
<source>Add Picture</source>
<translation>Add Picture</translation>
</message>
<message>
<source>Remove Picture</source>
<translation>Remove Picture</translation>
</message>
<message>
<source>Profile Pictures</source>
<translation>Profile Pictures</translation>
</message>
<message>
<source>Privacy Options</source>
<translation>Privacy Options</translation>
<source>Delete Picture</source>
<translation>Delete Picture</translation>
</message>
<message>
<source>Uploading...</source>
<translation>Uploading...</translation>
</message>
<message>
<source>Deleting profile picture</source>
<translation>Deleting profile picture</translation>
</message>
</context>
<context>

View file

@ -1620,16 +1620,20 @@
<source>Add Picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Remove Picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Profile Pictures</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Privacy Options</source>
<source>Delete Picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Uploading...</source>
<translation type="unfinished">Subiendo...</translation>
</message>
<message>
<source>Deleting profile picture</source>
<translation type="unfinished"></translation>
</message>
</context>

View file

@ -1621,16 +1621,20 @@
<source>Add Picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Remove Picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Profile Pictures</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Privacy Options</source>
<source>Delete Picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Uploading...</source>
<translation type="unfinished">Lähetetään...</translation>
</message>
<message>
<source>Deleting profile picture</source>
<translation type="unfinished"></translation>
</message>
</context>

View file

@ -1595,16 +1595,20 @@
<source>Add Picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Remove Picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Profile Pictures</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Privacy Options</source>
<source>Delete Picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Uploading...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Deleting profile picture</source>
<translation type="unfinished"></translation>
</message>
</context>

View file

@ -1620,16 +1620,20 @@
<source>Add Picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Remove Picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Profile Pictures</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Privacy Options</source>
<source>Delete Picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Uploading...</source>
<translation type="unfinished">Carica...</translation>
</message>
<message>
<source>Deleting profile picture</source>
<translation type="unfinished"></translation>
</message>
</context>

View file

@ -1645,16 +1645,20 @@
<source>Add Picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Remove Picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Profile Pictures</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Privacy Options</source>
<source>Delete Picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Uploading...</source>
<translation type="unfinished">Przesyłanie...</translation>
</message>
<message>
<source>Deleting profile picture</source>
<translation type="unfinished"></translation>
</message>
</context>

View file

@ -1645,16 +1645,20 @@
<source>Add Picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Remove Picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Profile Pictures</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Privacy Options</source>
<source>Delete Picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Uploading...</source>
<translation type="unfinished">Отправка...</translation>
</message>
<message>
<source>Deleting profile picture</source>
<translation type="unfinished"></translation>
</message>
</context>

View file

@ -1620,16 +1620,20 @@
<source>Add Picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Remove Picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Profile Pictures</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Privacy Options</source>
<source>Delete Picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Uploading...</source>
<translation type="unfinished">Ladda upp...</translation>
</message>
<message>
<source>Deleting profile picture</source>
<translation type="unfinished"></translation>
</message>
</context>

View file

@ -1595,16 +1595,20 @@
<source>Add Picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Remove Picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Profile Pictures</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Privacy Options</source>
<source>Delete Picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Uploading...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Deleting profile picture</source>
<translation type="unfinished"></translation>
</message>
</context>

View file

@ -1620,16 +1620,20 @@
<source>Add Picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Remove Picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Profile Pictures</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Privacy Options</source>
<source>Delete Picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Uploading...</source>
<translation type="unfinished">Uploading...</translation>
</message>
<message>
<source>Deleting profile picture</source>
<translation type="unfinished"></translation>
</message>
</context>