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

Added private timeline support.

parent 42149bba
......@@ -73,6 +73,7 @@ class PrivateWebServer
#
app.get '/all-friends-timeline', require('./private/routes/all-friends.coffee')(app)
app.get '/private-timeline', require('./private/routes/private.coffee')(app)
app.get '/conversation-with/:person', require('./private/routes/conversation.coffee')(app)
......
#
# All-Friends Timeline
#
# StreamWeaver = require '../../StreamWeaver'
moment = require 'moment'
module.exports = (app) ->
route = (request, response) ->
#
# TODO: Refactor these formatter to remove redundancy.
#
# Custom formatter for message body ids
messageBodyIDFormatter = (messageID) ->
return messageID + '-body'
# Custom formatter for message status ids
messageStatusIDFormatter = (messageID) ->
return messageID + '-status'
# Format the post date
postDateFormatter = (messageID) ->
#
# Parses message IDs in the following forms into separate groups for
# * timeline clock (deprecated)
# * message time (replace underscores with colons to convert to valid timestamp)
# * account handle (optional)
#
# 000000001-2015-08-10T18_49_10.467Z-laura
# 000000001-2015-08-10T18_49_10.467Z
# 2015-08-10T18_49_10.467Z-laura
# 2015-08-10T18_49_10.467Z
#
messageIDParserRegExp = /^(\d{9})?-?(\d{4}-\d{2}-\d{2}T\d{2}_\d{2}_\d{2}\.\d{3}Z)-?(.*)?/
matches = messageID.match messageIDParserRegExp
if matches != null
depracatedOptionalMessageClock = matches[1]
timestamp = matches[2]
optionalAccountHandle = matches[3]
# Desearialise the timestamp.
timestamp = timestamp.replace /_/g, ':'
console.log "Depracated message clock: #{depracatedOptionalMessageClock}" if depracatedOptionalMessageClock
console.log "Timestamp: #{timestamp}"
console.log (if depracatedOptionalMessageClock then "Account handle #{optionalAccountHandle}" else "Account handle: this is your message")
now = new Date()
timeOfPost = new Date timestamp
# to secs -> mins -> hours -> days
timeSincePostInDays = (now - timeOfPost)/1000/60/60/24
humanTime = moment(timeOfPost).fromNow()
return "#{humanTime} "
else
# This should never happen and probably shows that some sort of corrupted date got through somehow.
return 'No date.'
app.get('config').streamWeaver.getTimeline('private').then (messages) ->
# Massage the asset URLs
for message in messages
# Replace asset URLs
personHandleDelimeter = message.key.lastIndexOf 'Z-'
if personHandleDelimeter != -1
personHandle = message.key.substr(personHandleDelimeter+2)
message.value = message.value.replace new RegExp('all-friends/to', 'g'), "all-friends/from/#{personHandle}"
# TODO: Add the formatters to the messages themselves so we don’t have to duplicate them on the client.
# Reverse the message order to match that of the Cocoa client.
response.render 'private', {messages: messages, __set: { formatters: {messageBodyIDFormatter: messageBodyIDFormatter, messageStatusIDFormatter: messageStatusIDFormatter, postDateFormatter:postDateFormatter}}}
<!doctype html>
<html lang='en'>
<head>
<title>Private</title>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width'>
<link rel='stylesheet' href='/css/styles.css'>
<script type='text/javascript' src='/js/superagent.js'></script>
<script src="/js/set.js"></script>
<script src="/js/all-friends.js"></script>
<script data-set-text='meta'></script>
</head>
<body>
<section id='public-timeline'>
<h1>Private</h1>
<!-- Notice to display if there are no messages yet. -->
<div data-set-if='not messages' id='notice'>
<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>
</div>
<div id='messages' class='messages' data-set-if='messages'>
<!-- Repeater -->
<div class='message' data-set-repeat='message messages' data-set-attribute='id message.key' >
<div class='messageBody' data-set-attribute='id message.key messageBodyIDFormatter'>
<div class="image-and-body">
<img class="profileImage" src='http://localhost:42000/about/me.jpg'>
<div class="bodyText" data-set-text='html message.value'>Message body HTML</div>
<div class="meta"><span data-set-text='message.key postDateFormatter'></span></div>
</div>
</div>
<!-- <div class='messageStatus' data-set-attribute='id message.key messageStatusIDFormatter'></div>-->
</div>
</div>
<section>
</body>
</html>
\ 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