aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--context.cpp28
-rw-r--r--context.h2
-rw-r--r--qml/ChatlistItem.qml9
-rw-r--r--qml/ComposePane.qml34
-rw-r--r--qml/Message.qml2
-rw-r--r--qml/SettingsPage.qml63
6 files changed, 132 insertions, 6 deletions
diff --git a/context.cpp b/context.cpp
index 59d8211..11372d0 100644
--- a/context.cpp
+++ b/context.cpp
@@ -100,6 +100,34 @@ Context::acceptChat(uint32_t chatId)
dc_accept_chat(m_context, chatId);
}
+void
+Context::blockContact(uint32_t contactId, uint32_t blockMode)
+{
+ dc_block_contact(m_context, contactId, blockMode);
+}
+
+QVariantMap
+Context::getBlockedContacts()
+{
+ QVariantMap blockList;
+ uint32_t CID;
+ char *addr;
+ dc_contact_t *contact;
+ dc_array_t *blockedContacts = dc_get_blocked_contacts(m_context);
+ size_t max = dc_array_get_cnt(blockedContacts);
+
+ for (size_t i = 0; i < max; i++) {
+ CID = dc_array_get_id(blockedContacts, i);
+ contact = dc_get_contact(m_context, CID);
+ addr = dc_contact_get_addr(contact);
+ blockList.insert(addr, CID);
+ dc_contact_unref(contact);
+ dc_str_unref(addr);
+ }
+ dc_array_unref(blockedContacts);
+ return blockList;
+}
+
QString
Context::getChatEncrinfo(uint32_t chatId)
{
diff --git a/context.h b/context.h
index bad963e..8990524 100644
--- a/context.h
+++ b/context.h
@@ -37,6 +37,8 @@ public:
Q_INVOKABLE DcChat *getChat(uint32_t chatId);
Q_INVOKABLE QVariantList getContacts(uint32_t flags, QString query);
Q_INVOKABLE QVariantList getMsgIdList(uint32_t chatId);
+ Q_INVOKABLE QVariantMap getBlockedContacts();
+ Q_INVOKABLE void blockContact(uint32_t contactId, uint32_t blockMode);
Q_INVOKABLE int getFreshMsgCnt(uint32_t chatId);
Q_INVOKABLE void marknoticedChat(uint32_t chatId);
Q_INVOKABLE void markseenMsgs(QVector<uint32_t> msg_ids);
diff --git a/qml/ChatlistItem.qml b/qml/ChatlistItem.qml
index aa05d42..6e37331 100644
--- a/qml/ChatlistItem.qml
+++ b/qml/ChatlistItem.qml
@@ -36,6 +36,15 @@ Kirigami.AbstractListItem {
id: contextMenu
Action {
+ text: "Block chat"
+ onTriggered: {
+ root.context.blockChat(root.chatId)
+ updateChatlist()
+ }
+
+ }
+
+ Action {
icon.name: "pin"
text: "Pin chat"
onTriggered: root.context.setChatVisibility(root.chatId, 2)
diff --git a/qml/ComposePane.qml b/qml/ComposePane.qml
index 06b623d..254e484 100644
--- a/qml/ComposePane.qml
+++ b/qml/ComposePane.qml
@@ -3,18 +3,18 @@ import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Dialogs 1.3
import QtQuick.Layouts 1.12
+import org.kde.kirigami 2.12 as Kirigami
Pane {
id: root
-
required property DcContext context
required property var chatId
required property var chat
property var attachFileUrl: ""
+ property bool isContactBlocked: false
property bool canSend: root.chat && root.chat.canSend
property bool isContactRequest: root.chat && root.chat.isContactRequest
readonly property string vChatUrl: root.context.getConfig("webrtc_instance")
-
function createMessage() {
let DC_MSG_TEXT = 10;
let DC_MSG_FILE = 60;
@@ -102,7 +102,7 @@ Pane {
Button {
id: sendVChatUrl
enabled: vChatUrl.length > 0 ? true : false
- visible: root.isContactRequest ? false : true
+ visible: root.canSend
hoverEnabled: true
ToolTip.visible: hovered
ToolTip.text: "Send videochat invitation"
@@ -149,23 +149,47 @@ Pane {
}
Button {
+ id: acceptCBtn
Layout.alignment: Qt.AlignBottom
Layout.fillWidth: true
text: "Accept"
- onClicked: root.context.acceptChat(root.chatId)
+ onClicked: {
+ root.context.acceptChat(root.chatId);
+ root.isContactBlocked = 0;
+ }
visible: root.isContactRequest
icon.name: "call-start"
}
Button {
+ id: blockCBtn
Layout.alignment: Qt.AlignBottom
Layout.fillWidth: true
text: "Block"
- onClicked: root.context.blockChat(root.chatId)
+ onClicked: {
+ root.context.blockChat(root.chatId)
+ updateChatlist();
+ acceptCBtn.visible = false;
+ blockCBtn.visible = false;
+ root.isContactBlocked = true;
+ }
visible: root.isContactRequest
icon.name: "call-stop"
}
+
+ TextEdit {
+ selectByMouse: true
+ readOnly: true
+ text: "This contact has been blocked.<br>You can see who you've blocked <br>in 'Settings' > 'View blocked users'"
+ font.bold: true
+ textFormat: TextEdit.RichText
+ visible: root.isContactBlocked
+ Layout.preferredWidth: root.width
+ Layout.maximumWidth: root.width
+ horizontalAlignment: TextEdit.AlignHCenter
+ padding: Kirigami.Units.largeSpacing
+ }
}
}
diff --git a/qml/Message.qml b/qml/Message.qml
index 14d68a8..d255430 100644
--- a/qml/Message.qml
+++ b/qml/Message.qml
@@ -84,6 +84,7 @@ RowLayout {
}
Rectangle {
+ id: msgRect
Layout.leftMargin: Kirigami.Units.largeSpacing
Layout.preferredWidth: messageContents.width
Layout.preferredHeight: messageContents.height
@@ -447,6 +448,7 @@ RowLayout {
}
Label {
+ padding: Kirigami.Units.largeSpacing
font.pixelSize: 14
color: Kirigami.Theme.disabledTextColor
text: Qt.formatDateTime(root.message.timestamp, "dd. MMM yyyy, hh:mm")
diff --git a/qml/SettingsPage.qml b/qml/SettingsPage.qml
index c963162..4d89ebc 100644
--- a/qml/SettingsPage.qml
+++ b/qml/SettingsPage.qml
@@ -9,6 +9,7 @@ Kirigami.ScrollablePage {
id: root
required property DcContext context
+ property int bannedListHeight: 0
title: "Settings"
@@ -20,6 +21,10 @@ Kirigami.ScrollablePage {
source: "file:" + root.context.getConfig("selfavatar")
}
+ ListModel {
+ id: bannedList
+ }
+
FileDialog {
id: changePfpDialog
@@ -42,7 +47,7 @@ Kirigami.ScrollablePage {
text: "Change avatar"
icon.name: "avatar-default"
hoverEnabled: true
- anchors.horizontalCenter: pfp.horizontalCenter
+ anchors.horizontalCenter: parent.horizontalCenter
onClicked: changePfpDialog.open()
}
@@ -110,8 +115,64 @@ Kirigami.ScrollablePage {
onToggled: root.context.setConfig("mvbox_move", checked ? "1" : "0")
}
+ Button {
+ id: blockedUsers
+ text: "View blocked users"
+ icon.name: "avatar-default"
+ hoverEnabled: true
+ anchors.horizontalCenter: parent.horizontalCenter
+ onClicked: {
+ bannedList.clear()
+ let banListObj = root.context.getBlockedContacts()
+ for (var addr in banListObj){
+ let chatId = banListObj[addr]
+ console.log("Chat ID " + chatId + " is " + addr)
+ bannedList.append({"email": addr, "bannedContactId": chatId});
+ }
+ bannedListHeight = 0
+ }
+ }
+
+ Rectangle {
+ id: listContainer
+ height: bannedListHeight
+ Layout.preferredHeight: height
+ radius: 10
+ data: ListView {
+ id: blocked
+ currentIndex: -1
+ anchors.fill: parent
+ model: bannedList
+ delegate: RowLayout {
+
+ Button {
+ id: unblockBtn
+ text: "X"
+ ToolTip.text: "Click to unblock"
+ ToolTip.visible: hovered
+ hoverEnabled: true
+ onClicked: {
+ root.context.blockContact(bannedContactId, 0);
+ console.log("Unblocking " + email + "(contact id "+ bannedContactId + ")")
+ blockedUsers.clicked();
+ updateChatlist()
+ }
+ }
+
+ TextEdit {
+ selectByMouse: true
+ readOnly: true
+ text: email
+ padding: 4
+ }
+ Component.onCompleted: bannedListHeight += height
+ }
+ }
+ }
+
ComboBox {
Kirigami.FormData.label: "Show classic emails: "
+ Layout.preferredWidth: 250
textRole: "text"
currentIndex: root.context.getConfig("show_emails")
onActivated: root.context.setConfig("show_emails", currentIndex)