Commit 6574c4e3 authored by Aral Balkan's avatar Aral Balkan
Browse files

Transition to main interface and the public new user announcement are being posted correctly.

parent 2d099b51
......@@ -32,6 +32,7 @@ public class NotificationHandler:NSObject
public func handlerProxy(notification:NSNotification!)
{
println("HANDLER PROXY: Handler = \(handler)")
handler(notification)
}
......
......@@ -234,14 +234,15 @@ class MainInterfaceSplitViewController: NSSplitViewController
// Add the message split view controller to the main interface split view items view controller.
mainInterfaceSplitViewItem!.viewController.addChildViewController(messageSplitViewController!)
mainInterfaceSplitViewItem!.viewController.view.addSubview(messageSplitViewController!.view)
// If we’re going to transition, let’s hide the view for now
if transition
{
messageSplitViewController!.view.hidden = true
messageSplitViewController!.view.hidden = true
}
mainInterfaceSplitViewItem!.viewController.view.addSubview(messageSplitViewController!.view)
if resize
{
// Set the window to the default size
......@@ -356,16 +357,22 @@ class MainInterfaceSplitViewController: NSSplitViewController
// Show the Public timeline
// TODO: Get the timeline.
let userInfo = ["timeline":Timelines.sharedInstance[.Public]!]
post(TimelineNavigationRequestNotification, from: self, with: userInfo)
delay(10.0)
{
// TODO: REMOVE THIS DELAY HACK!!!
println("About to post the timeline request.")
let userInfo = ["timeline":Timelines.sharedInstance[.Public]!]
post(TimelineNavigationRequestNotification, from: nil, with: userInfo)
}
delay(20.0)
{
// TODO: REMOVE THIS DELAY HACK!!!
println("About to post the new person message")
// Create the message, persist it, and notify the timeline to show it.
let message = "<p><img src='\(SetupData.photoPath)'> Hey everyone, <a href='indie://friend/\(SetupData.accountHandle)'>\(SetupData.displayName)</a> just joined Ind.ie!</p>"
let message = NSAttributedString(string: "<p><img src='\(SetupData.photoPath)'> Hey everyone, <a href='indie://friend/\(SetupData.accountHandle!)'>\(SetupData.displayName!)</a> just joined Ind.ie!</p>")
println("NEW PERSON MESSAGE: \(message)")
......
......@@ -38,6 +38,14 @@ class MessageSplitViewController: NSSplitViewController
func addNotificationHandlers()
{
println("\(self): adding notification handlers.")
if (sendMessageNotificationHandler != nil)
{
println("\(self): CORRECTION: not adding notification handlers as sendMessageNotificationHandler already exists.")
return
}
//
// MARK: - .SendMessage
//
......@@ -45,6 +53,9 @@ class MessageSplitViewController: NSSplitViewController
{
/* as */ notification in
println("SEND MESSAGE NOTIFICATION HANDLER!!!!")
println(notification.userInfo)
if let userInfo = (notification.userInfo as Dictionary!), messageAttributedString = userInfo["message"] as? NSAttributedString
{
println("Send message: received text: \(messageAttributedString)")
......@@ -150,11 +161,6 @@ class MessageSplitViewController: NSSplitViewController
//
let message = Message(id: messageFileName, assetURLPrefix: assetURLPrefix, folderURL: fileURL, html: indexHTML as String, synced: false)
//
// Notify that we need to have the message displayed in the respective timeline
//
post(MessageNotification.named(.ShowMessage), from: self, with: ["message": message])
//
// Inform Node that it should post the message to the timeline
// (TODO: Research: should we base this on the Pulse event flow instead? Which is cleaner?)
......@@ -165,12 +171,19 @@ class MessageSplitViewController: NSSplitViewController
// *
//
Node.sharedInstance.call(remoteFunction.named(.postMessage), withArguments: [messageFileName, indexHTML, CurrentTimeline.id!])
{
/* and handle callback with */ result in
println("<<<<< POST MESSAGE CALLBACK!!!! >>>>>")
println(result)
{
/* and handle callback with */ result in
println("<<<<< POST MESSAGE CALLBACK!!!! >>>>>")
println(result)
}
//
// Notify that we need to have the message displayed in the respective timeline
//
post(MessageNotification.named(.ShowMessage), from: self, with: ["message": message])
break
}
......@@ -185,7 +198,10 @@ class MessageSplitViewController: NSSplitViewController
func removeNotificationHandlers()
{
println("\(self): removing notification handlers")
sendMessageNotificationHandler?.remove()
sendMessageNotificationHandler = nil
}
......
......@@ -51,7 +51,34 @@ extension NSNotificationCenter
{
self.removeObserver(observer, name: name, object: object)
}
//
// MARK: - Post notifications only on the main thread for safety
// (See http://www.cocoanetics.com/2010/05/nsnotifications-and-background-threads/)
//
public func postNotificationOnMainThread(notification:NSNotification)
{
println("Posting notification on main thread: \(notification)")
dispatch_async(dispatch_get_main_queue())
{
self.postNotification(notification)
}
}
public func postNotificationNameOnMainThread(name:String, object:AnyObject?)
{
println("postNotificationNameOnMainThread with name: \(name), object: \(object)")
let notification = NSNotification(name: name, object: object)
self.postNotificationOnMainThread(notification)
}
public func postNotificationNameOnMainThread(name:String, object:AnyObject?, userInfo:[NSObject : AnyObject]?)
{
println("postNotificationNameOnMainThread with name: \(name), object: \(object)), userInfo: \(userInfo)")
let notification = NSNotification(name: name, object: object, userInfo: userInfo)
self.postNotificationOnMainThread(notification)
}
//
// MARK: - Posting notifications
......@@ -60,7 +87,9 @@ extension NSNotificationCenter
public func post(notificationName:String, from object:AnyObject?, with userInfo:[NSObject : AnyObject]?)
{
self.postNotificationName(notificationName, object: object, userInfo: userInfo)
println("Post received: notificationName: \(notificationName) from object: \(object) with userInfo: \(userInfo)")
self.postNotificationNameOnMainThread(notificationName, object: object, userInfo: userInfo)
}
......
......@@ -41,6 +41,8 @@ class TimelineViewController: NSViewController
override func viewDidLoad()
{
println("TimelineViewController::viewDidLoad")
super.viewDidLoad()
//
......@@ -86,6 +88,8 @@ class TimelineViewController: NSViewController
override func viewWillAppear()
{
println("TimelineViewController::viewWillAppear")
createConstraints()
addEventHandlers()
......@@ -103,6 +107,8 @@ class TimelineViewController: NSViewController
func addEventHandlers()
{
println("\(self): adding event handlers")
//
// KVO handlers for web kit view load progress.
//
......@@ -116,7 +122,7 @@ class TimelineViewController: NSViewController
//
// MARK: * showMessageHandler
showMessageHandler = handle(MessageNotification.named(.ShowMessage))
showMessageHandler = showMessageHandler ?? handle(MessageNotification.named(.ShowMessage))
{
/* as */ notification in
......@@ -132,7 +138,7 @@ class TimelineViewController: NSViewController
//
// MARK: * timelineNavigationRequestHandler
timelineNavigationRequestHandler = handle(TimelineNavigationRequestNotification)
timelineNavigationRequestHandler = timelineNavigationRequestHandler ?? handle(TimelineNavigationRequestNotification)
{
/* as */ notification in
......@@ -153,7 +159,7 @@ class TimelineViewController: NSViewController
//
// MARK: * pulseRemoteIndexUpdateHandler
pulseRemoteIndexUpdateHandler = handle(PulseNotification.named(.RemoteIndexUpdated))
pulseRemoteIndexUpdateHandler = pulseRemoteIndexUpdateHandler ?? handle(PulseNotification.named(.RemoteIndexUpdated))
{
/* as */ notification in
......@@ -183,9 +189,12 @@ class TimelineViewController: NSViewController
func removeEventHandlers()
{
println("\(self): removing event handlers")
webkit.removeObserver(self, forKeyPath: "loading", context: nil)
webkit.removeObserver(self, forKeyPath: "estimatedProgress", context: nil)
showMessageHandler?.remove()
timelineNavigationRequestHandler?.remove()
pulseRemoteIndexUpdateHandler?.remove()
}
......
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