Change username, prepare privacy setting rules

This commit is contained in:
Sebastian Wolf 2021-01-19 23:58:58 +01:00
parent 3a59ec54ba
commit f0d14bc440
No known key found for this signature in database
GPG key ID: CEA9522B5F38A90A
14 changed files with 207 additions and 47 deletions

View file

@ -33,6 +33,7 @@ Page {
onOwnUserUpdated: { onOwnUserUpdated: {
firstNameEditArea.text = userInformation.first_name; firstNameEditArea.text = userInformation.first_name;
lastNameEditArea.text = userInformation.last_name; lastNameEditArea.text = userInformation.last_name;
userNameEditArea.text = userInformation.username;
} }
} }
@ -53,66 +54,88 @@ Page {
text: qsTr("User Profile") text: qsTr("User Profile")
} }
InformationEditArea { Grid {
id: firstNameEditArea
visible: true
canEdit: true
headerText: qsTr("First Name", "first name of the logged-in profile - header")
text: tdLibWrapper.getUserInformation().first_name
width: parent.width - ( 2 * Theme.horizontalPageMargin ) width: parent.width - ( 2 * Theme.horizontalPageMargin )
headerLeftAligned: true columns: landscapeLayout ? 2 : 1
columnSpacing: Theme.horizontalPageMargin
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
onSaveButtonClicked: { readonly property real columnWidth: width/columns
if(!editItem.errorHighlight) {
tdLibWrapper.setName(textValue, lastNameEditArea.text); InformationEditArea {
} else { id: firstNameEditArea
isEditing = true; visible: true
canEdit: true
headerText: qsTr("First Name", "first name of the logged-in profile - header")
text: tdLibWrapper.getUserInformation().first_name
width: parent.columnWidth
headerLeftAligned: true
onSaveButtonClicked: {
if(!editItem.errorHighlight) {
tdLibWrapper.setName(textValue, lastNameEditArea.text);
} else {
isEditing = true;
}
}
onTextEdited: {
if(textValue.length > 0 && textValue.length < 65) {
editItem.errorHighlight = false;
editItem.label = "";
editItem.placeholderText = "";
} else {
editItem.label = qsTr("Enter 1-64 characters");
editItem.placeholderText = editItem.label;
editItem.errorHighlight = true;
}
} }
} }
onTextEdited: { InformationEditArea {
if(textValue.length > 0 && textValue.length < 65) { id: lastNameEditArea
editItem.errorHighlight = false; visible: true
editItem.label = ""; canEdit: true
editItem.placeholderText = ""; headerText: qsTr("Last Name", "last name of the logged-in profile - header")
} else { text: tdLibWrapper.getUserInformation().last_name
editItem.label = qsTr("Enter 1-64 characters"); width: parent.columnWidth
editItem.placeholderText = editItem.label; headerLeftAligned: true
editItem.errorHighlight = true;
onSaveButtonClicked: {
if(!editItem.errorHighlight) {
tdLibWrapper.setName(firstNameEditArea.text, textValue);
} else {
isEditing = true;
}
} }
}
}
InformationEditArea { onTextEdited: {
id: lastNameEditArea if(textValue.length >= 0 && textValue.length < 65) {
visible: true editItem.errorHighlight = false;
canEdit: true editItem.label = "";
headerText: qsTr("Last Name", "last name of the logged-in profile - header") editItem.placeholderText = "";
text: tdLibWrapper.getUserInformation().last_name } else {
width: parent.width - ( 2 * Theme.horizontalPageMargin ) editItem.label = qsTr("Enter 0-64 characters");
headerLeftAligned: true editItem.placeholderText = editItem.label;
anchors.horizontalCenter: parent.horizontalCenter editItem.errorHighlight = true;
}
onSaveButtonClicked: {
if(!editItem.errorHighlight) {
tdLibWrapper.setName(firstNameEditArea.text, textValue);
} else {
isEditing = true;
} }
} }
onTextEdited: { InformationEditArea {
if(textValue.length >= 0 && textValue.length < 65) { id: userNameEditArea
editItem.errorHighlight = false; visible: true
editItem.label = ""; canEdit: true
editItem.placeholderText = ""; headerText: qsTr("Username", "user name of the logged-in profile - header")
} else { text: tdLibWrapper.getUserInformation().username
editItem.label = qsTr("Enter 0-64 characters"); width: parent.columnWidth
editItem.placeholderText = editItem.label; headerLeftAligned: true
editItem.errorHighlight = true;
onSaveButtonClicked: {
tdLibWrapper.setUsername(textValue);
} }
} }
} }
SectionHeader { SectionHeader {

View file

@ -1188,6 +1188,68 @@ void TDLibWrapper::setName(const QString &firstName, const QString &lastName)
this->sendRequest(requestObject); this->sendRequest(requestObject);
} }
void TDLibWrapper::setUsername(const QString &userName)
{
LOG("Set username of current user" << userName);
QVariantMap requestObject;
requestObject.insert(_TYPE, "setUsername");
requestObject.insert("username", userName);
this->sendRequest(requestObject);
}
void TDLibWrapper::setUserPrivacySettingRule(TDLibWrapper::UserPrivacySetting setting, TDLibWrapper::UserPrivacySettingRule rule)
{
LOG("Set user privecy setting rule of current user" << setting << rule);
QVariantMap requestObject;
requestObject.insert(_TYPE, "setUserPrivacySettingRules");
QVariantMap settingMap;
switch (setting) {
case SettingShowStatus:
settingMap.insert(_TYPE, "userPrivacySettingShowStatus");
break;
case SettingShowPhoneNumber:
settingMap.insert(_TYPE, "userPrivacySettingShowPhoneNumber");
break;
case SettingAllowChatInvites:
settingMap.insert(_TYPE, "userPrivacySettingAllowChatInvites");
break;
case SettingShowProfilePhoto:
settingMap.insert(_TYPE, "userPrivacySettingShowProfilePhoto");
break;
case SettingAllowFindingByPhoneNumber:
settingMap.insert(_TYPE, "userPrivacySettingAllowFindingByPhoneNumber");
break;
case SettingShowLinkInForwardedMessages:
settingMap.insert(_TYPE, "userPrivacySettingShowLinkInForwardedMessages");
break;
}
requestObject.insert("setting", settingMap);
QVariantMap ruleMap;
switch (rule) {
case RuleAllowAll:
ruleMap.insert(_TYPE, "userPrivacySettingRuleAllowAll");
break;
case RuleAllowContacts:
ruleMap.insert(_TYPE, "userPrivacySettingRuleAllowContacts");
break;
case RuleRestrictAll:
ruleMap.insert(_TYPE, "userPrivacySettingRuleRestrictAll");
break;
case RuleRestrictContacts:
ruleMap.insert(_TYPE, "userPrivacySettingRuleRestrictContacts");
break;
}
QVariantList ruleMaps;
ruleMaps.append(ruleMap);
requestObject.insert("rules", ruleMaps);
this->sendRequest(requestObject);
}
void TDLibWrapper::searchEmoji(const QString &queryString) void TDLibWrapper::searchEmoji(const QString &queryString)
{ {
LOG("Searching emoji" << queryString); LOG("Searching emoji" << queryString);

View file

@ -89,6 +89,24 @@ public:
}; };
Q_ENUM(SecretChatState) Q_ENUM(SecretChatState)
enum UserPrivacySetting {
SettingAllowChatInvites,
SettingAllowFindingByPhoneNumber,
SettingShowLinkInForwardedMessages,
SettingShowPhoneNumber,
SettingShowProfilePhoto,
SettingShowStatus
};
Q_ENUM(UserPrivacySetting)
enum UserPrivacySettingRule {
RuleAllowAll,
RuleAllowContacts,
RuleRestrictAll,
RuleRestrictContacts
};
Q_ENUM(UserPrivacySettingRule)
class Group { class Group {
public: public:
Group(qlonglong id) : groupId(id) { } Group(qlonglong id) : groupId(id) { }
@ -197,6 +215,8 @@ public:
Q_INVOKABLE void cancelUploadFile(int fileId); Q_INVOKABLE void cancelUploadFile(int fileId);
Q_INVOKABLE void deleteFile(int fileId); Q_INVOKABLE void deleteFile(int fileId);
Q_INVOKABLE void setName(const QString &firstName, const QString &lastName); Q_INVOKABLE void setName(const QString &firstName, const QString &lastName);
Q_INVOKABLE void setUsername(const QString &userName);
Q_INVOKABLE void setUserPrivacySettingRule(UserPrivacySetting setting, UserPrivacySettingRule rule);
// Others (candidates for extraction ;)) // Others (candidates for extraction ;))
Q_INVOKABLE void searchEmoji(const QString &queryString); Q_INVOKABLE void searchEmoji(const QString &queryString);

View file

@ -1530,6 +1530,11 @@
<source>Enter 0-64 characters</source> <source>Enter 0-64 characters</source>
<translation type="unfinished">Geben Sie 1-128 Zeichen ein {0-64 ?}</translation> <translation type="unfinished">Geben Sie 1-128 Zeichen ein {0-64 ?}</translation>
</message> </message>
<message>
<source>Username</source>
<comment>user name of the logged-in profile - header</comment>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>StickerPicker</name> <name>StickerPicker</name>

View file

@ -1530,6 +1530,11 @@
<source>Enter 0-64 characters</source> <source>Enter 0-64 characters</source>
<translation type="unfinished">Enter 1-128 characters {0-64 ?}</translation> <translation type="unfinished">Enter 1-128 characters {0-64 ?}</translation>
</message> </message>
<message>
<source>Username</source>
<comment>user name of the logged-in profile - header</comment>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>StickerPicker</name> <name>StickerPicker</name>

View file

@ -1530,6 +1530,11 @@
<source>Enter 0-64 characters</source> <source>Enter 0-64 characters</source>
<translation type="unfinished">Marcar caracteres 1-128 {0-64 ?}</translation> <translation type="unfinished">Marcar caracteres 1-128 {0-64 ?}</translation>
</message> </message>
<message>
<source>Username</source>
<comment>user name of the logged-in profile - header</comment>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>StickerPicker</name> <name>StickerPicker</name>

View file

@ -1531,6 +1531,11 @@
<source>Enter 0-64 characters</source> <source>Enter 0-64 characters</source>
<translation type="unfinished">Syötä 1-128 merkkiä {0-64 ?}</translation> <translation type="unfinished">Syötä 1-128 merkkiä {0-64 ?}</translation>
</message> </message>
<message>
<source>Username</source>
<comment>user name of the logged-in profile - header</comment>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>StickerPicker</name> <name>StickerPicker</name>

View file

@ -1505,6 +1505,11 @@
<source>Enter 0-64 characters</source> <source>Enter 0-64 characters</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Username</source>
<comment>user name of the logged-in profile - header</comment>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>StickerPicker</name> <name>StickerPicker</name>

View file

@ -1530,6 +1530,11 @@
<source>Enter 0-64 characters</source> <source>Enter 0-64 characters</source>
<translation type="unfinished">Inserisci da 1 a 128 caratteri {0-64 ?}</translation> <translation type="unfinished">Inserisci da 1 a 128 caratteri {0-64 ?}</translation>
</message> </message>
<message>
<source>Username</source>
<comment>user name of the logged-in profile - header</comment>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>StickerPicker</name> <name>StickerPicker</name>

View file

@ -1555,6 +1555,11 @@
<source>Enter 0-64 characters</source> <source>Enter 0-64 characters</source>
<translation type="unfinished">Wprowadź znaki 1-128 {0-64 ?}</translation> <translation type="unfinished">Wprowadź znaki 1-128 {0-64 ?}</translation>
</message> </message>
<message>
<source>Username</source>
<comment>user name of the logged-in profile - header</comment>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>StickerPicker</name> <name>StickerPicker</name>

View file

@ -1555,6 +1555,11 @@
<source>Enter 0-64 characters</source> <source>Enter 0-64 characters</source>
<translation type="unfinished">Введите 1-128 символов {0-64 ?}</translation> <translation type="unfinished">Введите 1-128 символов {0-64 ?}</translation>
</message> </message>
<message>
<source>Username</source>
<comment>user name of the logged-in profile - header</comment>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>StickerPicker</name> <name>StickerPicker</name>

View file

@ -1530,6 +1530,11 @@
<source>Enter 0-64 characters</source> <source>Enter 0-64 characters</source>
<translation type="unfinished">Ange 1-128 tecken {0-64 ?}</translation> <translation type="unfinished">Ange 1-128 tecken {0-64 ?}</translation>
</message> </message>
<message>
<source>Username</source>
<comment>user name of the logged-in profile - header</comment>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>StickerPicker</name> <name>StickerPicker</name>

View file

@ -1505,6 +1505,11 @@
<source>Enter 0-64 characters</source> <source>Enter 0-64 characters</source>
<translation type="unfinished"> 1-128 {0-64 ?}</translation> <translation type="unfinished"> 1-128 {0-64 ?}</translation>
</message> </message>
<message>
<source>Username</source>
<comment>user name of the logged-in profile - header</comment>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>StickerPicker</name> <name>StickerPicker</name>

View file

@ -1530,6 +1530,11 @@
<source>Enter 0-64 characters</source> <source>Enter 0-64 characters</source>
<translation type="unfinished">Enter 1-128 characters {0-64 ?}</translation> <translation type="unfinished">Enter 1-128 characters {0-64 ?}</translation>
</message> </message>
<message>
<source>Username</source>
<comment>user name of the logged-in profile - header</comment>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>StickerPicker</name> <name>StickerPicker</name>