diff options
author | Nicolás Reynolds <fauno@endefensadelsl.org> | 2015-06-11 02:23:11 +0300 |
---|---|---|
committer | Nicolás Reynolds <fauno@endefensadelsl.org> | 2015-06-11 02:32:34 +0300 |
commit | 1ecec5547964316bbaa2966e48e902e9c2621285 (patch) | |
tree | 8bc4d6622441a053ec7563acdb4b47393cffad37 | |
parent | 4a2730193aa634f876794d2bd959cfdc94a45871 (diff) |
Use the resource when receiving a message from an anonymous account
I realized that the nickname option for anonymous accounts only applies
to MUCs. The nickname is sent with every message as per XEP-0172
suggestion but Jappix Desktop nor Pidgin set the nickname using this
method, making the UUID the visible name.
The only part of the full JID that's modifiable for anonymous accounts
is the resource, so this patch checks if the JID is anonymous (the
username is an UUID) and if so, uses the resource.
-rw-r--r-- | app/javascripts/message.js | 2 | ||||
-rw-r--r-- | app/javascripts/name.js | 58 |
2 files changed, 39 insertions, 21 deletions
diff --git a/app/javascripts/message.js b/app/javascripts/message.js index ec979d65..8374ab81 100644 --- a/app/javascripts/message.js +++ b/app/javascripts/message.js @@ -591,7 +591,9 @@ var Message = (function () { // It does not come from a groupchat user, get the full name if(!is_groupchat_user) { + if (!Name.buddyIsAnonymous(xid)) { fromName = Name.getBuddy(xid); + } } else { chatType = 'private'; } diff --git a/app/javascripts/name.js b/app/javascripts/name.js index 0feacfe1..1328fe9c 100644 --- a/app/javascripts/name.js +++ b/app/javascripts/name.js @@ -131,26 +131,33 @@ var Name = (function () { // Initialize var cname, bname; - // Cut the XID resource - xid = Common.bareXID(xid); - - // This is me? - if(Utils.isAnonymous() && !xid) { - bname = Common._e("You"); - } else if(xid == Common.getXID()) { - bname = self.get(); - } - - // Not me! - else { - cname = $('#roster .buddy[data-xid="' + escape(xid) + '"]:first .buddy-name').html(); - - // Complete name exists? - if(cname) { - bname = cname.revertHtmlEnc(); - } else { - bname = Common.getXIDNick(xid); - } + // If the buddy is an anonymous account we use the resource + // if not empty + if (self.buddyIsAnonymous(xid) && Common.thisResource(xid)) { + bname = Common.thisResource(xid); + } else { + + // Cut the XID resource + xid = Common.bareXID(xid); + + // This is me? + if(Utils.isAnonymous() && !xid) { + bname = Common._e("You"); + } else if(xid == Common.getXID()) { + bname = self.get(); + } + + // Not me! + else { + cname = $('#roster .buddy[data-xid="' + escape(xid) + '"]:first .buddy-name').html(); + + // Complete name exists? + if(cname) { + bname = cname.revertHtmlEnc(); + } else { + bname = Common.getXIDNick(xid); + } + } } return bname; @@ -225,10 +232,19 @@ var Name = (function () { }; + /* + * Checks if the XID is from an anonymous account + * @public + * @param {string} xid + */ + self.buddyIsAnonymous = function(xid) { + return /^([a-f\d]{8}(-[a-f\d]{4}){3}-[a-f\d]{12}?)@/ig.test(xid) + } + /** * Return class scope */ return self; -})();
\ No newline at end of file +})(); |