Skip to content

Commit

Permalink
feat(requestToJoin): add addressesToShare to requestToJoin call
Browse files Browse the repository at this point in the history
Fixes #11154
  • Loading branch information
jrainville committed Jun 26, 2023
1 parent 04183a6 commit 49684a6
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 53 deletions.
22 changes: 12 additions & 10 deletions src/app/modules/main/chat_section/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ type
tokenService: token_service.Service
collectibleService: collectible_service.Service
communityTokensService: community_tokens_service.Service
tmpRequestToJoinCommunityId: string
tmpAuthenticationForJoinInProgress: bool
tmpRequestToJoinEnsName: string
tmpRequestToJoinAddressesToShare: seq[string]

proc newController*(delegate: io_interface.AccessInterface, sectionId: string, isCommunity: bool, events: EventEmitter,
settingsService: settings_service.Service, nodeConfigurationService: node_configuration_service.Service,
Expand Down Expand Up @@ -74,8 +75,9 @@ proc newController*(delegate: io_interface.AccessInterface, sectionId: string, i
result.tokenService = tokenService
result.collectibleService = collectibleService
result.communityTokensService = communityTokensService
result.tmpRequestToJoinCommunityId = ""
result.tmpAuthenticationForJoinInProgress = false
result.tmpRequestToJoinEnsName = ""
result.tmpRequestToJoinAddressesToShare = @[]

proc delete*(self: Controller) =
self.events.disconnect()
Expand All @@ -90,21 +92,21 @@ proc setIsCurrentSectionActive*(self: Controller, active: bool) =
self.isCurrentSectionActive = active

proc requestToJoinCommunityAuthenticated*(self: Controller, password: string) =
self.communityService.asyncRequestToJoinCommunity(self.tmpRequestToJoinCommunityId, self.tmpRequestToJoinEnsName, password)
self.tmpRequestToJoinCommunityId = ""
self.communityService.asyncRequestToJoinCommunity(self.sectionId, self.tmpRequestToJoinEnsName,
password, self.tmpRequestToJoinAddressesToShare)
self.tmpAuthenticationForJoinInProgress = false
self.tmpRequestToJoinEnsName = ""

proc requestToJoinCommunity*(self: Controller, communityId: string, ensName: string) =
self.communityService.asyncRequestToJoinCommunity(communityId, ensName, "")
self.tmpRequestToJoinAddressesToShare = @[]

proc authenticate*(self: Controller, keyUid = "") =
let data = SharedKeycarModuleAuthenticationArgs(uniqueIdentifier: UNIQUE_MAIN_MODULE_AUTH_IDENTIFIER,
keyUid: keyUid)
self.events.emit(SIGNAL_SHARED_KEYCARD_MODULE_AUTHENTICATE_USER, data)

proc authenticateToRequestToJoinCommunity*(self: Controller, communityId: string, ensName: string) =
self.tmpRequestToJoinCommunityId = communityId
proc authenticateToRequestToJoinCommunity*(self: Controller, ensName: string, addressesToShare: seq[string]) =
self.tmpAuthenticationForJoinInProgress = true
self.tmpRequestToJoinEnsName = ensName
self.tmpRequestToJoinAddressesToShare = addressesToShare
self.authenticate()

proc getMySectionId*(self: Controller): string =
Expand Down Expand Up @@ -192,7 +194,7 @@ proc init*(self: Controller) =
let args = SharedKeycarModuleArgs(e)
if args.uniqueIdentifier != UNIQUE_MAIN_MODULE_AUTH_IDENTIFIER:
return
if self.tmpRequestToJoinCommunityId == self.sectionId:
if self.tmpAuthenticationForJoinInProgress:
self.delegate.onUserAuthenticated(args.pin, args.password, args.keyUid)

if (self.isCommunitySection):
Expand Down
5 changes: 1 addition & 4 deletions src/app/modules/main/chat_section/io_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -385,13 +385,10 @@ method onAcceptRequestToJoinFailedNoPermission*(self: AccessInterface, community
method onUserAuthenticated*(self: AccessInterface, pin: string, password: string, keyUid: string) {.base.} =
raise newException(ValueError, "No implementation available")

method requestToJoinCommunity*(self: AccessInterface, communityId: string, ensName: string) {.base.} =
raise newException(ValueError, "No implementation available")

method onDeactivateChatLoader*(self: AccessInterface, chatId: string) {.base.} =
raise newException(ValueError, "No implementation available")

method requestToJoinCommunityWithAuthentication*(self: AccessInterface, communityId: string, ensName: string) {.base.} =
method requestToJoinCommunityWithAuthentication*(self: AccessInterface, ensName: string, addressesToShare: seq[string]) {.base.} =
raise newException(ValueError, "No implementation available")

method onOwnedcollectiblesUpdated*(self: AccessInterface) {.base.} =
Expand Down
7 changes: 2 additions & 5 deletions src/app/modules/main/chat_section/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1378,11 +1378,8 @@ method createOrEditCommunityTokenPermission*(self: Module, communityId: string,
method deleteCommunityTokenPermission*(self: Module, communityId: string, permissionId: string) =
self.controller.deleteCommunityTokenPermission(communityId, permissionId)

method requestToJoinCommunity*(self: Module, communityId: string, ensName: string) =
self.controller.requestToJoinCommunity(communityId, ensName)

method requestToJoinCommunityWithAuthentication*(self: Module, communityId: string, ensName: string) =
self.controller.authenticateToRequestToJoinCommunity(communityId, ensName)
method requestToJoinCommunityWithAuthentication*(self: Module, ensName: string, addressesToShare: seq[string]) =
self.controller.authenticateToRequestToJoinCommunity(ensName, addressesToShare)

method onDeactivateChatLoader*(self: Module, chatId: string) =
self.view.chatsModel().disableChatLoader(chatId)
Expand Down
15 changes: 10 additions & 5 deletions src/app/modules/main/chat_section/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,16 @@ QtObject:
proc createGroupChat*(self: View, communityID: string, groupName: string, pubKeys: string) {.slot.} =
self.delegate.createGroupChat(communityID, groupName, pubKeys)

proc requestToJoinCommunity*(self: View, communityId: string, ensName: string) {.slot.} =
self.delegate.requestToJoinCommunity(communityId, ensName)

proc requestToJoinCommunityWithAuthentication*(self: View, communityId: string, ensName: string) {.slot.} =
self.delegate.requestToJoinCommunityWithAuthentication(communityId, ensName)
proc requestToJoinCommunityWithAuthentication*(self: View, ensName: string) {.slot.} =
self.delegate.requestToJoinCommunityWithAuthentication(ensName, @[])

proc requestToJoinCommunityWithAuthenticationWithSharedAddresses*(self: View, ensName: string,
addressesToShare: string) {.slot.} =
try:
let addressesArray = map(parseJson(addressesToShare).getElems(), proc(x:JsonNode):string = x.getStr())
self.delegate.requestToJoinCommunityWithAuthentication(ensName, addressesArray)
except Exception as e:
echo "Error requesting to join community with authetication and shared addresses: ", e.msg

proc joinGroupChatFromInvitation*(self: View, groupName: string, chatId: string, adminPK: string) {.slot.} =
self.delegate.joinGroupChatFromInvitation(groupName, chatId, adminPK)
Expand Down
3 changes: 0 additions & 3 deletions src/app/modules/main/communities/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,6 @@ proc spectateCommunity*(self: Controller, communityId: string): string =
proc cancelRequestToJoinCommunity*(self: Controller, communityId: string) =
self.communityService.cancelRequestToJoinCommunity(communityId)

proc requestToJoinCommunity*(self: Controller, communityId: string, ensName: string) =
self.communityService.asyncRequestToJoinCommunity(communityId, ensName, password="")

proc createCommunity*(
self: Controller,
name: string,
Expand Down
3 changes: 0 additions & 3 deletions src/app/modules/main/communities/io_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ method isCommunityRequestPending*(self: AccessInterface, communityId: string): b
method cancelRequestToJoinCommunity*(self: AccessInterface, communityId: string) {.base.} =
raise newException(ValueError, "No implementation available")

method requestToJoinCommunity*(self: AccessInterface, communityId: string, ensName: string) {.base.} =
raise newException(ValueError, "No implementation available")

method requestCommunityInfo*(self: AccessInterface, communityId: string, importing: bool) {.base.} =
raise newException(ValueError, "No implementation available")

Expand Down
3 changes: 0 additions & 3 deletions src/app/modules/main/communities/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,6 @@ method discordCategoriesAndChannelsExtracted*(self: Module, categories: seq[Disc
method cancelRequestToJoinCommunity*(self: Module, communityId: string) =
self.controller.cancelRequestToJoinCommunity(communityId)

method requestToJoinCommunity*(self: Module, communityId: string, ensName: string) =
self.controller.requestToJoinCommunity(communityId, ensName)

method requestCommunityInfo*(self: Module, communityId: string, importing: bool) =
self.controller.requestCommunityInfo(communityId, importing)

Expand Down
3 changes: 0 additions & 3 deletions src/app/modules/main/communities/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,6 @@ QtObject:
proc cancelRequestToJoinCommunity*(self: View, communityId: string) {.slot.} =
self.delegate.cancelRequestToJoinCommunity(communityId)

proc requestToJoinCommunity*(self: View, communityId: string, ensName: string) {.slot.} =
self.delegate.requestToJoinCommunity(communityId, ensName)

proc requestCommunityInfo*(self: View, communityId: string, importing: bool) {.slot.} =
self.delegate.requestCommunityInfo(communityId, importing)

Expand Down
3 changes: 2 additions & 1 deletion src/app_service/service/community/async_tasks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ type
communityId: string
ensName: string
password: string
addressesToShare: seq[string]

const asyncRequestToJoinCommunityTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
let arg = decode[AsyncRequestToJoinCommunityTaskArg](argEncoded)
try:
let response = status_go.requestToJoinCommunity(arg.communityId, arg.ensName, arg.password)
let response = status_go.requestToJoinCommunity(arg.communityId, arg.ensName, arg.password, arg.addressesToShare)
arg.finish(%* {
"response": response,
"communityId": arg.communityId,
Expand Down
7 changes: 4 additions & 3 deletions src/app_service/service/community/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1461,15 +1461,17 @@ QtObject:
let errMsg = e.msg
error "error checking all channels permissions: ", errMsg

proc asyncRequestToJoinCommunity*(self: Service, communityId: string, ensName: string, password: string) =
proc asyncRequestToJoinCommunity*(self: Service, communityId: string, ensName: string, password: string,
addressesToShare: seq[string]) =
try:
let arg = AsyncRequestToJoinCommunityTaskArg(
tptr: cast[ByteAddress](asyncRequestToJoinCommunityTask),
vptr: cast[ByteAddress](self.vptr),
slot: "onAsyncRequestToJoinCommunityDone",
communityId: communityId,
ensName: ensName,
password: password
password: password,
addressesToShare: addressesToShare,
)
self.threadpool.start(arg)
except Exception as e:
Expand All @@ -1483,7 +1485,6 @@ QtObject:
error "Error requesting community info", msg = error.message
return

let communityId = rpcResponseObj{"communityId"}.getStr()
let rpcResponse = Json.decode($rpcResponseObj["response"], RpcResponse[JsonNode])
self.activityCenterService.parseActivityCenterResponse(rpcResponse)

Expand Down
10 changes: 8 additions & 2 deletions src/backend/communities.nim
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,18 @@ proc getAllCommunities*(): RpcResponse[JsonNode] {.raises: [Exception].} =
proc spectateCommunity*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("spectateCommunity".prefix, %*[communityId])

proc requestToJoinCommunity*(communityId: string, ensName: string, password: string): RpcResponse[JsonNode] {.raises: [Exception].} =
proc requestToJoinCommunity*(
communityId: string,
ensName: string,
password: string,
addressesToShare: seq[string],
): RpcResponse[JsonNode] {.raises: [Exception].} =
var passwordToSend = password
result = callPrivateRPC("requestToJoinCommunity".prefix, %*[{
"communityId": communityId,
"ensName": ensName,
"password": if passwordToSend != "": utils.hashPassword(password) else: ""
"password": if passwordToSend != "": utils.hashPassword(password) else: "",
"addressesToShare": addressesToShare,
}])

proc checkPermissionsToJoinCommunity*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
Expand Down
2 changes: 1 addition & 1 deletion ui/app/AppLayouts/Chat/ChatLayout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ StackLayout {
property string communityId

onJoined: {
root.rootStore.requestToJoinCommunityWithAuthentication(communityIntroDialog.communityId, root.rootStore.userProfileInst.name)
root.rootStore.requestToJoinCommunityWithAuthentication(root.rootStore.userProfileInst.name)
}

onCancelMembershipRequest: {
Expand Down
10 changes: 3 additions & 7 deletions ui/app/AppLayouts/Chat/stores/RootStore.qml
Original file line number Diff line number Diff line change
Expand Up @@ -376,12 +376,8 @@ QtObject {
return communitiesModuleInst.spectateCommunity(id, ensName)
}

function requestToJoinCommunity(id, ensName) {
chatCommunitySectionModule.requestToJoinCommunity(id, ensName)
}

function requestToJoinCommunityWithAuthentication(id, ensName) {
chatCommunitySectionModule.requestToJoinCommunityWithAuthentication(id, ensName)
function requestToJoinCommunityWithAuthentication(ensName) {
chatCommunitySectionModule.requestToJoinCommunityWithAuthentication(ensName)
}

function userCanJoin(id) {
Expand Down Expand Up @@ -477,7 +473,7 @@ QtObject {
const userCanJoin = userCanJoin(result.communityId)
// TODO find what to do when you can't join
if (userCanJoin) {
requestToJoinCommunity(result.communityId, userProfileInst.preferredName)
requestToJoinCommunityWithAuthentication(userProfileInst.preferredName)
}
}
return result
Expand Down
2 changes: 1 addition & 1 deletion ui/app/AppLayouts/Chat/views/CommunityColumnView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Item {

onJoined: {
joinCommunityButton.loading = true
root.store.requestToJoinCommunityWithAuthentication(communityData.id, root.store.userProfileInst.name)
root.store.requestToJoinCommunityWithAuthentication(root.store.userProfileInst.name)
}
onCancelMembershipRequest: {
root.store.cancelPendingRequest(communityData.id)
Expand Down
2 changes: 1 addition & 1 deletion ui/app/AppLayouts/Profile/views/CommunitiesView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ SettingsContentBase {
}

onJoined: {
chatCommunitySectionModule.requestToJoinCommunityWithAuthentication(communityIntroDialog.communityId, root.rootStore.userProfileInst.name)
chatCommunitySectionModule.requestToJoinCommunityWithAuthentication(root.rootStore.userProfileInst.name)
}

onCancelMembershipRequest: {
Expand Down

0 comments on commit 49684a6

Please sign in to comment.