-
Notifications
You must be signed in to change notification settings - Fork 24
feat: Chat Bubbles - Show reactions - WPB-19515 #3466
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
base: feature/CB-4-update-sender-name
Are you sure you want to change the base?
Changes from all commits
de95682
3a200ff
29aa52d
9c656d8
ae4d3f3
1d6f1a8
c4bc8ff
b80a285
b21623f
cc83a63
764c189
ee92ba6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// Wire | ||
// Copyright (C) 2025 Wire Swiss GmbH | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see http://www.gnu.org/licenses/. | ||
// | ||
|
||
import Foundation | ||
public import Combine | ||
|
||
public protocol ReactionsObserverProtocol { | ||
var reactionsPublisher: AnyPublisher<ReactionsModel, Never>? { get } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: Same question here. Why is the result optional? |
||
} | ||
|
||
public typealias ReactionsObserverProvider = (MessageModel) -> (any ReactionsObserverProtocol)? |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,22 +16,26 @@ | |
// along with this program. If not, see http://www.gnu.org/licenses/. | ||
// | ||
|
||
import Combine | ||
package import WireMessagingDomain | ||
|
||
// Need to be wrapped to type eraser as @unchecked Sendable to be able to pass to datasource actor | ||
// also performs mapping of domain model which is just raw string | ||
// to UI model which is Attributed string | ||
package struct AnySenderNameObserverProvider: @unchecked Sendable { | ||
package struct AnyObserverProvider: @unchecked Sendable { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Rename
|
||
|
||
private var observerProvider: SenderNameObserverProvider? | ||
package let senderNameObserverProvider: SenderNameObserverProvider? | ||
package let reactionsObserverProvider: ReactionsObserverProvider? | ||
|
||
package init( | ||
_ observerProvider: SenderNameObserverProvider? | ||
senderNameObserverProvider: SenderNameObserverProvider?, | ||
reactionsObserverProvider: ReactionsObserverProvider? | ||
) { | ||
self.observerProvider = observerProvider | ||
self.senderNameObserverProvider = senderNameObserverProvider | ||
self.reactionsObserverProvider = reactionsObserverProvider | ||
} | ||
|
||
func get(for model: UserModel?) -> (any SenderNameObserverProtocol)? { | ||
observerProvider?(model) | ||
func get(for message: MessageModel) -> AnyPublisher<ReactionsModel, Never>? { | ||
reactionsObserverProvider?(message)?.reactionsPublisher | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// Wire | ||
// Copyright (C) 2025 Wire Swiss GmbH | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see http://www.gnu.org/licenses/. | ||
// | ||
|
||
import Combine | ||
import Foundation | ||
import WireMessagingDomain | ||
|
||
class ReactionsViewModel: ObservableObject { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Make final |
||
|
||
package enum State { | ||
case empty | ||
case exists(ReactionsModel) | ||
} | ||
|
||
@Published var state: State | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: This could be |
||
|
||
private var cancellables: Set<AnyCancellable> = [] | ||
|
||
init( | ||
state: State, | ||
publisher: AnyPublisher<ReactionsModel, Never>? | ||
) { | ||
self.state = state | ||
publisher?.sink { [weak self] reactions in | ||
self?.state = Self.state(from: reactions) | ||
}.store(in: &cancellables) | ||
} | ||
|
||
static func state(from reactions: ReactionsModel) -> State { | ||
reactions.hasReactions() ? .exists(reactions) : .empty | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// Wire | ||
// Copyright (C) 2025 Wire Swiss GmbH | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see http://www.gnu.org/licenses/. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct ReactionsView: View { | ||
|
||
@ObservedObject var viewModel: ReactionsViewModel | ||
|
||
var body: some View { | ||
HStack(spacing: 0) { | ||
switch viewModel.state { | ||
case .empty: | ||
EmptyView() | ||
case let .exists(reactions): | ||
Text(reactions.map { "\($0.0): \($0.1.count)" | ||
}.joined(separator: " ")) | ||
.frame(maxWidth: .infinity, alignment: .leading) | ||
.fixedSize(horizontal: false, vertical: true) | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
import WireMessagingDomain | ||
|
||
#Preview { | ||
ReactionsView( | ||
viewModel: .init( | ||
state: .exists( | ||
["😂": [ | ||
UserModel( | ||
objectID: UUID(), | ||
remoteIdentifier: UUID(), | ||
name: "User", | ||
handle: "@handle" | ||
) | ||
]] | ||
), | ||
publisher: nil | ||
) | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: I'm not sure why these are optional but maybe I'm missing something?