feat(@desktop/communities): add new join community workflow
- user is able to see community without being a member - invitation bubble always display "Go to Community" - join community buttons are displayed in community view main part of: #7072
This commit is contained in:
parent
79730b0d01
commit
acbf6fce51
|
@ -83,8 +83,8 @@ proc getAllCommunities*(self: Controller): seq[CommunityDto] =
|
|||
proc getCuratedCommunities*(self: Controller): seq[CuratedCommunity] =
|
||||
result = self.communityService.getCuratedCommunities()
|
||||
|
||||
proc joinCommunity*(self: Controller, communityId: string): string =
|
||||
self.communityService.joinCommunity(communityId)
|
||||
proc spectateCommunity*(self: Controller, communityId: string): string =
|
||||
self.communityService.spectateCommunity(communityId)
|
||||
|
||||
proc requestToJoinCommunity*(self: Controller, communityId: string, ensName: string) =
|
||||
self.communityService.requestToJoinCommunity(communityId, ensName)
|
||||
|
|
|
@ -26,7 +26,7 @@ method setCuratedCommunities*(self: AccessInterface, curatedCommunities: seq[Com
|
|||
method getCommunityItem*(self: AccessInterface, community: CommunityDto): SectionItem {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method joinCommunity*(self: AccessInterface, communityId: string): string {.base.} =
|
||||
method spectateCommunity*(self: AccessInterface, communityId: string): string {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method createCommunity*(self: AccessInterface, name: string, description, introMessage, outroMessage: string, access: int,
|
||||
|
|
|
@ -118,6 +118,7 @@ method getCommunityItem(self: Module, c: CommunityDto): SectionItem =
|
|||
enabled = true,
|
||||
c.joined,
|
||||
c.canJoin,
|
||||
c.spectated,
|
||||
c.canManageUsers,
|
||||
c.canRequestAccess,
|
||||
c.isMember,
|
||||
|
@ -171,8 +172,8 @@ method setAllCommunities*(self: Module, communities: seq[CommunityDto]) =
|
|||
method communityAdded*(self: Module, community: CommunityDto) =
|
||||
self.view.addItem(self.getCommunityItem(community))
|
||||
|
||||
method joinCommunity*(self: Module, communityId: string): string =
|
||||
self.controller.joinCommunity(communityId)
|
||||
method spectateCommunity*(self: Module, communityId: string): string =
|
||||
self.controller.spectateCommunity(communityId)
|
||||
|
||||
method communityEdited*(self: Module, community: CommunityDto) =
|
||||
self.view.model().editItem(self.getCommunityItem(community))
|
||||
|
|
|
@ -315,10 +315,8 @@ QtObject:
|
|||
read = getDiscordImportCommunityName
|
||||
notify = discordImportCommunityNameChanged
|
||||
|
||||
proc joinCommunity*(self: View, communityId: string, ensName: string) {.slot.} =
|
||||
# Users always have to request to join a community but might
|
||||
# get automatically accepted.
|
||||
self.delegate.requestToJoinCommunity(communityId, ensName)
|
||||
proc spectateCommunity*(self: View, communityId: string, ensName: string) {.slot.} =
|
||||
discard self.delegate.spectateCommunity(communityId)
|
||||
|
||||
proc createCommunity*(self: View, name: string,
|
||||
description: string, introMessage: string, outroMessage: string,
|
||||
|
|
|
@ -119,6 +119,21 @@ proc init*(self: Controller) =
|
|||
setActive = args.fromUserAction
|
||||
)
|
||||
|
||||
self.events.on(SIGNAL_COMMUNITY_SPECTATED) do(e:Args):
|
||||
let args = CommunityArgs(e)
|
||||
self.delegate.communityJoined(
|
||||
args.community,
|
||||
self.events,
|
||||
self.settingsService,
|
||||
self.contactsService,
|
||||
self.chatService,
|
||||
self.communityService,
|
||||
self.messageService,
|
||||
self.gifService,
|
||||
self.mailserversService,
|
||||
setActive = args.fromUserAction
|
||||
)
|
||||
|
||||
self.events.on(TOGGLE_SECTION) do(e:Args):
|
||||
let args = ToggleSectionArgs(e)
|
||||
self.delegate.toggleSection(args.sectionType)
|
||||
|
|
|
@ -241,6 +241,7 @@ proc createChannelGroupItem[T](self: Module[T], c: ChannelGroupDto): SectionItem
|
|||
enabled = true,
|
||||
if (isCommunity): communityDetails.joined else: true,
|
||||
if (isCommunity): communityDetails.canJoin else: true,
|
||||
if (isCommunity): communityDetails.spectated else: false,
|
||||
c.canManageUsers,
|
||||
if (isCommunity): communityDetails.canRequestAccess else: true,
|
||||
if (isCommunity): communityDetails.isMember else: true,
|
||||
|
|
|
@ -35,6 +35,7 @@ type
|
|||
isMember: bool
|
||||
joined: bool
|
||||
canJoin: bool
|
||||
spectated: bool
|
||||
canManageUsers: bool
|
||||
canRequestAccess: bool
|
||||
access: int
|
||||
|
@ -67,6 +68,7 @@ proc initItem*(
|
|||
enabled = true,
|
||||
joined = false,
|
||||
canJoin = false,
|
||||
spectated = false,
|
||||
canManageUsers = false,
|
||||
canRequestAccess = false,
|
||||
isMember = false,
|
||||
|
@ -99,6 +101,7 @@ proc initItem*(
|
|||
result.enabled = enabled
|
||||
result.joined = joined
|
||||
result.canJoin = canJoin
|
||||
result.spectated = spectated
|
||||
result.canManageUsers = canManageUsers
|
||||
result.canRequestAccess = canRequestAccess
|
||||
result.isMember = isMember
|
||||
|
@ -141,6 +144,7 @@ proc `$`*(self: SectionItem): string =
|
|||
enabled:{self.enabled},
|
||||
joined:{self.joined},
|
||||
canJoin:{self.canJoin},
|
||||
spectated:{self.spectated},
|
||||
canManageUsers:{self.canManageUsers},
|
||||
canRequestAccess:{self.canRequestAccess},
|
||||
isMember:{self.isMember},
|
||||
|
@ -221,6 +225,9 @@ proc joined*(self: SectionItem): bool {.inline.} =
|
|||
proc canJoin*(self: SectionItem): bool {.inline.} =
|
||||
self.canJoin
|
||||
|
||||
proc spectated*(self: SectionItem): bool {.inline.} =
|
||||
self.spectated
|
||||
|
||||
proc canRequestAccess*(self: SectionItem): bool {.inline.} =
|
||||
self.canRequestAccess
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ type
|
|||
Active
|
||||
Enabled
|
||||
Joined
|
||||
Spectated
|
||||
IsMember
|
||||
CanJoin
|
||||
CanManageUsers
|
||||
|
@ -89,6 +90,7 @@ QtObject:
|
|||
ModelRole.Active.int:"active",
|
||||
ModelRole.Enabled.int:"enabled",
|
||||
ModelRole.Joined.int:"joined",
|
||||
ModelRole.Spectated.int:"spectated",
|
||||
ModelRole.IsMember.int:"isMember",
|
||||
ModelRole.CanJoin.int:"canJoin",
|
||||
ModelRole.CanManageUsers.int:"canManageUsers",
|
||||
|
@ -148,6 +150,8 @@ QtObject:
|
|||
result = newQVariant(item.enabled)
|
||||
of ModelRole.Joined:
|
||||
result = newQVariant(item.joined)
|
||||
of ModelRole.Spectated:
|
||||
result = newQVariant(item.spectated)
|
||||
of ModelRole.IsMember:
|
||||
result = newQVariant(item.isMember)
|
||||
of ModelRole.CanJoin:
|
||||
|
@ -272,6 +276,7 @@ QtObject:
|
|||
ModelRole.IsMember.int,
|
||||
ModelRole.CanJoin.int,
|
||||
ModelRole.Joined.int,
|
||||
ModelRole.Spectated.int,
|
||||
ModelRole.Muted.int,
|
||||
ModelRole.MembersModel.int,
|
||||
ModelRole.PendingRequestsToJoinModel.int,
|
||||
|
@ -390,6 +395,7 @@ QtObject:
|
|||
"active": item.active,
|
||||
"enabled": item.enabled,
|
||||
"joined": item.joined,
|
||||
"spectated": item.spectated,
|
||||
"canJoin": item.canJoin,
|
||||
"canManageUsers": item.canManageUsers,
|
||||
"canRequestAccess": item.canRequestAccess,
|
||||
|
|
|
@ -47,6 +47,7 @@ type CommunityDto* = object
|
|||
admin*: bool
|
||||
verified*: bool
|
||||
joined*: bool
|
||||
spectated*: bool
|
||||
requestedAccessAt: int64
|
||||
name*: string
|
||||
description*: string
|
||||
|
@ -148,6 +149,7 @@ proc toCommunityDto*(jsonObj: JsonNode): CommunityDto =
|
|||
discard jsonObj.getProp("admin", result.admin)
|
||||
discard jsonObj.getProp("verified", result.verified)
|
||||
discard jsonObj.getProp("joined", result.joined)
|
||||
discard jsonObj.getProp("spectated", result.spectated)
|
||||
discard jsonObj.getProp("requestedAccessAt", result.requestedAccessAt)
|
||||
discard jsonObj.getProp("name", result.name)
|
||||
discard jsonObj.getProp("description", result.description)
|
||||
|
|
|
@ -91,6 +91,7 @@ type
|
|||
|
||||
# Signals which may be emitted by this service:
|
||||
const SIGNAL_COMMUNITY_JOINED* = "communityJoined"
|
||||
const SIGNAL_COMMUNITY_SPECTATED* = "communitySpectated"
|
||||
const SIGNAL_COMMUNITY_MY_REQUEST_ADDED* = "communityMyRequestAdded"
|
||||
const SIGNAL_COMMUNITY_LEFT* = "communityLeft"
|
||||
const SIGNAL_COMMUNITY_CREATED* = "communityCreated"
|
||||
|
@ -281,22 +282,15 @@ QtObject:
|
|||
var community = communities[0]
|
||||
|
||||
if(not self.allCommunities.hasKey(community.id)):
|
||||
self.allCommunities[community.id] = community
|
||||
self.events.emit(SIGNAL_COMMUNITY_ADDED, CommunityArgs(community: community))
|
||||
# add or update community
|
||||
self.allCommunities[community.id] = community
|
||||
return
|
||||
|
||||
if(self.curatedCommunities.hasKey(community.id)):
|
||||
self.curatedCommunities[community.id].available = true
|
||||
self.curatedCommunities[community.id].community = community
|
||||
|
||||
if(not self.joinedCommunities.hasKey(community.id)):
|
||||
if (community.joined and community.isMember):
|
||||
self.joinedCommunities[community.id] = community
|
||||
keepIf(self.myCommunityRequests, request => request.communityId != community.id)
|
||||
self.events.emit(SIGNAL_COMMUNITY_JOINED, CommunityArgs(community: community, fromUserAction: false))
|
||||
return
|
||||
|
||||
let prev_community = self.joinedCommunities[community.id]
|
||||
let prev_community = self.allCommunities[community.id]
|
||||
|
||||
# If there's settings without `id` it means the original
|
||||
# signal didn't include actual communitySettings, hence we
|
||||
|
@ -380,9 +374,18 @@ QtObject:
|
|||
let data = CommunityChatArgs(chat: updatedChat)
|
||||
self.events.emit(SIGNAL_COMMUNITY_CHANNEL_EDITED, data)
|
||||
|
||||
self.saveUpdatedJoinedCommunity(community)
|
||||
self.allCommunities[community.id] = community
|
||||
self.events.emit(SIGNAL_COMMUNITIES_UPDATE, CommunitiesArgs(communities: @[community]))
|
||||
|
||||
if(not self.joinedCommunities.hasKey(community.id)):
|
||||
if (community.joined and community.isMember):
|
||||
self.joinedCommunities[community.id] = community
|
||||
self.events.emit(SIGNAL_COMMUNITY_JOINED, CommunityArgs(community: community, fromUserAction: false))
|
||||
# remove my pending requests
|
||||
keepIf(self.myCommunityRequests, request => request.communityId != community.id)
|
||||
else:
|
||||
self.saveUpdatedJoinedCommunity(community)
|
||||
|
||||
proc init*(self: Service) =
|
||||
self.doConnect()
|
||||
self.communityTags = self.loadCommunityTags();
|
||||
|
@ -539,6 +542,11 @@ QtObject:
|
|||
return false
|
||||
return self.allCommunities[communityId].joined and self.allCommunities[communityId].isMember
|
||||
|
||||
proc isUserSpectatingCommunity*(self: Service, communityId: string): bool =
|
||||
if(not self.allCommunities.contains(communityId)):
|
||||
return false
|
||||
return self.allCommunities[communityId].spectated
|
||||
|
||||
proc userCanJoin*(self: Service, communityId: string): bool =
|
||||
if(not self.allCommunities.contains(communityId)):
|
||||
return false
|
||||
|
@ -555,39 +563,35 @@ QtObject:
|
|||
|
||||
return true
|
||||
|
||||
proc joinCommunity*(self: Service, communityId: string): string =
|
||||
proc spectateCommunity*(self: Service, communityId: string): string =
|
||||
result = ""
|
||||
try:
|
||||
if (not self.userCanJoin(communityId) or self.isUserMemberOfCommunity(communityId)):
|
||||
if (self.isUserSpectatingCommunity(communityId) or self.isUserMemberOfCommunity(communityId)):
|
||||
return
|
||||
|
||||
let response = status_go.joinCommunity(communityId)
|
||||
let response = status_go.spectateCommunity(communityId)
|
||||
|
||||
if response.error != nil:
|
||||
let error = Json.decode($response.error, RpcError)
|
||||
raise newException(RpcException, "Error joining community: " & error.message)
|
||||
|
||||
if response.result == nil or response.result.kind == JNull:
|
||||
error "error: ", procName="joinCommunity", errDesription = "result is nil"
|
||||
error "error: ", procName="spectateCommunity", errDesription = "result is nil"
|
||||
return
|
||||
|
||||
if not response.result.hasKey("communities") or response.result["communities"].kind != JArray or response.result["communities"].len == 0:
|
||||
error "error: ", procName="joinCommunity", errDesription = "no 'communities' key in response"
|
||||
error "error: ", procName="spectateCommunity", errDesription = "no 'communities' key in response"
|
||||
return
|
||||
|
||||
if not response.result.hasKey("communitiesSettings") or response.result["communitiesSettings"].kind != JArray or response.result["communitiesSettings"].len == 0:
|
||||
error "error: ", procName="joinCommunity", errDesription = "no 'communitiesSettings' key in response"
|
||||
error "error: ", procName="spectateCommunity", errDesription = "no 'communitiesSettings' key in response"
|
||||
return
|
||||
|
||||
if not self.processRequestsToJoinCommunity(response.result):
|
||||
error "error: ", procName="joinCommunity", errDesription = "no 'requestsToJoinCommunity' key in response"
|
||||
|
||||
var updatedCommunity = response.result["communities"][0].toCommunityDto()
|
||||
let communitySettings = response.result["communitiesSettings"][0].toCommunitySettingsDto()
|
||||
|
||||
updatedCommunity.settings = communitySettings
|
||||
self.allCommunities[communityId] = updatedCommunity
|
||||
self.joinedCommunities[communityId] = updatedCommunity
|
||||
|
||||
for k, chat in updatedCommunity.chats:
|
||||
let fullChatId = communityId & chat.id
|
||||
|
@ -602,7 +606,7 @@ QtObject:
|
|||
self.chatService.updateOrAddChat(chatDto)
|
||||
|
||||
self.events.emit(SIGNAL_COMMUNITIES_UPDATE, CommunitiesArgs(communities: @[updatedCommunity]))
|
||||
self.events.emit(SIGNAL_COMMUNITY_JOINED, CommunityArgs(community: updatedCommunity, fromUserAction: true))
|
||||
self.events.emit(SIGNAL_COMMUNITY_SPECTATED, CommunityArgs(community: updatedCommunity, fromUserAction: true))
|
||||
except Exception as e:
|
||||
error "Error joining the community", msg = e.msg
|
||||
result = fmt"Error joining the community: {e.msg}"
|
||||
|
@ -672,6 +676,9 @@ QtObject:
|
|||
self.joinedCommunities.del(communityId)
|
||||
self.events.emit(SIGNAL_COMMUNITY_LEFT, CommunityIdArgs(communityId: communityId))
|
||||
|
||||
# remove related community requests
|
||||
keepIf(self.myCommunityRequests, request => request.communityId != communityId)
|
||||
|
||||
except Exception as e:
|
||||
error "Error leaving community", msg = e.msg, communityId
|
||||
|
||||
|
@ -1220,7 +1227,7 @@ QtObject:
|
|||
var pubKeys: seq[string] = @[]
|
||||
for pubKey in pubKeysParsed:
|
||||
pubKeys.add(pubKey.getStr)
|
||||
# We no longer send invites, but merely share the community so
|
||||
# We no longer send invites, but merely share the community so
|
||||
# users can request access (with automatic acception)
|
||||
let response = status_go.shareCommunityToUsers(communityId, pubKeys, inviteMessage)
|
||||
discard self.chatService.processMessageUpdateAfterSend(response)
|
||||
|
|
|
@ -28,8 +28,8 @@ proc getCuratedCommunities*(): RpcResponse[JsonNode] {.raises: [Exception].} =
|
|||
proc getAllCommunities*(): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
result = callPrivateRPC("communities".prefix)
|
||||
|
||||
proc joinCommunity*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
result = callPrivateRPC("joinCommunity".prefix, %*[communityId])
|
||||
proc spectateCommunity*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
result = callPrivateRPC("spectateCommunity".prefix, %*[communityId])
|
||||
|
||||
proc requestToJoinCommunity*(communityId: string, ensName: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
result = callPrivateRPC("requestToJoinCommunity".prefix, %*[{
|
||||
|
|
|
@ -194,7 +194,7 @@ StatusModal {
|
|||
// text = qsTr("Pending")
|
||||
// }
|
||||
} else {
|
||||
error = root.store.communitiesModuleInst.joinCommunity(root.communityId, root.store.userProfileInst.ensName)
|
||||
error = root.store.communitiesModuleInst.requestToJoinCommunity(root.communityId, root.store.userProfileInst.ensName)
|
||||
}
|
||||
|
||||
if (error) {
|
||||
|
|
|
@ -342,8 +342,8 @@ QtObject {
|
|||
chatCommunitySectionModule.reorderCommunityChat(categoryId, chatId, to)
|
||||
}
|
||||
|
||||
function joinCommunity(id, ensName) {
|
||||
return communitiesModuleInst.joinCommunity(id, ensName)
|
||||
function spectateCommunity(id, ensName) {
|
||||
return communitiesModuleInst.spectateCommunity(id, ensName)
|
||||
}
|
||||
|
||||
function requestToJoinCommunity(id, ensName) {
|
||||
|
@ -440,7 +440,7 @@ QtObject {
|
|||
const userCanJoin = userCanJoin(communityId)
|
||||
// TODO find what to do when you can't join
|
||||
if (userCanJoin) {
|
||||
joinCommunity(communityId, userProfileInst.ensName)
|
||||
requestToJoinCommunity(communityId, userProfileInst.ensName)
|
||||
}
|
||||
}
|
||||
return result
|
||||
|
|
|
@ -54,6 +54,9 @@ ColumnLayout {
|
|||
|
||||
property bool stickersLoaded: false
|
||||
|
||||
// FIXME: this should be section data related only to that view, not the active one
|
||||
readonly property var activeSectionData: rootStore.mainModuleInst ? rootStore.mainModuleInst.activeSection || {} : {}
|
||||
|
||||
// NOTE: Used this property change as it is the current way used for displaying new channel/chat data of content view.
|
||||
// If in the future content is loaded dynamically, input focus should be activated when loaded / created content view.
|
||||
onHeightChanged: {
|
||||
|
@ -173,6 +176,8 @@ ColumnLayout {
|
|||
anchors.fill: parent
|
||||
anchors.margins: Style.current.smallPadding
|
||||
|
||||
enabled: root.activeSectionData.joined
|
||||
|
||||
store: root.rootStore
|
||||
usersStore: root.usersStore
|
||||
|
||||
|
@ -190,6 +195,11 @@ ColumnLayout {
|
|||
value: qsTr("This user has been blocked.")
|
||||
}
|
||||
|
||||
Binding on chatInputPlaceholder {
|
||||
when: !root.activeSectionData.joined
|
||||
value: qsTr("You need to join this community to send messages")
|
||||
}
|
||||
|
||||
onSendTransactionCommandButtonClicked: {
|
||||
if(!chatContentModule) {
|
||||
console.debug("error on sending transaction command - chat content module is not set")
|
||||
|
|
|
@ -17,6 +17,7 @@ import shared.status 1.0
|
|||
import "../popups/community"
|
||||
import "../panels/communities"
|
||||
|
||||
// FIXME: Rework me to use ColumnLayout instead of anchors!!
|
||||
Item {
|
||||
id: root
|
||||
objectName: "communityColumnView"
|
||||
|
@ -94,12 +95,53 @@ Item {
|
|||
}
|
||||
}
|
||||
|
||||
StatusButton {
|
||||
id: joinCommunityButton
|
||||
|
||||
property bool invitationPending: root.store.isCommunityRequestPending(communityData.id)
|
||||
|
||||
anchors.top: communityHeader.bottom
|
||||
anchors.topMargin: 8
|
||||
anchors.bottomMargin: Style.current.halfPadding
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
|
||||
visible: !communityData.joined
|
||||
enabled: !invitationPending
|
||||
|
||||
text: {
|
||||
if (invitationPending) return qsTr("Pending")
|
||||
return root.communityData.access === Constants.communityChatOnRequestAccess ?
|
||||
qsTr("Request to join") : qsTr("Join Community")
|
||||
}
|
||||
|
||||
onClicked: communityIntroDialog.open()
|
||||
|
||||
Connections {
|
||||
target: root.store.communitiesModuleInst
|
||||
onCommunityAccessRequested: function (communityId) {
|
||||
if (communityId === communityData.id) {
|
||||
joinCommunityButton.invitationPending = root.store.isCommunityRequestPending(communityData.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CommunityIntroDialog {
|
||||
id: communityIntroDialog
|
||||
|
||||
name: communityData.name
|
||||
introMessage: communityData.introMessage
|
||||
imageSrc: communityData.image
|
||||
|
||||
onJoined: root.store.requestToJoinCommunity(communityData.id, root.store.userProfileInst.name)
|
||||
}
|
||||
}
|
||||
|
||||
Loader {
|
||||
id: membershipRequests
|
||||
|
||||
property int nbRequests: root.communityData.pendingRequestsToJoin.count || 0
|
||||
|
||||
anchors.top: communityHeader.bottom
|
||||
anchors.top: joinCommunityButton.visible ? joinCommunityButton.bottom : communityHeader.bottom
|
||||
anchors.topMargin: active ? 8 : 0
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@ Item {
|
|||
id: d
|
||||
|
||||
property var invitedCommunity
|
||||
property bool invitationPending
|
||||
|
||||
readonly property int margin: 12
|
||||
|
||||
|
@ -48,7 +47,6 @@ Item {
|
|||
|
||||
function reevaluate() {
|
||||
invitedCommunity = getCommunity()
|
||||
invitationPending = root.store.isCommunityRequestPending(communityId)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,15 +72,6 @@ Item {
|
|||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: root.store.communitiesModuleInst
|
||||
onCommunityAccessRequested: function (communityId) {
|
||||
if (communityId === root.communityId) {
|
||||
d.reevaluate()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loader {
|
||||
id: loader
|
||||
|
||||
|
@ -98,65 +87,6 @@ Item {
|
|||
border.color: Style.current.border
|
||||
border.width: 1
|
||||
|
||||
states: [
|
||||
State {
|
||||
name: "pending"
|
||||
when: d.invitationPending
|
||||
PropertyChanges {
|
||||
target: joinBtn
|
||||
text: qsTr("Pending")
|
||||
enabled: false
|
||||
}
|
||||
},
|
||||
State {
|
||||
name: "requiresEns"
|
||||
when: d.invitedCommunity.ensOnly && !userProfile.ensName
|
||||
PropertyChanges {
|
||||
target: joinBtn
|
||||
text: qsTr("Membership requires an ENS username")
|
||||
enabled: false
|
||||
}
|
||||
},
|
||||
State {
|
||||
name: "inviteOnly"
|
||||
when: d.invitedCommunity.access === Constants.communityChatInvitationOnlyAccess
|
||||
PropertyChanges {
|
||||
target: joinBtn
|
||||
text: qsTr("You need to be invited")
|
||||
enabled: false
|
||||
}
|
||||
},
|
||||
State {
|
||||
name: "joined"
|
||||
when: (d.invitedCommunity.joined && d.invitedCommunity.isMember) ||
|
||||
(d.invitedCommunity.access === Constants.communityChatPublicAccess &&
|
||||
d.invitedCommunity.joined)
|
||||
PropertyChanges {
|
||||
target: joinBtn
|
||||
text: qsTr("View")
|
||||
}
|
||||
},
|
||||
State {
|
||||
name: "requestToJoin"
|
||||
when: d.invitedCommunity.access === Constants.communityChatOnRequestAccess &&
|
||||
!d.invitedCommunity.joined
|
||||
PropertyChanges {
|
||||
target: joinBtn
|
||||
text: qsTr("Request Access")
|
||||
|
||||
}
|
||||
},
|
||||
State {
|
||||
name: "unjoined"
|
||||
when: d.invitedCommunity.access === Constants.communityChatPublicAccess &&
|
||||
!d.invitedCommunity.joined
|
||||
PropertyChanges {
|
||||
target: joinBtn
|
||||
text: qsTr("Join")
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
ColumnLayout {
|
||||
id: columnLayout
|
||||
|
||||
|
@ -280,81 +210,28 @@ Item {
|
|||
color: Style.current.separator
|
||||
}
|
||||
|
||||
Item {
|
||||
StatusFlatButton {
|
||||
id: joinBtn
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: 44
|
||||
clip: true
|
||||
StatusFlatButton {
|
||||
id: joinBtn
|
||||
width: parent.width
|
||||
height: (parent.height+Style.current.padding)
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: -Style.current.padding
|
||||
text: qsTr("Unsupported state")
|
||||
contentItem: Item {
|
||||
StatusBaseText {
|
||||
anchors.centerIn: parent
|
||||
anchors.verticalCenterOffset: Style.current.halfPadding
|
||||
font: joinBtn.font
|
||||
color: joinBtn.enabled ? joinBtn.textColor : joinBtn.disabledTextColor
|
||||
text: joinBtn.text
|
||||
}
|
||||
}
|
||||
|
||||
onClicked: {
|
||||
if (rectangleBubble.state === "joined") {
|
||||
root.store.setActiveCommunity(communityId);
|
||||
return
|
||||
}
|
||||
if (rectangleBubble.state === "unjoined") {
|
||||
Global.openPopup(communityIntroDialog, { joinMethod: () => {
|
||||
let error = root.store.joinCommunity(communityId, userProfile.name)
|
||||
if (error) joiningError.showError(error)
|
||||
} });
|
||||
}
|
||||
else if (rectangleBubble.state === "requestToJoin") {
|
||||
Global.openPopup(communityIntroDialog, { joinMethod: () => {
|
||||
let error = root.store.requestToJoinCommunity(communityId, userProfile.name)
|
||||
if (error) joiningError.showError(error)
|
||||
} });
|
||||
}
|
||||
}
|
||||
text: qsTr("Go to Community")
|
||||
|
||||
Component.onCompleted: {
|
||||
background.radius = Style.current.padding;
|
||||
onClicked: {
|
||||
if (d.invitedCommunity.joined || d.invitedCommunity.spectated) {
|
||||
root.store.setActiveCommunity(communityId)
|
||||
} else {
|
||||
root.store.spectateCommunity(communityId, userProfile.name)
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
// FIXME: extract StatusButtonBackground or expose radius property in StatusBaseButton
|
||||
background.radius = 16
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: communityIntroDialog
|
||||
|
||||
CommunityIntroDialog {
|
||||
anchors.centerIn: parent
|
||||
|
||||
property var joinMethod: () => {}
|
||||
|
||||
name: d.invitedCommunity ? d.invitedCommunity.name : ""
|
||||
introMessage: d.invitedCommunity ? d.invitedCommunity.introMessage : ""
|
||||
imageSrc: d.invitedCommunity ? d.invitedCommunity.image : ""
|
||||
|
||||
onJoined: joinMethod()
|
||||
}
|
||||
}
|
||||
|
||||
MessageDialog {
|
||||
id: joiningError
|
||||
|
||||
function showError(error) {
|
||||
joiningError.text = error
|
||||
joiningError.open()
|
||||
}
|
||||
|
||||
title: qsTr("Error joining the community")
|
||||
icon: StandardIcon.Critical
|
||||
standardButtons: StandardButton.Ok
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue