Pin/Unpin Logic (#3084)

This commit is contained in:
Mauro
2024-07-26 20:41:00 +02:00
committed by GitHub
parent 5a4d21ab7a
commit 0da2d4917b
24 changed files with 659 additions and 69 deletions
@@ -8251,6 +8251,23 @@ class RoomProxyMock: RoomProxyProtocol {
}
var underlyingIsFavourite: Bool!
var isFavouriteClosure: (() async -> Bool)?
var pinnedEventIDsCallsCount = 0
var pinnedEventIDsCalled: Bool {
return pinnedEventIDsCallsCount > 0
}
var pinnedEventIDs: [String] {
get async {
pinnedEventIDsCallsCount += 1
if let pinnedEventIDsClosure = pinnedEventIDsClosure {
return await pinnedEventIDsClosure()
} else {
return underlyingPinnedEventIDs
}
}
}
var underlyingPinnedEventIDs: [String]!
var pinnedEventIDsClosure: (() async -> [String])?
var membership: Membership {
get { return underlyingMembership }
set(value) { underlyingMembership = value }
@@ -10406,6 +10423,76 @@ class RoomProxyMock: RoomProxyProtocol {
return canUserTriggerRoomNotificationUserIDReturnValue
}
}
//MARK: - canUserPinOrUnpin
var canUserPinOrUnpinUserIDUnderlyingCallsCount = 0
var canUserPinOrUnpinUserIDCallsCount: Int {
get {
if Thread.isMainThread {
return canUserPinOrUnpinUserIDUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = canUserPinOrUnpinUserIDUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
canUserPinOrUnpinUserIDUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
canUserPinOrUnpinUserIDUnderlyingCallsCount = newValue
}
}
}
}
var canUserPinOrUnpinUserIDCalled: Bool {
return canUserPinOrUnpinUserIDCallsCount > 0
}
var canUserPinOrUnpinUserIDReceivedUserID: String?
var canUserPinOrUnpinUserIDReceivedInvocations: [String] = []
var canUserPinOrUnpinUserIDUnderlyingReturnValue: Result<Bool, RoomProxyError>!
var canUserPinOrUnpinUserIDReturnValue: Result<Bool, RoomProxyError>! {
get {
if Thread.isMainThread {
return canUserPinOrUnpinUserIDUnderlyingReturnValue
} else {
var returnValue: Result<Bool, RoomProxyError>? = nil
DispatchQueue.main.sync {
returnValue = canUserPinOrUnpinUserIDUnderlyingReturnValue
}
return returnValue!
}
}
set {
if Thread.isMainThread {
canUserPinOrUnpinUserIDUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
canUserPinOrUnpinUserIDUnderlyingReturnValue = newValue
}
}
}
}
var canUserPinOrUnpinUserIDClosure: ((String) async -> Result<Bool, RoomProxyError>)?
func canUserPinOrUnpin(userID: String) async -> Result<Bool, RoomProxyError> {
canUserPinOrUnpinUserIDCallsCount += 1
canUserPinOrUnpinUserIDReceivedUserID = userID
DispatchQueue.main.async {
self.canUserPinOrUnpinUserIDReceivedInvocations.append(userID)
}
if let canUserPinOrUnpinUserIDClosure = canUserPinOrUnpinUserIDClosure {
return await canUserPinOrUnpinUserIDClosure(userID)
} else {
return canUserPinOrUnpinUserIDReturnValue
}
}
//MARK: - kickUser
var kickUserUnderlyingCallsCount = 0
@@ -12527,6 +12614,146 @@ class TimelineProxyMock: TimelineProxyProtocol {
return redactReasonReturnValue
}
}
//MARK: - pin
var pinEventIDUnderlyingCallsCount = 0
var pinEventIDCallsCount: Int {
get {
if Thread.isMainThread {
return pinEventIDUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = pinEventIDUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
pinEventIDUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
pinEventIDUnderlyingCallsCount = newValue
}
}
}
}
var pinEventIDCalled: Bool {
return pinEventIDCallsCount > 0
}
var pinEventIDReceivedEventID: String?
var pinEventIDReceivedInvocations: [String] = []
var pinEventIDUnderlyingReturnValue: Result<Bool, TimelineProxyError>!
var pinEventIDReturnValue: Result<Bool, TimelineProxyError>! {
get {
if Thread.isMainThread {
return pinEventIDUnderlyingReturnValue
} else {
var returnValue: Result<Bool, TimelineProxyError>? = nil
DispatchQueue.main.sync {
returnValue = pinEventIDUnderlyingReturnValue
}
return returnValue!
}
}
set {
if Thread.isMainThread {
pinEventIDUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
pinEventIDUnderlyingReturnValue = newValue
}
}
}
}
var pinEventIDClosure: ((String) async -> Result<Bool, TimelineProxyError>)?
func pin(eventID: String) async -> Result<Bool, TimelineProxyError> {
pinEventIDCallsCount += 1
pinEventIDReceivedEventID = eventID
DispatchQueue.main.async {
self.pinEventIDReceivedInvocations.append(eventID)
}
if let pinEventIDClosure = pinEventIDClosure {
return await pinEventIDClosure(eventID)
} else {
return pinEventIDReturnValue
}
}
//MARK: - unpin
var unpinEventIDUnderlyingCallsCount = 0
var unpinEventIDCallsCount: Int {
get {
if Thread.isMainThread {
return unpinEventIDUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = unpinEventIDUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
unpinEventIDUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
unpinEventIDUnderlyingCallsCount = newValue
}
}
}
}
var unpinEventIDCalled: Bool {
return unpinEventIDCallsCount > 0
}
var unpinEventIDReceivedEventID: String?
var unpinEventIDReceivedInvocations: [String] = []
var unpinEventIDUnderlyingReturnValue: Result<Bool, TimelineProxyError>!
var unpinEventIDReturnValue: Result<Bool, TimelineProxyError>! {
get {
if Thread.isMainThread {
return unpinEventIDUnderlyingReturnValue
} else {
var returnValue: Result<Bool, TimelineProxyError>? = nil
DispatchQueue.main.sync {
returnValue = unpinEventIDUnderlyingReturnValue
}
return returnValue!
}
}
set {
if Thread.isMainThread {
unpinEventIDUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
unpinEventIDUnderlyingReturnValue = newValue
}
}
}
}
var unpinEventIDClosure: ((String) async -> Result<Bool, TimelineProxyError>)?
func unpin(eventID: String) async -> Result<Bool, TimelineProxyError> {
unpinEventIDCallsCount += 1
unpinEventIDReceivedEventID = eventID
DispatchQueue.main.async {
self.unpinEventIDReceivedInvocations.append(eventID)
}
if let unpinEventIDClosure = unpinEventIDClosure {
return await unpinEventIDClosure(eventID)
} else {
return unpinEventIDReturnValue
}
}
//MARK: - sendAudio
var sendAudioUrlAudioInfoProgressSubjectRequestHandleUnderlyingCallsCount = 0
@@ -10243,6 +10243,81 @@ open class RoomSDKMock: MatrixRustSDK.Room {
}
}
//MARK: - canUserPinUnpin
open var canUserPinUnpinUserIdThrowableError: Error?
var canUserPinUnpinUserIdUnderlyingCallsCount = 0
open var canUserPinUnpinUserIdCallsCount: Int {
get {
if Thread.isMainThread {
return canUserPinUnpinUserIdUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = canUserPinUnpinUserIdUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
canUserPinUnpinUserIdUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
canUserPinUnpinUserIdUnderlyingCallsCount = newValue
}
}
}
}
open var canUserPinUnpinUserIdCalled: Bool {
return canUserPinUnpinUserIdCallsCount > 0
}
open var canUserPinUnpinUserIdReceivedUserId: String?
open var canUserPinUnpinUserIdReceivedInvocations: [String] = []
var canUserPinUnpinUserIdUnderlyingReturnValue: Bool!
open var canUserPinUnpinUserIdReturnValue: Bool! {
get {
if Thread.isMainThread {
return canUserPinUnpinUserIdUnderlyingReturnValue
} else {
var returnValue: Bool? = nil
DispatchQueue.main.sync {
returnValue = canUserPinUnpinUserIdUnderlyingReturnValue
}
return returnValue!
}
}
set {
if Thread.isMainThread {
canUserPinUnpinUserIdUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
canUserPinUnpinUserIdUnderlyingReturnValue = newValue
}
}
}
}
open var canUserPinUnpinUserIdClosure: ((String) async throws -> Bool)?
open override func canUserPinUnpin(userId: String) async throws -> Bool {
if let error = canUserPinUnpinUserIdThrowableError {
throw error
}
canUserPinUnpinUserIdCallsCount += 1
canUserPinUnpinUserIdReceivedUserId = userId
DispatchQueue.main.async {
self.canUserPinUnpinUserIdReceivedInvocations.append(userId)
}
if let canUserPinUnpinUserIdClosure = canUserPinUnpinUserIdClosure {
return try await canUserPinUnpinUserIdClosure(userId)
} else {
return canUserPinUnpinUserIdReturnValue
}
}
//MARK: - canUserRedactOther
open var canUserRedactOtherUserIdThrowableError: Error?
@@ -18491,6 +18566,81 @@ open class TimelineSDKMock: MatrixRustSDK.Timeline {
}
}
//MARK: - pinEvent
open var pinEventEventIdThrowableError: Error?
var pinEventEventIdUnderlyingCallsCount = 0
open var pinEventEventIdCallsCount: Int {
get {
if Thread.isMainThread {
return pinEventEventIdUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = pinEventEventIdUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
pinEventEventIdUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
pinEventEventIdUnderlyingCallsCount = newValue
}
}
}
}
open var pinEventEventIdCalled: Bool {
return pinEventEventIdCallsCount > 0
}
open var pinEventEventIdReceivedEventId: String?
open var pinEventEventIdReceivedInvocations: [String] = []
var pinEventEventIdUnderlyingReturnValue: Bool!
open var pinEventEventIdReturnValue: Bool! {
get {
if Thread.isMainThread {
return pinEventEventIdUnderlyingReturnValue
} else {
var returnValue: Bool? = nil
DispatchQueue.main.sync {
returnValue = pinEventEventIdUnderlyingReturnValue
}
return returnValue!
}
}
set {
if Thread.isMainThread {
pinEventEventIdUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
pinEventEventIdUnderlyingReturnValue = newValue
}
}
}
}
open var pinEventEventIdClosure: ((String) async throws -> Bool)?
open override func pinEvent(eventId: String) async throws -> Bool {
if let error = pinEventEventIdThrowableError {
throw error
}
pinEventEventIdCallsCount += 1
pinEventEventIdReceivedEventId = eventId
DispatchQueue.main.async {
self.pinEventEventIdReceivedInvocations.append(eventId)
}
if let pinEventEventIdClosure = pinEventEventIdClosure {
return try await pinEventEventIdClosure(eventId)
} else {
return pinEventEventIdReturnValue
}
}
//MARK: - redactEvent
open var redactEventItemReasonThrowableError: Error?
@@ -19338,6 +19488,81 @@ open class TimelineSDKMock: MatrixRustSDK.Timeline {
}
try await toggleReactionEventIdKeyClosure?(eventId, key)
}
//MARK: - unpinEvent
open var unpinEventEventIdThrowableError: Error?
var unpinEventEventIdUnderlyingCallsCount = 0
open var unpinEventEventIdCallsCount: Int {
get {
if Thread.isMainThread {
return unpinEventEventIdUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = unpinEventEventIdUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
unpinEventEventIdUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
unpinEventEventIdUnderlyingCallsCount = newValue
}
}
}
}
open var unpinEventEventIdCalled: Bool {
return unpinEventEventIdCallsCount > 0
}
open var unpinEventEventIdReceivedEventId: String?
open var unpinEventEventIdReceivedInvocations: [String] = []
var unpinEventEventIdUnderlyingReturnValue: Bool!
open var unpinEventEventIdReturnValue: Bool! {
get {
if Thread.isMainThread {
return unpinEventEventIdUnderlyingReturnValue
} else {
var returnValue: Bool? = nil
DispatchQueue.main.sync {
returnValue = unpinEventEventIdUnderlyingReturnValue
}
return returnValue!
}
}
set {
if Thread.isMainThread {
unpinEventEventIdUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
unpinEventEventIdUnderlyingReturnValue = newValue
}
}
}
}
open var unpinEventEventIdClosure: ((String) async throws -> Bool)?
open override func unpinEvent(eventId: String) async throws -> Bool {
if let error = unpinEventEventIdThrowableError {
throw error
}
unpinEventEventIdCallsCount += 1
unpinEventEventIdReceivedEventId = eventId
DispatchQueue.main.async {
self.unpinEventEventIdReceivedInvocations.append(eventId)
}
if let unpinEventEventIdClosure = unpinEventEventIdClosure {
return try await unpinEventEventIdClosure(eventId)
} else {
return unpinEventEventIdReturnValue
}
}
}
open class TimelineDiffSDKMock: MatrixRustSDK.TimelineDiff {
init() {
@@ -29,6 +29,7 @@ struct RoomProxyMockConfiguration {
var isEncrypted = true
var hasOngoingCall = true
var canonicalAlias: String?
var pinnedEventIDs: [String] = []
var timelineStartReached = false
@@ -63,6 +64,8 @@ extension RoomProxyMock {
hasOngoingCall = configuration.hasOngoingCall
canonicalAlias = configuration.canonicalAlias
underlyingPinnedEventIDs = configuration.pinnedEventIDs
let timeline = TimelineProxyMock()
timeline.sendMessageEventContentReturnValue = .success(())
timeline.paginateBackwardsRequestSizeReturnValue = .success(())