feat: show default unfurling for community links
This commit is contained in:
parent
c5c348b0b1
commit
5581fca41d
|
@ -123,6 +123,20 @@ QtObject:
|
|||
QtProperty[QVariant] joinedCommunities:
|
||||
read = getJoinedComunities
|
||||
notify = joinedCommunitiesChanged
|
||||
|
||||
proc getCommunityNameById*(self: CommunitiesView, communityId: string): string {.slot.} =
|
||||
let communities = self.getCommunitiesIfNotFetched()
|
||||
for community in communities.communities:
|
||||
if community.id == communityId:
|
||||
return community.name
|
||||
return ""
|
||||
|
||||
proc isUserMemberOfCommunity*(self: CommunitiesView, communityId: string): bool {.slot.} =
|
||||
let communities = self.getCommunitiesIfNotFetched()
|
||||
for community in communities.communities:
|
||||
if community.id == communityId:
|
||||
return community.joined and community.isMember
|
||||
return false
|
||||
|
||||
proc activeCommunityChanged*(self: CommunitiesView) {.signal.}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ Rectangle {
|
|||
anchors.rightMargin: Style.current.padding
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
width: 13
|
||||
|
||||
height: 7
|
||||
|
||||
ColorOverlay {
|
||||
anchors.fill: parent
|
||||
|
|
|
@ -329,6 +329,32 @@ QtObject {
|
|||
return result
|
||||
}
|
||||
|
||||
// Community
|
||||
// TODO this will probably change
|
||||
index = link.lastIndexOf("/cc/")
|
||||
if (index > -1) {
|
||||
const communityId = link.substring(index + 4)
|
||||
|
||||
const communityName = chatsModel.communities.getCommunityNameById(communityId)
|
||||
|
||||
if (!communityName) {
|
||||
// Unknown community
|
||||
// TODO use a function to fetch that community?
|
||||
return result
|
||||
}
|
||||
|
||||
result.title = qsTr("Join the %1 community").arg(communityName)
|
||||
result.callback = function () {
|
||||
const isUserMemberOfCommunity = chatsModel.communities.isUserMemberOfCommunity(communityId)
|
||||
if (isUserMemberOfCommunity) {
|
||||
chatsModel.communities.setActiveCommunity(communityId)
|
||||
return
|
||||
}
|
||||
chatsModel.communities.joinCommunity(communityId, true)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Public chat
|
||||
// This needs to be the last check because it is as VERY loose check
|
||||
index = link.lastIndexOf("/")
|
||||
|
|
Loading…
Reference in New Issue