@@ -21,19 +21,10 @@ protocol UpdateableWithUser: class {
22// MARK:- Controller with posts and channels availiable.
22// MARK:- Controller with posts and channels availiable.
23// Search is availiable within every table (posts and channels). Has button-functionality for boths post and chnnels
23// Search is availiable within every table (posts and channels). Has button-functionality for boths post and chnnels
24−class NewsController: UIViewController, UISearchControllerDelegate, NewPostDelegate, UpdateableWithChannel, DataDelegate
24+class NewsController: UIViewController, UISearchControllerDelegate, NewPostDelegate, UpdateableWithChannel
27 var changedChannelName: ((String)->())?
26 var changedChannelName: ((String)->())?
29− func passData(for row: Int, channel: Model.Channels) {
33− self.channel = channel
37 @IBOutlet weak var tableView: UITableView!
28 @IBOutlet weak var tableView: UITableView!
39 var dictionary: [Int: Model.Users]? {
30 var dictionary: [Int: Model.Users]? {
@@ -49,19 +40,15 @@ class NewsController: UIViewController, UISearchControllerDelegate, NewPostDeleg
53 news.dataSourse = newPosts
43 news.dataSourse = newPosts
54 tableView.reloadData()
44 tableView.reloadData()
58− var posts: [Model.Posts]? {
48+ var posts: [Model.Posts]?
64 var channel: Model.Channels?
50 var channel: Model.Channels?
51+ var anonymousChannel: (users: [Int: Model.Users],posts: [Model.Posts])?
66 // MARK: - Output -
53 // MARK: - Output -
67 var onSelectChannel: (() -> Void)?
54 var onSelectChannel: (() -> Void)?
@@ -73,6 +60,7 @@ class NewsController: UIViewController, UISearchControllerDelegate, NewPostDeleg
73 var searchController = UISearchController(searchResultsController: nil)
60 var searchController = UISearchController(searchResultsController: nil)
75 var news = NewsVC()
62 var news = NewsVC()
63+ var type: HeaderType? = .NEWS
77 var refreshContr = UIRefreshControl()
65 var refreshContr = UIRefreshControl()
@@ -90,7 +78,7 @@ class NewsController: UIViewController, UISearchControllerDelegate, NewPostDeleg
90 // setUpSearchContr()
78 // setUpSearchContr()
92 news.viewController = self
80 news.viewController = self
93− news.type = .NEWS
81+ news.type = type == .NEWS ? .NEWS : type!
95 setUpNavigationItemsforPosts()
83 setUpNavigationItemsforPosts()
@@ -134,22 +122,32 @@ class NewsController: UIViewController, UISearchControllerDelegate, NewPostDeleg
136 func decideWhatChannelDisplay(){
124 func decideWhatChannelDisplay(){
137− if let channel = channel, let id = channel.id {
127+ if let channel = channel, let id = channel.id {
139− Model.getChannel(with: id) { [weak self] in
129+ Model.getChannel(with: id) { [weak self] in
140− self?.posts = $0.posts
130+ self?.posts = $0.posts
141− self?.dictionary = $0.users
131+ self?.dictionary = $0.users
142− self?.refreshContr.endRefreshing()
132+ self?.refreshContr.endRefreshing()
143− self?.changedChannelName?(channel.name)
133+ self?.changedChannelName?(channel.name)
136+ } else if let _ = posts {
139+ Model.getLast { [weak self] in
140+ self?.posts = $0.posts
141+ self?.dictionary = $0.users
142+ self?.refreshContr.endRefreshing()
143+ self?.changedChannelName?("General")
146− } else {
147+ if let anonChannel = anonymousChannel {
148− Model.getLast { [weak self] in
149− self?.posts = $0.posts
148+ posts = anonChannel.posts
150− self?.dictionary = $0.users
149+ dictionary = anonChannel.users
151− self?.refreshContr.endRefreshing()
152− self?.changedChannelName?("General")
150+ changedChannelName?("Anonymous")