Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix space-members access type to be set upon creation #7741

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// Copyright 2024 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation
import MatrixSDK

struct MXSpaceCreationParametersFactory {
private let creationParams: SpaceCreationParameters
private let parentSpaceId: String?
private let stateEventBuilder: MXRoomInitialStateEventBuilder
private let homeServers: [String]

init(creationParams: SpaceCreationParameters, parentSpaceId: String?, stateEventBuilder: MXRoomInitialStateEventBuilder, homeServers: [String]) {
self.creationParams = creationParams
self.parentSpaceId = parentSpaceId
self.stateEventBuilder = stateEventBuilder
self.homeServers = homeServers
}

func make() -> MXSpaceCreationParameters {
var alias = creationParams.address
if let userDefinedAlias = creationParams.userDefinedAddress, !userDefinedAlias.isEmpty {
alias = userDefinedAlias
}
let userIdInvites = creationParams.inviteType == .userId ? creationParams.userIdInvites : []
let isPublic = creationParams.isPublic

let parameters = MXSpaceCreationParameters()
parameters.name = creationParams.name
parameters.topic = creationParams.topic
parameters.preset = isPublic ? kMXRoomPresetPublicChat : kMXRoomPresetPrivateChat
parameters.visibility = isPublic ? kMXRoomDirectoryVisibilityPublic : kMXRoomDirectoryVisibilityPrivate
parameters.inviteArray = userIdInvites

if isPublic {
parameters.roomAlias = alias
let guestAccessStateEvent = stateEventBuilder.buildGuestAccessEvent(withAccess: .canJoin)
parameters.addOrUpdateInitialStateEvent(guestAccessStateEvent)
let historyVisibilityStateEvent = stateEventBuilder.buildHistoryVisibilityEvent(withVisibility: .worldReadable)
parameters.addOrUpdateInitialStateEvent(historyVisibilityStateEvent)
parameters.powerLevelContentOverride?.invite = 0 // default
} else {
parameters.powerLevelContentOverride?.invite = 50 // moderator

if let parentSpaceId = parentSpaceId, creationParams.isShared {
let guestAccessStateEvent = stateEventBuilder.buildJoinRuleEvent(withJoinRule: .restricted, allowedParentsList: [parentSpaceId])
parameters.addOrUpdateInitialStateEvent(guestAccessStateEvent)
}
}

return parameters
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,8 @@ class SpaceCreationPostProcessService: SpaceCreationPostProcessServiceProtocol {
private func createSpace(andUpdate task: SpaceCreationPostProcessTask) {
updateCurrentTask(with: .started)

var alias = creationParams.address
if let userDefinedAlias = creationParams.userDefinedAddress, !userDefinedAlias.isEmpty {
alias = userDefinedAlias
}
let userIdInvites = creationParams.inviteType == .userId ? creationParams.userIdInvites : []
session.spaceService.createSpace(withName: creationParams.name, topic: creationParams.topic, isPublic: creationParams.isPublic, aliasLocalPart: alias, inviteArray: userIdInvites) { [weak self] response in
let parameters = makeSpaceCreationParameters()
session.spaceService.createSpace(with: parameters) { [weak self] response in
guard let self = self else { return }

if response.isFailure {
Expand All @@ -189,6 +185,12 @@ class SpaceCreationPostProcessService: SpaceCreationPostProcessServiceProtocol {
}
}

private func makeSpaceCreationParameters() -> MXSpaceCreationParameters {
let homeserverWellknown = session.credentials.homeServerName() ?? ""
let spaceCreationParametersFactory = MXSpaceCreationParametersFactory(creationParams: creationParams, parentSpaceId: parentSpaceId, stateEventBuilder: stateEventBuilder, homeServers: [homeserverWellknown])
return spaceCreationParametersFactory.make()
}

private func uploadAvatar(andUpdate task: SpaceCreationPostProcessTask) {
updateCurrentTask(with: .started)

Expand Down
1 change: 1 addition & 0 deletions changelog.d/7741.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Create space: if the `space-members` access type is selected, it will be set upon creation.