Some improvements as suggested by @jgibbon, add unpin feature

This commit is contained in:
Sebastian Wolf 2020-11-18 14:22:08 +01:00
parent b35d268b12
commit af47ae2c72
17 changed files with 138 additions and 37 deletions

View file

@ -102,34 +102,11 @@ ListItem {
text: qsTr("Select Message")
}
MenuItem {
function amIVisible() {
console.log("Is pin message menu visible?");
if (page.isPrivateChat) {
console.log("Private Chat: No!");
return false;
}
if (page.chatGroupInformation.status["@type"] === "chatMemberStatusCreator") {
console.log("Creator of this chat: Yes!");
return true;
}
if (page.chatInformation.permissions.can_pin_messages) {
console.log("All people can pin: Yes!");
return true;
}
if (page.chatGroupInformation.status["@type"] === "chatMemberStatusAdministrator") {
console.log("Admin with privileges? " + page.chatGroupInformation.status.can_pin_messages);
return page.chatGroupInformation.status.can_pin_messages;
}
console.log("Something else: No!");
return false;
}
onClicked: {
tdLibWrapper.pinMessage(page.chatInformation.id, myMessage.id);
}
text: qsTr("Pin Message")
visible: amIVisible()
visible: canPinMessages()
}
MenuItem {
onClicked: {

View file

@ -38,13 +38,14 @@ Flickable {
signal requestClose;
function getOriginalAuthor(forwardInformation, fontSize) {
if (forwardInformation.origin["@type"] === "messageForwardOriginChannel") {
switch (forwardInformation.origin["@type"]) {
case "messageForwardOriginChannel":
var otherChatInformation = tdLibWrapper.getChat(forwardInformation.origin.chat_id);
return Emoji.emojify(otherChatInformation.title, fontSize);
} else if (forwardInformation.origin["@type"] === "messageForwardOriginUser") {
case "messageForwardOriginUser":
var otherUserInformation = tdLibWrapper.getUserInformation(forwardInformation.origin.sender_user_id);
return Emoji.emojify(Functions.getUserName(otherUserInformation), fontSize);
} else {
default:
return Emoji.emojify(forwardInformation.origin.sender_name, fontSize);
}
}
@ -77,7 +78,8 @@ Flickable {
Rectangle {
id: messageContentBackground
color: (Theme.colorScheme === Theme.LightOnDark) ? Theme.darkSecondaryColor : Theme.lightSecondaryColor
color: Theme.overlayBackgroundColor
opacity: 0.7
width: parent.width
height: messageContentColumn.height >= messageOverlayFlickable.height ? messageContentColumn.height : messageOverlayFlickable.height
MouseArea {

View file

@ -27,6 +27,7 @@ Item {
property var pinnedMessage;
signal requestShowMessage;
signal requestCloseMessage;
onPinnedMessageChanged: {
if (pinnedMessage) {
@ -43,7 +44,7 @@ Item {
visible: false
anchors.left: parent.left
anchors.right: parent.right
height: pinnedMessageRow.height
height: visible ? pinnedMessageRow.height : 0
Rectangle {
id: pinnedMessageBackground
@ -68,7 +69,7 @@ Item {
}
Item {
width: parent.width - pinnedMessageButton.width - removePinnedMessageIconButton.width
width: parent.width - pinnedMessageButton.width - unpinMessageIconLoader.width - removePinnedMessageIconButton.width
height: pinnedMessageColumn.height
anchors.verticalCenter: parent.verticalCenter
Column {
@ -108,11 +109,33 @@ Item {
}
}
Loader {
id: unpinMessageIconLoader
asynchronous: true
active: canPinMessages()
Behavior on opacity { FadeAnimation {} }
width: active ? item.width : 0
height: active ? item.height : 0
anchors.verticalCenter: parent.verticalCenter
sourceComponent: Component {
IconButton {
id: unpinMessageIconButton
icon.source: "image://theme/icon-m-remove"
onClicked: {
Remorse.itemAction(pinnedMessageRow, qsTr("Message unpinned"), function() { tdLibWrapper.unpinMessage(chatPage.chatInformation.id);
pinnedMessageItem.requestCloseMessage(); });
}
}
}
}
IconButton {
id: removePinnedMessageIconButton
icon.source: "image://theme/icon-m-clear"
anchors.verticalCenter: parent.verticalCenter
onClicked: {
pinnedMessageItem.requestCloseMessage();
pinnedMessage = undefined;
}
}

View file

@ -17,6 +17,7 @@
along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.6
import QtGraphicalEffects 1.0
import Sailfish.Silica 1.0
import Sailfish.Pickers 1.0
import Nemo.Thumbnailer 1.0
@ -282,6 +283,31 @@ Page {
|| groupStatusType === "chatMemberStatusCreator"
|| (groupStatusType === "chatMemberStatusRestricted" && groupStatus.permissions[privilege])
}
function canPinMessages() {
console.log("Can we pin messages?");
if (chatPage.isPrivateChat) {
console.log("Private Chat: No!");
return false;
}
if (chatPage.chatGroupInformation.status["@type"] === "chatMemberStatusCreator") {
console.log("Creator of this chat: Yes!");
return true;
}
if (chatPage.chatInformation.permissions.can_pin_messages) {
console.log("All people can pin: Yes!");
return true;
}
if (chatPage.chatGroupInformation.status["@type"] === "chatMemberStatusAdministrator") {
console.log("Admin with privileges? " + chatPage.chatGroupInformation.status.can_pin_messages);
return chatPage.chatGroupInformation.status.can_pin_messages;
}
if (chatPage.chatGroupInformation.status["@type"] === "chatMemberStatusRestricted") {
console.log("Restricted, but can pin messages? " + chatPage.chatGroupInformation.status.permissions.can_pin_messages);
return chatPage.chatGroupInformation.status.permissions.can_pin_messages;
}
console.log("Something else: No!");
return false;
}
Timer {
id: forwardMessagesTimer
@ -613,14 +639,18 @@ Page {
id: pinnedMessageItem
onRequestShowMessage: {
messageOverlayLoader.overlayMessage = pinnedMessageItem.pinnedMessage;
messageOverlayLoader.active = !messageOverlayLoader.active;
messageOverlayLoader.active = true;
}
onRequestCloseMessage: {
messageOverlayLoader.overlayMessage = undefined;
messageOverlayLoader.active = false;
}
}
Item {
id: chatViewItem
width: parent.width
height: parent.height - headerRow.height - ( pinnedMessageItem.visible ? pinnedMessageItem.height : 0 ) - newMessageColumn.height - selectedMessagesActions.height
height: parent.height - headerRow.height - pinnedMessageItem.height - newMessageColumn.height - selectedMessagesActions.height
property int previousHeight;
@ -645,10 +675,24 @@ Page {
}
}
Loader {
asynchronous: true
active: chatView.blurred
anchors.fill: chatView
sourceComponent: Component {
FastBlur {
source: chatView
radius: Theme.paddingLarge
}
}
}
SilicaListView {
id: chatView
visible: !blurred
property bool blurred: messageOverlayLoader.item
anchors.fill: parent
opacity: chatPage.loading ? 0 : 1
Behavior on opacity { FadeAnimation {} }
@ -1208,6 +1252,7 @@ Page {
}
}
}
Loader {
id: selectedMessagesActions
asynchronous: true

View file

@ -303,6 +303,15 @@ void TDLibWrapper::pinMessage(const QString &chatId, const QString &messageId, b
this->sendRequest(requestObject);
}
void TDLibWrapper::unpinMessage(const QString &chatId)
{
LOG("Unpin message from chat" << chatId);
QVariantMap requestObject;
requestObject.insert(_TYPE, "unpinChatMessage");
requestObject.insert("chat_id", chatId);
this->sendRequest(requestObject);
}
void TDLibWrapper::sendTextMessage(const QString &chatId, const QString &message, const QString &replyToMessageId)
{
LOG("Sending text message" << chatId << message << replyToMessageId);

View file

@ -123,6 +123,7 @@ public:
Q_INVOKABLE void getChatHistory(qlonglong chatId, const qlonglong &fromMessageId = 0, int offset = 0, int limit = 50, bool onlyLocal = false);
Q_INVOKABLE void viewMessage(const QString &chatId, const QString &messageId, bool force);
Q_INVOKABLE void pinMessage(const QString &chatId, const QString &messageId, bool disableNotification = false);
Q_INVOKABLE void unpinMessage(const QString &chatId);
Q_INVOKABLE void sendTextMessage(const QString &chatId, const QString &message, const QString &replyToMessageId = "0");
Q_INVOKABLE void sendPhotoMessage(const QString &chatId, const QString &filePath, const QString &message, const QString &replyToMessageId = "0");
Q_INVOKABLE void sendVideoMessage(const QString &chatId, const QString &filePath, const QString &message, const QString &replyToMessageId = "0");

View file

@ -922,6 +922,10 @@
<source>Pinned Message</source>
<translation>Angeheftete Nachricht</translation>
</message>
<message>
<source>Message unpinned</source>
<translation>Nachricht losgeheftet</translation>
</message>
</context>
<context>
<name>PollCreationPage</name>

View file

@ -922,6 +922,10 @@
<source>Pinned Message</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Message unpinned</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PollCreationPage</name>

View file

@ -918,6 +918,10 @@
<source>Pinned Message</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Message unpinned</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PollCreationPage</name>

View file

@ -923,6 +923,10 @@
<source>Pinned Message</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Message unpinned</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PollCreationPage</name>

View file

@ -918,6 +918,10 @@
<source>Pinned Message</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Message unpinned</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PollCreationPage</name>

View file

@ -922,6 +922,10 @@
<source>Pinned Message</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Message unpinned</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PollCreationPage</name>

View file

@ -926,6 +926,10 @@
<source>Pinned Message</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Message unpinned</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PollCreationPage</name>

View file

@ -926,6 +926,10 @@
<source>Pinned Message</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Message unpinned</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PollCreationPage</name>

View file

@ -922,6 +922,10 @@
<source>Pinned Message</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Message unpinned</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PollCreationPage</name>

View file

@ -918,6 +918,10 @@
<source>Pinned Message</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Message unpinned</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PollCreationPage</name>

View file

@ -918,6 +918,10 @@
<source>Pinned Message</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Message unpinned</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PollCreationPage</name>