no message

This commit is contained in:
Peter 2016-11-22 21:30:16 +03:00
parent 45f81135c2
commit 6ab5c9b3b0
3 changed files with 80 additions and 19 deletions

View File

@ -31,6 +31,10 @@ public func declareEncodable(_ type: Any.Type, f: @escaping(Decoder) -> Coding)
typeStore.dict[murMurHashString32("\(type)")] = f typeStore.dict[murMurHashString32("\(type)")] = f
} }
public func persistentHash32(_ string: String) -> Int32 {
return murMurHashString32(string)
}
private let emptyMemory = malloc(1)! private let emptyMemory = malloc(1)!
public class MemoryBuffer: Equatable, CustomStringConvertible { public class MemoryBuffer: Equatable, CustomStringConvertible {

View File

@ -201,8 +201,14 @@ public final class MediaBox {
} }
if fetchingData { if fetchingData {
//status = .Fetching(progress: Float(currentSize) / Float(resourceSize)) let currentSize = fileSize(paths.partial) ?? 0
status = .Fetching(progress: 0.0)
if let resourceSize = resource.size {
status = .Fetching(progress: Float(currentSize) / Float(resourceSize))
} else {
status = .Fetching(progress: 0.0)
}
} else { } else {
status = .Remote status = .Remote
} }
@ -239,24 +245,50 @@ public final class MediaBox {
} }
public func resourceData(_ resource: MediaResource, pathExtension: String? = nil, complete: Bool = true) -> Signal<MediaResourceData, NoError> { public func resourceData(_ resource: MediaResource, pathExtension: String? = nil, complete: Bool = true) -> Signal<MediaResourceData, NoError> {
assert(pathExtension == nil)
return Signal { subscriber in return Signal { subscriber in
let disposable = MetaDisposable() let disposable = MetaDisposable()
self.concurrentQueue.async { self.concurrentQueue.async {
let paths = self.storePathsForId(resource.id) let paths = self.storePathsForId(resource.id)
if let completeSize = fileSize(paths.complete) { if let completeSize = fileSize(paths.complete) {
subscriber.putNext(MediaResourceData(path: paths.complete, size: completeSize, complete: true)) if let pathExtension = pathExtension {
subscriber.putCompletion() let symlinkPath = paths.complete + ".\(pathExtension)"
if fileSize(symlinkPath) == nil {
let _ = try? FileManager.default.createSymbolicLink(atPath: symlinkPath, withDestinationPath: URL(fileURLWithPath: paths.complete).lastPathComponent)
}
subscriber.putNext(MediaResourceData(path: symlinkPath, size: completeSize, complete: true))
subscriber.putCompletion()
} else {
subscriber.putNext(MediaResourceData(path: paths.complete, size: completeSize, complete: true))
subscriber.putCompletion()
}
} else { } else {
self.dataQueue.async { self.dataQueue.async {
let resourceId = WrappedMediaResourceId(resource.id) let resourceId = WrappedMediaResourceId(resource.id)
var currentContext: ResourceDataContext? = self.dataContexts[resourceId] var currentContext: ResourceDataContext? = self.dataContexts[resourceId]
if let currentContext = currentContext, currentContext.data.complete { if let currentContext = currentContext, currentContext.data.complete {
subscriber.putNext(currentContext.data) if let pathExtension = pathExtension {
subscriber.putCompletion() let symlinkPath = paths.complete + ".\(pathExtension)"
if fileSize(symlinkPath) == nil {
let _ = try? FileManager.default.createSymbolicLink(atPath: symlinkPath, withDestinationPath: URL(fileURLWithPath: paths.complete).lastPathComponent)
}
subscriber.putNext(MediaResourceData(path: symlinkPath, size: currentContext.data.size, complete: currentContext.data.complete))
subscriber.putCompletion()
} else {
subscriber.putNext(currentContext.data)
subscriber.putCompletion()
}
} else if let completeSize = fileSize(paths.complete) { } else if let completeSize = fileSize(paths.complete) {
subscriber.putNext(MediaResourceData(path: paths.complete, size: completeSize, complete: true)) if let pathExtension = pathExtension {
subscriber.putCompletion() let symlinkPath = paths.complete + ".\(pathExtension)"
if fileSize(symlinkPath) == nil {
let _ = try? FileManager.default.createSymbolicLink(atPath: symlinkPath, withDestinationPath: URL(fileURLWithPath: paths.complete).lastPathComponent)
}
subscriber.putNext(MediaResourceData(path: symlinkPath, size: completeSize, complete: true))
subscriber.putCompletion()
} else {
subscriber.putNext(MediaResourceData(path: paths.complete, size: completeSize, complete: true))
subscriber.putCompletion()
}
} else { } else {
let dataContext: ResourceDataContext let dataContext: ResourceDataContext
if let currentContext = currentContext { if let currentContext = currentContext {
@ -270,15 +302,33 @@ public final class MediaBox {
let index: Bag<(MediaResourceData) -> Void>.Index let index: Bag<(MediaResourceData) -> Void>.Index
if complete { if complete {
index = dataContext.completeDataSubscribers.add { data in index = dataContext.completeDataSubscribers.add { data in
subscriber.putNext(data) if let pathExtension = pathExtension, data.complete {
subscriber.putCompletion() let symlinkPath = paths.complete + ".\(pathExtension)"
if fileSize(symlinkPath) == nil {
let _ = try? FileManager.default.createSymbolicLink(atPath: symlinkPath, withDestinationPath: URL(fileURLWithPath: paths.complete).lastPathComponent)
}
subscriber.putNext(MediaResourceData(path: symlinkPath, size: data.size, complete: data.complete))
subscriber.putCompletion()
} else {
subscriber.putNext(data)
subscriber.putCompletion()
}
} }
subscriber.putNext(MediaResourceData(path: dataContext.data.path, size: 0, complete: false)) subscriber.putNext(MediaResourceData(path: dataContext.data.path, size: 0, complete: false))
} else { } else {
index = dataContext.progresiveDataSubscribers.add { data in index = dataContext.progresiveDataSubscribers.add { data in
subscriber.putNext(data) if let pathExtension = pathExtension, data.complete {
if data.complete { let symlinkPath = paths.complete + ".\(pathExtension)"
if fileSize(symlinkPath) == nil {
let _ = try? FileManager.default.createSymbolicLink(atPath: symlinkPath, withDestinationPath: URL(fileURLWithPath: paths.complete).lastPathComponent)
}
subscriber.putNext(MediaResourceData(path: symlinkPath, size: data.size, complete: data.complete))
subscriber.putCompletion() subscriber.putCompletion()
} else {
subscriber.putNext(data)
if data.complete {
subscriber.putCompletion()
}
} }
} }
subscriber.putNext(dataContext.data) subscriber.putNext(dataContext.data)
@ -455,8 +505,12 @@ public final class MediaBox {
let index: Bag<Void>.Index = dataContext.fetchSubscribers.add(Void()) let index: Bag<Void>.Index = dataContext.fetchSubscribers.add(Void())
if dataContext.fetchDisposable == nil { if dataContext.fetchDisposable == nil {
//let status: MediaResourceStatus = .Fetching(progress: Float(currentSize) / Float(resourceSize)) let status: MediaResourceStatus
let status: MediaResourceStatus = .Fetching(progress: 0.0) if let resourceSize = resource.size {
status = .Fetching(progress: Float(currentSize) / Float(resourceSize))
} else {
status = .Fetching(progress: 0.0)
}
self.statusQueue.async { self.statusQueue.async {
if let statusContext = self.statusContexts[resourceId] { if let statusContext = self.statusContexts[resourceId] {
statusContext.status = status statusContext.status = status
@ -526,8 +580,11 @@ public final class MediaBox {
if updatedData.complete { if updatedData.complete {
status = .Local status = .Local
} else { } else {
//status = .Fetching(progress: Float(updatedSize) / Float(resourceSize)) if let resourceSize = resource.size {
status = .Fetching(progress: 0.0) status = .Fetching(progress: Float(updatedSize) / Float(resourceSize))
} else {
status = .Fetching(progress: 0.0)
}
} }
self.statusQueue.async { self.statusQueue.async {

View File

@ -11,7 +11,7 @@ public enum PeerNameIndex {
} }
extension PeerIndexNameRepresentation { extension PeerIndexNameRepresentation {
func indexName(_ index: PeerNameIndex) -> String { public func indexName(_ index: PeerNameIndex) -> String {
switch self { switch self {
case let .title(title): case let .title(title):
return title return title
@ -25,7 +25,7 @@ extension PeerIndexNameRepresentation {
} }
} }
func match(query: String) -> Bool { public func match(query: String) -> Bool {
switch self { switch self {
case let .title(title): case let .title(title):
return title.lowercased().hasPrefix(query) return title.lowercased().hasPrefix(query)