X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=jappixmini%2Flib.js;h=31302732874ea9c6bf186c4e981442f34ec2cd57;hb=d9330e3b05c71bbd172293fb223271033d3b19f7;hp=94e465d1ea57c8e8773f8112e15abf8acdd56681;hpb=6034ba3263fcfea911e914b38f6cdac188c7a596;p=friendica-addons.git diff --git a/jappixmini/lib.js b/jappixmini/lib.js index 94e465d1..31302732 100644 --- a/jappixmini/lib.js +++ b/jappixmini/lib.js @@ -1,9 +1,15 @@ +// +// Copyright 2012 "Leberwurscht" +// +// This file is dual-licensed under the MIT license (see MIT.txt) and the AGPL license (see jappix/COPYING). +// + function jappixmini_addon_xor(str1, str2) { if (str1.length != str2.length) throw "not same length"; - encoded = ""; + var encoded = ""; - for (i=0; iRetype your Friendica password for chatting:
'); + div = $('
Retype your Friendica password for chatting:
'); - input = $('') + var input = $('') div.append(input); - button = $(''); + var button = $(''); div.append(button); $("body").append(div); } button.click(function(){ - password = $("#jappixmini-password-query-input").val(); + var password = $("#jappixmini-password-query-input").val(); jappixmini_addon_set_client_secret(password); div.remove(); - client_secret = getDB('jappix-mini', 'client-secret'); + var client_secret = getPersistent('jappix-mini', 'client-secret'); callback(client_secret); }); } @@ -68,7 +74,7 @@ function jappixmini_addon_encrypt_password(password, callback) { } // xor password with secret - encrypted_password = jappixmini_addon_xor(client_secret, password); + var encrypted_password = jappixmini_addon_xor(client_secret, password); encrypted_password = encodeURI(encrypted_password) callback(encrypted_password); @@ -80,18 +86,18 @@ function jappixmini_addon_decrypt_password(encrypted_password, callback) { jappixmini_addon_get_client_secret(function(client_secret){ // xor password with secret - password = jappixmini_addon_xor(client_secret, encrypted_password); + var password = jappixmini_addon_xor(client_secret, encrypted_password); // remove \0 - first_null = password.indexOf("\0") - // TODO: check first_null==null + var first_null = password.indexOf("\0") + if (first_null==-1) throw "Decrypted password does not contain \\0"; password = password.substr(0, first_null); callback(password); }); } -function jappixmini_manage_roster(contacts, autoapprove, autosubscribe) { +function jappixmini_manage_roster(contacts, contacts_hash, autoapprove, autosubscribe) { // listen for subscriptions con.registerHandler('presence',function(presence){ var type = presence.getType(); @@ -99,25 +105,125 @@ function jappixmini_manage_roster(contacts, autoapprove, autosubscribe) { var from = fullXID(getStanzaFrom(presence)); var xid = bareXID(from); + var pstatus = presence.getStatus(); + + var approve; - approve = true; - if ((!autoapprove) || contacts[xid]===undefined) - approve = confirm("Accept "+xid+" for chat?"); + if (autoapprove && contacts[xid]!==undefined) { + // approve known address + approve = true; + console.log("Approve known Friendica contact "+xid+"."); + } + else if (autoapprove && pstatus && pstatus.indexOf("Friendica")!=-1) { + // Unknown address claims to be a Friendica contact. + // This is probably because the other side knows our + // address, but we do not know the other side yet. + // But it's only a matter of time, so wait - do not + // approve yet and do not annoy the user by asking. + approve = false; + console.log("Do not approve unknown Friendica contact "+xid+" - wait instead."); + } + else { + // In all other cases, ask the user. + var message = "Accept "+xid+" for chat?"; + if (pstatus) message += "\n\nStatus:\n"+pstatus; + approve = confirm(message); + + // do not ask any more + if (!approve) sendSubscribe(xid, "unsubscribed"); + } if (approve) { - acceptSubscribe(xid, contacts[xid]); - console.log("Accepted "+xid+" for chat."); + var name = contacts[xid]; + if (!name) name = xid; + + acceptSubscribe(xid, name); + console.log("Accepted "+xid+" ("+name+") for chat."); } }); // autosubscribe - if (autosubscribe) { - for (i=0; i