Ind.ie is now Small Technology Foundation.
Commit 6da5c6c1 authored by Aral Balkan's avatar Aral Balkan

Conversations sidebar doesn’t open when you don’t have friends. Closes #80....

Conversations sidebar doesn’t open when you don’t have friends. Closes #80. Added friendly notice for the Conversations timeline when person doesn’t have any friends. Progress towards #118.
parent 60ea389e
......@@ -122,6 +122,17 @@ class SidebarViewController:NSViewController
println("ℹ️ Got list of friends.\n")
println(friends)
if friends.count == 0
{
// TODO: This is a hack — we must create a friends model that receives
// notifications of friends adds, etc., and updates the view
// accordingly. For the time being, this is some duct tape and gum.
println("No friends, closing the friends sidebar.")
post(SidebarNotification.named(.HideSidebar))
post(TimelineNoticeDisplayRequestNotification, from: self, with: ["title": "Private conversations", "body": "<p style='margin-bottom: 32px;'><strong>No friends yet? Let’s fix that!&nbsp;😜</strong></p><p>← This is the Everyone timeline. It’s the first item in the main navigation.</p><p>The Everyone timelime aggregates everyone’s public posts. You can also see who else has joined the pre-alpha and send them friendship requests.</p><p>Once you have friends, they will show up here and you can talk to them privately.</p>"]);
}
for friend in friends
{
if let key = friend["key"].string
......
......@@ -34,6 +34,7 @@ public class Timeline:NSObject
// MARK: TimelineNavigationRequestNotification
let TimelineNavigationRequestNotification:String = "TimelineNavigationRequestNotification"
let TimelineNoticeDisplayRequestNotification:String = "TimelineNoticeDisplayRequestNotification"
// MARK: - TimelineNotification
public enum TimelineNotification:String
......
......@@ -33,6 +33,8 @@ class TimelineViewController: NSViewController, WKNavigationDelegate
var timelineUpdateHandler: NotificationHandler?
var timelineNoticeDisplayRequestHandler: NotificationHandler?
var conversationTimelineUpdateHandler: NotificationHandler?
//
......@@ -122,6 +124,60 @@ class TimelineViewController: NSViewController, WKNavigationDelegate
webkit.addObserver(self, forKeyPath: "loading", options: .New, context: nil)
webkit.addObserver(self, forKeyPath: "estimatedProgress", options: .New, context: nil)
//
// Handle notice display requests
//
timelineNoticeDisplayRequestHandler = timelineNoticeDisplayRequestHandler ?? handle(TimelineNoticeDisplayRequestNotification)
{
/* as */ notification in
println("Received request to display a notice in the timeline area.")
if let userInfo = notification.userInfo, title = userInfo["title"] as? String, body = userInfo["body"] as? String
{
let noticeObject =
[
"title": title,
"body": body
]
// Convert to JSON and pass to the function
var noticeAsJSONString = JSON(noticeObject).rawString()
if let noticeAsJSONString = noticeAsJSONString
{
println("Notice as JSON string: \(noticeAsJSONString)")
let javascript = "displayNotice(\(noticeAsJSONString));"
println("ℹ️ Displaying notice with title: \(title) and body: \(body)\n")
println(javascript)
self.webkit.evaluateJavaScript(javascript)
{
(result, error) -> Void in
if error != nil
{
println("\t❌ JavaScript Error while displaying notice with title \(title): \(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("✅ Notice with title \(title) shown.Result: \(result)\n")
}
else
{
println("✅ Notice with title \(title) shown.\n")
}
}
}
}
}
}
//
// Handle timeline update notifications from Pulse / Node
......
......@@ -21,6 +21,11 @@
border-bottom: 2px solid #333;
}
#messages
{
max-width: 700px;
}
.message
{
/* border-radius: 12px; */
......@@ -94,6 +99,23 @@
return document.createElement('div');
}
//
// Displays a notice instead of a timeline.
// (e.g., being used to update the person when they have no friends yet
// and thus no conversation timelines.) Very rudimentary hack like quite
// a few things during the pre-alpha stage. The web side of things
// can use a little love soon. :)
//
function displayNotice(notice) {
console.log("Displaying notice: " + notice)
setTitle(notice.title);
var messagesDiv = document.getElementById('messages');
messagesDiv.innerHTML = notice.body
}
//
// Update the timeline with the passed HTML.
//
......
false
\ No newline at end of file
true
\ No newline at end of file
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