mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Removed Pill Avatar + @room is not displayed among suggestions for DM (#1968)
* removed pill avatar * completion suggestion service shows @room as first and only if not a DM * code improvement
This commit is contained in:
@@ -20,11 +20,8 @@ import Foundation
|
||||
@MainActor
|
||||
final class PillContext: ObservableObject {
|
||||
struct PillViewState: Equatable {
|
||||
let contentID: String
|
||||
let isOwnMention: Bool
|
||||
let name: String?
|
||||
let displayText: String
|
||||
let avatarURL: URL?
|
||||
}
|
||||
|
||||
@Published private(set) var viewState: PillViewState
|
||||
@@ -36,23 +33,29 @@ final class PillContext: ObservableObject {
|
||||
case let .user(id):
|
||||
let isOwnMention = id == roomContext.viewState.ownUserID
|
||||
if let profile = roomContext.viewState.members[id] {
|
||||
let name = profile.displayName ?? id
|
||||
viewState = PillViewState(contentID: id, isOwnMention: isOwnMention, name: name, displayText: name, avatarURL: profile.avatarURL)
|
||||
var name = id
|
||||
if let displayName = profile.displayName {
|
||||
name = "@\(displayName)"
|
||||
}
|
||||
viewState = PillViewState(isOwnMention: isOwnMention, displayText: name)
|
||||
} else {
|
||||
viewState = PillViewState(contentID: id, isOwnMention: isOwnMention, name: nil, displayText: id, avatarURL: nil)
|
||||
viewState = PillViewState(isOwnMention: isOwnMention, displayText: id)
|
||||
cancellable = roomContext.$viewState.sink { [weak self] viewState in
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
if let profile = viewState.members[id] {
|
||||
let name = profile.displayName ?? id
|
||||
self.viewState = PillViewState(contentID: id, isOwnMention: isOwnMention, name: name, displayText: name, avatarURL: profile.avatarURL)
|
||||
var name = id
|
||||
if let displayName = profile.displayName {
|
||||
name = "@\(displayName)"
|
||||
}
|
||||
self.viewState = PillViewState(isOwnMention: isOwnMention, displayText: name)
|
||||
cancellable = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
case .allUsers:
|
||||
viewState = PillViewState(contentID: roomContext.viewState.roomID, isOwnMention: true, name: roomContext.viewState.roomTitle, displayText: PillConstants.atRoom, avatarURL: roomContext.viewState.roomAvatarURL)
|
||||
viewState = PillViewState(isOwnMention: true, displayText: PillConstants.atRoom)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -71,16 +74,16 @@ extension PillContext {
|
||||
case .loadUser(let isOwn):
|
||||
pillType = .user(userID: testID)
|
||||
let viewModel = PillContext(roomContext: RoomScreenViewModel.mock.context, data: PillTextAttachmentData(type: pillType, font: .preferredFont(forTextStyle: .body)))
|
||||
viewModel.viewState = PillViewState(contentID: testID, isOwnMention: isOwn, name: nil, displayText: testID, avatarURL: nil)
|
||||
viewModel.viewState = PillViewState(isOwnMention: isOwn, displayText: testID)
|
||||
Task {
|
||||
try? await Task.sleep(for: .seconds(2))
|
||||
viewModel.viewState = PillViewState(contentID: "@test:test.com", isOwnMention: isOwn, name: nil, displayText: "Test Long Display Text", avatarURL: URL.documentsDirectory)
|
||||
viewModel.viewState = PillViewState(isOwnMention: isOwn, displayText: "@Test Long Display Text")
|
||||
}
|
||||
return viewModel
|
||||
case .loadedUser(let isOwn):
|
||||
pillType = .user(userID: "@test:test.com")
|
||||
let viewModel = PillContext(roomContext: RoomScreenViewModel.mock.context, data: PillTextAttachmentData(type: pillType, font: .preferredFont(forTextStyle: .body)))
|
||||
viewModel.viewState = PillViewState(contentID: "@test:test.com", isOwnMention: isOwn, name: nil, displayText: "Very Very Long Test Display Text", avatarURL: URL.documentsDirectory)
|
||||
viewModel.viewState = PillViewState(isOwnMention: isOwn, displayText: "@Very Very Long Test Display Text")
|
||||
return viewModel
|
||||
case .allUsers:
|
||||
pillType = .allUsers
|
||||
|
||||
@@ -31,20 +31,17 @@ struct PillView: View {
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 2) {
|
||||
LoadableAvatarImage(url: context.viewState.avatarURL, name: context.viewState.name, contentID: context.viewState.contentID, avatarSize: .custom(16), imageProvider: imageProvider)
|
||||
Text(context.viewState.displayText)
|
||||
.font(.compound.bodyLGSemibold)
|
||||
.foregroundColor(textColor)
|
||||
.lineLimit(1)
|
||||
}
|
||||
.padding(.leading, 4)
|
||||
.padding(.trailing, 6)
|
||||
.padding(.vertical, 1)
|
||||
.background { Capsule().foregroundColor(backgroundColor) }
|
||||
.onChange(of: context.viewState.displayText) { _ in
|
||||
didChangeText()
|
||||
}
|
||||
Text(context.viewState.displayText)
|
||||
.font(.compound.bodyLGSemibold)
|
||||
.foregroundColor(textColor)
|
||||
.lineLimit(1)
|
||||
.padding(.leading, 4)
|
||||
.padding(.trailing, 6)
|
||||
.padding(.vertical, 1)
|
||||
.background { Capsule().foregroundColor(backgroundColor) }
|
||||
.onChange(of: context.viewState.displayText) { _ in
|
||||
didChangeText()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import Combine
|
||||
import Foundation
|
||||
|
||||
final class CompletionSuggestionService: CompletionSuggestionServiceProtocol {
|
||||
private let roomProxy: RoomProxyProtocol
|
||||
private var canMentionAllUsers = false
|
||||
let areSuggestionsEnabled: Bool
|
||||
private(set) var suggestionsPublisher: AnyPublisher<[SuggestionItem], Never> = Empty().eraseToAnyPublisher()
|
||||
@@ -25,6 +26,7 @@ final class CompletionSuggestionService: CompletionSuggestionServiceProtocol {
|
||||
private let suggestionTriggerSubject = CurrentValueSubject<SuggestionPattern?, Never>(nil)
|
||||
|
||||
init(roomProxy: RoomProxyProtocol, areSuggestionsEnabled: Bool) {
|
||||
self.roomProxy = roomProxy
|
||||
self.areSuggestionsEnabled = areSuggestionsEnabled
|
||||
guard areSuggestionsEnabled else {
|
||||
return
|
||||
@@ -32,7 +34,8 @@ final class CompletionSuggestionService: CompletionSuggestionServiceProtocol {
|
||||
suggestionsPublisher = suggestionTriggerSubject
|
||||
.combineLatest(roomProxy.members)
|
||||
.map { [weak self] suggestionPattern, members -> [SuggestionItem] in
|
||||
guard let suggestionPattern else {
|
||||
guard let self,
|
||||
let suggestionPattern else {
|
||||
return []
|
||||
}
|
||||
|
||||
@@ -47,10 +50,11 @@ final class CompletionSuggestionService: CompletionSuggestionServiceProtocol {
|
||||
}
|
||||
return SuggestionItem.user(item: .init(id: member.userID, displayName: member.displayName, avatarURL: member.avatarURL))
|
||||
}
|
||||
if self?.canMentionAllUsers == true,
|
||||
if self.canMentionAllUsers,
|
||||
!self.roomProxy.isEncryptedOneToOneRoom,
|
||||
Self.isIncluded(searchText: suggestionPattern.text, userID: PillConstants.atRoom, displayName: PillConstants.everyone) {
|
||||
membersSuggestion
|
||||
.append(SuggestionItem.allUsers(item: .allUsersMention(roomAvatar: roomProxy.avatarURL)))
|
||||
.insert(SuggestionItem.allUsers(item: .allUsersMention(roomAvatar: self.roomProxy.avatarURL)), at: 0)
|
||||
}
|
||||
return membersSuggestion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user