Commit 89115161 authored by Aral Balkan's avatar Aral Balkan
Browse files

Now setting the timeline clock correctly (and also applied it to the Public...

Now setting the timeline clock correctly (and also applied it to the Public timeline). Also now padding message clock to 9 digits with zeros so that messages maintain correct lexographical sort order.
parent 12b91221
......@@ -75,8 +75,11 @@ class MessageSplitViewController: NSSplitViewController
//
let messageDirectoryWrapper:NSFileWrapper? = messageAttributedString.fileWrapperFromRange(NSMakeRange(0, messageAttributedString.length), documentAttributes: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding, NSExcludedElementsDocumentAttribute: ["xml", "html", "head", "body", "font", "span"], NSPrefixSpacesDocumentAttribute: 4], error: nil)
// The file name of the message folder (this is the unique ID — unique per message folder) is the current timestamp in ISO 8601 format
let messageFileName = "\(CurrentTimeline.messageClock)-\(ISO8601DateString())"
// The file name of the message folder (this is the unique ID — unique per message folder):
// Local message clock (padding to 9 digits — which should be large enough for any timeline as it would take
// about a thousand years to fill it up at ten seconds a message, every ten seconds, eight hours a day, continuously) + current timestamp in ISO 8601 format
CurrentTimeline.messageClock++
let messageFileName = String(format:"%09d-\(ISO8601DateString())", CurrentTimeline.messageClock)
// This is the URL that will be prefixed to all assets in the HTML (images, etc.)
let assetURLPrefix = CurrentTimeline.relativeWebPrefix!.stringByAppendingPathComponent(messageFileName)
......
......@@ -296,7 +296,7 @@ class TimelineViewController: NSViewController
// This is going to have a delay but let’s just get it working here
// first: call the server and ask for the timeline.
// TODO: This is hardcoded for the private timeline until I get it working. FIX THIS!
if (self.currentTimeline.id == "private")
if (self.currentTimeline.id == "private" || self.currentTimeline.id == "public")
{
println("Trying to get the timeline…")
Node.sharedInstance.call(remoteFunction.named(.getTimeline), withArguments: [CurrentTimeline.id!])
......@@ -353,6 +353,11 @@ class TimelineViewController: NSViewController
CurrentTimeline.path = timeline.path
CurrentTimeline.relativeWebPrefix = timeline.relativeWebPrefix
CurrentTimeline.id = timeline.id
// Reset the current timeline clock to zero.
// (The timeline will be requested again in Webkit Load Complete handler and the local clock will be updated based on the messages.)
// TODO: Review this whole process — it’s evolving quite organically (read: it’s quite a mess)
CurrentTimeline.messageClock = 0
// Notify anyone who cares that the timeline has changed.
post(TimelineNotification.named(.TimelineDidChange), from: self)
......@@ -433,12 +438,11 @@ class TimelineViewController: NSViewController
// Update the message clock based on either the message clock in the last received message
// or our current local clock, whichever is higher.
//
println("MESSAGE ID: \(message.id)")
if let clockFromMessage = ((message.id as NSString).firstMatchedGroupWithRegex("^(\\d+)-"))?.toInt()
{
println("Clock from message: \(clockFromMessage)")
println("Current local timeline clock: \(CurrentTimeline.messageClock)")
CurrentTimeline.messageClock = max(CurrentTimeline.messageClock + 1, clockFromMessage)
CurrentTimeline.messageClock = max(CurrentTimeline.messageClock, clockFromMessage)
}
else
{
......
......@@ -33,6 +33,7 @@
img
{
display:block;
max-width:50%;
}
.timestamp
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment