diff options
author | Valérian Saliou <valerian@valeriansaliou.name> | 2014-05-30 17:40:43 +0400 |
---|---|---|
committer | Valérian Saliou <valerian@valeriansaliou.name> | 2014-05-30 17:40:43 +0400 |
commit | e20423cc6d58b832cc27b89903e0903eb2fff0c0 (patch) | |
tree | 4076c4fb3e16fea676edbf7ff6b8ad63344be802 /app | |
parent | d887ceb0defe71e82148f4c775de032229c2ead0 (diff) |
fixes #470
Diffstat (limited to 'app')
-rw-r--r-- | app/javascripts/mam.js | 124 | ||||
-rw-r--r-- | app/javascripts/markers.js | 46 | ||||
-rw-r--r-- | app/javascripts/message.js | 4 |
3 files changed, 132 insertions, 42 deletions
diff --git a/app/javascripts/mam.js b/app/javascripts/mam.js index 64856795..0921d236 100644 --- a/app/javascripts/mam.js +++ b/app/javascripts/mam.js @@ -35,6 +35,7 @@ var MAM = (function () { self.map_reqs = {}; self.map_pending = {}; self.map_states = {}; + self.map_messages = {}; self.msg_queue = {}; @@ -311,11 +312,16 @@ var MAM = (function () { if(c_message[0]) { // Re-build a proper JSJaC message stanza var message = JSJaCPacket.wrapNode(c_message[0]); + var message_node = message.getNode(); // Check message type var type = message.getType() || 'chat'; if(type == 'chat') { + // Display function + var c_display_fn; + var c_display_msg_bool = false; + // Read message data var xid = Common.bareXID(Common.getStanzaFrom(message)); var id = message.getID(); @@ -331,50 +337,100 @@ var MAM = (function () { var hash = hex_md5(xid); var body = message.getBody(); - // Read delay (required since we deal w/ a past message!) - var time, stamp; - var delay = c_delay.attr('stamp'); + // Content message? + if(body) { + // Read delay (required since we deal w/ a past message!) + var time, stamp; + var delay = c_delay.attr('stamp'); - if(delay) { - time = DateUtils.relative(delay); - stamp = DateUtils.extractStamp(Date.jab2date(delay)); - } - - // Last-minute checks before display - if(time && stamp && body) { - var mam_chunk_path = '#' + hash + ' .mam-chunk'; - - // No chat auto-scroll? - var no_scroll = Common.exists(mam_chunk_path); - - // Select the custom target - var c_target_sel = function() { - return $(mam_chunk_path).filter(function() { - return $(this).attr('data-start') <= stamp && $(this).attr('data-end') >= stamp; - }).filter(':first'); - }; - - // Display the message in that target - var c_msg_display = function() { - Message.display(type, from_xid, hash, b_name.htmlEnc(), body, time, stamp, 'old-message', true, null, mode, null, c_target_sel(), no_scroll); - }; - - // Hack: do not display the message in case we would duplicate it w/ current session messages - // only used when initiating a new chat, avoids collisions - if(!(xid in self.map_states) && $('#' + hash).find('.one-line.user-message:last').text() == body) { - return; + if(delay) { + time = DateUtils.relative(delay); + stamp = DateUtils.extractStamp(Date.jab2date(delay)); } + + // Last-minute checks before display + if(time && stamp) { + var mam_chunk_path = '#' + hash + ' .mam-chunk'; + + // Markable message? + var is_markable = Markers.hasRequestMarker(message_node); + + // No chat auto-scroll? + var no_scroll = Common.exists(mam_chunk_path); + + // Select the custom target + var c_target_sel = function() { + return $(mam_chunk_path).filter(function() { + return $(this).attr('data-start') <= stamp && $(this).attr('data-end') >= stamp; + }).filter(':first'); + }; - if(c_target_sel().size()) { // Display the message in that target - c_msg_display(); + c_display_fn = function() { + // Display message + Message.display( + type, + from_xid, + hash, + b_name.htmlEnc(), + body, + time, + stamp, + 'old-message', + true, + null, + mode, + id + '-mam', + c_target_sel(), + no_scroll, + undefined, + undefined, + undefined, + is_markable + ); + + self.map_messages[id] = 1; + }; + + c_display_msg_bool = c_target_sel().size() ? true : false; + + // Hack: do not display the message in case we would duplicate it w/ current session messages + // only used when initiating a new chat, avoids collisions + if(!(xid in self.map_states) && $('#' + hash).find('.one-line.user-message:last').text() == body) { + return; + } + } + } else if(Markers.hasResponseMarker(message_node)) { + // Marked message? (by other party) + if(mode == 'him') { + var marked_message_id = Markers.getMessageID(message_node); + + c_display_fn = function() { + var is_mam_marker = true; + + Markers.handle( + from_xid, + message_node, + is_mam_marker + ); + }; + + c_display_msg_bool = (self.map_messages[marked_message_id] === 1) ? true : false; + } + } + + // Display message? + if(typeof c_display_fn == 'function') { + if(c_display_msg_bool === true) { + // Display message now + c_display_fn(); } else { // Delay display (we may not have received the MAM reply ATM) if(typeof self.msg_queue[xid] != 'object') { self.msg_queue[xid] = []; } - self.msg_queue[xid].push(c_msg_display); + self.msg_queue[xid].push(c_display_fn); } } } diff --git a/app/javascripts/markers.js b/app/javascripts/markers.js index 9f590e5a..d314f28b 100644 --- a/app/javascripts/markers.js +++ b/app/javascripts/markers.js @@ -34,7 +34,7 @@ var Markers = (function () { /** - * Return whether entity supports message markers + * Returns whether entity supports message markers * @public * @param {string} xid * @return {boolean} @@ -55,7 +55,7 @@ var Markers = (function () { /** - * Return whether request message is marked or not + * Returns whether request message is marked or not * @public * @param {object} message * @return {boolean} @@ -76,7 +76,7 @@ var Markers = (function () { /** - * Return whether response message is marked or not + * Returns whether response message is marked or not * @public * @param {object} message * @return {boolean} @@ -109,7 +109,28 @@ var Markers = (function () { /** - * Mark a message + * Returns the marked message ID + * @public + * @param {object} message + * @return {boolean} + */ + self.getMessageID = function(message) { + + var message_id = null; + + try { + message_id = $(message).find('[xmlns="' + NS_URN_MARKERS + '"]').attr('id'); + } catch(e) { + Console.error('Markers.getMessageID', e); + } finally { + return message_id; + } + + }; + + + /** + * Marks a message * @public * @param {object} message * @return {undefined} @@ -128,7 +149,7 @@ var Markers = (function () { /** - * Change received message status (once received or read) + * Changes received message status (once received or read) * @public * @param {string} mark_type * @param {object} message_id @@ -145,6 +166,8 @@ var Markers = (function () { message_sel.attr('data-mark', mark_type); var message = new JSJaCMessage(); + + message.setType('chat'); message.setTo(to); message.appendNode(mark_type, { @@ -163,7 +186,7 @@ var Markers = (function () { /** - * Handle marker change coming from Carbons + * Handles marker change coming from Carbons * @public * @param {string} message * @return {undefined} @@ -217,10 +240,12 @@ var Markers = (function () { /** * Handles a marked message * @public + * @param {string} from * @param {object} message + * @param {boolean} is_mam_marker * @return {undefined} */ - self.handle = function(from, message) { + self.handle = function(from, message, is_mam_marker) { try { var xid = Common.bareXID(from); @@ -229,9 +254,14 @@ var Markers = (function () { if(marker_sel.size()) { var mark_type = marker_sel.prop('tagName').toLowerCase(); var mark_message_id = marker_sel.attr('id'); - var mark_valid = false; + + if(is_mam_marker === true) { + mark_message_id += '-mam'; + } // Filter allowed markers + var mark_valid = false; + switch(mark_type) { case self.MARK_TYPE_RECEIVED: case self.MARK_TYPE_DISPLAYED: diff --git a/app/javascripts/message.js b/app/javascripts/message.js index 34993450..d6388b8a 100644 --- a/app/javascripts/message.js +++ b/app/javascripts/message.js @@ -1839,6 +1839,10 @@ var Message = (function () { * @param {string} id * @param {object} c_target_sel * @param {boolean} no_scroll + * @param {boolean} is_edited + * @param {number} edit_count + * @param {boolean} is_storable + * @param {boolean} is_markable * @return {object} */ self.display = function(type, xid, hash, name, body, time, stamp, message_type, html_escape, nick_quote, mode, id, c_target_sel, no_scroll, is_edited, edit_count, is_storable, is_markable) { |