public/js/conversation.js
// Constructs new DOM element from a message payload
Constructs new DOM element from a message payload
Constructs new DOM element from a message payload
function buildMessageDomElements(newPayload, isUser) {
    var textArray = isUser ? newPayload.input.text : newPayload.output.text;
    if (Object.prototype.toString.call( textArray ) !== '[object Array]') {
      textArray = [textArray];
    }
    var messageArray = [];
    textArray.forEach(function(currentText) {
      if (currentText) {
        var outputText = currentText;
        if (currentText.listing_name) {
          outputText = currentText.listing_name + ': ' +
            currentText.text
        }
        var messageJson = {
          'tagName': 'div',
          'classNames': ['segments'],
          'children': [{
            'tagName': 'div',
            'classNames': [(isUser ? 'from-user' : 'from-watson'), 'latest', ((messageArray.length === 0) ? 'top' : 'sub')],
            'children': [{
              'tagName': 'div',
              'classNames': ['message-inner'],
              'children': [{
                'tagName': 'p',
                'text': outputText
              }]
            }]
          }]
        };
        messageArray.push(Common.buildDomElement(messageJson));
      }
    });
    return messageArray;
  }
function buildMessageDomElements ( newPayload , isUser ) { var textArray = isUser ? newPayload . input . text : newPayload . output . text ; if ( Object . prototype . toString . call ( textArray ) !== '[object Array]' ) { textArray = [ textArray ] ; } var messageArray = [ ] ; textArray . forEach ( function ( currentText ) { if ( currentText ) { var outputText = currentText ; if ( currentText . listing_name ) { outputText = currentText . listing_name + ': ' + currentText . text } var messageJson = { 'tagName' : 'div' , 'classNames' : [ 'segments' ] , 'children' : [ { 'tagName' : 'div' , 'classNames' : [ ( isUser ? 'from-user' : 'from-watson' ) , 'latest' , ( ( messageArray . length === 0 ) ? 'top' : 'sub' ) ] , 'children' : [ { 'tagName' : 'div' , 'classNames' : [ 'message-inner' ] , 'children' : [ { 'tagName' : 'p' , 'text' : outputText } ] } ] } ] } ; messageArray . push ( Common . buildDomElement ( messageJson ) ) ; } } ) ; return messageArray ; }
Constructs new DOM element from a message payload
Constructs new DOM element from a message payload
// Check to see if we've received AirBnb data. // If so, output the listing names and review text // <div class='segments'> // <div class='from-user/from-watson latest'> // <div class='message-inner'> // <p>{messageText}</p>