feat: add id to profile object and verify membership on groups

This commit is contained in:
Richard Ramos 2020-06-15 13:41:19 -04:00 committed by Iuri Matias
parent b0a8bc3368
commit 88bf4fca66
8 changed files with 42 additions and 3 deletions

View File

@ -59,3 +59,11 @@ QtObject:
QtProperty[QVariant] members: QtProperty[QVariant] members:
read = getMembers read = getMembers
proc isMember*(self: ChatItemView, pubKey: string): bool {.slot.} =
if self.chatItem.isNil: return false
return self.chatItem.isMember(pubKey)
proc isAdmin*(self: ChatItemView, pubKey: string): bool {.slot.} =
if self.chatItem.isNil: return false
return self.chatItem.isAdmin(pubKey)

View File

@ -2,6 +2,8 @@ import NimQml
import ../../status/libstatus/mailservers as status_mailservers import ../../status/libstatus/mailservers as status_mailservers
import ../../signals/types import ../../signals/types
import "../../status/libstatus/types" as status_types import "../../status/libstatus/types" as status_types
import ../../status/libstatus/settings as status_settings
import json
import ../../status/profile import ../../status/profile
import ../../status/status import ../../status/status
@ -24,6 +26,13 @@ proc delete*(self: ProfileController) =
proc init*(self: ProfileController, account: Account) = proc init*(self: ProfileController, account: Account) =
let profile = account.toProfileModel() let profile = account.toProfileModel()
# (rramos) TODO: I added this because I needed the public key
# Ideally, this module should call getSettings once, and fill the
# profile with all the information comming from the settings.
let pubKey = status_settings.getSettings().parseJSON()["result"]["public-key"].getStr
profile.id = pubKey
self.view.setNewProfile(profile) self.view.setNewProfile(profile)
var mailservers = status_mailservers.getMailservers() var mailservers = status_mailservers.getMailservers()

View File

@ -5,6 +5,7 @@ QtObject:
type ProfileInfoView* = ref object of QObject type ProfileInfoView* = ref object of QObject
username*: string username*: string
identicon*: string identicon*: string
pubKey*: string
proc setup(self: ProfileInfoView) = proc setup(self: ProfileInfoView) =
self.QObject.setup self.QObject.setup
@ -15,6 +16,7 @@ QtObject:
proc newProfileInfoView*(): ProfileInfoView = proc newProfileInfoView*(): ProfileInfoView =
new(result, delete) new(result, delete)
result = ProfileInfoView() result = ProfileInfoView()
result.pubKey = ""
result.username = "" result.username = ""
result.identicon = "" result.identicon = ""
result.setup result.setup
@ -24,6 +26,7 @@ QtObject:
proc setProfile*(self: ProfileInfoView, profile: Profile) = proc setProfile*(self: ProfileInfoView, profile: Profile) =
self.username = profile.username self.username = profile.username
self.identicon = profile.identicon self.identicon = profile.identicon
self.pubKey = profile.id
self.profileChanged() self.profileChanged()
proc username*(self: ProfileInfoView): string {.slot.} = result = self.username proc username*(self: ProfileInfoView): string {.slot.} = result = self.username
@ -35,3 +38,13 @@ QtObject:
QtProperty[string] identicon: QtProperty[string] identicon:
read = identicon read = identicon
notify = profileChanged notify = profileChanged
proc pubKey*(self: ProfileInfoView): string {.slot.} = self.pubKey
proc setPubKey*(self: ProfileInfoView, pubKey: string) {.slot.} =
self.pubKey = pubKey
self.profileChanged()
QtProperty[string] pubKey:
read = pubKey
notify = profileChanged

View File

@ -48,3 +48,8 @@ proc isMember*(self: Chat, pubKey: string): bool =
if member.id == pubKey and member.joined: return true if member.id == pubKey and member.joined: return true
return false return false
proc isAdmin*(self: Chat, pubKey: string): bool =
for member in self.members:
if member.id == pubKey and member.joined and member.admin: return true
return false

View File

@ -45,6 +45,8 @@ proc sendTransaction*(self: WalletModel, from_value: string, to: string, value:
status_wallet.sendTransaction(from_value, to, value, password) status_wallet.sendTransaction(from_value, to, value, password)
proc getDefaultCurrency*(self: WalletModel): string = proc getDefaultCurrency*(self: WalletModel): string =
# TODO: this should come from a model? It is going to be used too in the
# profile section and ideally we should not call the settings more than once
status_settings.getSettings().parseJSON()["result"]["currency"].getStr status_settings.getSettings().parseJSON()["result"]["currency"].getStr
proc setDefaultCurrency*(self: WalletModel, currency: string) = proc setDefaultCurrency*(self: WalletModel, currency: string) =

View File

@ -14,6 +14,8 @@ Rectangle {
color: "white" color: "white"
border.width: 0 border.width: 0
visible: chatsModel.activeChannel.chatType != Constants.chatTypePrivateGroupChat || chatsModel.activeChannel.isMember(profileModel.profile.pubKey)
Rectangle { Rectangle {
id: rectangle id: rectangle
color: "#00000000" color: "#00000000"

View File

@ -101,7 +101,7 @@ Item {
} }
Item { Item {
visible: chatsModel.activeChannel.chatType == Constants.chatTypePrivateGroupChat // TODO: hide if the user is a member of the group (use chatsModel.activeChannel.isMember?) visible: chatsModel.activeChannel.chatType == Constants.chatTypePrivateGroupChat && !chatsModel.activeChannel.isMember(profileModel.profile.pubKey)
anchors.top: channelName.bottom anchors.top: channelName.bottom
anchors.topMargin: 16 anchors.topMargin: 16
id: joinOrDecline id: joinOrDecline

View File

@ -64,7 +64,7 @@ ModalPopup {
Rectangle { Rectangle {
id: editGroupNameBtn id: editGroupNameBtn
visible: true // TODO: only show this if the current user is admin visible: chatsModel.activeChannel.isAdmin(profileModel.profile.pubKey)
height: 24 height: 24
width: 24 width: 24
anchors.top: parent.top anchors.top: parent.top
@ -178,7 +178,7 @@ ModalPopup {
} }
Text { Text {
id: moreActionsBtn id: moreActionsBtn
visible: !model.isAdmin // TODO: && current user is admin visible: !model.isAdmin && chatsModel.activeChannel.isAdmin(profileModel.profile.pubKey)
text: "..." text: "..."
width: 100 width: 100
MouseArea { MouseArea {