Unverified Commit f465d490 authored by Aral Balkan's avatar Aral Balkan
Browse files

Removed original Cocoa-side timeline update hack. Private and Public timelines...

Removed original Cocoa-side timeline update hack. Private and Public timelines not implemented yet. Placeholder messages not implemented on Node side yet.
parent c4beee3a
......@@ -350,181 +350,80 @@ class TimelineViewController: NSViewController, WKNavigationDelegate
{
if let isLoading = change["new"] as? Bool where isLoading == false
{
// MARK: - Webkit Load Complete handler -
println("ℹ️ WebKit Load complete. About to set the title of the timeline to ‘\(self.currentTimeline.title)’. (\(self))\n")
println("ℹ️ WebKit Load complete.")// About to set the title of the timeline to ‘\(self.currentTimeline.title)’. (\(self))\n")
let javascript = "setTitle('\(self.currentTimeline.title)')"
// let javascript = "setTitle('\(self.currentTimeline.title)')"
// println(">> \(javascript)")
self.webkit.evaluateJavaScript(javascript, completionHandler:
{
(result, error) -> Void in
// self.webkit.evaluateJavaScript(javascript, completionHandler:
// {
// (result, error) -> Void in
//
// if error != nil
// {
// println("❌ JavaScript error while setting title of \(self.currentTimeline.id) timeline: \(error). (\(self))\n")
// }
// else
// {
// if result != nil
// {
// // There really shouldn’t be a result but let’s code defensively in case we break something later.
// println("✅ Title of timeline set to \(self.currentTimeline.title). Return value: \(result). (\(self))\n")
// }
// else
// {
// println("✅ Title of timeline set to \(self.currentTimeline.title). (\(self))\n")
// }
// }
// })
if error != nil
{
println("❌ JavaScript error while setting title of \(self.currentTimeline.id) timeline: \(error). (\(self))\n")
}
else
{
if result != nil
{
// There really shouldn’t be a result but let’s code defensively in case we break something later.
println("✅ Title of timeline set to \(self.currentTimeline.title). Return value: \(result). (\(self))\n")
}
else
{
println("✅ Title of timeline set to \(self.currentTimeline.title). (\(self))\n")
}
}
})
//
// Move the empty timeline contents to Heartbeat Node for rendering.
//
// This is going to have a delay but let’s just get it working here
// first: call the server and ask for the timeline. (All except the Everyone timeline, which is an exception
// as it is loaded from Waystone via the Web.)
if (self.currentTimeline.id != "everyone")
{
println("Trying to get the timeline \(CurrentTimeline.id!)…")
Node.sharedInstance.call(remoteFunction.named(.getTimeline), withArguments: [CurrentTimeline.id!])
{
/* and handle callback with */ messages in
// println("RECEIVED TIMELINE: \(messages)")
let messages = messages["messages"].array!
if messages.count == 0
{
println(">>>>>\(CurrentTimeline.id!)")
var noticeBody = "<p><strong>No messages yet.</strong></p>"
if CurrentTimeline.id! == "allfriends"
{
noticeBody += "<p>This is where you will see messages from all of your friends. Messages you send will also be seen by all of your friends.</p><p>To avoid confusion, when replying to friends here, start your messages them with <em>@<their handle></em>. Although this does nothing special at the moment, it might give them a notification in the future.</p><p>Also, remember that your friends won’t see each other’s messages unless they are also friends with each other. In the future, @handle could help with discovery if we link handles to people’s public pages (thereby making it possible for your friends to discover each other through your conversations on this timeline).</p>"
}
if CurrentTimeline.id! == "private"
{
noticeBody += "<p>This timeline is for you alone.</p><p>It is only synchronised between your own devices.</p><p><em>This timeline is currently not very useful as we are only supporting one device per account during the pre-alpha.</em> Once we can lift this limit, this section will be expanded to make it easy for you to store files and folders and keep them synchronised between your devices.</p>"
}
post(TimelineNoticeDisplayRequestNotification, from: self, with: ["title": self.currentTimeline.title, "body": noticeBody]);
return
}
for message in messages
{
// NOTE: Lots of repetition with MessageSplitViewController’s sendMessageNotificationHandler — TODO: REFACTOR!
let messageID = (message["key"]).string!
var messageHTML = (message["value"]).string!
//
// Check if this is a message *from* someone to the all friends timeline.
// If so, we need to massage the assetURLPrefix and filePath to take this into consideration.
//
println("Message ID: \(messageID)")
var fromPersonHandle:String = (messageID as NSString).firstMatchedGroupWithRegex(".+?Z-(.+?)$")
println("From person: \(fromPersonHandle).")
var relativeWebPrefix = CurrentTimeline.relativeWebPrefix!
if self.currentTimeline.id == fromPersonHandle
func loadIndexPage()
{
// For the specific friends timeline, massage the assetURLPrefix to remove the person handle first.
relativeWebPrefix = relativeWebPrefix.stringByReplacingOccurrencesOfString("\(fromPersonHandle)/", replacement: "\(CurrentPerson.sharedInstance.accountHandle!)/")
println("Relative web prefix after massaging for specific friends timeline: \(relativeWebPrefix)")
}
var assetURLPrefix = relativeWebPrefix.stringByAppendingPathComponent(messageID)
var filePath = NSHomeDirectory().stringByAppendingPathComponent("Pulse/Sync").stringByAppendingPathComponent(CurrentTimeline.path!).stringByAppendingPathComponent(messageID)
// println("Asset URL prefix: \(assetURLPrefix)")
// println("filePath: \(filePath)")
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// Refactoring in progress: moving to timelines served via the private web server.
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if fromPersonHandle != ""
{
println("The message was sent from person \(fromPersonHandle). Massaging the asset URL prefix and the file path.")
// Pre-refactor timeline URL.
var timelineToLoad = "http://127.0.0.1:42003/index.html"
//
// Remove the person’s handle (and the dash preceding it) from the end of the asset URL prefix.
// Special case: everyone timeline is loaded from Waystone.
//
let fromPersonHandleLengthIncludingDash = count(fromPersonHandle) + 1
let assetURLPrefixIndexOfThePersonsHandle = count(assetURLPrefix)-fromPersonHandleLengthIncludingDash
assetURLPrefix = assetURLPrefix.substringToIndex(assetURLPrefixIndexOfThePersonsHandle)
// Store the old asset URL prefix so we can swap it out later for the new one.
let oldAssetURLPrefix = assetURLPrefix
// Add the correct folder path.
if self.currentTimeline.id == fromPersonHandle
if let currentTimelineID = CurrentTimeline.id
{
// Specific friends
assetURLPrefix = assetURLPrefix.stringByReplacingOccurrencesOfString("/\(CurrentPerson.sharedInstance.accountHandle!)/to", replacement: "/\(fromPersonHandle)/from")
}
else
if currentTimelineID == "everyone"
{
assetURLPrefix = assetURLPrefix.stringByReplacingOccurrencesOfString("/to", replacement: "/from/\(fromPersonHandle)")
timelineToLoad = ApplicationModel.sharedInstance.waystoneURL
}
filePath = filePath.stringByReplacingOccurrencesOfString("/to", replacement: "/from/\(fromPersonHandle)")
// Remove the person’s handle (and the dash preceding it) from the end of the file path.
let filePathIndexOfThePersonsHandle = count(filePath)-fromPersonHandleLengthIncludingDash
filePath = filePath.substringToIndex(filePathIndexOfThePersonsHandle)
// println("Message HTML: \(messageHTML)")
// println("Old assetURLPrefix: \(oldAssetURLPrefix)")
// println("New assetURLPrefix: \(assetURLPrefix)")
// println("New filePath: \(filePath)")
// Actually replace the old asset URL prefix with the new one in the message HTML.
messageHTML = messageHTML.stringByReplacingOccurrencesOfString(oldAssetURLPrefix, replacement: assetURLPrefix)
// println("Message HTML after: \(messageHTML)")
}
else
if currentTimelineID == "allfriends"
{
// The message is one of ours.
fromPersonHandle = ""
}
let fileURL:NSURL? = NSURL(fileURLWithPath: filePath, isDirectory: true)
let message = Message(id: messageID, assetURLPrefix: assetURLPrefix, folderURL: fileURL!, html: messageHTML as String, personHandle: fromPersonHandle, synced: false)
post(MessageNotification.named(.ShowMessage), from: self, with: ["message": message])
}
timelineToLoad = "http://127.0.0.1:42003/all-friends-timeline"
}
}
}
}
}
func loadIndexPage()
{
var urlRequest = NSURLRequest(URL: NSURL(string: "http://127.0.0.1:42003/index.html")!)
// Refactoring: moving to timelines served via the private web server.
if CurrentTimeline.id == "allfriends"
if currentTimelineID != "allfriends" && currentTimelineID != "conversations" && currentTimelineID != "private" && currentTimelineID != "everyone" && currentTimelineID != "public"
{
println("Showing all friends timeline from the private web server.")
urlRequest = NSURLRequest(URL: NSURL(string: "http://127.0.0.1:42003/all-friends-timeline")!)
timelineToLoad = "http://127.0.0.1:42003/conversation-with/\(currentTimelineID)"
}
if CurrentTimeline.id != "allfriends" && CurrentTimeline.id != "conversations" && CurrentTimeline.id != "private" && CurrentTimeline.id != "everyone" && CurrentTimeline.id != "public" && CurrentTimeline.id != nil
{
// Show conversation timeline
println("Showing conversation timeline with \(CurrentTimeline.id) the private web server.")
urlRequest = NSURLRequest(URL: NSURL(string: "http://127.0.0.1:42003/conversation-with/\(CurrentTimeline.id!)")!)
}
var urlRequest = NSURLRequest(URL: NSURL(string: timelineToLoad)!)
webkit.loadRequest(urlRequest)
}
......@@ -559,18 +458,7 @@ class TimelineViewController: NSViewController, WKNavigationDelegate
// Notify anyone who cares that the timeline has changed.
post(TimelineNotification.named(.TimelineDidChange), from: self)
//
// Special case: everyone timeline is loaded from Waystone.
//
if timeline.id == "everyone"
{
let indieURL = NSURL(string: ApplicationModel.sharedInstance.waystoneURL)
webkit.loadRequest(NSURLRequest(URL: indieURL!))
return
}
// Load the current index page for the timeline
loadIndexPage()
}
......
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