Adds dates and add friend icons on posts for the Waystone public timeline...

Adds dates and add friend icons on posts for the Waystone public timeline (Everyone timeline). Closes #58.
parent dadc5ac4
......@@ -114,7 +114,7 @@ class PulseEventHandler
# Calculate the message ID
# (It’s the Heartbeat timestamp (sans local timeline order bit at the front) + '-<personname>')
messageTimestamp = messageFileName.substring messageFileName.indexOf('-')+1, messageFileName.indexOf('/')
messageTimestamp = messageFileName.substring 0, messageFileName.indexOf('/')
messageID = "#{messageTimestamp}-#{person}"
messageNameSlug = messageFileName.substr(messageFileName.indexOf('__'))
......
......@@ -2,6 +2,8 @@
# Waystone Public Timeline
#
moment = require 'moment'
PublicTimelineWeaver = require '../../PublicTimelineWeaver'
module.exports = (app) ->
......@@ -16,6 +18,92 @@ module.exports = (app) ->
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 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 " by #{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)
......@@ -33,4 +121,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}}}
response.render 'public', {messages: messages, __set: { formatters: {messageBodyIDFormatter: messageBodyIDFormatter, messageStatusIDFormatter: messageStatusIDFormatter, profileImagePathFormatter: profileImagePathFormatter, personFormatter:personFormatter, addFriendLinkFormatter: addFriendLinkFormatter, addFriendTextFormatter:addFriendTextFormatter, postDateFormatter:postDateFormatter}}}
......@@ -66,3 +66,22 @@ img
margin-right: 36px;
}
.meta
{
font-size:small;
color: #999;
font-style: italic;
}
.meta a
{
color: #999;
}
.add-friend-icon
{
width:18px;
opacity: 0.4;
display:inline;
vertical-align: middle;
}
......@@ -24,6 +24,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 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>
</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