From beb7a8b82808442e6ba6a0c9da8683bf92c81998 Mon Sep 17 00:00:00 2001 From: ShuMatsuki Date: Wed, 15 Jul 2020 17:14:58 +0900 Subject: [PATCH 1/6] =?UTF-8?q?SelectChat=E7=94=BB=E9=9D=A2=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MainTabBar/MainTabBarViewController.swift | 9 +-- .../Views/SelectChat/SelectChatBuilder.swift | 17 ++++ .../SelectChat/SelectChatTableViewCell.swift | 28 +++++++ .../SelectChat/SelectChatTableViewCell.xib | 78 +++++++++++++++++++ .../SelectChat/SelectChatViewController.swift | 48 ++++++++++++ .../Views/Storyboards/SelectChat.storyboard | 42 ++++++++++ 6 files changed, 217 insertions(+), 5 deletions(-) create mode 100644 chat-iOS/Views/SelectChat/SelectChatBuilder.swift create mode 100644 chat-iOS/Views/SelectChat/SelectChatTableViewCell.swift create mode 100644 chat-iOS/Views/SelectChat/SelectChatTableViewCell.xib create mode 100644 chat-iOS/Views/SelectChat/SelectChatViewController.swift create mode 100644 chat-iOS/Views/Storyboards/SelectChat.storyboard diff --git a/chat-iOS/Views/MainTabBar/MainTabBarViewController.swift b/chat-iOS/Views/MainTabBar/MainTabBarViewController.swift index ad3a78c..99936b7 100644 --- a/chat-iOS/Views/MainTabBar/MainTabBarViewController.swift +++ b/chat-iOS/Views/MainTabBar/MainTabBarViewController.swift @@ -21,10 +21,9 @@ final class MainTabBarViewController: UITabBarController { let userProfileVC = UserProfileViewBuilder.create() let userProfileNavigationController = UINavigationController(rootViewController: userProfileVC) - - //TODO:- ここはチャットセレクト画面に遷移すること - let chatsVC = ChatsViewBuilder.create() - let chatsNavigationController = UINavigationController(rootViewController: chatsVC) + + let selectChatVC = SelectChatViewBuilder.create() + let chatsNavigationController = UINavigationController(rootViewController: selectChatVC) //TODO:- iOS12以下の場合の画像を用意すること if #available(iOS 13.0, *) { @@ -35,7 +34,7 @@ final class MainTabBarViewController: UITabBarController { let userProfileTabBarItemSelectedImage = UIImage(systemName: "person.circle.fill") userProfileVC.tabBarItem = UITabBarItem(title: nil, image: userProfileTabBarItemImage, selectedImage: userProfileTabBarItemSelectedImage) - chatsVC.tabBarItem = UITabBarItem(title: nil, image: chatsTabBarItemImage, selectedImage: chatsTabBarItemSelectedImage) + selectChatVC.tabBarItem = UITabBarItem(title: nil, image: chatsTabBarItemImage, selectedImage: chatsTabBarItemSelectedImage) } else { // Fallback on earlier versions } diff --git a/chat-iOS/Views/SelectChat/SelectChatBuilder.swift b/chat-iOS/Views/SelectChat/SelectChatBuilder.swift new file mode 100644 index 0000000..48cdcd8 --- /dev/null +++ b/chat-iOS/Views/SelectChat/SelectChatBuilder.swift @@ -0,0 +1,17 @@ +// +// SelectChatBuilder.swift +// chat-iOS +// +// Created by 松木周 on 2020/07/15. +// + +import UIKit + +struct SelectChatViewBuilder { + static func create() -> UIViewController { + guard let selectChatViewController = SelectChatViewController.loadFromStoryboard() as? SelectChatViewController else { + fatalError("fatal: Failed to initialize the ChatsViewController") + } + return selectChatViewController + } +} diff --git a/chat-iOS/Views/SelectChat/SelectChatTableViewCell.swift b/chat-iOS/Views/SelectChat/SelectChatTableViewCell.swift new file mode 100644 index 0000000..f2d8a35 --- /dev/null +++ b/chat-iOS/Views/SelectChat/SelectChatTableViewCell.swift @@ -0,0 +1,28 @@ +// +// SelectChatTableViewCell.swift +// chat-iOS +// +// Created by 松木周 on 2020/07/15. +// + +import UIKit + +class SelectChatTableViewCell: UITableViewCell { + + @IBOutlet weak var userProfileImageView: UIImageView! + @IBOutlet weak var userNameLabel: UILabel! + @IBOutlet weak var lastMessageLabel: UILabel! + @IBOutlet weak var lastMessageTimeLabel: UILabel! + + override func awakeFromNib() { + super.awakeFromNib() + // Initialization code + } + + override func setSelected(_ selected: Bool, animated: Bool) { + super.setSelected(selected, animated: animated) + + // Configure the view for the selected state + } + +} diff --git a/chat-iOS/Views/SelectChat/SelectChatTableViewCell.xib b/chat-iOS/Views/SelectChat/SelectChatTableViewCell.xib new file mode 100644 index 0000000..876d957 --- /dev/null +++ b/chat-iOS/Views/SelectChat/SelectChatTableViewCell.xib @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/chat-iOS/Views/SelectChat/SelectChatViewController.swift b/chat-iOS/Views/SelectChat/SelectChatViewController.swift new file mode 100644 index 0000000..cc24eb3 --- /dev/null +++ b/chat-iOS/Views/SelectChat/SelectChatViewController.swift @@ -0,0 +1,48 @@ +// +// SelectChatViewController.swift +// chat-iOS +// +// Created by 松木周 on 2020/07/15. +// + +import UIKit + +class SelectChatViewController: UIViewController { + + @IBOutlet weak var selectChatTableView: UITableView! + + private let reuseCellId = "SelectChatTableViewCell" + + override func viewDidLoad() { + super.viewDidLoad() + + setupSelectChatTableView() + } + + func setupSelectChatTableView() { + + self.selectChatTableView.delegate = self + self.selectChatTableView.dataSource = self + self.selectChatTableView.register(UINib(nibName: reuseCellId, bundle: nil), forCellReuseIdentifier: reuseCellId) + self.selectChatTableView.tableFooterView = UIView() + + } + +} + +extension SelectChatViewController: UITableViewDelegate { +} + +extension SelectChatViewController: UITableViewDataSource { + + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return 10 + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: reuseCellId) as! SelectChatTableViewCell + + return cell + } + +} diff --git a/chat-iOS/Views/Storyboards/SelectChat.storyboard b/chat-iOS/Views/Storyboards/SelectChat.storyboard new file mode 100644 index 0000000..8f53afd --- /dev/null +++ b/chat-iOS/Views/Storyboards/SelectChat.storyboard @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 8316d54b6193573b2966fe30eb9bc0dbb22f931e Mon Sep 17 00:00:00 2001 From: ShuMatsuki Date: Wed, 15 Jul 2020 17:34:24 +0900 Subject: [PATCH 2/6] =?UTF-8?q?SelectChat=E7=94=BB=E9=9D=A2=E3=81=AB?= =?UTF-8?q?=E5=AF=BE=E5=BF=9C=E3=81=97=E3=81=9FPresenter=E3=81=A8Model?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Views/SelectChat/SelectChatBuilder.swift | 3 +++ .../Views/SelectChat/SelectChatModel.swift | 20 ++++++++++++++ .../SelectChat/SelectChatViewController.swift | 12 +++++++++ .../SelectChat/SelectChatViewPresenter.swift | 26 +++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 chat-iOS/Views/SelectChat/SelectChatModel.swift create mode 100644 chat-iOS/Views/SelectChat/SelectChatViewPresenter.swift diff --git a/chat-iOS/Views/SelectChat/SelectChatBuilder.swift b/chat-iOS/Views/SelectChat/SelectChatBuilder.swift index 48cdcd8..d517bf4 100644 --- a/chat-iOS/Views/SelectChat/SelectChatBuilder.swift +++ b/chat-iOS/Views/SelectChat/SelectChatBuilder.swift @@ -12,6 +12,9 @@ struct SelectChatViewBuilder { guard let selectChatViewController = SelectChatViewController.loadFromStoryboard() as? SelectChatViewController else { fatalError("fatal: Failed to initialize the ChatsViewController") } + let model = SelectChatModel() + let presenter = SelectChatViewPresenter(model: model) + selectChatViewController.inject(with: presenter) return selectChatViewController } } diff --git a/chat-iOS/Views/SelectChat/SelectChatModel.swift b/chat-iOS/Views/SelectChat/SelectChatModel.swift new file mode 100644 index 0000000..da674b4 --- /dev/null +++ b/chat-iOS/Views/SelectChat/SelectChatModel.swift @@ -0,0 +1,20 @@ +// +// SelectChatModel.swift +// chat-iOS +// +// Created by 松木周 on 2020/07/15. +// + +import Foundation + +protocol SelectChatModelProtocol { + var presenter: SelectChatModelOutput! { get set } +} + +protocol SelectChatModelOutput: class { +} + +final class SelectChatModel: SelectChatModelProtocol { + + weak var presenter: SelectChatModelOutput! +} diff --git a/chat-iOS/Views/SelectChat/SelectChatViewController.swift b/chat-iOS/Views/SelectChat/SelectChatViewController.swift index cc24eb3..d8e9b1f 100644 --- a/chat-iOS/Views/SelectChat/SelectChatViewController.swift +++ b/chat-iOS/Views/SelectChat/SelectChatViewController.swift @@ -12,6 +12,7 @@ class SelectChatViewController: UIViewController { @IBOutlet weak var selectChatTableView: UITableView! private let reuseCellId = "SelectChatTableViewCell" + private var presenter: SelectChatViewPresenterProtocol! override func viewDidLoad() { super.viewDidLoad() @@ -19,6 +20,13 @@ class SelectChatViewController: UIViewController { setupSelectChatTableView() } + func inject(with presenter: SelectChatViewPresenterProtocol) { + + self.presenter = presenter + self.presenter.view = self + + } + func setupSelectChatTableView() { self.selectChatTableView.delegate = self @@ -46,3 +54,7 @@ extension SelectChatViewController: UITableViewDataSource { } } + +extension SelectChatViewController: SelectChatViewPresenterOutput { + +} diff --git a/chat-iOS/Views/SelectChat/SelectChatViewPresenter.swift b/chat-iOS/Views/SelectChat/SelectChatViewPresenter.swift new file mode 100644 index 0000000..32baf70 --- /dev/null +++ b/chat-iOS/Views/SelectChat/SelectChatViewPresenter.swift @@ -0,0 +1,26 @@ +// +// SelectChatViewPresenter.swift +// chat-iOS +// +// Created by 松木周 on 2020/07/15. +// + +import Foundation + +protocol SelectChatViewPresenterProtocol { + var view: SelectChatViewPresenterOutput! { get set } +} + +protocol SelectChatViewPresenterOutput: class { +} + +final class SelectChatViewPresenter: SelectChatViewPresenterProtocol, SelectChatModelOutput { + + weak var view: SelectChatViewPresenterOutput! + private var model: SelectChatModelProtocol + + init(model: SelectChatModelProtocol) { + self.model = model + } + +} From 8342b7102c45dfa23ebc955a5782bcbf38381726 Mon Sep 17 00:00:00 2001 From: ShuMatsuki Date: Thu, 16 Jul 2020 15:44:19 +0900 Subject: [PATCH 3/6] =?UTF-8?q?=E3=83=81=E3=83=A3=E3=83=83=E3=83=88?= =?UTF-8?q?=E4=B8=AD=E3=81=AE=E7=9B=B8=E6=89=8B=E3=82=92=E5=8F=96=E5=BE=97?= =?UTF-8?q?=E3=81=97=E8=A1=A8=E7=A4=BA=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Views/SelectChat/SelectChatModel.swift | 49 ++++++++++++++++++- .../SelectChat/SelectChatTableViewCell.swift | 6 +++ .../SelectChat/SelectChatViewController.swift | 19 ++++++- .../SelectChat/SelectChatViewPresenter.swift | 27 ++++++++++ 4 files changed, 98 insertions(+), 3 deletions(-) diff --git a/chat-iOS/Views/SelectChat/SelectChatModel.swift b/chat-iOS/Views/SelectChat/SelectChatModel.swift index da674b4..b1ef192 100644 --- a/chat-iOS/Views/SelectChat/SelectChatModel.swift +++ b/chat-iOS/Views/SelectChat/SelectChatModel.swift @@ -5,16 +5,63 @@ // Created by 松木周 on 2020/07/15. // -import Foundation +import Firebase protocol SelectChatModelProtocol { var presenter: SelectChatModelOutput! { get set } + func setUpFirestore() + func fetchCurrentChatRoom() } protocol SelectChatModelOutput: class { + func successFetchCurrentChatRooms(currentChatRooms rooms: [Room]) + func onError(error: Error?) } final class SelectChatModel: SelectChatModelProtocol { weak var presenter: SelectChatModelOutput! + private var firestore: Firestore! + private var listener: ListenerRegistration? + + init() { + self.setUpFirestore() + } + + deinit { + listener?.remove() + } + + func setUpFirestore() { + self.firestore = Firestore.firestore() + let settings = FirestoreSettings() + self.firestore.settings = settings + } + + func fetchCurrentChatRoom() { + + guard let curretnUserId = Auth.auth().currentUser?.uid else { return } + + self.listener = self.firestore.collection("rooms").whereField("members", arrayContains: curretnUserId).addSnapshotListener { [weak self] (documentSnapshot, error) in + + if let error = error { + self?.presenter.onError(error: error) + return + } + + guard let documents = documentSnapshot?.documents else { + print("The document doesn't exist.") + return + } + + let rooms = documents.compactMap { queryDocumentSnapshot -> Room? in + return try? queryDocumentSnapshot.data(as: Room.self) + } + + self?.presenter.successFetchCurrentChatRooms(currentChatRooms: rooms) + } + + } + } + diff --git a/chat-iOS/Views/SelectChat/SelectChatTableViewCell.swift b/chat-iOS/Views/SelectChat/SelectChatTableViewCell.swift index f2d8a35..59d05c1 100644 --- a/chat-iOS/Views/SelectChat/SelectChatTableViewCell.swift +++ b/chat-iOS/Views/SelectChat/SelectChatTableViewCell.swift @@ -24,5 +24,11 @@ class SelectChatTableViewCell: UITableViewCell { // Configure the view for the selected state } + + func generateCell(withRoom room: Room) { + userNameLabel.text = room.name + lastMessageLabel.text = room.name + //TODO:- Storageから画像を取得して表示する + } } diff --git a/chat-iOS/Views/SelectChat/SelectChatViewController.swift b/chat-iOS/Views/SelectChat/SelectChatViewController.swift index d8e9b1f..fb0427a 100644 --- a/chat-iOS/Views/SelectChat/SelectChatViewController.swift +++ b/chat-iOS/Views/SelectChat/SelectChatViewController.swift @@ -12,12 +12,14 @@ class SelectChatViewController: UIViewController { @IBOutlet weak var selectChatTableView: UITableView! private let reuseCellId = "SelectChatTableViewCell" + private var currentChatRooms: [Room] = [] private var presenter: SelectChatViewPresenterProtocol! override func viewDidLoad() { super.viewDidLoad() setupSelectChatTableView() + self.presenter.didLoadViewController() } func inject(with presenter: SelectChatViewPresenterProtocol) { @@ -44,17 +46,30 @@ extension SelectChatViewController: UITableViewDelegate { extension SelectChatViewController: UITableViewDataSource { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return 10 + return currentChatRooms.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: reuseCellId) as! SelectChatTableViewCell - + cell.generateCell(withRoom: currentChatRooms[indexPath.row]) return cell } } extension SelectChatViewController: SelectChatViewPresenterOutput { + + func setCurrentChatUsers() { + self.currentChatRooms = self.presenter.currentChatRooms + self.selectChatTableView.reloadData() + } + + func showAlert(withMessage message: String) { + let alert = UIAlertController(title: "エラーが発生しました", message: message, preferredStyle: .alert) + let defaultAction: UIAlertAction = UIAlertAction(title: "OK", style: .default, handler: nil) + + alert.addAction(defaultAction) + present(alert, animated: false, completion: nil) + } } diff --git a/chat-iOS/Views/SelectChat/SelectChatViewPresenter.swift b/chat-iOS/Views/SelectChat/SelectChatViewPresenter.swift index 32baf70..663f09c 100644 --- a/chat-iOS/Views/SelectChat/SelectChatViewPresenter.swift +++ b/chat-iOS/Views/SelectChat/SelectChatViewPresenter.swift @@ -9,9 +9,13 @@ import Foundation protocol SelectChatViewPresenterProtocol { var view: SelectChatViewPresenterOutput! { get set } + var currentChatRooms: [Room] { get } + func didLoadViewController() } protocol SelectChatViewPresenterOutput: class { + func setCurrentChatUsers() + func showAlert(withMessage message: String) } final class SelectChatViewPresenter: SelectChatViewPresenterProtocol, SelectChatModelOutput { @@ -19,8 +23,31 @@ final class SelectChatViewPresenter: SelectChatViewPresenterProtocol, SelectChat weak var view: SelectChatViewPresenterOutput! private var model: SelectChatModelProtocol + private(set) var _currentChatRooms: [Room] = [] + init(model: SelectChatModelProtocol) { self.model = model + self.model.presenter = self + } + + var currentChatRooms: [Room] { + return _currentChatRooms + } + + func didLoadViewController() { + self.model.fetchCurrentChatRoom() + } + + func successFetchCurrentChatRooms(currentChatRooms rooms: [Room]) { + self._currentChatRooms = rooms + self.view.setCurrentChatUsers() + } + + func onError(error: Error?) { + DispatchQueue.main.async { [weak self] in + let message = error?.localizedDescription ?? "チャット相手を取得できませんでした" + self?.view.showAlert(withMessage: message) + } } } From 05e4327e832d0059e263573e3d122d0f70d7f011 Mon Sep 17 00:00:00 2001 From: ShuMatsuki Date: Thu, 16 Jul 2020 16:25:31 +0900 Subject: [PATCH 4/6] =?UTF-8?q?=E3=83=81=E3=83=A3=E3=83=83=E3=83=88?= =?UTF-8?q?=E9=81=B8=E6=8A=9E=E7=94=BB=E9=9D=A2=E3=81=8B=E3=82=89=E3=83=81?= =?UTF-8?q?=E3=83=A3=E3=83=83=E3=83=88=E7=94=BB=E9=9D=A2=E3=81=B8=E9=81=B7?= =?UTF-8?q?=E7=A7=BB=E3=81=99=E3=82=8B=E5=87=A6=E7=90=86=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Views/SelectChat/SelectChatViewController.swift | 13 +++++++++++++ .../Views/SelectChat/SelectChatViewPresenter.swift | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/chat-iOS/Views/SelectChat/SelectChatViewController.swift b/chat-iOS/Views/SelectChat/SelectChatViewController.swift index fb0427a..b2b0eb4 100644 --- a/chat-iOS/Views/SelectChat/SelectChatViewController.swift +++ b/chat-iOS/Views/SelectChat/SelectChatViewController.swift @@ -41,6 +41,13 @@ class SelectChatViewController: UIViewController { } extension SelectChatViewController: UITableViewDelegate { + + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + tableView.deselectRow(at: indexPath, animated: true) + let selectedRoom = currentChatRooms[indexPath.row] + self.presenter.didTapTableViewCell(selectedRoom: selectedRoom) + } + } extension SelectChatViewController: UITableViewDataSource { @@ -71,5 +78,11 @@ extension SelectChatViewController: SelectChatViewPresenterOutput { alert.addAction(defaultAction) present(alert, animated: false, completion: nil) } + + func transitionToChatsViewController(selectedRoom room: Room) { + //TODO:- 画面遷移時に加えて値の引き渡しをする + let chatsViewController = ChatsViewBuilder.create() + self.navigationController?.pushViewController(chatsViewController, animated: true) + } } diff --git a/chat-iOS/Views/SelectChat/SelectChatViewPresenter.swift b/chat-iOS/Views/SelectChat/SelectChatViewPresenter.swift index 663f09c..594b98e 100644 --- a/chat-iOS/Views/SelectChat/SelectChatViewPresenter.swift +++ b/chat-iOS/Views/SelectChat/SelectChatViewPresenter.swift @@ -11,11 +11,13 @@ protocol SelectChatViewPresenterProtocol { var view: SelectChatViewPresenterOutput! { get set } var currentChatRooms: [Room] { get } func didLoadViewController() + func didTapTableViewCell(selectedRoom room: Room) } protocol SelectChatViewPresenterOutput: class { func setCurrentChatUsers() func showAlert(withMessage message: String) + func transitionToChatsViewController(selectedRoom room: Room) } final class SelectChatViewPresenter: SelectChatViewPresenterProtocol, SelectChatModelOutput { @@ -50,4 +52,10 @@ final class SelectChatViewPresenter: SelectChatViewPresenterProtocol, SelectChat } } + func didTapTableViewCell(selectedRoom room: Room) { + DispatchQueue.main.async { [weak self] in + self?.view.transitionToChatsViewController(selectedRoom : room) + } + } + } From 0296a9cdc6bdb31a1d8dcf7f40b0ac0d2a63a7d3 Mon Sep 17 00:00:00 2001 From: ShuMatsuki Date: Wed, 22 Jul 2020 16:34:46 +0900 Subject: [PATCH 5/6] =?UTF-8?q?Room=E3=81=AB=E6=96=B0=E3=81=97=E3=81=8F?= =?UTF-8?q?=E3=83=97=E3=83=AD=E3=83=91=E3=83=86=E3=82=A3=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chat-iOS/Model/Room.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/chat-iOS/Model/Room.swift b/chat-iOS/Model/Room.swift index a8027d4..cd9db7d 100644 --- a/chat-iOS/Model/Room.swift +++ b/chat-iOS/Model/Room.swift @@ -4,10 +4,13 @@ // // Created by 戸高新也 on 2020/07/04. // +import Firebase struct Room: Codable { let name: String? let thumbnailImageURL: String? let members: [String] let message: String + @DocumentID var id: String? + @ServerTimestamp var updateAt: Timestamp? } From 51ba11b50e98cd8197a0a1a0593cb643d86efd55 Mon Sep 17 00:00:00 2001 From: ShuMatsuki Date: Wed, 22 Jul 2020 17:09:05 +0900 Subject: [PATCH 6/6] =?UTF-8?q?=E7=94=BB=E9=9D=A2=E9=81=B7=E7=A7=BB?= =?UTF-8?q?=E6=99=82=E3=81=AB=E3=83=91=E3=83=A9=E3=83=A1=E3=83=BC=E3=82=BF?= =?UTF-8?q?=E3=83=BC=E3=81=AE=E5=8F=97=E3=81=91=E6=B8=A1=E3=81=97=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chat-iOS/Views/Chats/ChatsViewBuilder.swift | 4 ++-- chat-iOS/Views/Chats/ChatsViewController.swift | 2 +- chat-iOS/Views/Chats/ChatsViewPresenter.swift | 6 +++++- chat-iOS/Views/SelectChat/SelectChatViewController.swift | 7 +++++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/chat-iOS/Views/Chats/ChatsViewBuilder.swift b/chat-iOS/Views/Chats/ChatsViewBuilder.swift index c00a20e..7efce0c 100644 --- a/chat-iOS/Views/Chats/ChatsViewBuilder.swift +++ b/chat-iOS/Views/Chats/ChatsViewBuilder.swift @@ -8,12 +8,12 @@ import UIKit struct ChatsViewBuilder { - static func create() -> UIViewController { + static func create(withRoomId roomId: String, withRoomName roomName: String) -> UIViewController { guard let chatsViewController = ChatsViewController.loadFromStoryboard() as? ChatsViewController else { fatalError("fatal: Failed to initialize the ChatsViewController") } let model = ChatsViewModel() - let presenter = ChatsViewPresenter(model: model) + let presenter = ChatsViewPresenter(model: model, withRoomId: roomId, withRoomName: roomName) chatsViewController.inject(with: presenter) return chatsViewController } diff --git a/chat-iOS/Views/Chats/ChatsViewController.swift b/chat-iOS/Views/Chats/ChatsViewController.swift index aca0a03..573760f 100644 --- a/chat-iOS/Views/Chats/ChatsViewController.swift +++ b/chat-iOS/Views/Chats/ChatsViewController.swift @@ -19,7 +19,7 @@ final class ChatsViewController: UIViewController, UICollectionViewDelegateFlowL @IBOutlet weak var sendButton: UIButton! var transScripts: [Transcript] = Array() - + let chatsCellID = "chatsCellID" override func viewDidLoad() { diff --git a/chat-iOS/Views/Chats/ChatsViewPresenter.swift b/chat-iOS/Views/Chats/ChatsViewPresenter.swift index d81630c..723d63f 100644 --- a/chat-iOS/Views/Chats/ChatsViewPresenter.swift +++ b/chat-iOS/Views/Chats/ChatsViewPresenter.swift @@ -20,9 +20,13 @@ protocol ChatsViewPresenterOutput: class { final class ChatsViewPresenter: ChatsViewPresenterProtocol, ChatsViewModelOutput { weak var view: ChatsViewPresenterOutput! private var model: ChatsViewModelProtocol + private var roomId: String + private var roomName: String - init(model: ChatsViewModelProtocol) { + init(model: ChatsViewModelProtocol, withRoomId roomId: String, withRoomName roomName: String) { self.model = model + self.roomId = roomId + self.roomName = roomName self.model.presenter = self } diff --git a/chat-iOS/Views/SelectChat/SelectChatViewController.swift b/chat-iOS/Views/SelectChat/SelectChatViewController.swift index b2b0eb4..c2e24cb 100644 --- a/chat-iOS/Views/SelectChat/SelectChatViewController.swift +++ b/chat-iOS/Views/SelectChat/SelectChatViewController.swift @@ -80,9 +80,12 @@ extension SelectChatViewController: SelectChatViewPresenterOutput { } func transitionToChatsViewController(selectedRoom room: Room) { - //TODO:- 画面遷移時に加えて値の引き渡しをする - let chatsViewController = ChatsViewBuilder.create() + + guard let roomId = room.id else { return } + guard let roomName = room.name else { return } + let chatsViewController = ChatsViewBuilder.create(withRoomId: roomId, withRoomName: roomName) self.navigationController?.pushViewController(chatsViewController, animated: true) + } }