mirror of
https://github.com/status-im/status-desktop.git
synced 2025-02-16 16:47:24 +00:00
parent
bee583d448
commit
16e7d16c8c
@ -133,7 +133,8 @@ proc newAppController*(statusFoundation: StatusFoundation): AppController =
|
||||
statusFoundation.events, statusFoundation.threadpool, result.settingsService
|
||||
)
|
||||
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.contactsService)
|
||||
result.activityCenterService = activity_center_service.newService(statusFoundation.events,
|
||||
|
@ -36,6 +36,10 @@ method init*(self: Controller) =
|
||||
let args = CommunityArgs(e)
|
||||
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):
|
||||
let args = CommunityArgs(e)
|
||||
if(args.error.len > 0):
|
||||
@ -117,3 +121,12 @@ method setCommunityMuted*(self: Controller, communityId: string, muted: bool) =
|
||||
method getContactNameAndImage*(self: Controller, contactId: string):
|
||||
tuple[name: string, image: string, isIdenticon: bool] =
|
||||
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)
|
@ -37,6 +37,15 @@ method deleteCommunityCategory*(self: AccessInterface, communityId: string, cate
|
||||
method requestCommunityInfo*(self: AccessInterface, communityId: string) {.base.} =
|
||||
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.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
|
@ -105,6 +105,7 @@ method joinCommunity*(self: Module, communityId: string): string =
|
||||
|
||||
method communityEdited*(self: Module, community: CommunityDto) =
|
||||
self.view.model().editItem(self.getCommunityItem(community))
|
||||
self.view.communityChanged(community.id)
|
||||
|
||||
method requestAdded*(self: Module) =
|
||||
# TODO to model or view
|
||||
@ -163,6 +164,15 @@ method requestToJoinCommunity*(self: Module, communityId: string, ensName: strin
|
||||
method requestCommunityInfo*(self: Module, communityId: string) =
|
||||
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) =
|
||||
self.controller.deleteCommunityChat(communityId, channelId)
|
||||
|
||||
|
@ -37,6 +37,15 @@ method removeUserFromCommunity*(self: AccessInterface, communityId: string, pubK
|
||||
method banUserFromCommunity*(self: AccessInterface, pubKey: string, communityId: string) {.base.} =
|
||||
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.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
|
@ -30,8 +30,12 @@ QtObject:
|
||||
proc load*(self: View) =
|
||||
self.delegate.viewDidLoad()
|
||||
|
||||
proc communityAdded*(self: View, communityId: string) {.signal.}
|
||||
proc communityChanged*(self: View, communityId: string) {.signal.}
|
||||
|
||||
proc addItem*(self: View, item: SectionItem) =
|
||||
self.model.addItem(item)
|
||||
self.communityAdded(item.id)
|
||||
|
||||
proc model*(self: View): SectionModel =
|
||||
result = self.model
|
||||
@ -61,9 +65,6 @@ QtObject:
|
||||
proc joinCommunity*(self: View, communityId: string): string {.slot.} =
|
||||
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,
|
||||
access: int, ensOnly: bool, color: string,
|
||||
imagePath: string,
|
||||
@ -91,6 +92,15 @@ QtObject:
|
||||
proc requestCommunityInfo*(self: View, communityId: string) {.slot.} =
|
||||
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.} =
|
||||
self.delegate.deleteCommunityChat(communityId, channelId)
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
import NimQml, Tables, strutils, strformat
|
||||
|
||||
import section_item
|
||||
import json, json_serialization
|
||||
|
||||
import section_item, user_model
|
||||
|
||||
type
|
||||
ModelRole {.pure.} = enum
|
||||
@ -267,3 +269,34 @@ QtObject:
|
||||
self.items[i].notificationsCount = notificationsCount
|
||||
self.dataChanged(index, index, @[ModelRole.HasNotification.int, ModelRole.NotificationsCount.int])
|
||||
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
|
@ -41,7 +41,7 @@ QtObject:
|
||||
result &= fmt"""User Model:
|
||||
[{i}]:({$self.items[i]})
|
||||
"""
|
||||
proc getCount(self: Model): int {.slot.} =
|
||||
proc getCount*(self: Model): int {.slot.} =
|
||||
self.items.len
|
||||
QtProperty[int] count:
|
||||
read = getCount
|
||||
|
12
src/app_service/service/community/async_tasks.nim
Normal file
12
src/app_service/service/community/async_tasks.nim
Normal 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)
|
@ -7,8 +7,12 @@ import ../chat/service as chat_service
|
||||
import ../../../app/global/global_singleton
|
||||
import ../../../app/core/signals/types
|
||||
import ../../../app/core/eventemitter
|
||||
import ../../../app/core/[main]
|
||||
import ../../../app/core/tasks/[qt, threadpool]
|
||||
import ../../../backend/communities as status_go
|
||||
|
||||
include ./async_tasks
|
||||
|
||||
export community_dto
|
||||
|
||||
logScope:
|
||||
@ -63,6 +67,7 @@ const SIGNAL_COMMUNITY_MY_REQUEST_ADDED* = "communityMyRequestAdded"
|
||||
const SIGNAL_COMMUNITY_LEFT* = "communityLeft"
|
||||
const SIGNAL_COMMUNITY_CREATED* = "communityCreated"
|
||||
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_COMMUNITIES_UPDATE* = "communityUpdated"
|
||||
const SIGNAL_COMMUNITY_CHANNEL_CREATED* = "communityChannelCreated"
|
||||
@ -77,6 +82,7 @@ const SIGNAL_COMMUNITY_MEMBER_APPROVED* = "communityMemberApproved"
|
||||
QtObject:
|
||||
type
|
||||
Service* = ref object of QObject
|
||||
threadpool: ThreadPool
|
||||
events: EventEmitter
|
||||
chatService: chat_service.Service
|
||||
joinedCommunities: Table[string, CommunityDto] # [community_id, CommunityDto]
|
||||
@ -93,15 +99,25 @@ QtObject:
|
||||
proc delete*(self: Service) =
|
||||
discard
|
||||
|
||||
proc newService*(events: EventEmitter, chatService: chat_service.Service): Service =
|
||||
proc newService*(
|
||||
events: EventEmitter,
|
||||
threadpool: ThreadPool,
|
||||
chatService: chat_service.Service
|
||||
): Service =
|
||||
result = Service()
|
||||
result.events = events
|
||||
result.threadpool = threadpool
|
||||
result.chatService = chatService
|
||||
result.joinedCommunities = initTable[string, CommunityDto]()
|
||||
result.allCommunities = initTable[string, CommunityDto]()
|
||||
result.myCommunityRequests = @[]
|
||||
|
||||
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):
|
||||
var receivedData = MessageSignal(e)
|
||||
|
||||
@ -156,9 +172,7 @@ QtObject:
|
||||
|
||||
proc handleCommunityUpdates(self: Service, communities: seq[CommunityDto], updatedChats: seq[ChatDto]) =
|
||||
let community = communities[0]
|
||||
var sortingOrderChanged = false
|
||||
if(not self.joinedCommunities.hasKey(community.id)):
|
||||
error "error: community doesn't exist"
|
||||
return
|
||||
|
||||
let prev_community = self.joinedCommunities[community.id]
|
||||
@ -676,16 +690,28 @@ QtObject:
|
||||
except Exception as e:
|
||||
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) =
|
||||
try:
|
||||
let response = status_go.requestCommunityInfo(communityId)
|
||||
if (response.error != nil):
|
||||
let error = Json.decode($response.error, RpcError)
|
||||
raise newException(RpcException, fmt"Error requesting community info: {error.message}")
|
||||
self.asyncActivityNotificationLoad(communityId)
|
||||
except Exception as e:
|
||||
error "Error requesting community info", msg = e.msg, communityId
|
||||
|
||||
|
||||
proc importCommunity*(self: Service, communityKey: string) =
|
||||
try:
|
||||
let response = status_go.importCommunity(communityKey)
|
||||
@ -814,3 +840,9 @@ QtObject:
|
||||
discard status_go.setCommunityMuted(communityId, muted)
|
||||
except Exception as e:
|
||||
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
|
@ -205,7 +205,7 @@ proc deleteCommunityCategory*(
|
||||
}])
|
||||
|
||||
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].} =
|
||||
result = callPrivateRPC("importCommunity".prefix, %*[communityKey])
|
||||
|
@ -110,6 +110,7 @@ ModalPopup {
|
||||
|
||||
MessageView {
|
||||
id: messageItem
|
||||
store: popup.store
|
||||
messageStore: popup.messageStore
|
||||
messageContextMenu: msgContextMenu
|
||||
|
||||
|
@ -58,15 +58,6 @@ QtObject {
|
||||
|
||||
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 mainModuleInst: mainModule
|
||||
@ -211,11 +202,157 @@ QtObject {
|
||||
chatCommunitySectionModule.removeCommunityChat(chatId)
|
||||
}
|
||||
|
||||
function reorderCommunityCategories(categoryId, to){
|
||||
function reorderCommunityCategories(categoryId, to) {
|
||||
chatCommunitySectionModule.reorderCommunityCategories(categoryId, to)
|
||||
}
|
||||
|
||||
function reorderCommunityChat(categoryId, chatId, to){
|
||||
function 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -111,6 +111,7 @@ Item {
|
||||
MessageView {
|
||||
id: notificationMessage
|
||||
anchors.right: undefined
|
||||
store: root.store
|
||||
messageStore: root.store.messageStore
|
||||
messageId: model.id
|
||||
senderDisplayName: model.message.senderDisplayName
|
||||
|
@ -296,6 +296,7 @@ Item {
|
||||
delegate: MessageView {
|
||||
id: msgDelegate
|
||||
|
||||
store: root.store
|
||||
messageStore: root.messageStore
|
||||
usersStore: root.usersStore
|
||||
contactsStore: root.contactsStore
|
||||
|
@ -14,6 +14,7 @@ import StatusQ.Controls 0.1 as StatusQControls
|
||||
Item {
|
||||
id: root
|
||||
|
||||
property var store
|
||||
property var messageStore
|
||||
property var usersStore
|
||||
property var contactsStore
|
||||
@ -594,6 +595,7 @@ Item {
|
||||
linkUrls: root.linkUrls
|
||||
container: root.container
|
||||
messageStore: root.messageStore
|
||||
store: root.store
|
||||
isCurrentUser: isCurrentUser
|
||||
}
|
||||
}
|
||||
|
@ -23,37 +23,32 @@ Item {
|
||||
property var store
|
||||
|
||||
function getCommunity() {
|
||||
// Not Refactored Yet
|
||||
// try {
|
||||
// const communityJson = root.store.chatsModelInst.communities.list.getCommunityByIdJson(communityId)
|
||||
// if (!communityJson) {
|
||||
// return null
|
||||
// }
|
||||
try {
|
||||
const communityJson = root.store.getSectionByIdJson(communityId)
|
||||
if (!communityJson) {
|
||||
return null
|
||||
}
|
||||
|
||||
// let community = JSON.parse(communityJson);
|
||||
// if (community) {
|
||||
// community.nbMembers = community.members.length;
|
||||
// }
|
||||
// return community
|
||||
// } catch (e) {
|
||||
// console.error("Error parsing community", e)
|
||||
// }
|
||||
return JSON.parse(communityJson);
|
||||
} catch (e) {
|
||||
console.error("Error parsing community", e)
|
||||
}
|
||||
|
||||
return null
|
||||
return null
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
root.invitedCommunity = getCommunity()
|
||||
}
|
||||
|
||||
// Connections {
|
||||
// target: root.store.chatsModelInst.communities
|
||||
// onCommunityChanged: function (communityId) {
|
||||
// if (communityId === root.communityId) {
|
||||
// root.invitedCommunity = getCommunity()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
Connections {
|
||||
target: root.store.communitiesModuleInst
|
||||
onCommunityChanged: function (communityId) {
|
||||
if (communityId === root.communityId) {
|
||||
root.invitedCommunity = getCommunity()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: confirmationPopupComponent
|
||||
@ -89,8 +84,7 @@ Item {
|
||||
Rectangle {
|
||||
id: rectangleBubble
|
||||
property alias button: joinBtn
|
||||
// Not Refactored Yet
|
||||
property bool isPendingRequest: false //root.store.chatsModelInst.communities.isCommunityRequestPending(communityId)
|
||||
property bool isPendingRequest: root.store.isCommunityRequestPending(communityId)
|
||||
width: 270
|
||||
height: title.height + title.anchors.topMargin +
|
||||
invitedYou.height + invitedYou.anchors.topMargin +
|
||||
@ -108,8 +102,7 @@ Item {
|
||||
states: [
|
||||
State {
|
||||
name: "requiresEns"
|
||||
// Not Refactored Yet
|
||||
// when: invitedCommunity.ensOnly && !root.store.profileModelInst.profile.ensVerified
|
||||
when: invitedCommunity.ensOnly && !userProfile.ensName
|
||||
PropertyChanges {
|
||||
target: joinBtn
|
||||
//% "Membership requires an ENS username"
|
||||
@ -152,7 +145,7 @@ Item {
|
||||
State {
|
||||
name: "requestToJoin"
|
||||
when: invitedCommunity.access === Constants.communityChatOnRequestAccess &&
|
||||
// !invitedCommunity.joined && !invitedCommunity.isMember
|
||||
!invitedCommunity.joined && !invitedCommunity.isMember &&
|
||||
invitedCommunity.canRequestAccess
|
||||
PropertyChanges {
|
||||
target: joinBtn
|
||||
@ -272,7 +265,7 @@ Item {
|
||||
id: communityNbMembers
|
||||
// TODO add the plural support
|
||||
//% "%1 members"
|
||||
text: qsTrId("-1-members").arg(invitedCommunity.members.count)
|
||||
text: qsTrId("-1-members").arg(invitedCommunity.nbMembers)
|
||||
anchors.top: communityDesc.bottom
|
||||
anchors.topMargin: 2
|
||||
anchors.left: parent.left
|
||||
@ -304,34 +297,33 @@ Item {
|
||||
//% "Unsupported state"
|
||||
text: qsTrId("unsupported-state")
|
||||
onClicked: {
|
||||
// Not Refactored Yet
|
||||
// let onBtnClick = function(){
|
||||
// let error
|
||||
let onBtnClick = function(){
|
||||
let error
|
||||
|
||||
// if (rectangleBubble.state === "joined") {
|
||||
// root.store.chatsModelInst.communities.setActiveCommunity(communityId);
|
||||
// return
|
||||
// } else if (rectangleBubble.state === "unjoined") {
|
||||
// error = root.store.chatsModelInst.communities.joinCommunity(communityId, true)
|
||||
// }
|
||||
// else if (rectangleBubble.state === "requestToJoin") {
|
||||
// error = root.store.chatsModelInst.communities.requestToJoinCommunity(communityId, userProfile.name)
|
||||
// if (!error) {
|
||||
// rectangleBubble.isPendingRequest = root.store.chatsModelInst.communities.isCommunityRequestPending(communityId)
|
||||
// }
|
||||
// }
|
||||
if (rectangleBubble.state === "joined") {
|
||||
root.store.setActiveCommunity(communityId);
|
||||
return
|
||||
} else if (rectangleBubble.state === "unjoined") {
|
||||
error = root.store.joinCommunity(communityId)
|
||||
}
|
||||
else if (rectangleBubble.state === "requestToJoin") {
|
||||
error = root.store.requestToJoinCommunity(communityId, userProfile.name)
|
||||
if (!error) {
|
||||
rectangleBubble.isPendingRequest = root.store.isCommunityRequestPending(communityId)
|
||||
}
|
||||
}
|
||||
|
||||
// if (error) {
|
||||
// joiningError.text = error
|
||||
// return joiningError.open()
|
||||
// }
|
||||
// }
|
||||
if (error) {
|
||||
joiningError.text = error
|
||||
return joiningError.open()
|
||||
}
|
||||
}
|
||||
|
||||
// if (localAccountSensitiveSettings.communitiesEnabled) {
|
||||
// onBtnClick();
|
||||
// } else {
|
||||
// Global.openPopup(confirmationPopupComponent, { onConfirmed: onBtnClick });
|
||||
// }
|
||||
if (localAccountSensitiveSettings.communitiesEnabled) {
|
||||
onBtnClick();
|
||||
} else {
|
||||
Global.openPopup(confirmationPopupComponent, { onConfirmed: onBtnClick });
|
||||
}
|
||||
}
|
||||
|
||||
MessageDialog {
|
||||
|
@ -16,6 +16,7 @@ import shared.controls.chat 1.0
|
||||
|
||||
Column {
|
||||
id: root
|
||||
property var store
|
||||
property var messageStore
|
||||
property var container
|
||||
property string linkUrls: ""
|
||||
@ -98,27 +99,26 @@ Column {
|
||||
}
|
||||
}
|
||||
|
||||
// Not Refactored Yet
|
||||
// Connections {
|
||||
// id: linkCommunityFetchConnections
|
||||
// enabled: false
|
||||
// target: root.store.chatsModelInst.communities
|
||||
// onCommunityAdded: {
|
||||
// if (communityId !== linkData.communityId) {
|
||||
// return
|
||||
// }
|
||||
// linkCommunityFetchConnections.enabled = false
|
||||
// const data = Utils.getLinkDataForStatusLinks(link)
|
||||
// if (data) {
|
||||
// linkData = data
|
||||
// if (!data.fetching && data.communityId) {
|
||||
// return linkMessageLoader.sourceComponent = invitationBubble
|
||||
// }
|
||||
Connections {
|
||||
id: linkCommunityFetchConnections
|
||||
enabled: false
|
||||
target: root.store.communitiesModuleInst
|
||||
onCommunityAdded: {
|
||||
if (communityId !== linkData.communityId) {
|
||||
return
|
||||
}
|
||||
linkCommunityFetchConnections.enabled = false
|
||||
const data = root.store.getLinkDataForStatusLinks(link)
|
||||
if (data) {
|
||||
linkData = data
|
||||
if (!data.fetching && data.communityId) {
|
||||
return linkMessageLoader.sourceComponent = invitationBubble
|
||||
}
|
||||
|
||||
// return linkMessageLoader.sourceComponent = unfurledLinkComponent
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
return linkMessageLoader.sourceComponent = unfurledLinkComponent
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getSourceComponent() {
|
||||
// Reset the height in case we set it to 0 below. See note below
|
||||
@ -165,12 +165,11 @@ Column {
|
||||
}
|
||||
fetched = true
|
||||
|
||||
const data = Utils.getLinkDataForStatusLinks(link)
|
||||
const data = root.store.getLinkDataForStatusLinks(link)
|
||||
if (data) {
|
||||
linkData = data
|
||||
if (data.fetching && data.communityId) {
|
||||
// TODO uncomment when linkCommunityFetchConnections is refactored
|
||||
// linkCommunityFetchConnections.enabled = true
|
||||
linkCommunityFetchConnections.enabled = true
|
||||
return
|
||||
}
|
||||
if (data.communityId) {
|
||||
@ -221,7 +220,7 @@ Column {
|
||||
Component {
|
||||
id: invitationBubble
|
||||
InvitationBubbleView {
|
||||
// store: root.store
|
||||
store: root.store
|
||||
communityId: linkData.communityId
|
||||
isLink: true
|
||||
anchors.left: parent.left
|
||||
|
@ -17,6 +17,7 @@ Column {
|
||||
anchors.right: !isCurrentUser ? undefined : parent.right
|
||||
z: (typeof chatLogView === "undefined") ? 1 : (chatLogView.count - index)
|
||||
|
||||
property var store
|
||||
property var messageStore
|
||||
property var usersStore
|
||||
property var contactsStore
|
||||
@ -342,6 +343,7 @@ Column {
|
||||
id: compactMessageComponent
|
||||
|
||||
CompactMessageView {
|
||||
store: root.store
|
||||
messageStore: root.messageStore
|
||||
usersStore: root.usersStore
|
||||
contactsStore: root.contactsStore
|
||||
|
@ -379,132 +379,6 @@ QtObject {
|
||||
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) {
|
||||
return (wordCount === 12 || wordCount === 15 ||
|
||||
wordCount === 18 || wordCount === 21 || wordCount === 24)
|
||||
|
2
vendor/status-go
vendored
2
vendor/status-go
vendored
@ -1 +1 @@
|
||||
Subproject commit 62a0439234c76388e6992647b5599d65ff0b0e24
|
||||
Subproject commit ece535aaf7795fc54ade844d9703ce7a2ab71819
|
Loading…
x
Reference in New Issue
Block a user