Skip to content
Permalink
Browse files

Major Overhaul

Move all components into this repository
Move extra info from READMEs to wiki
Consolidate READMEs into one
Database: Move pg into its own folder
REST: Add some picture_id code to POST /users
      Only strip first & last names & email
Chat: Add a simple chat server
iPhone: Strip first & last names & email
  • Loading branch information...
ma11hew28 committed Jun 26, 2015
1 parent 36e45fe commit fd6416470e6f2ff07df6701d8bcc2f38908dc8d6
Showing with 5,484 additions and 63 deletions.
  1. +3 −6 .gitmodules
  2. +58 −0 CREDITS.md
  3. +0 −1 Clients/iPhone
  4. +2 −0 Clients/iPhone/.gitignore
  5. +630 −0 Clients/iPhone/Chats.xcodeproj/project.pbxproj
  6. +7 −0 Clients/iPhone/Chats.xcodeproj/project.xcworkspace/contents.xcworkspacedata
  7. +103 −0 Clients/iPhone/Chats/Account.swift
  8. +106 −0 Clients/iPhone/Chats/AppDelegate.swift
  9. +41 −0 Clients/iPhone/Chats/Chat.swift
  10. +64 −0 Clients/iPhone/Chats/ChatTableViewCell.swift
  11. +341 −0 Clients/iPhone/Chats/ChatViewController.swift
  12. +51 −0 Clients/iPhone/Chats/ChatsTableViewController.swift
  13. +72 −0 Clients/iPhone/Chats/ComposeViewController.swift
  14. +46 −0 Clients/iPhone/Chats/EditPhoneTableViewController.swift
  15. +98 −0 Clients/iPhone/Chats/EnterCodeViewController.swift
  16. +106 −0 Clients/iPhone/Chats/EnterPhoneTableViewController.swift
  17. +28 −0 Clients/iPhone/Chats/Images.xcassets/AppIcon.appiconset/Contents.json
  18. +23 −0 Clients/iPhone/Chats/Images.xcassets/LaunchImage.launchimage/Contents.json
  19. +24 −0 Clients/iPhone/Chats/Images.xcassets/MessageBubble.imageset/Contents.json
  20. BIN Clients/iPhone/Chats/Images.xcassets/MessageBubble.imageset/MessageBubble@2x.png
  21. BIN Clients/iPhone/Chats/Images.xcassets/Tab Bar/Chats.imageset/Chats@3x.png
  22. +21 −0 Clients/iPhone/Chats/Images.xcassets/Tab Bar/Chats.imageset/Contents.json
  23. +21 −0 Clients/iPhone/Chats/Images.xcassets/Tab Bar/Profile.imageset/Contents.json
  24. BIN Clients/iPhone/Chats/Images.xcassets/Tab Bar/Profile.imageset/Profile@3x.png
  25. +21 −0 Clients/iPhone/Chats/Images.xcassets/Tab Bar/Settings.imageset/Contents.json
  26. BIN Clients/iPhone/Chats/Images.xcassets/Tab Bar/Settings.imageset/Settings@3x.png
  27. +21 −0 Clients/iPhone/Chats/Images.xcassets/Tab Bar/Users.imageset/Contents.json
  28. BIN Clients/iPhone/Chats/Images.xcassets/Tab Bar/Users.imageset/Users@3x.png
  29. +21 −0 Clients/iPhone/Chats/Images.xcassets/Users/User0.imageset/Contents.json
  30. BIN Clients/iPhone/Chats/Images.xcassets/Users/User0.imageset/User0@2x.png
  31. +21 −0 Clients/iPhone/Chats/Images.xcassets/Users/User1.imageset/Contents.json
  32. BIN Clients/iPhone/Chats/Images.xcassets/Users/User1.imageset/User1@2x.jpg
  33. +24 −0 Clients/iPhone/Chats/Images.xcassets/Users/User10.imageset/Contents.json
  34. BIN Clients/iPhone/Chats/Images.xcassets/Users/User10.imageset/User10@2x.jpg
  35. +24 −0 Clients/iPhone/Chats/Images.xcassets/Users/User11.imageset/Contents.json
  36. BIN Clients/iPhone/Chats/Images.xcassets/Users/User11.imageset/User11@2x.jpg
  37. +24 −0 Clients/iPhone/Chats/Images.xcassets/Users/User12.imageset/Contents.json
  38. BIN Clients/iPhone/Chats/Images.xcassets/Users/User12.imageset/User12@2x.jpg
  39. +24 −0 Clients/iPhone/Chats/Images.xcassets/Users/User13.imageset/Contents.json
  40. BIN Clients/iPhone/Chats/Images.xcassets/Users/User13.imageset/User13@2x.jpg
  41. +24 −0 Clients/iPhone/Chats/Images.xcassets/Users/User14.imageset/Contents.json
  42. BIN Clients/iPhone/Chats/Images.xcassets/Users/User14.imageset/User14@2x.jpg
  43. +24 −0 Clients/iPhone/Chats/Images.xcassets/Users/User15.imageset/Contents.json
  44. BIN Clients/iPhone/Chats/Images.xcassets/Users/User15.imageset/User15@2x.jpg
  45. +24 −0 Clients/iPhone/Chats/Images.xcassets/Users/User16.imageset/Contents.json
  46. BIN Clients/iPhone/Chats/Images.xcassets/Users/User16.imageset/User16@2x.jpg
  47. +24 −0 Clients/iPhone/Chats/Images.xcassets/Users/User17.imageset/Contents.json
  48. BIN Clients/iPhone/Chats/Images.xcassets/Users/User17.imageset/User17@2x.jpg
  49. +24 −0 Clients/iPhone/Chats/Images.xcassets/Users/User18.imageset/Contents.json
  50. BIN Clients/iPhone/Chats/Images.xcassets/Users/User18.imageset/User18@2x.jpg
  51. +24 −0 Clients/iPhone/Chats/Images.xcassets/Users/User19.imageset/Contents.json
  52. BIN Clients/iPhone/Chats/Images.xcassets/Users/User19.imageset/User19@2x.jpg
  53. +24 −0 Clients/iPhone/Chats/Images.xcassets/Users/User2.imageset/Contents.json
  54. BIN Clients/iPhone/Chats/Images.xcassets/Users/User2.imageset/User2@2x.jpg
  55. +24 −0 Clients/iPhone/Chats/Images.xcassets/Users/User20.imageset/Contents.json
  56. BIN Clients/iPhone/Chats/Images.xcassets/Users/User20.imageset/User20@2x.jpg
  57. +24 −0 Clients/iPhone/Chats/Images.xcassets/Users/User21.imageset/Contents.json
  58. BIN Clients/iPhone/Chats/Images.xcassets/Users/User21.imageset/User21@2x.jpg
  59. +24 −0 Clients/iPhone/Chats/Images.xcassets/Users/User3.imageset/Contents.json
  60. BIN Clients/iPhone/Chats/Images.xcassets/Users/User3.imageset/User3@2x.jpg
  61. +24 −0 Clients/iPhone/Chats/Images.xcassets/Users/User4.imageset/Contents.json
  62. BIN Clients/iPhone/Chats/Images.xcassets/Users/User4.imageset/User4@2x.jpg
  63. +24 −0 Clients/iPhone/Chats/Images.xcassets/Users/User5.imageset/Contents.json
  64. BIN Clients/iPhone/Chats/Images.xcassets/Users/User5.imageset/User5@2x.jpg
  65. +24 −0 Clients/iPhone/Chats/Images.xcassets/Users/User6.imageset/Contents.json
  66. BIN Clients/iPhone/Chats/Images.xcassets/Users/User6.imageset/User6@2x.jpg
  67. +24 −0 Clients/iPhone/Chats/Images.xcassets/Users/User7.imageset/Contents.json
  68. BIN Clients/iPhone/Chats/Images.xcassets/Users/User7.imageset/User7@2x.jpg
  69. +24 −0 Clients/iPhone/Chats/Images.xcassets/Users/User8.imageset/Contents.json
  70. BIN Clients/iPhone/Chats/Images.xcassets/Users/User8.imageset/User8@2x.jpg
  71. +24 −0 Clients/iPhone/Chats/Images.xcassets/Users/User9.imageset/Contents.json
  72. BIN Clients/iPhone/Chats/Images.xcassets/Users/User9.imageset/User9@2x.jpg
  73. +32 −0 Clients/iPhone/Chats/Info.plist
  74. +31 −0 Clients/iPhone/Chats/LaunchScreen.xib
  75. +13 −0 Clients/iPhone/Chats/Message.swift
  76. +113 −0 Clients/iPhone/Chats/MessageBubbleTableViewCell.swift
  77. BIN Clients/iPhone/Chats/MessageIncoming.aiff
  78. BIN Clients/iPhone/Chats/MessageOutgoing.aiff
  79. +27 −0 Clients/iPhone/Chats/MessageSentDateTableViewCell.swift
  80. +367 −0 Clients/iPhone/Chats/NewProfileTableViewController.swift
  81. +41 −0 Clients/iPhone/Chats/PlaceholderTextView.swift
  82. +261 −0 Clients/iPhone/Chats/ProfileTableViewController.swift
  83. +97 −0 Clients/iPhone/Chats/SettingsTableViewController.swift
  84. +32 −0 Clients/iPhone/Chats/TextFieldTableViewCell.swift
  85. +32 −0 Clients/iPhone/Chats/User.swift
  86. +31 −0 Clients/iPhone/Chats/UserCollectionViewCell.swift
  87. +43 −0 Clients/iPhone/Chats/UserPictureImageView.swift
  88. +38 −0 Clients/iPhone/Chats/UserTableViewCell.swift
  89. +101 −0 Clients/iPhone/Chats/UsersCollectionViewController.swift
  90. +22 −0 Clients/iPhone/ChatsTests/ChatsTests.swift
  91. +24 −0 Clients/iPhone/ChatsTests/Info.plist
  92. +63 −0 Clients/iPhone/Libraries/Activity Views/ActivityOverlayView.swift
  93. +57 −0 Clients/iPhone/Libraries/Activity Views/ActivityView.swift
  94. +74 −0 Clients/iPhone/Libraries/CodeInputView/CodeInputView.swift
  95. +92 −0 Clients/iPhone/Libraries/Networking/Networking.swift
  96. +1 −0 Clients/iPhone/Libraries/UIButtonBackgroundColor
  97. BIN Documents/Signup-Login-Flow.jpg
  98. BIN Documents/Signup-Login-Flow.key
  99. BIN Documents/iPhone-Screenshots.gif
  100. +34 −55 README.md
  101. +1 −0 Servers/.gitignore
  102. +1 −0 Servers/Chat/.gitignore
  103. +1 −0 Servers/Chat/Procfile
  104. +10 −0 Servers/Chat/package.json
  105. +54 −0 Servers/Chat/server.js
  106. +1 −0 Servers/Database/Procfile
  107. +23 −0 Servers/Database/Rakefile
  108. +6 −0 Servers/Database/chats.sql
  109. +24 −0 Servers/Database/functions/codes.sql
  110. +8 −0 Servers/Database/functions/helpers.sql
  111. +34 −0 Servers/Database/functions/keys.sql
  112. +68 −0 Servers/Database/functions/me.sql
  113. +52 −0 Servers/Database/functions/sessions.sql
  114. +33 −0 Servers/Database/functions/users.sql
  115. +7 −0 Servers/Database/tables/codes.sql
  116. +7 −0 Servers/Database/tables/keys.sql
  117. +7 −0 Servers/Database/tables/sessions.sql
  118. +11 −0 Servers/Database/tables/users.sql
  119. +0 −1 Servers/REST
  120. +4 −0 Servers/REST/.env.example
  121. +15 −0 Servers/REST/Gemfile
  122. +40 −0 Servers/REST/Gemfile.lock
  123. +1 −0 Servers/REST/Procfile
  124. +6 −0 Servers/REST/Rakefile
  125. +25 −0 Servers/REST/app/controllers/codes_controller.rb
  126. +27 −0 Servers/REST/app/controllers/keys_controller.rb
  127. +73 −0 Servers/REST/app/controllers/me_controller.rb
  128. +46 −0 Servers/REST/app/controllers/sessions_controller.rb
  129. +91 −0 Servers/REST/app/controllers/users_controller.rb
  130. +24 −0 Servers/REST/app/helpers/authorization.rb
  131. +22 −0 Servers/REST/app/helpers/text_belt.rb
  132. +55 −0 Servers/REST/app/helpers/validation.rb
  133. +16 −0 Servers/REST/app/views/form.erb
  134. +20 −0 Servers/REST/app/views/form.html
  135. +10 −0 Servers/REST/app/views/form.rb
  136. +3 −0 Servers/REST/config.ru
  137. +21 −0 Servers/REST/config/application.rb
  138. +8 −0 Servers/REST/config/puma.rb
  139. +49 −0 Servers/REST/config/routes.rb
  140. +40 −0 Servers/REST/test/controllers/codes_controller_test.rb
  141. +56 −0 Servers/REST/test/controllers/keys_controller_test.rb
  142. +89 −0 Servers/REST/test/controllers/me_controller_test.rb
  143. +74 −0 Servers/REST/test/controllers/sessions_controller_test.rb
  144. +87 −0 Servers/REST/test/controllers/users_controller_test.rb
  145. +32 −0 Servers/REST/test/helpers/text_belt_mock.rb
  146. +7 −0 Servers/REST/test/helpers/text_belt_test.rb
  147. +13 −0 Servers/REST/test/routes_test.rb
  148. +120 −0 Servers/REST/test/test_helper.rb
  149. +27 −0 TODO.txt
@@ -1,6 +1,3 @@
[submodule "Clients/iPhone"]
path = Clients/iPhone
url = git@github.com:acani/Chats-iPhone.git
[submodule "Servers/REST"]
path = Servers/REST
url = git@github.com:acani/Chats-Server-REST.git
[submodule "Clients/iPhone/Libraries/UIButtonBackgroundColor"]
path = Clients/iPhone/Libraries/UIButtonBackgroundColor
url = git@github.com:acani/UIButtonBackgroundColor.git
@@ -0,0 +1,58 @@
# Credits

## Art & Design

Compliments of Apple

* [`MessageBubble@2x.png`][1] is a derivative of Apple's iOS Messages app message bubble.
* [`MessageIncoming.aiff`][2] is a copy of [`Received Message.aiff `][11].
* [`MessageOutgoing.aiff`][3] is a copy of [`Sent Message.aiff`][12].

Command to find files: `find /Applications/Xcode.app/ -name *.png`

## Avatars

1. http://uifaces.com/mattdipasquale
2. http://uifaces.com/samihah
3. http://uifaces.com/walterstephanie
4. http://uifaces.com/wake_gs
5. http://uifaces.com/kfriedson
6. http://uifaces.com/mmorits
7. http://uifaces.com/krystalfister
8. http://uifaces.com/christianramsey
9. http://uifaces.com/curiousonaut
10. http://uifaces.com/acoops_
11. http://uifaces.com/tpatteri
12. http://uifaces.com/giuliusa
13. http://uifaces.com/liang
14. http://uifaces.com/dhoot_amit
15. http://uifaces.com/leezlee
16. http://uifaces.com/elenadissi
17. http://uifaces.com/juanadearte
18. http://uifaces.com/teleject
19. http://uifaces.com/oksanafrewer
20. http://uifaces.com/cynthiasavard
21. http://uifaces.com/stushona

Blank Avatar. [User][4] designed by [Lynn Christensen][5] from the [Noun Project][6]

## Tab Bar Icons

1. [Users][7]
2. [Chats][8]
3. [Profile][9]
4. [Settings][10]


[1]: https://github.com/acani/Chats-iPhone/blob/master/Chats/Images.xcassets/MessageBubble.imageset/MessageBubble@2x.png
[2]: https://github.com/acani/Chats-iPhone/blob/master/Chats/MessageIncoming.aiff
[3]: https://github.com/acani/Chats-iPhone/blob/master/Chats/MessageOutgoing.aiff
[4]: http://www.thenounproject.com/term/user/4520/
[5]: http://www.thenounproject.com/lynnthemac
[6]: http://www.thenounproject.com
[7]: https://thenounproject.com/term/users/12931/
[8]: https://thenounproject.com/term/message/1332/
[9]: https://thenounproject.com/term/profile/12930/
[10]: https://thenounproject.com/term/settings/89645/
[11]: file:///Applications/Messages.app/Contents/Resources/Received Message.aiff
[12]: file:///Applications/Messages.app/Contents/Resources/Sent Message.aiff
Submodule iPhone deleted from 0e4c07
@@ -0,0 +1,2 @@
xcuserdata
xcshareddata

Large diffs are not rendered by default.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,103 @@
import UIKit

class Account: NSObject {
var phone: String!
dynamic var accessToken: String! {
get {
return NSUserDefaults.standardUserDefaults().stringForKey(AccountAccessTokenKey)
}
set {
NSUserDefaults.standardUserDefaults().setObject(newValue, forKey: AccountAccessTokenKey)
}
}
var user: User!
dynamic var users = [User]()
var email: String?
var chats = [Chat]()

func logOut() -> NSURLSessionDataTask {
let activityOverlayView = ActivityOverlayView.sharedView()
activityOverlayView.showWithTitle("Deleting")

let request = NSMutableURLRequest(URL: api.URLWithPath("/sessions"))
request.HTTPMethod = "DELETE"
request.setValue("Bearer "+accessToken, forHTTPHeaderField: "Authorization")
let dataTask = NSURLSession.sharedSession().dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in
if response != nil {
let statusCode = (response as! NSHTTPURLResponse).statusCode

dispatch_async(dispatch_get_main_queue(), {
activityOverlayView.dismissAnimated(true)

if statusCode == 200 {
self.reset()
} else {
let dictionary = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions(0), error: nil) as! Dictionary<String, String>?
UIAlertView(dictionary: dictionary, error: error, delegate: nil).show()
}
})
} else {
dispatch_async(dispatch_get_main_queue(), {
activityOverlayView.dismissAnimated(true)
UIAlertView(dictionary: nil, error: error, delegate: nil).show()
})
}
})
dataTask.resume()
return dataTask
}

func deleteAccount() -> NSURLSessionDataTask {
let activityOverlayView = ActivityOverlayView.sharedView()
activityOverlayView.showWithTitle("Deleting")

let request = NSMutableURLRequest(URL: api.URLWithPath("/me"))
request.HTTPMethod = "DELETE"
request.setValue("Bearer "+accessToken, forHTTPHeaderField: "Authorization")
let dataTask = NSURLSession.sharedSession().dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in
if response != nil {
let statusCode = (response as! NSHTTPURLResponse).statusCode

dispatch_async(dispatch_get_main_queue(), {
activityOverlayView.dismissAnimated(true)

switch statusCode {
case 200:
self.reset()
default:
let dictionary = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions(0), error: nil) as! Dictionary<String, String>?
UIAlertView(dictionary: dictionary, error: error, delegate: nil).show()
}
})
} else {
dispatch_async(dispatch_get_main_queue(), {
activityOverlayView.dismissAnimated(true)
UIAlertView(dictionary: nil, error: error, delegate: nil).show()

})
}
})
dataTask.resume()
return dataTask
}

func setUserWithAccessToken(accessToken: String, firstName: String, lastName: String) {
let userIDString = accessToken.substringToIndex(advance(accessToken.endIndex, -33))
let userID = UInt(userIDString.toInt()!)
user = User(ID: userID, username: "", firstName: firstName, lastName: lastName)
}

private func reset() {
phone = nil
accessToken = nil
user = nil
users = []
chats = []
}

func logOutGuest() {
reset()
}
}

private let AccountAccessTokenKey = "AccountAccessTokenKey"
@@ -0,0 +1,106 @@
import UIKit

let account = Account()
let api = API(baseURL: NSURL(string: "https://acani-chats.herokuapp.com"))
//let api = API(baseURL: NSURL(string: "http://localhost:5100"))
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
if let accessToken = account.accessToken {
if accessToken == "guest_access_token" {
account.accessToken = nil
} else {
account.setUserWithAccessToken(accessToken, firstName: "", lastName: "")
}
}
account.addObserver(self, forKeyPath: "accessToken", options: NSKeyValueObservingOptions(0), context: nil) // always
window = UIWindow(frame: UIScreen.mainScreen().bounds)
window!.backgroundColor = UIColor.whiteColor()
updateWindowRootViewController()
// window!.rootViewController = UINavigationController(rootViewController: NewProfileTableViewController(phone: "2032553432", key: "abc123")) // test
window!.makeKeyAndVisible()
return true
}

// MARK: - NSKeyValueObserving
override func observeValueForKeyPath(keyPath: String, ofObject object: AnyObject, change: [NSObject : AnyObject], context: UnsafeMutablePointer<Void>) {
updateWindowRootViewController()
}

func updateWindowRootViewController() {
if account.accessToken == nil {
window!.rootViewController = UINavigationController(rootViewController: EnterPhoneTableViewController())
} else {
window!.rootViewController = createTabBarController()
}
}

// MARK: - Helpers
func createTabBarController() -> UITabBarController {
// Create `usersCollectionViewController`
let usersCollectionViewController = UsersCollectionViewController()
usersCollectionViewController.tabBarItem.image = UIImage(named: "Users")
let usersNavigationController = UINavigationController(rootViewController: usersCollectionViewController)

// Create `chatsTableViewController`
let chatsTableViewController = ChatsTableViewController()
chatsTableViewController.tabBarItem.image = UIImage(named: "Chats")
let chatsNavigationController = UINavigationController(rootViewController: chatsTableViewController)

// Create `profileTableViewController`
let profileTableViewController = ProfileTableViewController(user: account.user)
profileTableViewController.tabBarItem.image = UIImage(named: "Profile")
let profileNavigationController = UINavigationController(rootViewController: profileTableViewController)

// Create `settingsTableViewController`
let settingsTableViewController = SettingsTableViewController()
settingsTableViewController.tabBarItem.image = UIImage(named: "Settings")
let settingsNavigationController = UINavigationController(rootViewController: settingsTableViewController)

let tabBarController = UITabBarController(nibName: nil, bundle: nil)
tabBarController.viewControllers = [usersNavigationController, chatsNavigationController, profileNavigationController, settingsNavigationController]
return tabBarController
}

func continueAsGuest() {
let minute: NSTimeInterval = 60, hour = minute * 60, day = hour * 24
account.chats = [
Chat(user: User(ID: 1, username: "mattdipasquale", firstName: "Matt", lastName: "Di Pasquale"), lastMessageText: "Thatnks for checking out Chats! :-)", lastMessageSentDate: NSDate()),
Chat(user: User(ID: 2, username: "samihah", firstName: "Angel", lastName: "Rao"), lastMessageText: "6 sounds good :-)", lastMessageSentDate: NSDate(timeIntervalSinceNow: -minute)),
Chat(user: User(ID: 3, username: "walterstephanie", firstName: "Valentine", lastName: "Sanchez"), lastMessageText: "Haha", lastMessageSentDate: NSDate(timeIntervalSinceNow: -minute*12)),
Chat(user: User(ID: 23, username: "benlu", firstName: "Ben", lastName: "Lu"), lastMessageText: "I have no profile picture.", lastMessageSentDate: NSDate(timeIntervalSinceNow: -hour*5)),
Chat(user: User(ID: 4, username: "wake_gs", firstName: "Aghbalu", lastName: "Amghar"), lastMessageText: "Damn", lastMessageSentDate: NSDate(timeIntervalSinceNow: -hour*13)),
Chat(user: User(ID: 22, username: "doitlive", firstName: "中文 日本語", lastName: "한국인"), lastMessageText: "I have no profile picture or extended ASCII initials.", lastMessageSentDate: NSDate(timeIntervalSinceNow: -hour*24)),
Chat(user: User(ID: 5, username: "kfriedson", firstName: "Candice", lastName: "Meunier"), lastMessageText: "I can't wait to see you! ❤️", lastMessageSentDate: NSDate(timeIntervalSinceNow: -hour*34)),
Chat(user: User(ID: 6, username: "mmorits", firstName: "Ferdynand", lastName: "Kaźmierczak"), lastMessageText: "http://youtu.be/UZb2NOHPA2A", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*2-1)),
Chat(user: User(ID: 7, username: "krystalfister", firstName: "Lauren", lastName: "Cooper"), lastMessageText: "Thinking of you...", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*3)),
Chat(user: User(ID: 8, username: "christianramsey", firstName: "Bradley", lastName: "Simpson"), lastMessageText: "👍", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*4)),
Chat(user: User(ID: 9, username: "curiousonaut", firstName: "Clotilde", lastName: "Thomas"), lastMessageText: "Sounds good!", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*5)),
Chat(user: User(ID: 10, username: "acoops_", firstName: "Tania", lastName: "Caramitru"), lastMessageText: "Cool. Thanks!", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*6)),
Chat(user: User(ID: 11, username: "tpatteri", firstName: "Ileana", lastName: "Mazilu"), lastMessageText: "Hey, what are you up to?", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*7)),
Chat(user: User(ID: 12, username: "giuliusa", firstName: "Asja", lastName: "Zuhrić"), lastMessageText: "Drinks tonight?", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*8)),
Chat(user: User(ID: 13, username: "liang", firstName: "Sarah", lastName: "Lam"), lastMessageText: "Are you going to Blues on the Green tonight?", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*9)),
Chat(user: User(ID: 14, username: "dhoot_amit", firstName: "Ishan", lastName: "Sarin"), lastMessageText: "Thanks for open sourcing Chats.", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*10)),
Chat(user: User(ID: 15, username: "leezlee", firstName: "Stella", lastName: "Vosper"), lastMessageText: "Those who dance are considered insane by those who can't hear the music.", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*11)),
Chat(user: User(ID: 16, username: "elenadissi", firstName: "Georgeta", lastName: "Mihăileanu"), lastMessageText: "Hey, what are you up to?", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*11)),
Chat(user: User(ID: 17, username: "juanadearte", firstName: "Alice", lastName: "Adams"), lastMessageText: "Hey, want to hang out tonight?", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*11)),
Chat(user: User(ID: 18, username: "teleject", firstName: "Gerard", lastName: "Gómez"), lastMessageText: "Haha. Hell yeah! No problem, bro!", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*11)),
Chat(user: User(ID: 19, username: "oksanafrewer", firstName: "Melinda", lastName: "Osváth"), lastMessageText: "I am excellent!!! I was thinking recently that you are a very inspirational person.", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*11)),
Chat(user: User(ID: 20, username: "cynthiasavard", firstName: "Saanvi", lastName: "Sarin"), lastMessageText: "See you soon!", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*11)),
Chat(user: User(ID: 21, username: "stushona", firstName: "Jade", lastName: "Roger"), lastMessageText: "😊", lastMessageSentDate: NSDate(timeIntervalSinceNow: -day*11))
]

for chat in account.chats {
account.users.append(chat.user)
}

account.phone = "2102390602"
account.user = User(ID: 24, username: "guest", firstName: "Guest", lastName: "User")
account.accessToken = "guest_access_token"
}
}
@@ -0,0 +1,41 @@
import Foundation.NSDate

var dateFormatter = NSDateFormatter()

class Chat {
let user: User
var lastMessageText: String
var lastMessageSentDate: NSDate
var lastMessageSentDateString: String {
return formatDate(lastMessageSentDate)
}
var loadedMessages = [[Message]]()
var unreadMessageCount: Int = 0 // subtacted from total when read
var hasUnloadedMessages = false
var draft = ""

init(user: User, lastMessageText: String, lastMessageSentDate: NSDate) {
self.user = user
self.lastMessageText = lastMessageText
self.lastMessageSentDate = lastMessageSentDate
}

func formatDate(date: NSDate) -> String {
let calendar = NSCalendar.currentCalendar()

let last18hours = (-18*60*60 < date.timeIntervalSinceNow)
let isToday = calendar.isDateInToday(date)
let isLast7Days = (calendar.compareDate(NSDate(timeIntervalSinceNow: -7*24*60*60), toDate: date, toUnitGranularity: .CalendarUnitDay) == NSComparisonResult.OrderedAscending)

if last18hours || isToday {
dateFormatter.dateStyle = .NoStyle
dateFormatter.timeStyle = .ShortStyle
} else if isLast7Days {
dateFormatter.dateFormat = "ccc"
} else {
dateFormatter.dateStyle = .ShortStyle
dateFormatter.timeStyle = .NoStyle
}
return dateFormatter.stringFromDate(date)
}
}
Oops, something went wrong.

0 comments on commit fd64164

Please sign in to comment.
You can’t perform that action at this time.