feat(communities): re-implement community link unfurling

Fixes #4788
This commit is contained in:
Jonathan Rainville 2022-02-11 16:41:34 -05:00 committed by Iuri Matias
parent bee583d448
commit 16e7d16c8c
21 changed files with 369 additions and 231 deletions

View File

@ -133,7 +133,8 @@ proc newAppController*(statusFoundation: StatusFoundation): AppController =
statusFoundation.events, statusFoundation.threadpool, result.settingsService statusFoundation.events, statusFoundation.threadpool, result.settingsService
) )
result.chatService = chat_service.newService(statusFoundation.events, result.contactsService) result.chatService = chat_service.newService(statusFoundation.events, result.contactsService)
result.communityService = community_service.newService(statusFoundation.events, result.chatService) result.communityService = community_service.newService(statusFoundation.events,
statusFoundation.threadpool, result.chatService)
result.messageService = message_service.newService(statusFoundation.events, statusFoundation.threadpool, result.messageService = message_service.newService(statusFoundation.events, statusFoundation.threadpool,
result.contactsService) result.contactsService)
result.activityCenterService = activity_center_service.newService(statusFoundation.events, result.activityCenterService = activity_center_service.newService(statusFoundation.events,

View File

@ -36,6 +36,10 @@ method init*(self: Controller) =
let args = CommunityArgs(e) let args = CommunityArgs(e)
self.delegate.communityAdded(args.community) self.delegate.communityAdded(args.community)
self.events.on(SIGNAL_COMMUNITY_DATA_IMPORTED) do(e:Args):
let args = CommunityArgs(e)
self.delegate.communityAdded(args.community)
self.events.on(SIGNAL_COMMUNITY_IMPORTED) do(e:Args): self.events.on(SIGNAL_COMMUNITY_IMPORTED) do(e:Args):
let args = CommunityArgs(e) let args = CommunityArgs(e)
if(args.error.len > 0): if(args.error.len > 0):
@ -117,3 +121,12 @@ method setCommunityMuted*(self: Controller, communityId: string, muted: bool) =
method getContactNameAndImage*(self: Controller, contactId: string): method getContactNameAndImage*(self: Controller, contactId: string):
tuple[name: string, image: string, isIdenticon: bool] = tuple[name: string, image: string, isIdenticon: bool] =
return self.contactsService.getContactNameAndImage(contactId) return self.contactsService.getContactNameAndImage(contactId)
method isUserMemberOfCommunity*(self: Controller, communityId: string): bool =
return self.communityService.isUserMemberOfCommunity(communityId)
method userCanJoin*(self: Controller, communityId: string): bool =
return self.communityService.userCanJoin(communityId)
method isCommunityRequestPending*(self: Controller, communityId: string): bool =
return self.communityService.isCommunityRequestPending(communityId)

View File

@ -37,6 +37,15 @@ method deleteCommunityCategory*(self: AccessInterface, communityId: string, cate
method requestCommunityInfo*(self: AccessInterface, communityId: string) {.base.} = method requestCommunityInfo*(self: AccessInterface, communityId: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method isUserMemberOfCommunity*(self: AccessInterface, communityId: string): bool {.base.} =
raise newException(ValueError, "No implementation available")
method userCanJoin*(self: AccessInterface, communityId: string): bool {.base.} =
raise newException(ValueError, "No implementation available")
method isCommunityRequestPending*(self: AccessInterface, communityId: string): bool {.base.} =
raise newException(ValueError, "No implementation available")
method importCommunity*(self: AccessInterface, communityKey: string) {.base.} = method importCommunity*(self: AccessInterface, communityKey: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")

View File

@ -105,6 +105,7 @@ method joinCommunity*(self: Module, communityId: string): string =
method communityEdited*(self: Module, community: CommunityDto) = method communityEdited*(self: Module, community: CommunityDto) =
self.view.model().editItem(self.getCommunityItem(community)) self.view.model().editItem(self.getCommunityItem(community))
self.view.communityChanged(community.id)
method requestAdded*(self: Module) = method requestAdded*(self: Module) =
# TODO to model or view # TODO to model or view
@ -163,6 +164,15 @@ method requestToJoinCommunity*(self: Module, communityId: string, ensName: strin
method requestCommunityInfo*(self: Module, communityId: string) = method requestCommunityInfo*(self: Module, communityId: string) =
self.controller.requestCommunityInfo(communityId) self.controller.requestCommunityInfo(communityId)
method isUserMemberOfCommunity*(self: Module, communityId: string): bool =
self.controller.isUserMemberOfCommunity(communityId)
method userCanJoin*(self: Module, communityId: string): bool =
self.controller.userCanJoin(communityId)
method isCommunityRequestPending*(self: Module, communityId: string): bool =
self.controller.isCommunityRequestPending(communityId)
method deleteCommunityChat*(self: Module, communityId: string, channelId: string) = method deleteCommunityChat*(self: Module, communityId: string, channelId: string) =
self.controller.deleteCommunityChat(communityId, channelId) self.controller.deleteCommunityChat(communityId, channelId)

View File

@ -37,6 +37,15 @@ method removeUserFromCommunity*(self: AccessInterface, communityId: string, pubK
method banUserFromCommunity*(self: AccessInterface, pubKey: string, communityId: string) {.base.} = method banUserFromCommunity*(self: AccessInterface, pubKey: string, communityId: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method isUserMemberOfCommunity*(self: AccessInterface, communityId: string): bool {.base.} =
raise newException(ValueError, "No implementation available")
method userCanJoin*(self: AccessInterface, communityId: string): bool {.base.} =
raise newException(ValueError, "No implementation available")
method isCommunityRequestPending*(self: AccessInterface, communityId: string): bool {.base.} =
raise newException(ValueError, "No implementation available")
method requestToJoinCommunity*(self: AccessInterface, communityId: string, ensName: string) {.base.} = method requestToJoinCommunity*(self: AccessInterface, communityId: string, ensName: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")

View File

@ -30,8 +30,12 @@ QtObject:
proc load*(self: View) = proc load*(self: View) =
self.delegate.viewDidLoad() self.delegate.viewDidLoad()
proc communityAdded*(self: View, communityId: string) {.signal.}
proc communityChanged*(self: View, communityId: string) {.signal.}
proc addItem*(self: View, item: SectionItem) = proc addItem*(self: View, item: SectionItem) =
self.model.addItem(item) self.model.addItem(item)
self.communityAdded(item.id)
proc model*(self: View): SectionModel = proc model*(self: View): SectionModel =
result = self.model result = self.model
@ -61,9 +65,6 @@ QtObject:
proc joinCommunity*(self: View, communityId: string): string {.slot.} = proc joinCommunity*(self: View, communityId: string): string {.slot.} =
result = self.delegate.joinCommunity(communityId) result = self.delegate.joinCommunity(communityId)
proc communityAdded*(self: View, communityId: string) {.signal.}
proc communityChanged*(self: View, communityId: string) {.signal.}
proc createCommunity*(self: View, name: string, description: string, proc createCommunity*(self: View, name: string, description: string,
access: int, ensOnly: bool, color: string, access: int, ensOnly: bool, color: string,
imagePath: string, imagePath: string,
@ -91,6 +92,15 @@ QtObject:
proc requestCommunityInfo*(self: View, communityId: string) {.slot.} = proc requestCommunityInfo*(self: View, communityId: string) {.slot.} =
self.delegate.requestCommunityInfo(communityId) self.delegate.requestCommunityInfo(communityId)
proc isUserMemberOfCommunity*(self: View, communityId: string): bool {.slot.} =
self.delegate.isUserMemberOfCommunity(communityId)
proc userCanJoin*(self: View, communityId: string): bool {.slot.} =
self.delegate.userCanJoin(communityId)
proc isCommunityRequestPending*(self: View, communityId: string): bool {.slot.} =
self.delegate.isCommunityRequestPending(communityId)
proc deleteCommunityChat*(self: View, communityId: string, channelId: string) {.slot.} = proc deleteCommunityChat*(self: View, communityId: string, channelId: string) {.slot.} =
self.delegate.deleteCommunityChat(communityId, channelId) self.delegate.deleteCommunityChat(communityId, channelId)

View File

@ -1,6 +1,8 @@
import NimQml, Tables, strutils, strformat import NimQml, Tables, strutils, strformat
import section_item import json, json_serialization
import section_item, user_model
type type
ModelRole {.pure.} = enum ModelRole {.pure.} = enum
@ -267,3 +269,34 @@ QtObject:
self.items[i].notificationsCount = notificationsCount self.items[i].notificationsCount = notificationsCount
self.dataChanged(index, index, @[ModelRole.HasNotification.int, ModelRole.NotificationsCount.int]) self.dataChanged(index, index, @[ModelRole.HasNotification.int, ModelRole.NotificationsCount.int])
return return
proc getSectionNameById*(self: SectionModel, sectionId: string): string {.slot.} =
for item in self.items:
if item.id == sectionId:
return item.name
proc getSectionByIdJson(self: SectionModel, sectionId: string): string {.slot.} =
for item in self.items:
if (item.id == sectionId):
let jsonObj = %* {
"id": item.id,
"name": item.name,
"amISectionAdmin": item.amISectionAdmin,
"description": item.description,
"image": item.image,
"icon": item.icon,
"color": item.color,
"hasNotification": item.hasNotification,
"notificationsCount": item.notificationsCount,
"active": item.active,
"enabled": item.enabled,
"joined": item.joined,
"canJoin": item.canJoin,
"canManageUsers": item.canManageUsers,
"canRequestAccess": item.canRequestAccess,
"isMember": item.isMember,
"access": item.access,
"ensOnly": item.ensOnly,
"nbMembers": item.members.getCount()
}
return $jsonObj

View File

@ -41,7 +41,7 @@ QtObject:
result &= fmt"""User Model: result &= fmt"""User Model:
[{i}]:({$self.items[i]}) [{i}]:({$self.items[i]})
""" """
proc getCount(self: Model): int {.slot.} = proc getCount*(self: Model): int {.slot.} =
self.items.len self.items.len
QtProperty[int] count: QtProperty[int] count:
read = getCount read = getCount

View File

@ -0,0 +1,12 @@
include ../../common/json_utils
include ../../../app/core/tasks/common
type
AsyncRequestCommunityInfoTaskArg = ref object of QObjectTaskArg
communityId: string
const asyncRequestCommunityInfoTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
let arg = decode[AsyncRequestCommunityInfoTaskArg](argEncoded)
let response = status_go.requestCommunityInfo(arg.communityId)
arg.finish(response)

View File

@ -7,8 +7,12 @@ import ../chat/service as chat_service
import ../../../app/global/global_singleton import ../../../app/global/global_singleton
import ../../../app/core/signals/types import ../../../app/core/signals/types
import ../../../app/core/eventemitter import ../../../app/core/eventemitter
import ../../../app/core/[main]
import ../../../app/core/tasks/[qt, threadpool]
import ../../../backend/communities as status_go import ../../../backend/communities as status_go
include ./async_tasks
export community_dto export community_dto
logScope: logScope:
@ -63,6 +67,7 @@ const SIGNAL_COMMUNITY_MY_REQUEST_ADDED* = "communityMyRequestAdded"
const SIGNAL_COMMUNITY_LEFT* = "communityLeft" const SIGNAL_COMMUNITY_LEFT* = "communityLeft"
const SIGNAL_COMMUNITY_CREATED* = "communityCreated" const SIGNAL_COMMUNITY_CREATED* = "communityCreated"
const SIGNAL_COMMUNITY_IMPORTED* = "communityImported" const SIGNAL_COMMUNITY_IMPORTED* = "communityImported"
const SIGNAL_COMMUNITY_DATA_IMPORTED* = "communityDataImported" # This one is when just loading the data with requestCommunityInfo
const SIGNAL_COMMUNITY_EDITED* = "communityEdited" const SIGNAL_COMMUNITY_EDITED* = "communityEdited"
const SIGNAL_COMMUNITIES_UPDATE* = "communityUpdated" const SIGNAL_COMMUNITIES_UPDATE* = "communityUpdated"
const SIGNAL_COMMUNITY_CHANNEL_CREATED* = "communityChannelCreated" const SIGNAL_COMMUNITY_CHANNEL_CREATED* = "communityChannelCreated"
@ -77,6 +82,7 @@ const SIGNAL_COMMUNITY_MEMBER_APPROVED* = "communityMemberApproved"
QtObject: QtObject:
type type
Service* = ref object of QObject Service* = ref object of QObject
threadpool: ThreadPool
events: EventEmitter events: EventEmitter
chatService: chat_service.Service chatService: chat_service.Service
joinedCommunities: Table[string, CommunityDto] # [community_id, CommunityDto] joinedCommunities: Table[string, CommunityDto] # [community_id, CommunityDto]
@ -93,15 +99,25 @@ QtObject:
proc delete*(self: Service) = proc delete*(self: Service) =
discard discard
proc newService*(events: EventEmitter, chatService: chat_service.Service): Service = proc newService*(
events: EventEmitter,
threadpool: ThreadPool,
chatService: chat_service.Service
): Service =
result = Service() result = Service()
result.events = events result.events = events
result.threadpool = threadpool
result.chatService = chatService result.chatService = chatService
result.joinedCommunities = initTable[string, CommunityDto]() result.joinedCommunities = initTable[string, CommunityDto]()
result.allCommunities = initTable[string, CommunityDto]() result.allCommunities = initTable[string, CommunityDto]()
result.myCommunityRequests = @[] result.myCommunityRequests = @[]
proc doConnect(self: Service) = proc doConnect(self: Service) =
self.events.on(SignalType.CommunityFound.event) do(e: Args):
var receivedData = CommunitySignal(e)
self.allCommunities[receivedData.community.id] = receivedData.community
self.events.emit(SIGNAL_COMMUNITY_DATA_IMPORTED, CommunityArgs(community: receivedData.community))
self.events.on(SignalType.Message.event) do(e: Args): self.events.on(SignalType.Message.event) do(e: Args):
var receivedData = MessageSignal(e) var receivedData = MessageSignal(e)
@ -156,9 +172,7 @@ QtObject:
proc handleCommunityUpdates(self: Service, communities: seq[CommunityDto], updatedChats: seq[ChatDto]) = proc handleCommunityUpdates(self: Service, communities: seq[CommunityDto], updatedChats: seq[ChatDto]) =
let community = communities[0] let community = communities[0]
var sortingOrderChanged = false
if(not self.joinedCommunities.hasKey(community.id)): if(not self.joinedCommunities.hasKey(community.id)):
error "error: community doesn't exist"
return return
let prev_community = self.joinedCommunities[community.id] let prev_community = self.joinedCommunities[community.id]
@ -676,16 +690,28 @@ QtObject:
except Exception as e: except Exception as e:
error "Error reordering category channel", msg = e.msg, communityId, categoryId, position error "Error reordering category channel", msg = e.msg, communityId, categoryId, position
proc asyncActivityNotificationLoad*(self: Service, communityId: string) =
let arg = AsyncRequestCommunityInfoTaskArg(
tptr: cast[ByteAddress](asyncRequestCommunityInfoTask),
vptr: cast[ByteAddress](self.vptr),
slot: "asyncCommunityInfoLoaded",
communityId: communityId
)
self.threadpool.start(arg)
proc asyncCommunityInfoLoaded*(self: Service, rpcResponse: string) {.slot.} =
let rpcResponseObj = rpcResponse.parseJson
if (rpcResponseObj{"error"}.kind != JNull):
let error = Json.decode($rpcResponseObj["error"], RpcError)
error "Error requesting community info", msg = error.message
proc requestCommunityInfo*(self: Service, communityId: string) = proc requestCommunityInfo*(self: Service, communityId: string) =
try: try:
let response = status_go.requestCommunityInfo(communityId) self.asyncActivityNotificationLoad(communityId)
if (response.error != nil):
let error = Json.decode($response.error, RpcError)
raise newException(RpcException, fmt"Error requesting community info: {error.message}")
except Exception as e: except Exception as e:
error "Error requesting community info", msg = e.msg, communityId error "Error requesting community info", msg = e.msg, communityId
proc importCommunity*(self: Service, communityKey: string) = proc importCommunity*(self: Service, communityKey: string) =
try: try:
let response = status_go.importCommunity(communityKey) let response = status_go.importCommunity(communityKey)
@ -814,3 +840,9 @@ QtObject:
discard status_go.setCommunityMuted(communityId, muted) discard status_go.setCommunityMuted(communityId, muted)
except Exception as e: except Exception as e:
error "Error setting community un/muted", msg = e.msg error "Error setting community un/muted", msg = e.msg
proc isCommunityRequestPending*(self: Service, communityId: string): bool {.slot.} =
for communityRequest in self.myCommunityRequests:
if (communityRequest.communityId == communityId):
return true
return false

View File

@ -205,7 +205,7 @@ proc deleteCommunityCategory*(
}]) }])
proc requestCommunityInfo*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} = proc requestCommunityInfo*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("requestCommunityInfoFromMailserver".prefix, %*[communityId]) result = callPrivateRPC("requestCommunityInfoFromMailserverAsync".prefix, %*[communityId])
proc importCommunity*(communityKey: string): RpcResponse[JsonNode] {.raises: [Exception].} = proc importCommunity*(communityKey: string): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("importCommunity".prefix, %*[communityKey]) result = callPrivateRPC("importCommunity".prefix, %*[communityKey])

View File

@ -110,6 +110,7 @@ ModalPopup {
MessageView { MessageView {
id: messageItem id: messageItem
store: popup.store
messageStore: popup.messageStore messageStore: popup.messageStore
messageContextMenu: msgContextMenu messageContextMenu: msgContextMenu

View File

@ -58,15 +58,6 @@ QtObject {
property var emojiReactionsModel property var emojiReactionsModel
// Not Refactored Yet
// property var chatsModelInst: chatsModel
// Not Refactored Yet
// property var utilsModelInst: utilsModel
// Not Refactored Yet
// property var walletModelInst: walletModel
// Not Refactored Yet
// property var profileModelInst: profileModel
property var globalUtilsInst: globalUtils property var globalUtilsInst: globalUtils
property var mainModuleInst: mainModule property var mainModuleInst: mainModule
@ -211,11 +202,157 @@ QtObject {
chatCommunitySectionModule.removeCommunityChat(chatId) chatCommunitySectionModule.removeCommunityChat(chatId)
} }
function reorderCommunityCategories(categoryId, to){ function reorderCommunityCategories(categoryId, to) {
chatCommunitySectionModule.reorderCommunityCategories(categoryId, to) chatCommunitySectionModule.reorderCommunityCategories(categoryId, to)
} }
function reorderCommunityChat(categoryId, chatId, to){ function reorderCommunityChat(categoryId, chatId, to) {
chatCommunitySectionModule.reorderCommunityChat(categoryId, chatId, to) chatCommunitySectionModule.reorderCommunityChat(categoryId, chatId, to)
} }
function joinCommunity(id) {
return communitiesModuleInst.joinCommunity(id)
}
function requestToJoinCommunity(id, ensName) {
return communitiesModuleInst.requestToJoinCommunity(id, ensName)
}
function userCanJoin(id) {
return communitiesModuleInst.userCanJoin(id)
}
function isUserMemberOfCommunity(id) {
return communitiesModuleInst.isUserMemberOfCommunity(id)
}
function isCommunityRequestPending(id) {
return communitiesModuleInst.isCommunityRequestPending(id)
}
function getSectionNameById(id) {
return communitiesList.getSectionNameById(id)
}
function getSectionByIdJson(id) {
return communitiesList.getSectionByIdJson(id)
}
function getLinkTitleAndCb(link) {
const result = {
title: "Status",
callback: null
}
// Link to send a direct message
let index = link.indexOf("/u/")
if (index === -1) {
// Try /p/ as well
index = link.indexOf("/p/")
}
if (index > -1) {
const pk = link.substring(index + 3)
//% "Start a 1-on-1 chat with %1"
result.title = qsTrId("start-a-1-on-1-chat-with--1")
.arg(isChatKey(pk) ? globalUtils.generateAlias(pk) : ("@" + removeStatusEns(pk)))
result.callback = function () {
if (isChatKey(pk)) {
chatCommunitySectionModule.createOneToOneChat(pk, "")
} else {
// Not Refactored Yet
// chatsModel.channelView.joinWithENS(pk);
}
}
return result
}
// Community
index = link.lastIndexOf("/c/")
if (index > -1) {
const communityId = link.substring(index + 3)
const communityName = getSectionNameById(communityId)
if (!communityName) {
// Unknown community, fetch the info if possible
communitiesModuleInst.requestCommunityInfo(communityId)
result.communityId = communityId
result.fetching = true
return result
}
//% "Join the %1 community"
result.title = qsTrId("join-the--1-community").arg(communityName)
result.communityId = communityId
result.callback = function () {
const isUserMemberOfCommunity = isUserMemberOfCommunity(communityId)
if (isUserMemberOfCommunity) {
setActiveCommunity(communityId)
return
}
const userCanJoin = userCanJoin(communityId)
// TODO find what to do when you can't join
if (userCanJoin) {
joinCommunity(communityId, true)
}
}
return result
}
// Group chat
index = link.lastIndexOf("/g/")
if (index > -1) {
let indexAdminPk = link.lastIndexOf("a=")
let indexChatName = link.lastIndexOf("a1=")
let indexChatId = link.lastIndexOf("a2=")
const pubKey = link.substring(indexAdminPk + 2, indexChatName - 1)
const chatName = link.substring(indexChatName + 3, indexChatId - 1)
const chatId = link.substring(indexChatId + 3, link.length)
//% "Join the %1 group chat"
result.title = qsTrId("join-the--1-group-chat").arg(chatName)
result.callback = function () {
// Not Refactored Yet
// chatsModel.groups.joinGroupChatFromInvitation(chatName, chatId, pubKey);
}
return result
}
// Not Refactored Yet (when we get to this we will most likely remove it, since other approach will be used)
// // Public chat
// // This needs to be the last check because it is as VERY loose check
// index = link.lastIndexOf("/")
// if (index > -1) {
// const chatId = link.substring(index + 1)
// //% "Join the %1 public channel"
// result.title = qsTrId("join-the--1-public-channel").arg(chatId)
// result.callback = function () {
// chatsModel.channelView.joinPublicChat(chatId);
// }
// return result
// }
return result
}
function getLinkDataForStatusLinks(link) {
if (!link.includes(Constants.deepLinkPrefix) && !link.includes(Constants.joinStatusLink)) {
return
}
const result = getLinkTitleAndCb(link)
return {
site: "https://join.status.im",
title: result.title,
communityId: result.communityId,
fetching: result.fetching,
thumbnailUrl: Style.png("status"),
contentType: "",
height: 0,
width: 0,
callback: result.callback
}
}
} }

View File

@ -111,6 +111,7 @@ Item {
MessageView { MessageView {
id: notificationMessage id: notificationMessage
anchors.right: undefined anchors.right: undefined
store: root.store
messageStore: root.store.messageStore messageStore: root.store.messageStore
messageId: model.id messageId: model.id
senderDisplayName: model.message.senderDisplayName senderDisplayName: model.message.senderDisplayName

View File

@ -296,6 +296,7 @@ Item {
delegate: MessageView { delegate: MessageView {
id: msgDelegate id: msgDelegate
store: root.store
messageStore: root.messageStore messageStore: root.messageStore
usersStore: root.usersStore usersStore: root.usersStore
contactsStore: root.contactsStore contactsStore: root.contactsStore

View File

@ -14,6 +14,7 @@ import StatusQ.Controls 0.1 as StatusQControls
Item { Item {
id: root id: root
property var store
property var messageStore property var messageStore
property var usersStore property var usersStore
property var contactsStore property var contactsStore
@ -594,6 +595,7 @@ Item {
linkUrls: root.linkUrls linkUrls: root.linkUrls
container: root.container container: root.container
messageStore: root.messageStore messageStore: root.messageStore
store: root.store
isCurrentUser: isCurrentUser isCurrentUser: isCurrentUser
} }
} }

View File

@ -23,37 +23,32 @@ Item {
property var store property var store
function getCommunity() { function getCommunity() {
// Not Refactored Yet try {
// try { const communityJson = root.store.getSectionByIdJson(communityId)
// const communityJson = root.store.chatsModelInst.communities.list.getCommunityByIdJson(communityId) if (!communityJson) {
// if (!communityJson) { return null
// return null }
// }
// let community = JSON.parse(communityJson); return JSON.parse(communityJson);
// if (community) { } catch (e) {
// community.nbMembers = community.members.length; console.error("Error parsing community", e)
// } }
// return community
// } catch (e) {
// console.error("Error parsing community", e)
// }
return null return null
} }
Component.onCompleted: { Component.onCompleted: {
root.invitedCommunity = getCommunity() root.invitedCommunity = getCommunity()
} }
// Connections { Connections {
// target: root.store.chatsModelInst.communities target: root.store.communitiesModuleInst
// onCommunityChanged: function (communityId) { onCommunityChanged: function (communityId) {
// if (communityId === root.communityId) { if (communityId === root.communityId) {
// root.invitedCommunity = getCommunity() root.invitedCommunity = getCommunity()
// } }
// } }
// } }
Component { Component {
id: confirmationPopupComponent id: confirmationPopupComponent
@ -89,8 +84,7 @@ Item {
Rectangle { Rectangle {
id: rectangleBubble id: rectangleBubble
property alias button: joinBtn property alias button: joinBtn
// Not Refactored Yet property bool isPendingRequest: root.store.isCommunityRequestPending(communityId)
property bool isPendingRequest: false //root.store.chatsModelInst.communities.isCommunityRequestPending(communityId)
width: 270 width: 270
height: title.height + title.anchors.topMargin + height: title.height + title.anchors.topMargin +
invitedYou.height + invitedYou.anchors.topMargin + invitedYou.height + invitedYou.anchors.topMargin +
@ -108,8 +102,7 @@ Item {
states: [ states: [
State { State {
name: "requiresEns" name: "requiresEns"
// Not Refactored Yet when: invitedCommunity.ensOnly && !userProfile.ensName
// when: invitedCommunity.ensOnly && !root.store.profileModelInst.profile.ensVerified
PropertyChanges { PropertyChanges {
target: joinBtn target: joinBtn
//% "Membership requires an ENS username" //% "Membership requires an ENS username"
@ -152,7 +145,7 @@ Item {
State { State {
name: "requestToJoin" name: "requestToJoin"
when: invitedCommunity.access === Constants.communityChatOnRequestAccess && when: invitedCommunity.access === Constants.communityChatOnRequestAccess &&
// !invitedCommunity.joined && !invitedCommunity.isMember !invitedCommunity.joined && !invitedCommunity.isMember &&
invitedCommunity.canRequestAccess invitedCommunity.canRequestAccess
PropertyChanges { PropertyChanges {
target: joinBtn target: joinBtn
@ -272,7 +265,7 @@ Item {
id: communityNbMembers id: communityNbMembers
// TODO add the plural support // TODO add the plural support
//% "%1 members" //% "%1 members"
text: qsTrId("-1-members").arg(invitedCommunity.members.count) text: qsTrId("-1-members").arg(invitedCommunity.nbMembers)
anchors.top: communityDesc.bottom anchors.top: communityDesc.bottom
anchors.topMargin: 2 anchors.topMargin: 2
anchors.left: parent.left anchors.left: parent.left
@ -304,34 +297,33 @@ Item {
//% "Unsupported state" //% "Unsupported state"
text: qsTrId("unsupported-state") text: qsTrId("unsupported-state")
onClicked: { onClicked: {
// Not Refactored Yet let onBtnClick = function(){
// let onBtnClick = function(){ let error
// let error
// if (rectangleBubble.state === "joined") { if (rectangleBubble.state === "joined") {
// root.store.chatsModelInst.communities.setActiveCommunity(communityId); root.store.setActiveCommunity(communityId);
// return return
// } else if (rectangleBubble.state === "unjoined") { } else if (rectangleBubble.state === "unjoined") {
// error = root.store.chatsModelInst.communities.joinCommunity(communityId, true) error = root.store.joinCommunity(communityId)
// } }
// else if (rectangleBubble.state === "requestToJoin") { else if (rectangleBubble.state === "requestToJoin") {
// error = root.store.chatsModelInst.communities.requestToJoinCommunity(communityId, userProfile.name) error = root.store.requestToJoinCommunity(communityId, userProfile.name)
// if (!error) { if (!error) {
// rectangleBubble.isPendingRequest = root.store.chatsModelInst.communities.isCommunityRequestPending(communityId) rectangleBubble.isPendingRequest = root.store.isCommunityRequestPending(communityId)
// } }
// } }
// if (error) { if (error) {
// joiningError.text = error joiningError.text = error
// return joiningError.open() return joiningError.open()
// } }
// } }
// if (localAccountSensitiveSettings.communitiesEnabled) { if (localAccountSensitiveSettings.communitiesEnabled) {
// onBtnClick(); onBtnClick();
// } else { } else {
// Global.openPopup(confirmationPopupComponent, { onConfirmed: onBtnClick }); Global.openPopup(confirmationPopupComponent, { onConfirmed: onBtnClick });
// } }
} }
MessageDialog { MessageDialog {

View File

@ -16,6 +16,7 @@ import shared.controls.chat 1.0
Column { Column {
id: root id: root
property var store
property var messageStore property var messageStore
property var container property var container
property string linkUrls: "" property string linkUrls: ""
@ -98,27 +99,26 @@ Column {
} }
} }
// Not Refactored Yet Connections {
// Connections { id: linkCommunityFetchConnections
// id: linkCommunityFetchConnections enabled: false
// enabled: false target: root.store.communitiesModuleInst
// target: root.store.chatsModelInst.communities onCommunityAdded: {
// onCommunityAdded: { if (communityId !== linkData.communityId) {
// if (communityId !== linkData.communityId) { return
// return }
// } linkCommunityFetchConnections.enabled = false
// linkCommunityFetchConnections.enabled = false const data = root.store.getLinkDataForStatusLinks(link)
// const data = Utils.getLinkDataForStatusLinks(link) if (data) {
// if (data) { linkData = data
// linkData = data if (!data.fetching && data.communityId) {
// if (!data.fetching && data.communityId) { return linkMessageLoader.sourceComponent = invitationBubble
// return linkMessageLoader.sourceComponent = invitationBubble }
// }
// return linkMessageLoader.sourceComponent = unfurledLinkComponent return linkMessageLoader.sourceComponent = unfurledLinkComponent
// } }
// } }
// } }
function getSourceComponent() { function getSourceComponent() {
// Reset the height in case we set it to 0 below. See note below // Reset the height in case we set it to 0 below. See note below
@ -165,12 +165,11 @@ Column {
} }
fetched = true fetched = true
const data = Utils.getLinkDataForStatusLinks(link) const data = root.store.getLinkDataForStatusLinks(link)
if (data) { if (data) {
linkData = data linkData = data
if (data.fetching && data.communityId) { if (data.fetching && data.communityId) {
// TODO uncomment when linkCommunityFetchConnections is refactored linkCommunityFetchConnections.enabled = true
// linkCommunityFetchConnections.enabled = true
return return
} }
if (data.communityId) { if (data.communityId) {
@ -221,7 +220,7 @@ Column {
Component { Component {
id: invitationBubble id: invitationBubble
InvitationBubbleView { InvitationBubbleView {
// store: root.store store: root.store
communityId: linkData.communityId communityId: linkData.communityId
isLink: true isLink: true
anchors.left: parent.left anchors.left: parent.left

View File

@ -17,6 +17,7 @@ Column {
anchors.right: !isCurrentUser ? undefined : parent.right anchors.right: !isCurrentUser ? undefined : parent.right
z: (typeof chatLogView === "undefined") ? 1 : (chatLogView.count - index) z: (typeof chatLogView === "undefined") ? 1 : (chatLogView.count - index)
property var store
property var messageStore property var messageStore
property var usersStore property var usersStore
property var contactsStore property var contactsStore
@ -342,6 +343,7 @@ Column {
id: compactMessageComponent id: compactMessageComponent
CompactMessageView { CompactMessageView {
store: root.store
messageStore: root.messageStore messageStore: root.messageStore
usersStore: root.usersStore usersStore: root.usersStore
contactsStore: root.contactsStore contactsStore: root.contactsStore

View File

@ -379,132 +379,6 @@ QtObject {
return (/( |\t|\n|\r)/.test(c)) return (/( |\t|\n|\r)/.test(c))
} }
function getLinkTitleAndCb(link) {
const result = {
title: "Status",
callback: null
}
// Link to send a direct message
let index = link.indexOf("/u/")
if (index === -1) {
// Try /p/ as well
index = link.indexOf("/p/")
}
if (index > -1) {
const pk = link.substring(index + 3)
//% "Start a 1-on-1 chat with %1"
result.title = qsTrId("start-a-1-on-1-chat-with--1")
.arg(isChatKey(pk) ? globalUtils.generateAlias(pk) : ("@" + removeStatusEns(pk)))
result.callback = function () {
if(isChatKey(pk)){
// TODO refector those to call a store (somehow)
let chatCommunitySectionModule = mainModule.getChatSectionModule()
chatCommunitySectionModule.createOneToOneChat(pk, "")
} else {
// Not Refactored Yet
// chatsModel.channelView.joinWithENS(pk);
}
}
return result
}
// Community
index = link.lastIndexOf("/c/")
if (index > -1) {
const communityId = link.substring(index + 3)
// Not Refactored Yet
const communityName = "" //chatsModel.communities.getCommunityNameById(communityId)
if (!communityName) {
// Not Refactored Yet
// Unknown community, fetch the info if possible
// chatsModel.communities.requestCommunityInfo(communityId)
result.communityId = communityId
result.fetching = true
return result
}
//% "Join the %1 community"
result.title = qsTrId("join-the--1-community").arg(communityName)
result.communityId = communityId
result.callback = function () {
// Not Refactored Yet
const isUserMemberOfCommunity = ""//chatsModel.communities.isUserMemberOfCommunity(communityId)
if (isUserMemberOfCommunity) {
// Not Refactored Yet
// chatsModel.communities.setActiveCommunity(communityId)
return
}
// Not Refactored Yet
const userCanJoin = "" //chatsModel.communities.userCanJoin(communityId)
// TODO find what to do when you can't join
if (userCanJoin) {
// Not Refactored Yet
// chatsModel.communities.joinCommunity(communityId, true)
}
}
return result
}
// Group chat
index = link.lastIndexOf("/g/")
if (index > -1) {
let indexAdminPk = link.lastIndexOf("a=")
let indexChatName = link.lastIndexOf("a1=")
let indexChatId = link.lastIndexOf("a2=")
const pubKey = link.substring(indexAdminPk + 2, indexChatName - 1)
const chatName = link.substring(indexChatName + 3, indexChatId - 1)
const chatId = link.substring(indexChatId + 3, link.length)
//% "Join the %1 group chat"
result.title = qsTrId("join-the--1-group-chat").arg(chatName)
result.callback = function () {
// Not Refactored Yet
// chatsModel.groups.joinGroupChatFromInvitation(chatName, chatId, pubKey);
}
return result
}
// Not Refactored Yet (when we get to this we will most likely remove it, since other approach will be used)
// // Public chat
// // This needs to be the last check because it is as VERY loose check
// index = link.lastIndexOf("/")
// if (index > -1) {
// const chatId = link.substring(index + 1)
// //% "Join the %1 public channel"
// result.title = qsTrId("join-the--1-public-channel").arg(chatId)
// result.callback = function () {
// chatsModel.channelView.joinPublicChat(chatId);
// }
// return result
// }
return result
}
function getLinkDataForStatusLinks(link) {
if (!link.includes(Constants.deepLinkPrefix) && !link.includes(Constants.joinStatusLink)) {
return
}
const result = getLinkTitleAndCb(link)
return {
site: "https://join.status.im",
title: result.title,
communityId: result.communityId,
fetching: result.fetching,
thumbnailUrl: Style.png("status"),
contentType: "",
height: 0,
width: 0,
callback: result.callback
}
}
function getTick(wordCount) { function getTick(wordCount) {
return (wordCount === 12 || wordCount === 15 || return (wordCount === 12 || wordCount === 15 ||
wordCount === 18 || wordCount === 21 || wordCount === 24) wordCount === 18 || wordCount === 21 || wordCount === 24)

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit 62a0439234c76388e6992647b5599d65ff0b0e24 Subproject commit ece535aaf7795fc54ade844d9703ce7a2ab71819