Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Ind.ie Projects
Heartbeat Node
Commits
e18243fe
Unverified
Commit
e18243fe
authored
Aug 25, 2015
by
Aral Balkan
Browse files
Fixed regression in walk.coffee. All friends timeline now showing sent messages correctly.
parent
afa7e441
Changes
4
Hide whitespace changes
Inline
Side-by-side
private/routes/all-friends.coffee
View file @
e18243fe
...
...
@@ -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
...
...
private/views/all-friends.html
View file @
e18243fe
...
...
@@ -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'
>
...
...
private/views/js/all-friends.js
View file @
e18243fe
...
...
@@ -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
);
});
walk.coffee
View file @
e18243fe
...
...
@@ -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
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment