Browse Source

fix mentions thing in htmlFormatMsg()

master
Simon Grim 10 years ago
parent
commit
29e4130e72
  1. 4
      js/interface_common.js
  2. 2
      js/options.js
  3. 38
      js/twister_formatpost.js

4
js/interface_common.js

@ -587,7 +587,7 @@ function posPostPreview(event) {
- postPreview.css('padding-left') - postPreview.css('padding-right')); - postPreview.css('padding-left') - postPreview.css('padding-right'));
} }
if (textArea[0].value.length) if (textArea[0].value.length)
postPreview.html(htmlFormatMsg(textArea[0].value, [])).show(); postPreview.html(htmlFormatMsg(textArea[0].value).html).show();
else else
postPreview.hide(); postPreview.hide();
textArea.before(postPreview); textArea.before(postPreview);
@ -698,7 +698,7 @@ function replyTextInput(event) {
if ($.Options.postPreview.val) { if ($.Options.postPreview.val) {
if (textArea[0].value.length) if (textArea[0].value.length)
textAreaForm.find('#post-preview').html(htmlFormatMsg(textArea[0].value, [])).show(); textAreaForm.find('#post-preview').html(htmlFormatMsg(textArea[0].value).html).show();
else else
textAreaForm.find('#post-preview').html('').hide(); textAreaForm.find('#post-preview').html('').hide();
} }

2
js/options.js

@ -373,7 +373,7 @@ function tickOptionsPostPreview() {
var imgPreviewCont = elem.find('.preview-container'); var imgPreviewCont = elem.find('.preview-container');
elem.children().first().html(htmlFormatMsg( elem.children().first().html(htmlFormatMsg(
polyglot.t('post_preview_dummy', {logo: '/img/twister_mini.png', site: 'http://twister.net.co'}), [])); polyglot.t('post_preview_dummy', {logo: '/img/twister_mini.png', site: 'http://twister.net.co'})).html);
if ($.Options.displayPreview.val === 'enable') { if ($.Options.displayPreview.val === 'enable') {
imgPreviewCont.empty(); imgPreviewCont.empty();

38
js/twister_formatpost.js

@ -110,20 +110,26 @@ function postToElem(post, kind, promoted) {
getAvatar(username, elem.find('.avatar')); getAvatar(username, elem.find('.avatar'));
elem.find('.post-info-time').text(timeGmtToText(t)).attr('title', timeSincePost(t)); elem.find('.post-info-time').text(timeGmtToText(t)).attr('title', timeSincePost(t));
var mentions = []; msg = htmlFormatMsg(msg);
elem.find('.post-text').html(htmlFormatMsg(msg, mentions)); elem.find('.post-text').html(msg.html);
postData.attr('data-text-mentions', mentions); postData.attr('data-text-mentions', msg.mentions.join()); // FIXME no idea why do we need this attribute since we don't use it but use data-reply-to instead
var replyTo = ''; if (username !== defaultScreenName) {
if (username !== defaultScreenName) if (msg.mentions.indexOf(username) === -1)
replyTo += '@' + username + ' '; msg.mentions.splice(0, 0, username);
for (var i = 0; i < mentions.length; i++) { } else {
if (mentions[i] !== username && mentions[i] !== defaultScreenName) var i = msg.mentions.indexOf(defaultScreenName);
replyTo += '@' + mentions[i] + ' '; if (i !== -1)
msg.mentions.splice(i, 1);
} }
if (msg.mentions.length)
var replyTo = '@' + msg.mentions.join(' @') + ' ';
else
var replyTo = '';
var postTextArea = elem.find('.post-area-new textarea'); var postTextArea = elem.find('.post-area-new textarea');
postTextArea.attr('data-reply-to', replyTo); postTextArea.attr('data-reply-to', replyTo);
if (!defaultScreenName) if (!defaultScreenName)
postTextArea.attr('placeholder', polyglot.t('You have to log in to post replies.')); postTextArea.attr('placeholder', polyglot.t('You have to log in to post replies.'));
else else
@ -208,7 +214,7 @@ function dmDataToSnippetItem(dmData, remoteUser) {
getGroupChatName( remoteUser, dmItem.find("a.post-info-name") ); getGroupChatName( remoteUser, dmItem.find("a.post-info-name") );
else else
getFullname( remoteUser, dmItem.find("a.post-info-name") ); getFullname( remoteUser, dmItem.find("a.post-info-name") );
dmItem.find(".post-text").html(htmlFormatMsg(dmData.text, [])); dmItem.find(".post-text").html(htmlFormatMsg(dmData.text).html);
dmItem.find(".post-info-time").text(timeGmtToText(dmData.time)).attr("title",timeSincePost(dmData.time)); dmItem.find(".post-info-time").text(timeGmtToText(dmData.time)).attr("title",timeSincePost(dmData.time));
return dmItem; return dmItem;
@ -226,14 +232,13 @@ function dmDataToConversationItem(dmData, localUser, remoteUser) {
getAvatar(from, dmItem.find(".post-photo").find("img") ); getAvatar(from, dmItem.find(".post-photo").find("img") );
dmItem.find(".post-info-time").text(timeGmtToText(dmData.time)).attr("title",timeSincePost(dmData.time)); dmItem.find(".post-info-time").text(timeGmtToText(dmData.time)).attr("title",timeSincePost(dmData.time));
setPostInfoSent(from,dmData.k,dmItem.find('.post-info-sent')); setPostInfoSent(from,dmData.k,dmItem.find('.post-info-sent'));
var mentions = []; dmItem.find('.post-text').html(htmlFormatMsg(dmData.text).html);
dmItem.find('.post-text').html(htmlFormatMsg(dmData.text, mentions));
return dmItem; return dmItem;
} }
// convert message text to html, featuring @users and links formating. // convert message text to html, featuring @users and links formating.
function htmlFormatMsg(msg, mentions) { function htmlFormatMsg(msg) {
// TODO: add options for emotions; msg = $.emotions(msg); // TODO: add options for emotions; msg = $.emotions(msg);
// TODO make markup optionally mutable ? // TODO make markup optionally mutable ?
@ -534,6 +539,7 @@ function htmlFormatMsg(msg, mentions) {
+ whiteSpaces; + whiteSpaces;
var stopCharsMarkout = '/\\*~_-`.,:;?!%+=&\'"[](){}^|«»…\u201C\u201D\u2026\u2014\u4E00\u3002\uFF0C\uFF1A\uFF1F\uFF01\u3010\u3011\u2047\u2048\u2049'; var stopCharsMarkout = '/\\*~_-`.,:;?!%+=&\'"[](){}^|«»…\u201C\u201D\u2026\u2014\u4E00\u3002\uFF0C\uFF1A\uFF1F\uFF01\u3010\u3011\u2047\u2048\u2049';
var i, j, k, str; var i, j, k, str;
var mentions = [];
msg = {str: escapeHtmlEntities(msg), htmlEntities: []}; msg = {str: escapeHtmlEntities(msg), htmlEntities: []};
@ -663,7 +669,7 @@ function htmlFormatMsg(msg, mentions) {
break; break;
} }
str = msg.str.slice(i + 1, j).toLowerCase(); str = msg.str.slice(i + 1, j).toLowerCase();
mentions.push(str); // FIXME mentions.push(str);
msg = msgAddHtmlEntity(msg, i, i + str.length + 1, msg = msgAddHtmlEntity(msg, i, i + str.length + 1,
newHtmlEntityLink(_htmlFormatMsgLinkTemplateUser, newHtmlEntityLink(_htmlFormatMsgLinkTemplateUser,
$.MAL.userUrl(str), '@' + str) $.MAL.userUrl(str), '@' + str)
@ -713,7 +719,7 @@ function htmlFormatMsg(msg, mentions) {
if ($.Options.displayLineFeeds.val === 'enable') if ($.Options.displayLineFeeds.val === 'enable')
msg = msg.replace(/\n/g, '<br />'); msg = msg.replace(/\n/g, '<br />');
return msg; return {html: msg, mentions: mentions};
} }
function proxyURL(url) { function proxyURL(url) {

Loading…
Cancel
Save