Skip to content

Commit

Permalink
UI fixes.
Browse files Browse the repository at this point in the history
1. After sending the app with MessageVC on top into background,
   upon wakeup the app wouldn't connect and display new messages.
2. In ChatListVC the app wouldn't display latest messages.
  • Loading branch information
aforge committed Nov 11, 2022
1 parent 8d779a5 commit 644f4b7
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Tinodios/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
}
DispatchQueue.global(qos: .userInitiated).async {
if !SharedUtils.connectAndLoginSync(using: tinode, inBackground: false) {
UiUtils.logoutAndRouteToLoginVC()
DispatchQueue.main.async { UiUtils.showToast(message: "Failed to connect to server") }
} else {
UiUtils.routeToMessageVC(forTopic: topicName)
}
Expand Down
9 changes: 6 additions & 3 deletions Tinodios/ChatListInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,23 @@ class ChatListInteractor: ChatListBusinessLogic, ChatListDataStore {
super.init(connected: connected)
self.interactor = interactor
}
func onLogin(code: Int, text: String) {
override func onLogin(code: Int, text: String) {
super.onLogin(code: code, text: text)
self.interactor?.attachToMeTopic()
}
override func onDisconnect(byServer: Bool, code: URLSessionWebSocketTask.CloseCode, reason: String) {
super.onDisconnect(byServer: byServer, code: code, reason: reason)
// Update presence indicators (all should be off).
self.interactor?.loadAndPresentTopics()
}
func onDataMessage(data: MsgServerData?) {
override func onDataMessage(data: MsgServerData?) {
super.onDataMessage(data: data)
if let topic = data?.topic {
interactor?.updateChat(topic)
}
}
func onInfoMessage(info: MsgServerInfo?) {
override func onInfoMessage(info: MsgServerInfo?) {
super.onInfoMessage(info: info)
if info?.what != "call", let topic = info?.src {
interactor?.updateChat(topic)
}
Expand Down
4 changes: 3 additions & 1 deletion Tinodios/MessageInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ class MessageInteractor: DefaultComTopic.Listener, MessageBusinessLogic, Message
super.init(connected: connected)
self.interactor = interactor
}
func onLogin(code: Int, text: String) {

override func onLogin(code: Int, text: String) {
super.onLogin(code: code, text: text)
_ = UiUtils.attachToMeTopic(meListener: nil)
_ = interactor?.attachToTopic(interactively: false)
}
Expand Down
1 change: 1 addition & 0 deletions Tinodios/MessageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ class MessageViewController: UIViewController {
func appBecameActive() {
self.interactor?.setup(topicName: topicName, sendReadReceipts: self.sendReadReceipts)
self.interactor?.attachToTopic(interactively: true)
self.interactor?.loadMessagesFromCache(scrollToMostRecentMessage: false)
}
@objc
func appGoingInactive() {
Expand Down
12 changes: 12 additions & 0 deletions Tinodios/UiUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ class UiTinodeEventListener: TinodeEventListener {
init(connected: Bool) {
self.connected = connected
}

// Empty handlers. Otherwise, methods of subclasses of UiTinodeEventListener
// won't be called.
func onLogin(code: Int, text: String) {}
func onMessage(msg: ServerMessage?) {}
func onRawMessage(msg: String) {}
func onCtrlMessage(ctrl: MsgServerCtrl?) {}
func onDataMessage(data: MsgServerData?) {}
func onInfoMessage(info: MsgServerInfo?) {}
func onMetaMessage(meta: MsgServerMeta?) {}
func onPresMessage(pres: MsgServerPres?) {}

func onConnect(code: Int, reason: String, params: [String: JSONValue]?) {
connected = true
}
Expand Down

0 comments on commit 644f4b7

Please sign in to comment.