This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension MessagingDataSource: DataStoreDelegate { | |
| func dataStoreDidReceiveNewMessage(forConversationWith user: UserID) { | |
| delegate?.dataSourceDidUpdate() | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension MessagingViewController: MessagingDataSourceDelegate { | |
| func dataSourceDidUpdate() { | |
| tableView.reloadData() | |
| scrollToLastMessage() | |
| } | |
| private func scrollToLastMessage() { | |
| let rowCount = tableView.numberOfRows(inSection: 0) | |
| if rowCount > 1 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func send(_ message: Message) { | |
| guard let data = try? JSONEncoder().encode(message) else { | |
| // Handle error | |
| return | |
| } | |
| webSocket?.write(data: data) | |
| add(message, direction: .sent) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension Notification.Name { | |
| static let userDidLogin = Notification.Name(rawValue: "userDidLogin") | |
| static let userDidLogout = Notification.Name(rawValue: "userDidLogout") | |
| } |
OlderNewer