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

Fixed regression in walk.coffee. All friends timeline now showing sent messages correctly.

parent afa7e441
......@@ -71,7 +71,6 @@ module.exports = (app) ->
personFormatter = (messageID) ->
personHandleDelimeter = messageID.lastIndexOf('Z-')
profileImagePath = ''
if personHandleDelimeter != -1
# From someone else
personHandle = messageID.substr(personHandleDelimeter+2)
......@@ -86,7 +85,6 @@ module.exports = (app) ->
addFriendLinkFormatter = (messageID) ->
personHandleDelimeter = messageID.lastIndexOf('Z-')
profileImagePath = ''
if personHandleDelimeter != -1
# From someone else
personHandle = messageID.substr(personHandleDelimeter+2)
......@@ -101,7 +99,6 @@ module.exports = (app) ->
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
......
......@@ -6,9 +6,10 @@
<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>
<script type='text/javascript' src='/js/moment.js'></script>
<script type='text/javascript' src='/js/set.js'></script>
<script type='text/javascript' src='/js/all-friends.js'></script>
<script type='text/javascript' data-set-text='meta'></script>
</head>
<body>
<section id='public-timeline'>
......
......@@ -19,7 +19,7 @@ window.addEventListener('load', function(){
// TODO: Do not hard code this URL.
// TODO: Fix Set injectData so we don’t have to use this metadata injection workaround.
superagent
.get('http://127.0.0.1/posts-after/'+newestPostID+'/all-friends')
.get('http://127.0.0.1:42003/posts-after/'+newestPostID+'/allfriends')
.end(function(error, posts) {
//
// Optimisation: clone the repeater seed node and only apply the set
......@@ -40,6 +40,7 @@ window.addEventListener('load', function(){
+ " <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' data-set-text='message.key postDateFormatter'></span></div>"
+ " </div>"
+ " </div>"
+ " </div>";
......@@ -67,14 +68,136 @@ window.addEventListener('load', function(){
return messageID + "-status";
}
set.format['postDateFormatter'] = function (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
//
var messageIDParserRegExp = /^(\d{9})?-?(\d{4}-\d{2}-\d{2}T\d{2}_\d{2}_\d{2}\.\d{3}Z)-?(.*)?/;
var matches = messageID.match(messageIDParserRegExp);
if (matches != null){
var depracatedOptionalMessageClock = matches[1];
var timestamp = matches[2];
var optionalAccountHandle = matches[3];
// Desearialise the timestamp.
timestamp = timestamp.replace (/_/g, ':');
var now = new Date();
var timeOfPost = new Date(timestamp);
// to secs -> mins -> hours -> days
var timeSincePostInDays = (now - timeOfPost)/1000/60/60/24;
var 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
set.format['personFormatter'] = function (messageID) {
var personHandleDelimeter = messageID.lastIndexOf('Z-');
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 '';
}
}
set.format['addFriendLinkFormatter'] = function (messageID) {
personHandleDelimeter = messageID.lastIndexOf('Z-');
if (personHandleDelimeter != -1){
// From someone else
var personHandle = messageID.substr(personHandleDelimeter+2);
var addFriendLink = "indie://friend/#{personHandle}";
return addFriendLink;
}
else {
// This is the person themselves, no need to display a friend link.
return '';
}
}
set.format['addFriendTextFormatter'] = function (messageID) {
var personHandleDelimeter = messageID.lastIndexOf('Z-');
var 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
set.format['profileImagePathFormatter'] = function (messageID) {
var personHandle = messageID.substr(messageID.lastIndexOf('Z-')+2);
var profileImagePath = "/public/"+personHandle+"/about/me.jpg";
console.log("Formatting profile image for " + messageID)
var personHandleDelimeter = messageID.lastIndexOf('Z-');
var profileImagePath = '';
if (personHandleDelimeter != -1) {
// From someone else
var personHandle = messageID.substr(personHandleDelimeter+2);
console.log("Person handle for message: "+personHandle+".");
profileImagePath = "http://127.0.0.1:42003/all-friends/from/"+personHandle+"/about/me.jpg";
}
else {
// From you
console.log("Message is from you.");
profileImagePath = "http://localhost:42000/about/me.jpg";
}
return profileImagePath;
}
// Update the repeater node
set(repeaterNode, {messages: posts})
});
}, 5000);
// Update all the message clocks
var postDates = document.getElementsByClassName('postDate');
for (var i = 0; i < postDates.length; i++)
{
var postDate = postDates[i];
var timestamp = (postDate.getAttribute('data-timestamp')).replace (/_/g, ':');
var timeOfPost = new Date(timestamp);
var humanTime = moment(timeOfPost).fromNow();
postDate.innerHTML = humanTime + " ";
}
}, 1000);
});
......@@ -9,10 +9,10 @@ Promise = require 'thrush'
walkFiles = (directory) ->
results = []
(readdirAsync directory).map (file) ->
(fs.readdirAsync directory).map (file) ->
file = path.join directory, file
statAsync file
fs.statAsync file
.then (stat) ->
if stat.isFile()
......@@ -29,10 +29,10 @@ walkFiles = (directory) ->
walkFolders = (directory) ->
results = []
(readdirAsync directory).map (file) ->
(fs.readdirAsync directory).map (file) ->
file = path.join directory, file
statAsync file
fs.statAsync file
.then (stat) ->
if stat.isFile()
......
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