feat: show default unfurling for community links

This commit is contained in:
Jonathan Rainville 2021-03-05 14:42:41 -05:00 committed by Iuri Matias
parent c5c348b0b1
commit 5581fca41d
3 changed files with 41 additions and 1 deletions

View File

@ -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.}

View File

@ -50,7 +50,7 @@ Rectangle {
anchors.rightMargin: Style.current.padding
anchors.verticalCenter: parent.verticalCenter
width: 13
height: 7
ColorOverlay {
anchors.fill: parent

View File

@ -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("/")