Skip to content

Instantly share code, notes, and snippets.

extension MessagingDataSource: DataStoreDelegate {
func dataStoreDidReceiveNewMessage(forConversationWith user: UserID) {
delegate?.dataSourceDidUpdate()
}
}
extension MessagingViewController: MessagingDataSourceDelegate {
func dataSourceDidUpdate() {
tableView.reloadData()
scrollToLastMessage()
}
private func scrollToLastMessage() {
let rowCount = tableView.numberOfRows(inSection: 0)
if rowCount > 1 {
func send(_ message: Message) {
guard let data = try? JSONEncoder().encode(message) else {
// Handle error
return
}
webSocket?.write(data: data)
add(message, direction: .sent)
}
extension Notification.Name {
static let userDidLogin = Notification.Name(rawValue: "userDidLogin")
static let userDidLogout = Notification.Name(rawValue: "userDidLogout")
}