Files
letro-ios/ElementX/Sources/Other/Extensions/Publisher.swift
Alfonso Grillo 8aca9ba85b Add user search for dm chats (#739)
* Add searchUsers in ClientProxy

* Add UserSearchProtocol

* Delete UserSearch file

* Add search

* Refine StartChatScreen

* Improve StartChatViewModel

* Add localizations

* Fix no result style

* Update localizations

* Add UTs

* Add UI tests

* Cleanup

* Refine tests

* Add changelog.d file

* Naming refactor

* Refactor ClientProxyProtocol api

* Fix typo

* Add mark

* Rename tests

* Update Dangerfile

* Improve UI test code

* Refactor search api

* Improve style

* Improve combine chain

* Add comment

* Improve StartChatScreen

* Improve updateState

* Add extension Published.Publisher

* Improve UI tests

* Remove Combine import

* Cleanup

* Remove “proxy” wording

* Delete extra extensions

* Refactor Publisher api
2023-03-29 14:29:25 +02:00

40 lines
1.4 KiB
Swift

//
// Copyright 2023 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 Combine
extension Publisher where Self.Failure == Never {
func weakAssign<Root: AnyObject>(to keyPath: ReferenceWritableKeyPath<Root, Self.Output>, on object: Root) -> AnyCancellable {
sink { [weak object] value in
object?[keyPath: keyPath] = value
}
}
}
extension Published.Publisher {
/// Returns the next output from the publisher skipping the current value stored into it (which is readable from the @Published property itself).
/// - Returns: the next output from the publisher
var nextValue: Output? {
get async {
var iterator = values.makeAsyncIterator()
// skips the publisher's current value
_ = await iterator.next()
return await iterator.next()
}
}
}