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

Knocking feature polishing part 2 #3738

Merged
merged 6 commits into from
Feb 5, 2025
Merged
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
42 changes: 17 additions & 25 deletions ElementX.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

64 changes: 64 additions & 0 deletions ElementX/Sources/Mocks/Generated/GeneratedMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13393,6 +13393,70 @@ class RoomPreviewProxyMock: RoomPreviewProxyProtocol, @unchecked Sendable {
var underlyingOwnMembershipDetails: RoomMembershipDetailsProxyProtocol?
var ownMembershipDetailsClosure: (() async -> RoomMembershipDetailsProxyProtocol?)?

//MARK: - forgetRoom

var forgetRoomUnderlyingCallsCount = 0
var forgetRoomCallsCount: Int {
get {
if Thread.isMainThread {
return forgetRoomUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = forgetRoomUnderlyingCallsCount
}

return returnValue!
}
}
set {
if Thread.isMainThread {
forgetRoomUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
forgetRoomUnderlyingCallsCount = newValue
}
}
}
}
var forgetRoomCalled: Bool {
return forgetRoomCallsCount > 0
}

var forgetRoomUnderlyingReturnValue: Result<Void, RoomProxyError>!
var forgetRoomReturnValue: Result<Void, RoomProxyError>! {
get {
if Thread.isMainThread {
return forgetRoomUnderlyingReturnValue
} else {
var returnValue: Result<Void, RoomProxyError>? = nil
DispatchQueue.main.sync {
returnValue = forgetRoomUnderlyingReturnValue
}

return returnValue!
}
}
set {
if Thread.isMainThread {
forgetRoomUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
forgetRoomUnderlyingReturnValue = newValue
}
}
}
}
var forgetRoomClosure: (() async -> Result<Void, RoomProxyError>)?

func forgetRoom() async -> Result<Void, RoomProxyError> {
forgetRoomCallsCount += 1
if let forgetRoomClosure = forgetRoomClosure {
return await forgetRoomClosure()
} else {
return forgetRoomReturnValue
}
}
}
class RoomProxyMock: RoomProxyProtocol, @unchecked Sendable {
var id: String {
Expand Down
105 changes: 105 additions & 0 deletions ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11429,6 +11429,46 @@ open class RoomSDKMock: MatrixRustSDK.Room, @unchecked Sendable {
enableSendQueueEnableClosure?(enable)
}

//MARK: - forget

open var forgetThrowableError: Error?
var forgetUnderlyingCallsCount = 0
open var forgetCallsCount: Int {
get {
if Thread.isMainThread {
return forgetUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = forgetUnderlyingCallsCount
}

return returnValue!
}
}
set {
if Thread.isMainThread {
forgetUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
forgetUnderlyingCallsCount = newValue
}
}
}
}
open var forgetCalled: Bool {
return forgetCallsCount > 0
}
open var forgetClosure: (() async throws -> Void)?

open override func forget() async throws {
if let error = forgetThrowableError {
throw error
}
forgetCallsCount += 1
try await forgetClosure?()
}

//MARK: - getPowerLevels

open var getPowerLevelsThrowableError: Error?
Expand Down Expand Up @@ -19421,6 +19461,71 @@ open class SyncServiceBuilderSDKMock: MatrixRustSDK.SyncServiceBuilder, @uncheck
}
}

//MARK: - withOfflineMode

var withOfflineModeUnderlyingCallsCount = 0
open var withOfflineModeCallsCount: Int {
get {
if Thread.isMainThread {
return withOfflineModeUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = withOfflineModeUnderlyingCallsCount
}

return returnValue!
}
}
set {
if Thread.isMainThread {
withOfflineModeUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
withOfflineModeUnderlyingCallsCount = newValue
}
}
}
}
open var withOfflineModeCalled: Bool {
return withOfflineModeCallsCount > 0
}

var withOfflineModeUnderlyingReturnValue: SyncServiceBuilder!
open var withOfflineModeReturnValue: SyncServiceBuilder! {
get {
if Thread.isMainThread {
return withOfflineModeUnderlyingReturnValue
} else {
var returnValue: SyncServiceBuilder? = nil
DispatchQueue.main.sync {
returnValue = withOfflineModeUnderlyingReturnValue
}

return returnValue!
}
}
set {
if Thread.isMainThread {
withOfflineModeUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
withOfflineModeUnderlyingReturnValue = newValue
}
}
}
}
open var withOfflineModeClosure: (() -> SyncServiceBuilder)?

open override func withOfflineMode() -> SyncServiceBuilder {
withOfflineModeCallsCount += 1
if let withOfflineModeClosure = withOfflineModeClosure {
return withOfflineModeClosure()
} else {
return withOfflineModeReturnValue
}
}

//MARK: - withUtdHook

var withUtdHookDelegateUnderlyingCallsCount = 0
Expand Down
13 changes: 11 additions & 2 deletions ElementX/Sources/Mocks/RoomPreviewProxyMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ extension RoomPreviewProxyMock {
var roomID = "1"
var canonicalAlias = "#3🌞problem:matrix.org"
var name = "The Three-Body Problem - 三体"
var topic = "“Science and technology were the only keys to opening the door to the future, and people approached science with the faith and sincerity of elementary school students.”"
var topic: String? = "“Science and technology were the only keys to opening the door to the future, and people approached science with the faith and sincerity of elementary school students.”"
var avatarURL = URL.mockMXCAvatar.absoluteString
var numJoinedMembers = UInt64(100)
var numActiveMembers = UInt64(100)
var roomType = RoomType.room
var membership: Membership?
var joinRule: JoinRule
var isDirect = false
}

static var joinable: RoomPreviewProxyMock {
Expand All @@ -42,6 +43,14 @@ extension RoomPreviewProxyMock {
return .init(.init(membership: .invited, joinRule: .invite))
}

static func inviteDM(roomID: String? = nil) -> RoomPreviewProxyMock {
if let roomID {
return .init(.init(roomID: roomID, topic: nil, numJoinedMembers: 1, membership: .invited, joinRule: .invite, isDirect: true))
}

return .init(.init(topic: nil, numJoinedMembers: 1, membership: .invited, joinRule: .invite, isDirect: true))
}

static var knockable: RoomPreviewProxyMock {
.init(.init(membership: nil, joinRule: .knock))
}
Expand Down Expand Up @@ -71,7 +80,7 @@ extension RoomPreviewProxyMock {
isHistoryWorldReadable: nil,
membership: configuration.membership,
joinRule: configuration.joinRule,
isDirect: nil,
isDirect: configuration.isDirect,
heroes: nil))

let roomMembershipDetails = RoomMembershipDetailsProxyMock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,21 @@ enum JoinRoomScreenMode: Equatable {
case joinable
case restricted
case inviteRequired
case invited
case invited(isDM: Bool)
case knockable
case knocked
case banned(sender: String?, reason: String?)
case forbidden
}

struct JoinRoomScreenRoomDetails {
let name: String?
let topic: String?
let canonicalAlias: String?
let avatar: RoomAvatar
let memberCount: Int
let avatar: RoomAvatar?
let memberCount: Int?
let inviter: RoomInviterDetails?
let isDirect: Bool?
}

struct JoinRoomScreenViewState: BindableState {
Expand All @@ -39,28 +41,45 @@ struct JoinRoomScreenViewState: BindableState {
var roomDetails: JoinRoomScreenRoomDetails?

var mode: JoinRoomScreenMode = .loading

var bindings = JoinRoomScreenViewStateBindings()

var title: String {
roomDetails?.name ?? L10n.screenJoinRoomTitleNoPreview
if isDMInvite, let inviter = roomDetails?.inviter {
return inviter.displayName ?? inviter.id
} else {
return roomDetails?.name ?? L10n.screenJoinRoomTitleNoPreview
}
}

var subtitle: String? {
switch mode {
case .loading:
nil
case .unknown:
L10n.screenJoinRoomSubtitleNoPreview
case .knocked:
nil
case .invited(isDM: true):
if let inviter = roomDetails?.inviter {
return inviter.displayName != nil ? inviter.id : nil
}
return nil
case .loading, .unknown, .knocked:
return nil
default:
roomDetails?.canonicalAlias
return roomDetails?.canonicalAlias
}
}

var avatar: RoomAvatar? {
if isDMInvite, let inviter = roomDetails?.inviter {
return .room(id: roomID, name: inviter.displayName, avatarURL: inviter.avatarURL)
} else if let avatar = roomDetails?.avatar {
return avatar
} else if let name = roomDetails?.name {
return .room(id: roomID, name: name, avatarURL: nil)
} else {
return nil
}
}

var avatar: RoomAvatar {
roomDetails?.avatar ?? .room(id: roomID, name: title, avatarURL: nil)
var isDMInvite: Bool {
mode == .invited(isDM: true)
}
}

Expand All @@ -80,4 +99,6 @@ enum JoinRoomScreenViewAction {
case join
case acceptInvite
case declineInvite
case forget
case dismiss
}
Loading
Loading