More tweaks for User Status. (#6051)

* Make sure user profiles are up to date when mentioning.

* Automatically focus the custom status text field.

* Make sure to clear the previous custom status text before input.

* Attempt to fix the user status sheet sometimes disappearing.
This commit is contained in:
Doug
2026-08-21 11:23:33 +01:00
committed by GitHub
parent dd84da15b0
commit 0d222e8ac0
4 changed files with 80 additions and 9 deletions
@@ -6,12 +6,13 @@
// Please see LICENSE files in the repository root for full details.
//
import Combine
@testable import ElementX
import Testing
@MainActor
struct CompletionSuggestionServiceTests {
// MARK: User Suggestions
@Test
func userSuggestions() async throws {
let alice: RoomMemberProxyMock = .mockAlice
@@ -178,6 +179,40 @@ struct CompletionSuggestionServiceTests {
try await deffered.fulfill()
}
@Test
func userSuggestionRefreshesMembers() async throws {
let members: [RoomMemberProxyMock] = [.mockAlice, .mockBob, .mockMe]
let roomProxyMock = JoinedRoomProxyMock(.init(id: "roomID", name: "test", members: members))
let roomSummaryProvider = RoomSummaryProviderMock(.init(state: .loaded(.mockRooms)))
let (refreshesStream, refreshesContinuation) = AsyncStream<Void>.makeStream()
roomProxyMock.updateMembersClosure = { refreshesContinuation.yield() }
let service = CompletionSuggestionService(roomProxy: roomProxyMock,
roomListPublisher: roomSummaryProvider.roomListPublisher.eraseToAnyPublisher())
#expect(!roomProxyMock.updateMembersCalled)
// Beginning a mention refreshes the members once…
var deferred = deferFulfillment(refreshesStream) { _ in true }
service.setSuggestionTrigger(.init(type: .user, text: "", range: .init()))
try await deferred.fulfill()
#expect(roomProxyMock.updateMembersCallsCount == 1)
// …but typing further within the same mention doesn't refresh again.
service.setSuggestionTrigger(.init(type: .user, text: "a", range: .init()))
service.setSuggestionTrigger(.init(type: .user, text: "al", range: .init()))
#expect(roomProxyMock.updateMembersCallsCount == 1)
// Clearing and starting a new mention refreshes a second time.
deferred = deferFulfillment(refreshesStream) { _ in true }
service.setSuggestionTrigger(nil)
service.setSuggestionTrigger(.init(type: .user, text: "", range: .init()))
try await deferred.fulfill()
#expect(roomProxyMock.updateMembersCallsCount == 2)
}
// MARK: Room Suggestions
@Test
func roomSuggestions() async throws {
let alice: RoomMemberProxyMock = .mockAlice
@@ -353,6 +388,8 @@ struct CompletionSuggestionServiceTests {
try await deffered.fulfill()
}
// MARK: Common
@Test
func suggestionsWithMultipleDifferentTriggers() async throws {
let alice: RoomMemberProxyMock = .mockAlice