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

Conversation timeline message sends and receives working.

parent 72ee6b85
......@@ -2,8 +2,6 @@
# All-Friends Timeline
#
# StreamWeaver = require '../../StreamWeaver'
moment = require 'moment'
module.exports = (app) ->
......@@ -133,4 +131,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 'all-friends', {messages: messages, __set: { formatters: {messageBodyIDFormatter: messageBodyIDFormatter, messageStatusIDFormatter: messageStatusIDFormatter, profileImagePathFormatter: profileImagePathFormatter, personFormatter:personFormatter, postDateFormatter: postDateFormatter, timestampFormatter: timestampFormatter}}}
response.render 'all-friends', {messages: messages, __set: { formatters: {messageBodyIDFormatter: messageBodyIDFormatter, messageStatusIDFormatter: messageStatusIDFormatter, profileImagePathFormatter: profileImagePathFormatter, personFormatter: personFormatter, postDateFormatter: postDateFormatter, timestampFormatter: timestampFormatter}}}
......@@ -90,7 +90,6 @@ module.exports = (app) ->
personFormatter = (messageID) ->
personHandleDelimeter = messageID.lastIndexOf('Z-')
profileImagePath = ''
if personHandleDelimeter != -1
# From someone else
personHandle = messageID.substr(personHandleDelimeter+2)
......@@ -156,7 +155,4 @@ module.exports = (app) ->
# TODO: Add the formatters to the messages themselves so we don’t have to duplicate them on the client.
textWillChange = (node, newText) ->
console.log "About to modify: " + node + " text: " + newText
response.render 'conversation', {personsAccountHandle: person, personsName: personsName, messages: messages, __set: { textWillChange: textWillChange, formatters: {messageBodyIDFormatter: messageBodyIDFormatter, messageStatusIDFormatter: messageStatusIDFormatter, profileImagePathFormatter: profileImagePathFormatter, personFormatter: personFormatter, postDateFormatter:postDateFormatter, timestampFormatter: timestampFormatter}}}
response.render 'conversation', {personsAccountHandle: person, personsName: personsName, messages: messages, __set: { formatters: {messageBodyIDFormatter: messageBodyIDFormatter, messageStatusIDFormatter: messageStatusIDFormatter, profileImagePathFormatter: profileImagePathFormatter, personFormatter: personFormatter, postDateFormatter:postDateFormatter, timestampFormatter: timestampFormatter}}}
......@@ -8,6 +8,7 @@
<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/conversation.js'></script>
<script type='text/javascript' data-set-text='meta'></script>
</head>
......
......@@ -56,15 +56,13 @@ window.addEventListener('load', function(){
var firstMessage = messages.firstElementChild;
var newestPostID = 0;
if (firstMessage != null)
{
newestPostID = messages.firstElementChild.getAttribute('id');
if (firstMessage != null) {
newestPostID = firstMessage.getAttribute('id');
}
// console.log('Getting post after ' + newestPostID)
// 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/allfriends/'+newestPostID)
.end(function(error, posts) {
......@@ -104,6 +102,7 @@ window.addEventListener('load', function(){
div.innerHTML = repeaterNodeHTML;
// Insert new items at the beginning.
messages.insertBefore(div, messages.firstElementChild);
// messages.innerHTML = repeaterNodeHTML + messages.innerHTML;
......@@ -226,7 +225,7 @@ window.addEventListener('load', function(){
}
// Update the repeater node
set(repeaterNode, {messages: posts})
set(repeaterNode, {messages: posts});
});
// Update all the message clocks
......
......@@ -20,15 +20,49 @@ window.addEventListener('load', function(){
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};
mutationObserver.observe(messages, mutationObserverOptions);
//
// Poll every two seconds for new messages.
//
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 lastMessage = messages.lastElementChild;
// The latest message is at the bottom for conversation-style timelines.
var newestPostID = 0
var lastMessage = messages.lastElementChild
if (lastMessage != null) {
newestPostID = lastMessage.getAttribute('id');
......@@ -40,8 +74,6 @@ window.addEventListener('load', function(){
console.log(person);
// 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/'+person+'/'+newestPostID)
.end(function(error, posts) {
......@@ -51,7 +83,7 @@ window.addEventListener('load', function(){
// (I should pave this cowpath: https://source.ind.ie/project/set/issues/4)
//
posts = JSON.parse(posts.text);
console.log(posts);
// console.log(posts);
if (posts.length == 0){
console.log('No new posts.');
......@@ -82,7 +114,7 @@ window.addEventListener('load', function(){
div.innerHTML = repeaterNodeHTML;
// Insert new items at the end.
insertAfter(messages.firstElementChild, div);
insertAfter(messages.lastElementChild, div);
// messages.innerHTML = repeaterNodeHTML + messages.innerHTML;
......@@ -206,9 +238,7 @@ window.addEventListener('load', function(){
}
// Update the repeater node
set(repeaterNode, {messages: posts}, function(){
console.log("Set is done!");
})
set(repeaterNode, {messages: posts});
});
// Update all the message clocks
......
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