@@ -21,19 +21,10 @@ protocol UpdateableWithUser: class {
2121}
2222// MARK:- Controller with posts and channels availiable.
2323// 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
2525{
26−
2726 var changedChannelName: ((String)->())?
2827
29− func passData(for row: Int, channel: Model.Channels) {
30− if channel.id == -1{
31− self.channel = nil
32− } else {
33− self.channel = channel
34− }
35− }
36−
3728 @IBOutlet weak var tableView: UITableView!
3829
3930 var dictionary: [Int: Model.Users]? {
@@ -49,19 +40,15 @@ class NewsController: UIViewController, UISearchControllerDelegate, NewPostDeleg
4940
5041 })
5142
52−
5343 news.dataSourse = newPosts
5444 tableView.reloadData()
5545 }
5646 }
5747
58− var posts: [Model.Posts]? {
59− didSet{
60−
61− }
62− }
48+ var posts: [Model.Posts]?
6349
6450 var channel: Model.Channels?
51+ var anonymousChannel: (users: [Int: Model.Users],posts: [Model.Posts])?
6552
6653 // MARK: - Output -
6754 var onSelectChannel: (() -> Void)?
@@ -73,6 +60,7 @@ class NewsController: UIViewController, UISearchControllerDelegate, NewPostDeleg
7360 var searchController = UISearchController(searchResultsController: nil)
7461
7562 var news = NewsVC()
63+ var type: HeaderType? = .NEWS
7664
7765 var refreshContr = UIRefreshControl()
7866
@@ -90,7 +78,7 @@ class NewsController: UIViewController, UISearchControllerDelegate, NewPostDeleg
9078 // setUpSearchContr()
9179
9280 news.viewController = self
93− news.type = .NEWS
81+ news.type = type == .NEWS ? .NEWS : type!
9482
9583 setUpNavigationItemsforPosts()
9684
@@ -134,22 +122,32 @@ class NewsController: UIViewController, UISearchControllerDelegate, NewPostDeleg
134122 }
135123
136124 func decideWhatChannelDisplay(){
137− if let channel = channel, let id = channel.id {
138−
139− Model.getChannel(with: id) { [weak self] in
140− self?.posts = $0.posts
141− self?.dictionary = $0.users
142− self?.refreshContr.endRefreshing()
143− self?.changedChannelName?(channel.name)
125+ switch type! {
126+ case .NEWS, .NONE:
127+ if let channel = channel, let id = channel.id {
128+
129+ Model.getChannel(with: id) { [weak self] in
130+ self?.posts = $0.posts
131+ self?.dictionary = $0.users
132+ self?.refreshContr.endRefreshing()
133+ self?.changedChannelName?(channel.name)
134+ }
135+
136+ } else if let _ = posts {
137+ print("here!")
138+ } else {
139+ Model.getLast { [weak self] in
140+ self?.posts = $0.posts
141+ self?.dictionary = $0.users
142+ self?.refreshContr.endRefreshing()
143+ self?.changedChannelName?("General")
144+ }
144145 }
145−
146− } else {
147−
148− Model.getLast { [weak self] in
149− self?.posts = $0.posts
150− self?.dictionary = $0.users
151− self?.refreshContr.endRefreshing()
152− self?.changedChannelName?("General")
146+ default:
147+ if let anonChannel = anonymousChannel {
148+ posts = anonChannel.posts
149+ dictionary = anonChannel.users
150+ changedChannelName?("Anonymous")
153151 }
154152 }
155153 }