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:
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 ../../signals/types
import "../../status/libstatus/types" as status_types
import ../../status/libstatus/settings as status_settings
import json
import ../../status/profile
import ../../status/status
@ -24,6 +26,13 @@ proc delete*(self: ProfileController) =
proc init*(self: ProfileController, account: Account) =
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)
var mailservers = status_mailservers.getMailservers()

View File

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

View File

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

View File

@ -101,7 +101,7 @@ 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.topMargin: 16
id: joinOrDecline

View File

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