Advertisement
iamalizade

Untitled

Oct 5th, 2015
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 2.22 KB | None | 0 0
  1. func configurePhotoForCell(cell: onlineUserCell, user: XMPPUserCoreDataStorageObject) {
  2.         // Our xmppRosterStorage will cache photos as they arrive from the xmppvCardAvatarModule.
  3.         // We only need to ask the avatar module for a photo, if the roster doesn't have it.
  4.        
  5.         OneLastActivity.sendLastActivityQueryToJID(user.jidStr, sender: OneChat.sharedInstance.xmppLastActivity) { (sender, error) -> Void in
  6.             if let timeInSeconds = sender?.lastActivitySeconds() {
  7.                 let seconds = timeInSeconds
  8.                 print(seconds)
  9.                
  10.                 switch seconds {
  11.                 case let sec where sec == 0:
  12.                     cell.lastMessage.text = "online"
  13.                 case let sec where sec < 60:
  14.                     cell.lastMessage.text = "last seen \(seconds) seconds ago"
  15.                 case let sec where sec > 59 && sec < 3600:
  16.                     cell.lastMessage.text = "last seen \(seconds / 60) minutes ago"
  17.                 case let sec where sec > 3600 && sec < 86400:
  18.                     cell.lastMessage.text = "last seen \(seconds / 3600) hours ago"
  19.                 case let sec where sec > 86400:
  20.                     let seconds: NSNumber = NSNumber(unsignedLong: timeInSeconds)
  21.                    
  22.                     var dateFormatter = NSDateFormatter()
  23.                     dateFormatter.dateFormat = "dd.MM.yyyy"
  24.                    
  25.                     var a = dateFormatter.stringFromDate(NSDate(timeIntervalSinceNow:seconds.doubleValue))
  26.                     print(a)
  27.                    
  28.                     cell.lastMessage.text = NSString(format: "last seen |  %@", NSDate(timeIntervalSinceNow:seconds.doubleValue)) as String
  29.                 default:
  30.                     cell.lastMessage.text = "last seen long time ago"
  31.                 }
  32.             }
  33.         }
  34.  
  35.        
  36.         if user.photo != nil {
  37.             cell.avatarImage.image = user.photo!;
  38.         } else {
  39.             let photoData = OneChat.sharedInstance.xmppvCardAvatarModule?.photoDataForJID(user.jid)
  40.            
  41.             if let photoData = photoData {
  42.                 cell.avatarImage.image = UIImage(data: photoData)
  43.             } else {
  44.                 cell.imageView!.image = UIImage(named: "defaultPerson")
  45.             }
  46.         }
  47.        
  48.  
  49.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement