feat: introduce button to block users

Closes #158
This commit is contained in:
Pascal Precht 2020-06-11 10:22:20 +02:00 committed by Iuri Matias
parent b3a9bff381
commit 73eb4fe8b1
7 changed files with 82 additions and 24 deletions

View File

@ -132,3 +132,6 @@ QtObject:
if(self.activeChannel.id == chat.id):
self.activeChannel.setChatItem(chat)
self.activeChannelChanged()
proc blockContact*(self: ChatsView, id: string): string {.slot.} =
return self.status.chat.blockContact(id)

View File

@ -1,6 +1,8 @@
import eventemitter, json
import sequtils
import libstatus/chat as status_chat
import libstatus/core as libstatus_core
import ./profile as status_profile
import chronicles
import chat/[chat, message]
import ../signals/messages
@ -158,3 +160,9 @@ proc confirmJoiningGroup*(self: ChatModel, chatId: string) =
var response = parseJson(status_chat.confirmJoiningGroup(chatId))
var (chats, messages) = formatChatUpdate(response)
self.events.emit("pushMessage", PushMessageArgs(messages: messages, chats: chats))
proc blockContact*(self: ChatModel, id: string): string =
var contact = status_profile.getContactByID(id)
contact.systemTags.add(":contact/blocked")
result = status_chat.blockContact(contact)

View File

@ -6,6 +6,7 @@ import strutils
import chronicles
import ../chat/[chat, message]
import ../../signals/messages
import ../profile
proc buildFilter*(chatId: string, filterId: string = "", symKeyId: string = "", oneToOne: bool = false, identity: string = "", topic: string = "", discovery: bool = false, negotiated: bool = false, listen: bool = true):JsonNode =
result = %* {
@ -106,6 +107,19 @@ proc sendChatMessage*(chatId: string, msg: string): string =
}
])
proc blockContact*(contact: Profile): string =
callPrivateRPC("blockContact".prefix, %* [
{
"id": contact.id,
"ensVerified": contact.ensVerified,
"ensVerifiedAt": contact.ensVerifiedAt,
"ensVerificationRetries": contact.ensVerificationRetries,
"alias": contact.alias,
"identicon": contact.identicon,
"systemTags": contact.systemTags
}
])
proc markAllRead*(chatId: string): string =
callPrivateRPC("markAllRead".prefix, %* [chatId])

View File

@ -16,7 +16,8 @@ type Profile* = ref object
id*, alias*, username*, identicon*: string
ensVerified*: bool
ensVerifiedAt*: int
ensVerificationEntries*: int
ensVerificationRetries*: int
systemTags*: seq[string]
proc toProfileModel*(account: Account): Profile =
result = Profile(
@ -26,10 +27,15 @@ proc toProfileModel*(account: Account): Profile =
alias: account.name,
ensVerified: false,
ensVerifiedAt: 0,
ensVerificationEntries: 0,
ensVerificationRetries: 0,
systemTags: @[]
)
proc toProfileModel*(profile: JsonNode): Profile =
var systemTags: seq[string] = @[]
if profile["systemTags"].kind != JNull:
systemTags = profile["systemTags"].to(seq[string])
result = Profile(
id: profile["id"].str,
username: profile["alias"].str,
@ -37,14 +43,13 @@ proc toProfileModel*(profile: JsonNode): Profile =
alias: profile["alias"].str,
ensVerified: profile["ensVerified"].getBool,
ensVerifiedAt: profile["ensVerifiedAt"].getInt,
ensVerificationEntries: profile["ensVerificationEntries"].getInt
ensVerificationRetries: profile["ensVerificationRetries"].getInt,
systemTags: systemTags
)
proc getContactByID*(id: string): Profile =
let response = libstatus_core.getContactByID(id)
let val = parseJSON($response)
result = toProfileModel(val)
result = toProfileModel(parseJSON($response)["result"])
type
ProfileModel* = ref object

View File

@ -194,13 +194,36 @@ ModalPopup {
// }
// }
footer: StyledButton {
anchors.right: parent.right
anchors.rightMargin: Theme.smallPadding
label: "Add to contacts"
anchors.bottom: parent.bottom
onClicked: {
profilePopup.close()
footer: Item {
width: parent.width
height: children[0].height
StyledButton {
anchors.right: parent.right
anchors.rightMargin: addToContactsButton.width + 32
btnColor: "white"
btnBorderWidth: 1
btnBorderColor: "#EEF2F5"
textColor: "#FF2D55"
label: "Block User"
anchors.bottom: parent.bottom
onClicked: {
chatsModel.blockContact(fromAuthor)
// TODO(pascal): Change block user button state based
// on :contact/blocked state
profilePopup.close()
}
}
StyledButton {
id: addToContactsButton
anchors.right: parent.right
anchors.rightMargin: Theme.smallPadding
label: "Add to contacts"
anchors.bottom: parent.bottom
onClicked: {
profilePopup.close()
}
}
}
}

View File

@ -114,16 +114,17 @@ Popup {
}
Item {
id: footerContent
height: children[0] && children[0].height
width: parent.width
anchors.top: separator2.bottom
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.bottomMargin: Theme.padding
anchors.rightMargin: Theme.padding
anchors.leftMargin: Theme.padding
id: footerContent
height: children[0] && children[0].height
width: parent.width
anchors.top: separator2.bottom
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.topMargin: Theme.padding
anchors.bottomMargin: Theme.padding
anchors.rightMargin: Theme.padding
anchors.leftMargin: Theme.padding
}
}
}
}

View File

@ -8,6 +8,8 @@ import "../imports"
Button {
property string label: "My button"
property color btnColor: Theme.lightBlue
property color btnBorderColor: "transparent"
property int btnBorderWidth: 0
property color textColor: Theme.blue
property bool disabled: false
@ -20,6 +22,8 @@ Button {
color: disabled ? Theme.grey : btnStyled.btnColor
radius: Theme.radius
anchors.fill: parent
border.color: btnBorderColor
border.width: btnBorderWidth
}
Text {