Added permanent links and rudimentary post pages for public posts.

parent d3adc833
......@@ -82,6 +82,27 @@ class PublicTimelineWeaver
getPostsBefore: (key, limit = 20) =>
@getTimeline '\x00', key, limit
#
# Get one specific message
#
getMessage: (messageID) =>
console.log "Attempting to get message with ID: #{messageID}"
return new Promise ((fulfill, reject) =>
@publicTimeline.get messageID, (error, value) =>
if error
console.log "Error! #{error}"
reject new Error "#{error}"
else
console.log "Awesome: #{value}"
process.nextTick(=>
fulfill
key: messageID
value: value
)
)
#
# Returns a promise to return the requested timeline.
# (We need to stream the timelines contents from the database.)
......@@ -113,6 +134,8 @@ class PublicTimelineWeaver
toArray = WriteStream.toArray (arrayOfMessages) =>
# console.log "Streamweaver: got the timeline messages!"
# console.log arrayOfMessages
#
# We have the old messages in an array, fulfill the promise.
#
......@@ -125,4 +148,4 @@ class PublicTimelineWeaver
)
module.exports = PublicTimelineWeaver
module.exports = PublicTimelineWeaver
\ No newline at end of file
......@@ -314,6 +314,8 @@ app.use(bodyParser.json())
app.get '/', require('./routes/public/public.coffee')(app)
app.get '/person/:accountHandle/post/:messageID', require('./routes/public/post.coffee')(app)
#
# Ajax updates
......@@ -419,6 +421,4 @@ process.once 'SIGUSR2', () ->
gracefulShutdown = () ->
console.log 'Exiting… cleaning up and shutting down Pulse.'
root.pulseProcess.stop()
root.pulseProcess.stop()
\ No newline at end of file
#
# Waystone Public Timeline
#
moment = require 'moment'
PublicTimelineWeaver = require '../../PublicTimelineWeaver'
module.exports = (app) ->
route = (request, response) ->
messageID = request.params.messageID
# 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.'
# Format the post date
timestampFormatter = (messageID) ->
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
timestamp = matches[2]
# Desearialise the timestamp.
timestamp = timestamp.replace /_/g, ':'
return timestamp
else
# This should never happen and probably shows that some sort of corrupted ID got through somehow.
return (new Date())
# Format the person’s name
personFormatter = (messageID) ->
personHandleDelimeter = messageID.lastIndexOf('Z-')
profileImagePath = ''
if personHandleDelimeter != -1
# From someone else
personHandle = messageID.substr(personHandleDelimeter+2)
# TODO: Once public profile pages are implemented, link to them.
return "#{personHandle}"
else
# This is the person themselves.
# TODO: Once the timestamps are in there, just return that.
return ''
addFriendLinkFormatter = (messageID) ->
personHandleDelimeter = messageID.lastIndexOf('Z-')
profileImagePath = ''
if personHandleDelimeter != -1
# From someone else
personHandle = messageID.substr(personHandleDelimeter+2)
addFriendLink = "indie://friend/#{personHandle}"
return addFriendLink
else
# This is the person themselves, no need to display a friend link.
return ''
addFriendTextFormatter = (messageID) ->
personHandleDelimeter = messageID.lastIndexOf('Z-')
profileImagePath = ''
if personHandleDelimeter != -1
return "<img class='add-friend-icon' src='/images/person_add@2x.png' alt='Send friend request'>"
else
# This is the person themselves, no need to display a friend link.
return ''
# Custom formatter for the profile image
profileImagePathFormatter = (messageID) ->
personHandle = messageID.substr(messageID.lastIndexOf('Z-')+2)
# console.log "Person handle for message: #{personHandle}"
profileImagePath = "/public/#{personHandle}/about/me.jpg"
return profileImagePath
(new PublicTimelineWeaver).getMessage(messageID).then (message) ->
console.log 'Post route got message: '
console.log message
# 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 'post', {message: message, __set: { formatters: {messageBodyIDFormatter: messageBodyIDFormatter, messageStatusIDFormatter: messageStatusIDFormatter, profileImagePathFormatter: profileImagePathFormatter, personFormatter:personFormatter, addFriendLinkFormatter: addFriendLinkFormatter, addFriendTextFormatter:addFriendTextFormatter, postDateFormatter:postDateFormatter, timestampFormatter: timestampFormatter}}}
......@@ -18,7 +18,7 @@ module.exports = (app) ->
messageStatusIDFormatter = (messageID) ->
return messageID + '-status'
# Format the post date
# Format the post date and make it a permanent link to the post.
postDateFormatter = (messageID) ->
#
# Parses message IDs in the following forms into separate groups for
......@@ -56,12 +56,22 @@ module.exports = (app) ->
humanTime = moment(timeOfPost).fromNow()
return "#{humanTime} "
return humanTime
else
# This should never happen and probably shows that some sort of corrupted date got through somehow.
return 'No date.'
# Permanent link formatter
permanentLinkFormatter = (messageID) ->
# Get the person handle
personHandleDelimeter = messageID.lastIndexOf('Z-')
personHandle = messageID.substr(personHandleDelimeter+2)
return "/person/#{personHandle}/post/#{messageID}"
# Format the post date
timestampFormatter = (messageID) ->
messageIDParserRegExp = /^(\d{9})?-?(\d{4}-\d{2}-\d{2}T\d{2}_\d{2}_\d{2}\.\d{3}Z)-?(.*)?/
......@@ -138,4 +148,4 @@ module.exports = (app) ->
# 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 'public', {messages: messages, __set: { formatters: {messageBodyIDFormatter: messageBodyIDFormatter, messageStatusIDFormatter: messageStatusIDFormatter, profileImagePathFormatter: profileImagePathFormatter, personFormatter:personFormatter, addFriendLinkFormatter: addFriendLinkFormatter, addFriendTextFormatter:addFriendTextFormatter, postDateFormatter:postDateFormatter, timestampFormatter: timestampFormatter}}}
response.render 'public', {messages: messages, __set: { formatters: {messageBodyIDFormatter: messageBodyIDFormatter, messageStatusIDFormatter: messageStatusIDFormatter, profileImagePathFormatter: profileImagePathFormatter, personFormatter:personFormatter, addFriendLinkFormatter: addFriendLinkFormatter, addFriendTextFormatter:addFriendTextFormatter, postDateFormatter:postDateFormatter, timestampFormatter: timestampFormatter, permanentLinkFormatter: permanentLinkFormatter}}}
<!doctype html>
<html lang='en'>
<head>
<title>Post</title>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width'>
<link rel='stylesheet' href='/css/public.css'>
<script type='text/javascript' src='/js/superagent.js'></script>
<script type='text/javascript' src='/js/moment.js'></script>
<script src="/js/set.js"></script>
<script src="/js/public.js"></script>
<script data-set-text='meta'></script>
<style type="text/css">
.displayNone
{
display:none;
}
.progress-spinner
{
display:inline;
width:16px;
vertical-align:top;
padding-top: 2px;
padding-right:5px;
}
</style>
</head>
<body>
<section id='public-timeline'>
<h1><span data-set-text='message.key postDateFormatter'>X time ago</span>, <span data-set-text='message.key personFormatter'>Person</span> wrote…</h1>
<!-- This recreates what we’re doing via JavaScript on the Cocoa client. -->
<!-- TODO: Evaluate using Set on the Cocoa client also. -->
<div id='messages' class='messages'>
<div class='message' data-set-attribute='id message.key' >
<div class='messageBody' data-set-attribute='id message.key messageBodyIDFormatter'>
<!-- <p class="timestamp" data-set-text='message.key'>Message timestamp</p> -->
<div class="image-and-body">
<img class="profileImage" data-set-attribute='src message.key profileImagePathFormatter'>
<div class="bodyText" data-set-text='html message.value'>Message body HTML</div>
<div class="meta"><span class='postDate' data-set-attribute='data-timestamp message.key timestampFormatter' data-set-text='message.key postDateFormatter'></span> by <span data-set-text='message.key personFormatter'></span> <a data-set-attribute='href message.key addFriendLinkFormatter' data-set-text='html message.key addFriendTextFormatter'></a></div>
</div>
</div>
<!-- <div class='messageStatus' data-set-attribute='id message.key messageStatusIDFormatter'></div>-->
</div>
</div>
<p>Return to <a href='/'>Everyone</a>.</p>
<p><small>Sent from <a href='https://forum.ind.ie/t/heartbeat-pre-alpha-release/740'>Heartbeat</a>. Aggregated by <a href='https://forum.ind.ie/t/pre-alpha-conceptual-design/25'>Waystone</a>.</small></p>
<section>
</body>
</html>
\ No newline at end of file
......@@ -40,7 +40,7 @@
<div class="image-and-body">
<img class="profileImage" data-set-attribute='src message.key profileImagePathFormatter'>
<div class="bodyText" data-set-text='html message.value'>Message body HTML</div>
<div class="meta"><span class='postDate' data-set-attribute='data-timestamp message.key timestampFormatter' data-set-text='message.key postDateFormatter'></span><span data-set-text='message.key personFormatter'></span> <a data-set-attribute='href message.key addFriendLinkFormatter' data-set-text='html message.key addFriendTextFormatter'></a></div>
<div class="meta"><a data-set-attribute='href message.key permanentLinkFormatter'><span class='postDate' data-set-attribute='data-timestamp message.key timestampFormatter' data-set-text='message.key postDateFormatter'></span></a> <span data-set-text='message.key personFormatter'></span> <a data-set-attribute='href message.key addFriendLinkFormatter' data-set-text='html message.key addFriendTextFormatter'></a></div>
</div>
</div>
<!-- <div class='messageStatus' data-set-attribute='id message.key messageStatusIDFormatter'></div>-->
......
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