Skip to content
This repository was archived by the owner on Sep 19, 2023. It is now read-only.
Open
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
6 changes: 6 additions & 0 deletions Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
window!.rootViewController = nav
}

func logout() {
let keychain = Keychain(service: "com.voicely.voicely")
try? keychain.remove("token")
showLoginScreen()
}

private func isLoggedIn() -> Bool {
let keychain = Keychain(service: "com.voicely.voicely")
guard let _ = keychain[string: "token"] else {
Expand Down
20 changes: 20 additions & 0 deletions Sources/RoomListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ class RoomListViewController: UIViewController {
let item = UIBarButtonItem(title: "@" + UserDefaults.standard.string(forKey: "username")!, style: .plain, target: self, action: #selector(openProfile))
item.tintColor = .black
navigationItem.leftBarButtonItem = item

let rightItem = UIBarButtonItem(title: "Menu", style: .plain, target: self, action: #selector(openMenu))
item.tintColor = .black
navigationItem.rightBarButtonItem = rightItem
}

@objc private func openProfile() {
Expand All @@ -73,6 +77,22 @@ class RoomListViewController: UIViewController {
navigationController?.pushViewController(profile, animated: true)
}

@objc private func openMenu() {
let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)

let logout = UIAlertAction(title: "Logout", style: .destructive, handler: { _ in
DispatchQueue.main.async {
(UIApplication.shared.delegate as! AppDelegate).logout()
}
})
optionMenu.addAction(logout)

let cancel = UIAlertAction(title: NSLocalizedString("cancel", comment: ""), style: .cancel)
optionMenu.addAction(cancel)

present(optionMenu, animated: true)
}

@objc private func didPullToRefresh() {
loadData()
}
Expand Down