Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- Assembles and returns a feed for the provided band.
- This is not a pure getter - it splices chats and shows into the feed and sorts when called.
- This is why the result is stored in the feed controller and only recalled again after an update
- to either chat, feed, or shows.
- */
- func getFeedForBand(band:Band) -> [FeedItem]
- {
- var feedItems = feedItemsByBand[band.id] ?? [FeedItem]()
- //We already have the FB/Twitter items in this array, but we need to add chats.
- //Doing this at this step because we retrieve chats FAR more often than FB/Twitter items
- //Future efficiency todo would be to always maintain this array and tack new chats to the end of it when they arrive.
- addChatsToFeed(feed: &feedItems, forBand: band)
- feedItems.sort(by: { x, y in x.created > y.created })
- addShowsToFeed(feed: &feedItems, forBand: band)
- return feedItems
- }
- /**
- Splices chats from band X into the feed provided.
- No ordering - we'll sort the feed only after all items have been added.
- */
- private func addChatsToFeed(feed feedItems:inout [FeedItem], forBand band:Band)
- {
- for c in ChatManager.instance.currentBandChats
- {
- if c.bandId == band.id
- {
- feedItems.append(FeedItem(chat: c))
- }
- }
- }
- /**
- Add shows to feed at an interval.
- These are little reminder stubs.
- The interval is configured via server config (it's a get property to Config.getValue())
- */
- private func addShowsToFeed(feed feedItems:inout [FeedItem], forBand band:Band)
- {
- let shows = ShowManager.instance.upcomingVisibleShows
- var feedItemIndex = 0
- for show in shows
- {
- if feedItemIndex >= feedItems.count
- {
- feedItems.append(FeedItem(show:show))
- break
- }
- // Last line will return early but using explicit 'else' here for readability
- else
- {
- feedItems.insert(FeedItem(show: show), at: feedItemIndex)
- feedItemIndex += showFeedInterval
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement