Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func configurePhotoForCell(cell: onlineUserCell, user: XMPPUserCoreDataStorageObject) {
- // Our xmppRosterStorage will cache photos as they arrive from the xmppvCardAvatarModule.
- // We only need to ask the avatar module for a photo, if the roster doesn't have it.
- OneLastActivity.sendLastActivityQueryToJID(user.jidStr, sender: OneChat.sharedInstance.xmppLastActivity) { (sender, error) -> Void in
- if let timeInSeconds = sender?.lastActivitySeconds() {
- let seconds = timeInSeconds
- print(seconds)
- switch seconds {
- case let sec where sec == 0:
- cell.lastMessage.text = "online"
- case let sec where sec < 60:
- cell.lastMessage.text = "last seen \(seconds) seconds ago"
- case let sec where sec > 59 && sec < 3600:
- cell.lastMessage.text = "last seen \(seconds / 60) minutes ago"
- case let sec where sec > 3600 && sec < 86400:
- cell.lastMessage.text = "last seen \(seconds / 3600) hours ago"
- case let sec where sec > 86400:
- let seconds: NSNumber = NSNumber(unsignedLong: timeInSeconds)
- var dateFormatter = NSDateFormatter()
- dateFormatter.dateFormat = "dd.MM.yyyy"
- var a = dateFormatter.stringFromDate(NSDate(timeIntervalSinceNow:seconds.doubleValue))
- print(a)
- cell.lastMessage.text = NSString(format: "last seen | %@", NSDate(timeIntervalSinceNow:seconds.doubleValue)) as String
- default:
- cell.lastMessage.text = "last seen long time ago"
- }
- }
- }
- if user.photo != nil {
- cell.avatarImage.image = user.photo!;
- } else {
- let photoData = OneChat.sharedInstance.xmppvCardAvatarModule?.photoDataForJID(user.jid)
- if let photoData = photoData {
- cell.avatarImage.image = UIImage(data: photoData)
- } else {
- cell.imageView!.image = UIImage(named: "defaultPerson")
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement