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

Fixed the Private timeline.

parent a7ee70f4
......@@ -148,14 +148,10 @@ class PulseEventPipe
# TODO: Currently copied/pasted from PulseEventHandler in Waystone.
# ===== Refactor.
#
console.log 'Local index updated:'
console.log event
messageFileName = event.data.name
messageRepository = event.data.repo
console.log "Message file name: #{messageFileName}"
console.log "Message repository: #{messageRepository}"
console.log "ℹ️ [Local Index Update] #{messageFileName} (#{messageRepository})."
# Data from message file name
fileNameOfChangedFile = messageFileName.substr messageFileName.lastIndexOf('/')+1
......@@ -170,22 +166,23 @@ class PulseEventPipe
messageTimestamp = messageFileName.substring 0, messageFileName.indexOf('/')
messageID = "#{messageTimestamp}-#{person}"
console.log "Person: #{person}"
console.log "Message type: #{messageType}"
console.log "Message time stamp: #{messageTimestamp}"
console.log "Message ID: #{messageID}"
console.log "File name of changed file: #{fileNameOfChangedFile}"
console.log "ℹ️ [Pulse Event Pipe] Parsed LocalIndexUpdated event:"
console.log "\tPerson: >#{person}<"
console.log "\tMessage type: >#{messageType}<"
console.log "\tMessage time stamp: >#{messageTimestamp}<"
console.log "\tMessage ID: >#{messageID}<"
console.log "\tFile name of changed file: >#{fileNameOfChangedFile}<"
toAllFriendsMessageType = "#{person}-to-all-friends"
friendsCached = @streamWeaver.friendsCached
console.log "Checking if repository is #{toAllFriendsMessageType} or in:"
console.log "\nChecking if repository is #{toAllFriendsMessageType} or in:"
console.log friendsCached
messageFromFriend = false
for friend in friendsCached
console.log "Checking if #{person} == #{friend}…"
console.log "Checking if >#{person}< == >#{friend}<…"
if friend == person
console.log "Message received from friend"
messageFromFriend = true
......
......@@ -2,8 +2,6 @@
# Private Timeline
#
# StreamWeaver = require '../../StreamWeaver'
moment = require 'moment'
module.exports = (app) ->
......@@ -81,4 +79,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 'private', {messages: messages, __set: { formatters: {messageBodyIDFormatter: messageBodyIDFormatter, messageStatusIDFormatter: messageStatusIDFormatter, postDateFormatter:postDateFormatter}}}
response.render 'private', {postDateClassName: 'postDate', messages: messages, __set: { formatters: {messageBodyIDFormatter: messageBodyIDFormatter, messageStatusIDFormatter: messageStatusIDFormatter, postDateFormatter:postDateFormatter}}}
......@@ -7,17 +7,57 @@ window.addEventListener('load', function(){
return;
}
// Check if there are no messages to begin with, remove the pre-rendered repeater.
// (It’s ID will be different if there are.)
var messageRepeater = document.getElementById('messageRepeater');
if (messageRepeater != null)
{
messageRepeater.parentNode.removeChild(messageRepeater);
}
//
// Listen for mutations on messages so that we can intelligently respond to them.
// e.g., scroll to show a message when one arrives.
//
var mutationObserver = new MutationObserver(function(mutations){
mutations.forEach(function(mutation){
if(mutation.type == "childList") {
var addedNodes = mutation.addedNodes;
var forEach = Array.prototype.forEach;
forEach.call(addedNodes, function(node){
// Scroll the added node into view.
zenscroll.intoView(node, 750);
});
}
});
});
// Currently, we only care when the child list changes.
var mutationObserverOptions = {childList: true};
var messages = document.getElementById('messages');
mutationObserver.observe(messages, mutationObserverOptions);
setInterval(function(){
// console.log("Polling server for new public posts…")
//
// Get the ID of the last message loaded so we can use this
// to poll for new messages that have been received since the
// timeline initially loaded. Compensate for an empty timeline
// with no messages.
//
var messages = document.getElementById('messages');
var newestPostID = messages.firstElementChild.getAttribute('id')
var firstMessage = messages.firstElementChild;
// console.log('Getting post after ' + newestPostID)
var newestPostID = 0;
if (firstMessage != null) {
newestPostID = firstMessage.getAttribute('id');
}
// 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:42003/timeline/posts-after/private/'+newestPostID)
.end(function(error, posts) {
......@@ -34,6 +74,12 @@ window.addEventListener('load', function(){
return;
}
// Make sure that the notice is hidden and that the main section is showing.
// (Set can’t handle this automatically as we are not running it on the
// entire document but only on the delta repeat block below for performance reasons.)
document.getElementById('notice').style.display = 'none';
document.getElementById('messages').style.display = 'block';
var repeaterNodeHTML =
" <div style='background-color: rgb(200, 50, 50, 0.5);' class='message' data-set-repeat='message messages' data-set-attribute='id message.key' >"
+ " <div class='messageBody' data-set-attribute='id message.key messageBodyIDFormatter'>"
......@@ -51,6 +97,7 @@ window.addEventListener('load', function(){
div.innerHTML = repeaterNodeHTML;
// Insert new items at the beginning.
messages.insertBefore(div, messages.firstElementChild);
// messages.innerHTML = repeaterNodeHTML + messages.innerHTML;
......
......@@ -8,8 +8,9 @@
<script type='text/javascript' src='/js/superagent.js'></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/zenscroll.min.js'></script>
<script type='text/javascript' src='/js/private.js'></script>
<script data-set-text='meta'></script>
<script type='text/javascript' data-set-text='meta'></script>
</head>
<body>
<section id='public-timeline'>
......@@ -28,7 +29,13 @@
<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 class='postDate' data-set-attribute='data-timestamp message.key' data-set-text='message.key postDateFormatter'></span></div>
<!--
Setting the class name dynamically (although it is static), so that we don’t have to
check for null in validation code (we can be sure that if the class exists, it belongs
to a rendered node, not to this template repeater.) This might be a cowpath to pave in
Set itself.
-->
<div class='meta'><span data-set-attribute='class postDateClassName; data-timestamp message.key' data-set-text='message.key postDateFormatter'></span></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