Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Add a completion block to `LivestreamChannelController.resume()` to observe possible errors [#3774](https://github.com/GetStream/stream-chat-swift/pull/3774)
### 🐞 Fixed
- Fix pending message being added to `LivestreamChannelController.messages` when in paused state [#3774](https://github.com/GetStream/stream-chat-swift/pull/3774)
- Fix `LivestreamChannelController` not connecting chat after coming from background [#3778](https://github.com/GetStream/stream-chat-swift/pull/3778)
### 🔄 Changed
- The `LivestreamChannelController.resume()` should be manually called, previously, it was automatically called on a new message [#3774](https://github.com/GetStream/stream-chat-swift/pull/3774)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,15 @@ public class LivestreamChannelController: DataStoreProvider, EventsControllerDel
loadFirstPage()
}

public func applicationDidMoveToForeground() {
// The livestream controller is not impacted by the syncing of missing events.
// Since it won't get notified about messages updated from the DB.
// So we need to manually reset the channel once the user is connected again.
if client.connectionStatus != .connected {
loadFirstPage()
}
}

// MARK: - Private Methods

private func updateChannelData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class ChatClient_Mock: ChatClient {
mockedAppSettings
}

var mockedEventNotificationCenter: EventNotificationCenter_Mock? = nil
var mockedEventNotificationCenter: EventNotificationCenter_Mock?

override var eventNotificationCenter: EventNotificationCenter {
mockedEventNotificationCenter ?? super.eventNotificationCenter
Expand Down Expand Up @@ -64,7 +64,7 @@ final class ChatClient_Mock: ChatClient {
}

override var currentUserId: UserId? {
return currentUserId_mock
currentUserId_mock
}

public var currentUserId_mock: UserId? {
Expand All @@ -76,6 +76,16 @@ final class ChatClient_Mock: ChatClient {
}
}

public var connectionStatus_mock: ConnectionStatus?
override var connectionStatus: ConnectionStatus {
get {
connectionStatus_mock ?? super.connectionStatus
}
set {
connectionStatus_mock = newValue
}
}

override func createBackgroundWorkers() {
createBackgroundWorkers_called = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,35 @@ extension LivestreamChannelController_Tests {
let expectedEndpoint = Endpoint<ChannelPayload>.updateChannel(query: expectedQuery)
XCTAssertEqual(apiClient.request_endpoint, AnyEndpoint(expectedEndpoint))
}


func test_applicationDidMoveToForeground_whenNotConnected_callsLoadFirstPage() {
// Given
let apiClient = client.mockAPIClient
client.connectionStatus_mock = .disconnected(error: ClientError())

// When
controller.applicationDidMoveToForeground()

// Then
let expectedPagination = MessagesPagination(pageSize: 25, parameter: nil)
var expectedQuery = channelQuery!
expectedQuery.pagination = expectedPagination
let expectedEndpoint = Endpoint<ChannelPayload>.updateChannel(query: expectedQuery)
XCTAssertEqual(apiClient.request_endpoint, AnyEndpoint(expectedEndpoint))
}

func test_applicationDidMoveToForeground_whenConnected_doesNotCallLoadFirstPage() {
// Given
let apiClient = client.mockAPIClient
client.connectionStatus_mock = .connected

// When
controller.applicationDidMoveToForeground()

// Then
XCTAssertNil(apiClient.request_endpoint)
}

func test_didReceiveEvent_messageNewEvent_addsMessageToArray() {
let newMessage = ChatMessage.mock(id: "new", cid: controller.cid!, text: "New message")
let event = MessageNewEvent(
Expand Down
Loading