Skip to content

Commit

Permalink
Merge branch 'feature/crashes' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
nixzhu committed Jul 1, 2016
2 parents 3294d97 + c2b2357 commit 1e2014a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 26 deletions.
2 changes: 1 addition & 1 deletion FayeClient/FayeClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public typealias FayeClientPrivateHandler = (message: FayeMessage) -> Void
public class FayeClient: NSObject {

public private(set) var webSocket: SRWebSocket?
public private(set)var serverURL: NSURL!
public private(set) var serverURL: NSURL!
public private(set) var clientID: String!

public private(set) var sentMessageCount: Int = 0
Expand Down
2 changes: 1 addition & 1 deletion Yep/Services/YepFayeService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ extension YepFayeService {
return
}

self?.fayeClient.subscribeToChannel(personalChannel) { data in
self?.fayeClient.subscribeToChannel(personalChannel) { [weak self] data in

println("receive faye data: \(data)")

Expand Down
32 changes: 14 additions & 18 deletions Yep/ViewControllers/Conversation/ConversationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1510,24 +1510,24 @@ final class ConversationViewController: BaseViewController {

let newMessagesCount = Int(messages.count - _lastTimeMessagesCount)

let lastDisplayedMessagesRange = displayedMessagesRange

displayedMessagesRange.length += newMessagesCount

let needReloadLoadPreviousSection = self.needReloadLoadPreviousSection

// 异常:两种计数不相等,治标:reload,避免插入
if let messageIDs = messageIDs {
if newMessagesCount != messageIDs.count {
reloadConversationCollectionView()
println("newMessagesCount != messageIDs.count")
#if DEBUG
YepAlert.alertSorry(message: "请截屏报告!\nnewMessagesCount: \(newMessagesCount)\nmessageIDs.count: \(messageIDs.count): \(messageIDs)", inViewController: self)
YepAlert.alertSorry(message: "请截屏报告!\nnewMessagesCount: \(newMessagesCount)\nmessageIDs.count: \(messageIDs.count)", inViewController: self)
#endif
return
}
}

let lastDisplayedMessagesRange = displayedMessagesRange

displayedMessagesRange.length += newMessagesCount

let needReloadLoadPreviousSection = self.needReloadLoadPreviousSection

if newMessagesCount > 0 {

if let messageIDs = messageIDs {
Expand All @@ -1538,10 +1538,10 @@ final class ConversationViewController: BaseViewController {
if let
message = messageWithMessageID(messageID, inRealm: realm),
index = messages.indexOf(message) {
let indexPath = NSIndexPath(forItem: index - displayedMessagesRange.location, inSection: Section.Message.rawValue)
//println("insert item: \(indexPath.item), \(index), \(displayedMessagesRange.location)")
let indexPath = NSIndexPath(forItem: index - displayedMessagesRange.location, inSection: Section.Message.rawValue)
//println("insert item: \(indexPath.item), \(index), \(displayedMessagesRange.location)")

indexPaths.append(indexPath)
indexPaths.append(indexPath)

} else {
println("unknown message")
Expand All @@ -1566,8 +1566,7 @@ final class ConversationViewController: BaseViewController {

self?.conversationCollectionView.insertItemsAtIndexPaths(indexPaths)

}, completion: { _ in
})
}, completion: nil)

case .Old:
// 用 CATransaction 保证 CollectionView 在插入后不闪动
Expand Down Expand Up @@ -1596,11 +1595,9 @@ final class ConversationViewController: BaseViewController {
})
}

println("insert messages A")
println("insert other messages")

} else {
println("self message")

// 这里做了一个假设:本地刚创建的消息比所有的已有的消息都要新,这在创建消息里做保证(服务器可能传回创建在“未来”的消息)

var indexPaths = [NSIndexPath]()
Expand All @@ -1618,10 +1615,9 @@ final class ConversationViewController: BaseViewController {

self?.conversationCollectionView.insertItemsAtIndexPaths(indexPaths)

}, completion: { _ in
})
}, completion: nil)

println("insert messages B")
println("insert self messages")
}
}

Expand Down
6 changes: 3 additions & 3 deletions Yep/ViewControllers/PickPhotos/ImageCacheController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import Photos
final class ImageCacheController {

private var cachedIndices = NSIndexSet()
var cachePreheatSize: Int
var imageCache: PHCachingImageManager
var images: PHFetchResult
let cachePreheatSize: Int
let imageCache: PHCachingImageManager
let images: PHFetchResult
var targetSize = CGSize(width: 80, height: 80)
var contentMode = PHImageContentMode.AspectFill

Expand Down
7 changes: 4 additions & 3 deletions Yep/Views/Cells/QuickPickPhotos/QuickPickPhotosCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class QuickPickPhotosCell: UITableViewCell {
var pickedPhotosAction: (Set<PHAsset> -> Void)?

var images: PHFetchResult?
let imageManager = PHCachingImageManager()
lazy var imageManager = PHCachingImageManager()
var imageCacheController: ImageCacheController!

var pickedImageSet = Set<PHAsset>() {
Expand All @@ -40,8 +40,6 @@ final class QuickPickPhotosCell: UITableViewCell {
photosCollectionView.registerNibOf(CameraCell)
photosCollectionView.registerNibOf(PhotoCell)

photosCollectionView.dataSource = self
photosCollectionView.delegate = self
photosCollectionView.showsHorizontalScrollIndicator = false

if let layout = photosCollectionView.collectionViewLayout as? UICollectionViewFlowLayout {
Expand All @@ -63,6 +61,9 @@ final class QuickPickPhotosCell: UITableViewCell {
strongSelf.images = images
strongSelf.imageCacheController = ImageCacheController(imageManager: strongSelf.imageManager, images: images, preheatSize: 1)

strongSelf.photosCollectionView.dataSource = self
strongSelf.photosCollectionView.delegate = self

strongSelf.photosCollectionView.reloadData()

PHPhotoLibrary.sharedPhotoLibrary().registerChangeObserver(strongSelf)
Expand Down

0 comments on commit 1e2014a

Please sign in to comment.