Merge branch 'develop' of https://github.com/CatchChat/Yep into develop

This commit is contained in:
kevinzhow
2015-09-16 13:54:23 +08:00
11 changed files with 87 additions and 46 deletions
+20 -10
View File
@@ -365,11 +365,11 @@ class Conversation: Object {
switch type {
case ConversationType.OneToOne.rawValue:
if let withFriend = withFriend {
return withFriend.userID
return "user" + withFriend.userID
}
case ConversationType.Group.rawValue:
if let withGroup = withGroup {
return withGroup.groupID
return "group" + withGroup.groupID
}
default:
break
@@ -585,15 +585,25 @@ func tryCreateSectionDateMessageInConversation(conversation: Conversation, befor
if message.createdUnixTime - prevMessage.createdUnixTime > 180 { // TODO: Time Section
// insert a new SectionDate Message
let newSectionDateMessage = Message()
newSectionDateMessage.conversation = conversation
newSectionDateMessage.mediaType = MessageMediaType.SectionDate.rawValue
newSectionDateMessage.createdUnixTime = message.createdUnixTime - YepConfig.Message.sectionOlderTimeInterval //
newSectionDateMessage.arrivalUnixTime = message.arrivalUnixTime - YepConfig.Message.sectionOlderTimeInterval //
newSectionDateMessage.messageID = "sectionDate-\(newSectionDateMessage.createdUnixTime)"
//
let sectionDateMessageCreatedUnixTime = message.createdUnixTime - YepConfig.Message.sectionOlderTimeInterval
let sectionDateMessageID = "sectionDate-\(sectionDateMessageCreatedUnixTime)"
success(newSectionDateMessage)
if let _ = messageWithMessageID(sectionDateMessageID, inRealm: realm) {
// do nothing
} else {
// create a new SectionDate Message
let newSectionDateMessage = Message()
newSectionDateMessage.messageID = sectionDateMessageID
newSectionDateMessage.conversation = conversation
newSectionDateMessage.mediaType = MessageMediaType.SectionDate.rawValue
newSectionDateMessage.createdUnixTime = sectionDateMessageCreatedUnixTime
newSectionDateMessage.arrivalUnixTime = sectionDateMessageCreatedUnixTime
success(newSectionDateMessage)
}
}
}
}
+8 -6
View File
@@ -160,12 +160,14 @@ class FayeService: NSObject, MZFayeClientDelegate {
private func saveMessageWithMessageInfo(messageInfo: JSONDictionary) {
// realmQueue realmQueue
let realm = Realm()
syncMessageWithMessageInfo(messageInfo, inRealm: realm) { messageIDs in
dispatch_async(dispatch_get_main_queue()) {
let object = ["messageIDs": messageIDs]
NSNotificationCenter.defaultCenter().postNotificationName(YepNewMessagesReceivedNotification, object: object)
dispatch_async(dispatch_get_main_queue()) {
let realm = Realm()
syncMessageWithMessageInfo(messageInfo, inRealm: realm) { messageIDs in
dispatch_async(dispatch_get_main_queue()) {
let object = ["messageIDs": messageIDs]
NSNotificationCenter.defaultCenter().postNotificationName(YepNewMessagesReceivedNotification, object: object)
}
}
}
}
+4 -4
View File
@@ -607,10 +607,11 @@ private func syncGroupWithGroupInfo(groupInfo: JSONDictionary, inRealm realm: Re
func syncUnreadMessagesAndDoFurtherAction(furtherAction: (messageIDs: [String]) -> Void) {
unreadMessages { allUnreadMessages in
//println("\n allUnreadMessages: \(allUnreadMessages)")
println("Got unread message \(allUnreadMessages.count)")
println("Got unread message: \(allUnreadMessages.count)")
dispatch_async(realmQueue) {
dispatch_async(dispatch_get_main_queue()) {
let realm = Realm()
@@ -623,7 +624,6 @@ func syncUnreadMessagesAndDoFurtherAction(furtherAction: (messageIDs: [String])
}
// do futher action
println("加个打印,希望能等到 Realm 在线程间同步好")
furtherAction(messageIDs: messageIDs)
}
}
@@ -895,7 +895,7 @@ func syncMessageWithMessageInfo(messageInfo: JSONDictionary, inRealm realm: Real
// Do furtherAction after sync
if let sectionDateMessageID = sectionDateMessageID{
if let sectionDateMessageID = sectionDateMessageID {
furtherAction?(messageIDs: [sectionDateMessageID, messageID])
} else {
furtherAction?(messageIDs: [messageID])
@@ -78,11 +78,15 @@ class ContactsViewController: BaseViewController {
contactsTableView.tableFooterView = UIView()
YepUserDefaults.nickname.bindListener(Listener.Nickname) { [weak self] _ in
self?.updateContactsTableView()
dispatch_async(dispatch_get_main_queue()) {
self?.updateContactsTableView()
}
}
YepUserDefaults.avatarURLString.bindListener(Listener.Avatar) { [weak self] _ in
self?.updateContactsTableView()
dispatch_async(dispatch_get_main_queue()) {
self?.updateContactsTableView()
}
}
}
@@ -245,7 +245,9 @@ class ConversationViewController: BaseViewController {
NSNotificationCenter.defaultCenter().addObserver(self, selector: "tryInsertInActiveNewMessages:", name: AppDelegate.Notification.applicationDidBecomeActive, object: nil)
YepUserDefaults.avatarURLString.bindListener(Listener.Avatar) { [weak self] _ in
self?.reloadConversationCollectionView()
dispatch_async(dispatch_get_main_queue()) {
self?.reloadConversationCollectionView()
}
}
swipeUpView.hidden = true
@@ -59,11 +59,15 @@ class ConversationsViewController: UIViewController {
NSNotificationCenter.defaultCenter().addObserver(self, selector: "reloadConversationsTableView", name: YepNewMessagesReceivedNotification, object: nil)
YepUserDefaults.nickname.bindListener(Listener.Nickname) { [weak self] _ in
self?.reloadConversationsTableView()
dispatch_async(dispatch_get_main_queue()) {
self?.reloadConversationsTableView()
}
}
YepUserDefaults.avatarURLString.bindListener(Listener.Avatar) { [weak self] _ in
self?.reloadConversationsTableView()
dispatch_async(dispatch_get_main_queue()) {
self?.reloadConversationsTableView()
}
}
view.backgroundColor = UIColor.whiteColor()
@@ -220,19 +220,22 @@ extension EditProfileViewController: UITableViewDataSource, UITableViewDelegate
cell.annotationLabel.text = NSLocalizedString("Nickname", comment: "")
YepUserDefaults.nickname.bindAndFireListener(Listener.Nickname) { [weak cell] nickname in
cell?.infoLabel.text = nickname
dispatch_async(dispatch_get_main_queue()) {
cell?.infoLabel.text = nickname
}
}
YepUserDefaults.badge.bindAndFireListener(Listener.Badge) { [weak cell] badgeName in
dispatch_async(dispatch_get_main_queue()) {
if let badgeName = badgeName, badge = BadgeView.Badge(rawValue: badgeName) {
cell?.badgeImageView.image = badge.image
cell?.badgeImageView.tintColor = badge.color
cell?.infoLabelTrailingConstraint.constant = EditProfileLessInfoCell.ConstraintConstant.normalInfoLabelTrailing
if let badgeName = badgeName, badge = BadgeView.Badge(rawValue: badgeName) {
cell?.badgeImageView.image = badge.image
cell?.badgeImageView.tintColor = badge.color
cell?.infoLabelTrailingConstraint.constant = EditProfileLessInfoCell.ConstraintConstant.normalInfoLabelTrailing
} else {
cell?.badgeImageView.image = nil
cell?.infoLabelTrailingConstraint.constant = EditProfileLessInfoCell.ConstraintConstant.minInfoLabelTrailing
} else {
cell?.badgeImageView.image = nil
cell?.infoLabelTrailingConstraint.constant = EditProfileLessInfoCell.ConstraintConstant.minInfoLabelTrailing
}
}
}
@@ -245,7 +248,9 @@ extension EditProfileViewController: UITableViewDataSource, UITableViewDelegate
cell.annotationLabel.text = NSLocalizedString("Introduction", comment: "")
YepUserDefaults.introduction.bindAndFireListener(Listener.Introduction) { [weak cell] introduction in
cell?.infoTextView.text = introduction ?? NSLocalizedString("Introduce yourself here.", comment: "")
dispatch_async(dispatch_get_main_queue()) {
cell?.infoTextView.text = introduction ?? NSLocalizedString("Introduce yourself here.", comment: "")
}
}
cell.infoTextViewDidEndEditingAction = { [weak self] newIntroduction in
@@ -215,9 +215,11 @@ class ProfileViewController: UIViewController {
if user.friendState == UserFriendState.Me.rawValue {
YepUserDefaults.introduction.bindListener(Listener.Introduction) { [weak self] introduction in
if let introduction = introduction {
self?.introductionText = introduction
self?.updateProfileCollectionView()
dispatch_async(dispatch_get_main_queue()) {
if let introduction = introduction {
self?.introductionText = introduction
self?.updateProfileCollectionView()
}
}
}
}
@@ -416,7 +418,9 @@ class ProfileViewController: UIViewController {
if user.friendState == UserFriendState.Me.rawValue {
YepUserDefaults.nickname.bindListener(Listener.Nickname) { [weak self] nickname in
self?.customNavigationItem.title = nickname
dispatch_async(dispatch_get_main_queue()) {
self?.customNavigationItem.title = nickname
}
}
}
}
@@ -59,7 +59,9 @@ class SettingsViewController: BaseViewController {
settingsTableView.registerNib(UINib(nibName: settingsMoreCellIdentifier, bundle: nil), forCellReuseIdentifier: settingsMoreCellIdentifier)
YepUserDefaults.introduction.bindAndFireListener(Listener.Introduction) { [weak self] introduction in
self?.settingsTableView.reloadData()
dispatch_async(dispatch_get_main_queue()) {
self?.settingsTableView.reloadData()
}
}
if let gestures = navigationController?.view.gestureRecognizers {
@@ -81,9 +81,11 @@ class ProfileHeaderCell: UICollectionViewCell {
if user.friendState == UserFriendState.Me.rawValue {
YepUserDefaults.avatarURLString.bindListener(Listener.Avatar) { [weak self] avatarURLString in
if let avatarURLString = avatarURLString {
self?.blurredAvatarImage = nil // need reblur
self?.updateAvatarWithAvatarURLString(avatarURLString)
dispatch_async(dispatch_get_main_queue()) {
if let avatarURLString = avatarURLString {
self?.blurredAvatarImage = nil // need reblur
self?.updateAvatarWithAvatarURLString(avatarURLString)
}
}
}
@@ -38,15 +38,21 @@ class SettingsUserCell: UITableViewCell {
avatarImageViewWidthConstraint.constant = avatarSize
YepUserDefaults.avatarURLString.bindAndFireListener(Listener.Avatar) { [weak self] _ in
self?.updateAvatar()
dispatch_async(dispatch_get_main_queue()) {
self?.updateAvatar()
}
}
YepUserDefaults.nickname.bindAndFireListener(Listener.Nickname) { [weak self] nickname in
self?.nameLabel.text = nickname
dispatch_async(dispatch_get_main_queue()) {
self?.nameLabel.text = nickname
}
}
YepUserDefaults.introduction.bindAndFireListener(Listener.Introduction) { [weak self] introduction in
self?.introLabel.text = introduction
dispatch_async(dispatch_get_main_queue()) {
self?.introLabel.text = introduction
}
}
introLabel.font = YepConfig.Settings.introFont