|
|
@ -13,7 +13,7 @@ function twisterRpc(method, params, resultFunc, resultArg, errorFunc, errorArg) |
|
|
|
var foo = new $.JsonRpcClient({ajaxUrl: window.location.pathname.replace(/[^\/]*$/, '')}); |
|
|
|
var foo = new $.JsonRpcClient({ajaxUrl: window.location.pathname.replace(/[^\/]*$/, '')}); |
|
|
|
foo.call(method, params, |
|
|
|
foo.call(method, params, |
|
|
|
function(ret) {resultFunc(resultArg, ret);}, |
|
|
|
function(ret) {resultFunc(resultArg, ret);}, |
|
|
|
function(ret) { if(ret != null) errorFunc(errorArg, ret); } |
|
|
|
function(ret) {if (ret != null) errorFunc(errorArg, ret);} // FIXME why only if "(ret != null)"?
|
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -36,76 +36,72 @@ var _maxDhtgets = 5; |
|
|
|
var _queuedDhtgets = []; |
|
|
|
var _queuedDhtgets = []; |
|
|
|
|
|
|
|
|
|
|
|
// private function to define a key in _dhtgetPendingMap
|
|
|
|
// private function to define a key in _dhtgetPendingMap
|
|
|
|
function _dhtgetLocator(username, resource, multi) { |
|
|
|
function _dhtgetLocator(peerAlias, resource, multi) { |
|
|
|
return username+";"+resource+";"+multi; |
|
|
|
return peerAlias + ';' + resource + ';' + multi; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function _dhtgetAddPending(locator, cbFunc, cbArg) |
|
|
|
function _dhtgetAddPending(locator, cbFunc, cbReq) { |
|
|
|
{ |
|
|
|
if (!_dhtgetPendingMap[locator]) { |
|
|
|
if( !(locator in _dhtgetPendingMap) ) { |
|
|
|
|
|
|
|
_dhtgetPendingMap[locator] = []; |
|
|
|
_dhtgetPendingMap[locator] = []; |
|
|
|
} |
|
|
|
} |
|
|
|
_dhtgetPendingMap[locator].push( {cbFunc:cbFunc, cbArg:cbArg} ); |
|
|
|
_dhtgetPendingMap[locator].push({cbFunc: cbFunc, cbReq: cbReq}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function _dhtgetProcessPending(locator, multi, ret) |
|
|
|
function _dhtgetProcessPending(locator, multi, ret) { |
|
|
|
{ |
|
|
|
if (_dhtgetPendingMap[locator]) { |
|
|
|
if( locator in _dhtgetPendingMap ) { |
|
|
|
|
|
|
|
for (var i = 0; i < _dhtgetPendingMap[locator].length; i++) { |
|
|
|
for (var i = 0; i < _dhtgetPendingMap[locator].length; i++) { |
|
|
|
var cbFunc = _dhtgetPendingMap[locator][i].cbFunc; |
|
|
|
var cbFunc = _dhtgetPendingMap[locator][i].cbFunc; |
|
|
|
var cbArg = _dhtgetPendingMap[locator][i].cbArg; |
|
|
|
var cbReq = _dhtgetPendingMap[locator][i].cbReq; |
|
|
|
|
|
|
|
|
|
|
|
if( multi == 'url' ) { |
|
|
|
if (multi === 'url') { |
|
|
|
// here is decodeshorturl case
|
|
|
|
cbFunc(cbReq, ret); // here is decodeshorturl case
|
|
|
|
cbFunc(cbArg, ret); |
|
|
|
} else if (multi === 's') { |
|
|
|
} else if( multi == 's' ) { |
|
|
|
if (typeof ret[0] !== 'undefined') { |
|
|
|
if( ret[0] != undefined ) { |
|
|
|
cbFunc(cbReq, ret[0].p.v, ret); |
|
|
|
cbFunc(cbArg, ret[0]["p"]["v"], ret); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
cbFunc(cbArg, null); |
|
|
|
cbFunc(cbReq); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
var multiret = []; |
|
|
|
var multiret = []; |
|
|
|
for (var j = 0; j < ret.length; j++) { |
|
|
|
for (var j = 0; j < ret.length; j++) { |
|
|
|
multiret.push(ret[j]["p"]["v"]); |
|
|
|
multiret.push(ret[j].p.v); |
|
|
|
} |
|
|
|
} |
|
|
|
cbFunc(cbArg, multiret, ret); |
|
|
|
cbFunc(cbReq, multiret, ret); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
delete _dhtgetPendingMap[locator]; |
|
|
|
delete _dhtgetPendingMap[locator]; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
console.log("warning: _dhtgetProcessPending with unknown locator "+locator); |
|
|
|
console.warn('_dhtgetProcessPending(): unknown locator ' + locator); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function _dhtgetAbortPending(locator) |
|
|
|
function _dhtgetAbortPending(locator) { |
|
|
|
{ |
|
|
|
if (_dhtgetPendingMap[locator]) { |
|
|
|
if( locator in _dhtgetPendingMap ) { |
|
|
|
|
|
|
|
for (var i = 0; i < _dhtgetPendingMap[locator].length; i++) { |
|
|
|
for (var i = 0; i < _dhtgetPendingMap[locator].length; i++) { |
|
|
|
var cbFunc = _dhtgetPendingMap[locator][i].cbFunc; |
|
|
|
var cbFunc = _dhtgetPendingMap[locator][i].cbFunc; |
|
|
|
var cbArg = _dhtgetPendingMap[locator][i].cbArg; |
|
|
|
var cbReq = _dhtgetPendingMap[locator][i].cbReq; |
|
|
|
cbFunc(cbArg, null); |
|
|
|
cbFunc(cbReq); |
|
|
|
} |
|
|
|
} |
|
|
|
delete _dhtgetPendingMap[locator]; |
|
|
|
delete _dhtgetPendingMap[locator]; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
console.log("warning: _dhtgetAbortPending with unknown locator "+locator); |
|
|
|
console.warn('_dhtgetAbortPending(): unknown locator ' + locator); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// get data from dht resource
|
|
|
|
// get data from dht resource
|
|
|
|
// the value ["v"] is extracted from response and returned to callback
|
|
|
|
// the value ["v"] is extracted from response and returned to callback
|
|
|
|
// null is passed to callback in case of an error
|
|
|
|
// null is passed to callback in case of an error
|
|
|
|
function dhtget( username, resource, multi, cbFunc, cbArg, timeoutArgs ) { |
|
|
|
function dhtget(peerAlias, resource, multi, cbFunc, cbReq, timeoutArgs) { |
|
|
|
//console.log('dhtget '+username+' '+resource+' '+multi);
|
|
|
|
//console.log('dhtget ' + peerAlias + ' ' + resource + ' ' + multi);
|
|
|
|
var locator = _dhtgetLocator(username, resource, multi); |
|
|
|
var locator = _dhtgetLocator(peerAlias, resource, multi); |
|
|
|
if( locator in _dhtgetPendingMap) { |
|
|
|
if (_dhtgetPendingMap[locator]) { |
|
|
|
_dhtgetAddPending(locator, cbFunc, cbArg); |
|
|
|
_dhtgetAddPending(locator, cbFunc, cbReq); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
_dhtgetAddPending(locator, cbFunc, cbArg); |
|
|
|
_dhtgetAddPending(locator, cbFunc, cbReq); |
|
|
|
// limit the number of simultaneous dhtgets.
|
|
|
|
// limit the number of simultaneous dhtgets.
|
|
|
|
// this should leave some sockets for other non-blocking daemon requests.
|
|
|
|
// this should leave some sockets for other non-blocking daemon requests.
|
|
|
|
if (_dhtgetsInProgress < _maxDhtgets) { |
|
|
|
if (_dhtgetsInProgress < _maxDhtgets) { |
|
|
|
_dhtgetInternal( username, resource, multi, timeoutArgs ); |
|
|
|
_dhtgetInternal(peerAlias, resource, multi, timeoutArgs); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// just queue the locator. it will be unqueue when some dhtget completes.
|
|
|
|
// just queue the locator. it will be unqueue when some dhtget completes.
|
|
|
|
_queuedDhtgets.push(locator); |
|
|
|
_queuedDhtgets.push(locator); |
|
|
@ -116,11 +112,11 @@ function dhtget( username, resource, multi, cbFunc, cbArg, timeoutArgs ) { |
|
|
|
// decode shortened url
|
|
|
|
// decode shortened url
|
|
|
|
// the expanded url is returned to callback
|
|
|
|
// the expanded url is returned to callback
|
|
|
|
// null is passed to callback in case of an error
|
|
|
|
// null is passed to callback in case of an error
|
|
|
|
function decodeshorturl( locator, cbFunc, cbArg, timeoutArgs ) { |
|
|
|
function decodeShortURI(locator, cbFunc, cbReq, timeoutArgs) { |
|
|
|
if( locator in _dhtgetPendingMap) { |
|
|
|
if (_dhtgetPendingMap[locator]) { |
|
|
|
_dhtgetAddPending(locator, cbFunc, cbArg); |
|
|
|
_dhtgetAddPending(locator, cbFunc, cbReq); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
_dhtgetAddPending(locator, cbFunc, cbArg); |
|
|
|
_dhtgetAddPending(locator, cbFunc, cbReq); |
|
|
|
// limit the number of simultaneous decodeshorturl's and dhtgets.
|
|
|
|
// limit the number of simultaneous decodeshorturl's and dhtgets.
|
|
|
|
// this should leave some sockets for other non-blocking daemon requests.
|
|
|
|
// this should leave some sockets for other non-blocking daemon requests.
|
|
|
|
if (_dhtgetsInProgress < _maxDhtgets) { |
|
|
|
if (_dhtgetsInProgress < _maxDhtgets) { |
|
|
@ -132,25 +128,26 @@ function decodeshorturl( locator, cbFunc, cbArg, timeoutArgs ) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function _dhtgetInternal( username, resource, multi, timeoutArgs ) { |
|
|
|
function _dhtgetInternal(peerAlias, resource, multi, timeoutArgs) { |
|
|
|
var locator = _dhtgetLocator(username, resource, multi); |
|
|
|
var locator = _dhtgetLocator(peerAlias, resource, multi); |
|
|
|
_dhtgetsInProgress++; |
|
|
|
_dhtgetsInProgress++; |
|
|
|
argsList = [username,resource,multi]; |
|
|
|
argsList = [peerAlias, resource, multi]; |
|
|
|
if (typeof timeoutArgs !== 'undefined') { |
|
|
|
if (typeof timeoutArgs !== 'undefined') { |
|
|
|
argsList = argsList.concat(timeoutArgs); |
|
|
|
argsList = argsList.concat(timeoutArgs); |
|
|
|
} |
|
|
|
} |
|
|
|
twisterRpc("dhtget", argsList, |
|
|
|
twisterRpc('dhtget', argsList, |
|
|
|
function(args, ret) { |
|
|
|
function(req, ret) { |
|
|
|
_dhtgetsInProgress--; |
|
|
|
_dhtgetsInProgress--; |
|
|
|
_dhtgetProcessPending(args.locator, args.multi, ret); |
|
|
|
_dhtgetProcessPending(req.locator, req.multi, ret); |
|
|
|
_dhtgetDequeue(); |
|
|
|
_dhtgetDequeue(); |
|
|
|
}, {locator: locator, multi: multi}, |
|
|
|
}, {locator: locator, multi: multi}, |
|
|
|
function(cbArg, ret) { |
|
|
|
function(req, ret) { |
|
|
|
console.log("ajax error:" + ret); |
|
|
|
console.warn('RPC "dhtget" error: ' + (ret && ret.message) ? ret.message : ret); |
|
|
|
_dhtgetsInProgress--; |
|
|
|
_dhtgetsInProgress--; |
|
|
|
_dhtgetAbortPending(locator); |
|
|
|
_dhtgetAbortPending(req); |
|
|
|
_dhtgetDequeue(); |
|
|
|
_dhtgetDequeue(); |
|
|
|
}, locator); |
|
|
|
}, locator |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function _decodeshorturlInternal(locator, timeoutArgs) { |
|
|
|
function _decodeshorturlInternal(locator, timeoutArgs) { |
|
|
@ -159,25 +156,26 @@ function _decodeshorturlInternal( locator, timeoutArgs ) { |
|
|
|
if (typeof timeoutArgs !== 'undefined') { |
|
|
|
if (typeof timeoutArgs !== 'undefined') { |
|
|
|
argsList = argsList.concat(timeoutArgs); |
|
|
|
argsList = argsList.concat(timeoutArgs); |
|
|
|
} |
|
|
|
} |
|
|
|
twisterRpc("decodeshorturl", argsList, |
|
|
|
twisterRpc('decodeshorturl', argsList, |
|
|
|
function(args, ret) { |
|
|
|
function(req, ret) { |
|
|
|
_dhtgetsInProgress--; |
|
|
|
_dhtgetsInProgress--; |
|
|
|
_dhtgetProcessPending(args.locator, "url", ret); |
|
|
|
_dhtgetProcessPending(req, 'url', ret); |
|
|
|
_dhtgetDequeue(); |
|
|
|
_dhtgetDequeue(); |
|
|
|
}, {locator:locator}, |
|
|
|
}, locator, |
|
|
|
function(cbArg, ret) { |
|
|
|
function(req, ret) { |
|
|
|
console.log("ajax error:" + ret); |
|
|
|
console.warn('can\'t fetch URI "' + req + '" — RPC "decodeshorturl" error: ' + (ret && ret.message) ? ret.message : ret); |
|
|
|
_dhtgetsInProgress--; |
|
|
|
_dhtgetsInProgress--; |
|
|
|
_dhtgetAbortPending(locator); |
|
|
|
_dhtgetAbortPending(req); |
|
|
|
_dhtgetDequeue(); |
|
|
|
_dhtgetDequeue(); |
|
|
|
}, locator); |
|
|
|
}, locator |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function _dhtgetDequeue() { |
|
|
|
function _dhtgetDequeue() { |
|
|
|
if (_queuedDhtgets.length) { |
|
|
|
if (_queuedDhtgets.length) { |
|
|
|
var locator = _queuedDhtgets.pop(); |
|
|
|
var locator = _queuedDhtgets.pop(); |
|
|
|
var locatorSplit = locator.split(";"); |
|
|
|
var locatorSplit = locator.split(';'); |
|
|
|
if( locatorSplit.length == 3) { |
|
|
|
if (locatorSplit.length === 3) { |
|
|
|
_dhtgetInternal(locatorSplit[0], locatorSplit[1], locatorSplit[2]); |
|
|
|
_dhtgetInternal(locatorSplit[0], locatorSplit[1], locatorSplit[2]); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
_decodeshorturlInternal( locator ) |
|
|
|
_decodeshorturlInternal( locator ) |
|
|
@ -187,10 +185,10 @@ function _dhtgetDequeue() { |
|
|
|
|
|
|
|
|
|
|
|
// removes queued dhtgets (requests that have not been made to the daemon)
|
|
|
|
// removes queued dhtgets (requests that have not been made to the daemon)
|
|
|
|
// this is used by user search dropdown to discard old users we are not interested anymore
|
|
|
|
// this is used by user search dropdown to discard old users we are not interested anymore
|
|
|
|
function removeUserFromDhtgetQueue(username) { |
|
|
|
function removeUserFromDhtgetQueue(peerAlias) { |
|
|
|
var resources = ["profile","avatar"] |
|
|
|
var resources = ['profile', 'avatar'] |
|
|
|
for (var i = 0; i < resources.length; i++) { |
|
|
|
for (var i = 0; i < resources.length; i++) { |
|
|
|
var locator = _dhtgetLocator(username,resources[i],"s"); |
|
|
|
var locator = _dhtgetLocator(peerAlias, resources[i], 's'); |
|
|
|
var locatorIndex = _queuedDhtgets.indexOf(locator); |
|
|
|
var locatorIndex = _queuedDhtgets.indexOf(locator); |
|
|
|
if (locatorIndex > -1) { |
|
|
|
if (locatorIndex > -1) { |
|
|
|
_queuedDhtgets.splice(locatorIndex, 1); |
|
|
|
_queuedDhtgets.splice(locatorIndex, 1); |
|
|
@ -206,48 +204,50 @@ function removeUsersFromDhtgetQueue(users) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// store value at the dht resource
|
|
|
|
// store value at the dht resource
|
|
|
|
function dhtput( username, resource, multi, value, sig_user, seq, cbFunc, cbArg ) { |
|
|
|
function dhtput(peerAlias, resource, multi, value, sig_user, seq, cbFunc, cbReq) { |
|
|
|
twisterRpc("dhtput", [username,resource,multi, value, sig_user, seq], |
|
|
|
twisterRpc('dhtput', [peerAlias, resource, multi, value, sig_user, seq], |
|
|
|
function(args, ret) { |
|
|
|
function(req, ret) { |
|
|
|
if( args.cbFunc ) |
|
|
|
if (req.cbFunc) |
|
|
|
args.cbFunc(args.cbArg, true); |
|
|
|
req.cbFunc(req.cbReq, true); |
|
|
|
}, {cbFunc:cbFunc, cbArg:cbArg}, |
|
|
|
}, {cbFunc: cbFunc, cbReq: cbReq}, |
|
|
|
function(args, ret) { |
|
|
|
function(req, ret) { |
|
|
|
console.log("ajax error:" + ret); |
|
|
|
console.warn('RPC "dhtput" error: ' + (ret && ret.message) ? ret.message : ret); |
|
|
|
if( args.cbFunc ) |
|
|
|
if (req.cbFunc) |
|
|
|
args.cbFunc(args.cbArg, false); |
|
|
|
req.cbFunc(req.cbReq, false); |
|
|
|
}, cbArg); |
|
|
|
}, {cbFunc: cbFunc, cbReq: cbReq} |
|
|
|
} |
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
// get something from profile and store it in item.text or do callback
|
|
|
|
|
|
|
|
function getProfileResource( username, resource, item, cbFunc, cbArg ){ |
|
|
|
// get something from profile and store it in elem.text or do callback
|
|
|
|
var profile = undefined; |
|
|
|
function getProfileResource(peerAlias, resource, elem, cbFunc, cbReq) { |
|
|
|
if( username in _profileMap ) { |
|
|
|
var profile; |
|
|
|
profile = _profileMap[username]; |
|
|
|
if (_profileMap[peerAlias]) { |
|
|
|
|
|
|
|
profile = _profileMap[peerAlias]; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
profile = _getResourceFromStorage("profile:" + username); |
|
|
|
profile = _getResourceFromStorage('profile:' + peerAlias); |
|
|
|
} |
|
|
|
} |
|
|
|
if (profile) { |
|
|
|
if (profile) { |
|
|
|
_profileMap[username] = profile; |
|
|
|
_profileMap[peerAlias] = profile; |
|
|
|
if( item ) |
|
|
|
if (elem) |
|
|
|
item.text(profile[resource]); |
|
|
|
elem.text(profile[resource]); |
|
|
|
if (cbFunc) |
|
|
|
if (cbFunc) |
|
|
|
cbFunc(cbArg, profile[resource]); |
|
|
|
cbFunc(cbReq, profile[resource]); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
dhtget( username, "profile", "s", |
|
|
|
dhtget(peerAlias, 'profile', 's', |
|
|
|
function(args, profile) { |
|
|
|
function(req, profile) { |
|
|
|
if (profile) { |
|
|
|
if (profile) { |
|
|
|
_profileMap[args.username] = profile; |
|
|
|
_profileMap[req.peerAlias] = profile; |
|
|
|
_putResourceIntoStorage("profile:" + username, profile); |
|
|
|
_putResourceIntoStorage('profile:' + peerAlias, profile); |
|
|
|
if( args.item ) |
|
|
|
if (req.elem) |
|
|
|
args.item.text(profile[resource]); |
|
|
|
req.elem.text(profile[resource]); |
|
|
|
if( args.cbFunc ) |
|
|
|
if (req.cbFunc) |
|
|
|
args.cbFunc(args.cbArg, profile[resource]); |
|
|
|
req.cbFunc(req.cbReq, profile[resource]); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if( args.cbFunc ) |
|
|
|
if (req.cbFunc) |
|
|
|
args.cbFunc(args.cbArg, null); |
|
|
|
req.cbFunc(req.cbReq); |
|
|
|
} |
|
|
|
} |
|
|
|
}, {username:username,item:item,cbFunc:cbFunc,cbArg:cbArg}); |
|
|
|
}, {peerAlias: peerAlias, elem: elem, cbFunc: cbFunc, cbReq: cbReq} |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -307,56 +307,61 @@ function getBioToElem(peerAlias, elem) { |
|
|
|
getProfileResource(peerAlias, 'bio', undefined, fillElemWithTxt, elem); |
|
|
|
getProfileResource(peerAlias, 'bio', undefined, fillElemWithTxt, elem); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// get tox address and store it in item.text
|
|
|
|
// get tox address and store it in elem.text
|
|
|
|
function getTox( username, item ){ |
|
|
|
function getTox(peerAlias, elem) { |
|
|
|
getProfileResource( username, "tox", false, function(item, text){ |
|
|
|
getProfileResource(peerAlias, 'tox', false, |
|
|
|
//item.empty();
|
|
|
|
function(elem, val) { |
|
|
|
if(text) { |
|
|
|
if (val) { |
|
|
|
item.attr('href', 'tox:'+text); |
|
|
|
elem.attr('href', 'tox:' + val); |
|
|
|
item.next().attr('data', text).attr('title', 'Copy to clipboard'); |
|
|
|
elem.next().attr('data', val).attr('title', 'Copy to clipboard'); |
|
|
|
item.parent().css('display','inline-block').parent().show(); |
|
|
|
elem.parent().css('display', 'inline-block').parent().show(); |
|
|
|
} |
|
|
|
} |
|
|
|
}, item); |
|
|
|
}, elem |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// get bitmessage address and store it in item.text
|
|
|
|
// get bitmessage address and store it in elem.text
|
|
|
|
function getBitmessage( username, item ){ |
|
|
|
function getBitmessage(peerAlias, elem) { |
|
|
|
getProfileResource( username, "bitmessage", false, function(item, text){ |
|
|
|
getProfileResource(peerAlias, 'bitmessage', false, |
|
|
|
//item.empty();
|
|
|
|
function(elem, val) { |
|
|
|
if(text) { |
|
|
|
if (val) { |
|
|
|
item.attr('href', 'bitmsg:'+text+'?action=add&label='+username); |
|
|
|
elem.attr('href', 'bitmsg:' + val + '?action=add&label=' + peerAlias); |
|
|
|
item.next().attr('data', text).attr('title', 'Copy to clipboard'); |
|
|
|
elem.next().attr('data', val).attr('title', 'Copy to clipboard'); |
|
|
|
item.parent().css('display','inline-block').parent().show(); |
|
|
|
elem.parent().css('display', 'inline-block').parent().show(); |
|
|
|
} |
|
|
|
} |
|
|
|
}, item); |
|
|
|
}, elem |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// get location and store it in item.text
|
|
|
|
// get location and store it in elem.text
|
|
|
|
function getLocation( username, item ){ |
|
|
|
function getLocation(peerAlias, elem) { |
|
|
|
getProfileResource( username, "location", item); |
|
|
|
getProfileResource(peerAlias, 'location', elem); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// get location and store it in item.text
|
|
|
|
// get location and store it in elem.text
|
|
|
|
function getWebpage( username, item ){ |
|
|
|
function getWebpage(peerAlias, elem) { |
|
|
|
getProfileResource( username, "url", item, |
|
|
|
getProfileResource(peerAlias, 'url', elem, |
|
|
|
function(args, val) { |
|
|
|
function(elem, val) { |
|
|
|
if (typeof(val) !== 'undefined') { |
|
|
|
if (typeof(val) !== 'undefined') { |
|
|
|
if (val.indexOf("://") < 0) { |
|
|
|
if (val.indexOf('://') < 0) { |
|
|
|
val = "http://" + val; |
|
|
|
val = 'http://' + val; |
|
|
|
} |
|
|
|
} |
|
|
|
args.item.attr("href", val); |
|
|
|
elem.attr('href', val); |
|
|
|
} |
|
|
|
} |
|
|
|
}, {item:item} ); |
|
|
|
}, elem |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getGroupChatName( groupalias, item ){ |
|
|
|
function getGroupChatName(groupAlias, elem) { |
|
|
|
twisterRpc("getgroupinfo", [groupalias], |
|
|
|
twisterRpc('getgroupinfo', [groupAlias], |
|
|
|
function(args, ret) { |
|
|
|
function(elem, ret) { |
|
|
|
args.item.text(ret["description"]); |
|
|
|
elem.text(ret.description); |
|
|
|
}, {item:item}, |
|
|
|
}, elem, |
|
|
|
function(args, ret) { |
|
|
|
function(req, ret) { |
|
|
|
args.item.text("getgroupinfo error"); |
|
|
|
console.warn('RPC "getgroupinfo" error: ' + (ret && ret.message) ? ret.message : ret); |
|
|
|
}, {item:item}); |
|
|
|
req.elem.text(req.groupAlias); |
|
|
|
|
|
|
|
}, {elem: elem, groupAlias: groupAlias} |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// we must cache avatar results to disk to lower bandwidth on
|
|
|
|
// we must cache avatar results to disk to lower bandwidth on
|
|
|
@ -414,21 +419,21 @@ function cleanupStorage() { |
|
|
|
|
|
|
|
|
|
|
|
// get avatar and set it in img.attr("src")
|
|
|
|
// get avatar and set it in img.attr("src")
|
|
|
|
// TODO rename to getAvatarImgToELem(), move nin theme related stuff to nin's theme_option.js
|
|
|
|
// TODO rename to getAvatarImgToELem(), move nin theme related stuff to nin's theme_option.js
|
|
|
|
function getAvatar(username, img) { |
|
|
|
function getAvatar(peerAlias, img) { |
|
|
|
if (!img.length) |
|
|
|
if (!img.length) |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
if (username === 'nobody') { |
|
|
|
if (peerAlias === 'nobody') { |
|
|
|
img.attr('src', ($.Options.theme.val === 'nin') ? |
|
|
|
img.attr('src', ($.Options.theme.val === 'nin') ? |
|
|
|
'theme_nin/img/tornado_avatar.png' : 'img/tornado_avatar.png'); |
|
|
|
'theme_nin/img/tornado_avatar.png' : 'img/tornado_avatar.png'); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (_avatarMap[username]) { |
|
|
|
if (_avatarMap[peerAlias]) { |
|
|
|
//img.attr('src', 'data:image/jpg;base64,'+avatarMap[username]);
|
|
|
|
//img.attr('src', 'data:image/jpg;base64,'+avatarMap[peerAlias]);
|
|
|
|
img.attr('src', _avatarMap[username]); |
|
|
|
img.attr('src', _avatarMap[peerAlias]); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
var data = _getResourceFromStorage('avatar:' + username); |
|
|
|
var data = _getResourceFromStorage('avatar:' + peerAlias); |
|
|
|
|
|
|
|
|
|
|
|
if (data) { |
|
|
|
if (data) { |
|
|
|
switch (data.substr(0, 4)) { |
|
|
|
switch (data.substr(0, 4)) { |
|
|
@ -442,125 +447,134 @@ function getAvatar(username, img) { |
|
|
|
data = 'data:image/gif;base64,' + window.btoa(data.slice(4)); |
|
|
|
data = 'data:image/gif;base64,' + window.btoa(data.slice(4)); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
_avatarMap[username] = data; |
|
|
|
_avatarMap[peerAlias] = data; |
|
|
|
img.attr('src', data); |
|
|
|
img.attr('src', data); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
dhtget(username, 'avatar', 's', |
|
|
|
dhtget(peerAlias, 'avatar', 's', |
|
|
|
function(req, imagedata) { |
|
|
|
function(req, imagedata) { |
|
|
|
if (imagedata && imagedata.length) { |
|
|
|
if (imagedata && imagedata.length) { |
|
|
|
_avatarMap[req.username] = imagedata; |
|
|
|
_avatarMap[req.peerAlias] = imagedata; |
|
|
|
if (imagedata !== 'img/genericPerson.png') { |
|
|
|
if (imagedata !== 'img/genericPerson.png') { |
|
|
|
if (imagedata.substr(0, 27) === 'data:image/jpeg;base64,/9j/') |
|
|
|
if (imagedata.substr(0, 27) === 'data:image/jpeg;base64,/9j/') |
|
|
|
_putResourceIntoStorage('avatar:' + username, 'jpg/' + window.atob(imagedata.slice(27))); |
|
|
|
_putResourceIntoStorage('avatar:' + peerAlias, 'jpg/' + window.atob(imagedata.slice(27))); |
|
|
|
else { |
|
|
|
else { |
|
|
|
var s = imagedata.substr(0, 22); |
|
|
|
var s = imagedata.substr(0, 22); |
|
|
|
if (s === 'data:image/png;base64,' || s === 'data:image/gif;base64,') |
|
|
|
if (s === 'data:image/png;base64,' || s === 'data:image/gif;base64,') |
|
|
|
_putResourceIntoStorage('avatar:' + username, imagedata.substr(11, 3) + '/' + window.atob(imagedata.slice(22))); |
|
|
|
_putResourceIntoStorage('avatar:' + peerAlias, imagedata.substr(11, 3) + '/' + window.atob(imagedata.slice(22))); |
|
|
|
else |
|
|
|
else |
|
|
|
_putResourceIntoStorage('avatar:' + username, imagedata); |
|
|
|
_putResourceIntoStorage('avatar:' + peerAlias, imagedata); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
req.img.attr('src', imagedata); |
|
|
|
req.img.attr('src', imagedata); |
|
|
|
} |
|
|
|
} |
|
|
|
}, {username: username, img: img} |
|
|
|
}, {peerAlias: peerAlias, img: img} |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function clearAvatarAndProfileCache(username) { |
|
|
|
function clearAvatarAndProfileCache(peerAlias) { |
|
|
|
var storage = $.localStorage; |
|
|
|
var storage = $.localStorage; |
|
|
|
storage.remove("avatar:" + username); |
|
|
|
storage.remove('avatar:' + peerAlias); |
|
|
|
storage.remove("profile:" + username); |
|
|
|
storage.remove('profile:' + peerAlias); |
|
|
|
if( username in _avatarMap ) { |
|
|
|
if (_avatarMap[peerAlias]) { |
|
|
|
delete _avatarMap[username]; |
|
|
|
delete _avatarMap[peerAlias]; |
|
|
|
} |
|
|
|
} |
|
|
|
if( username in _profileMap ) { |
|
|
|
if (_profileMap[peerAlias]) { |
|
|
|
delete _profileMap[username]; |
|
|
|
delete _profileMap[peerAlias]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// get estimative for number of followers (use known peers of torrent tracker)
|
|
|
|
// get estimative for number of followers (use known peers of torrent tracker)
|
|
|
|
function getFollowers( username, item ) { |
|
|
|
function getFollowers(peerAlias, elem) { |
|
|
|
dhtget( username, "tracker", "m", |
|
|
|
dhtget(peerAlias, 'tracker', 'm', |
|
|
|
function(args, ret) { |
|
|
|
function(elem, ret) { |
|
|
|
if( ret && ret.length && ret[0]["followers"] ) { |
|
|
|
if (ret && ret.length && ret[0].followers) { |
|
|
|
args.item.text(ret[0]["followers"]) |
|
|
|
elem.text(ret[0].followers) |
|
|
|
} |
|
|
|
} |
|
|
|
}, {username:username,item:item} ); |
|
|
|
}, elem |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getPostsCount( username, item ) { |
|
|
|
function getPostsCount(peerAlias, elem) { |
|
|
|
dhtget( username, "status", "s", |
|
|
|
dhtget(peerAlias, 'status', 's', |
|
|
|
function(args, v) { |
|
|
|
function(req, v) { |
|
|
|
var count = 0; |
|
|
|
var count = 0; |
|
|
|
if( v && v["userpost"] ) { |
|
|
|
if (v && v.userpost) { |
|
|
|
count = v["userpost"]["k"]+1; |
|
|
|
count = v.userpost.k + 1; |
|
|
|
} |
|
|
|
} |
|
|
|
var oldCount = parseInt(args.item.text()); |
|
|
|
var oldCount = parseInt(req.elem.text()); |
|
|
|
if (!oldCount || count > oldCount) { |
|
|
|
if (!oldCount || count > oldCount) { |
|
|
|
args.item.text(count); |
|
|
|
req.elem.text(count); |
|
|
|
} |
|
|
|
} |
|
|
|
if( username == defaultScreenName && count ) { |
|
|
|
if (peerAlias === defaultScreenName && count) { |
|
|
|
incLastPostId( v["userpost"]["k"] ); |
|
|
|
incLastPostId(v.userpost.k); |
|
|
|
} |
|
|
|
} |
|
|
|
}, {username:username,item:item} ); |
|
|
|
}, {peerAlias: peerAlias, elem: elem} |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getPostMaxAvailability(username, k, cbFunc, cbArg) { |
|
|
|
function getPostMaxAvailability(peerAlias, k, cbFunc, cbReq) { |
|
|
|
twisterRpc("getpiecemaxseen", [username,k], |
|
|
|
twisterRpc('getpiecemaxseen', [peerAlias, k], |
|
|
|
function(args, ret) { |
|
|
|
function(req, ret) { |
|
|
|
args.cbFunc(args.cbArg, ret); |
|
|
|
req.cbFunc(req.cbReq, ret); |
|
|
|
}, {cbFunc:cbFunc, cbArg:cbArg}, |
|
|
|
}, {cbFunc: cbFunc, cbReq: cbReq}, |
|
|
|
function(args, ret) { |
|
|
|
function(req, ret) { |
|
|
|
console.log("getPostAvailability error"); |
|
|
|
console.warn('RPC "getpiecemaxseen" error: ' + (ret && ret.message) ? ret.message : ret); |
|
|
|
}, {cbFunc:cbFunc, cbArg:cbArg}); |
|
|
|
} |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function checkPubkeyExists(username, cbFunc, cbArg) { |
|
|
|
function checkPubkeyExists(peerAlias, cbFunc, cbReq) { |
|
|
|
// pubkey is checked in block chain db.
|
|
|
|
// pubkey is checked in block chain db.
|
|
|
|
// so only accepted registrations are reported (local wallet users are not)
|
|
|
|
// so only accepted registrations are reported (local wallet users are not)
|
|
|
|
twisterRpc("dumppubkey", [username], |
|
|
|
twisterRpc('dumppubkey', [peerAlias], |
|
|
|
function(args, ret) { |
|
|
|
function(req, ret) { |
|
|
|
args.cbFunc(args.cbArg, ret.length > 0); |
|
|
|
req.cbFunc(req.cbReq, ret.length > 0); |
|
|
|
}, {cbFunc:cbFunc, cbArg:cbArg}, |
|
|
|
}, {cbFunc: cbFunc, cbReq: cbReq}, |
|
|
|
function(args, ret) { |
|
|
|
function(req, ret) { |
|
|
|
alert(polyglot.t("error_connecting_to_daemon")); |
|
|
|
console.warn('RPC "dumppubkey" error: ' + (ret && ret.message) ? ret.message : ret); |
|
|
|
}, {cbFunc:cbFunc, cbArg:cbArg}); |
|
|
|
alert(polyglot.t('error_connecting_to_daemon')); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// pubkey is obtained from block chain db.
|
|
|
|
// pubkey is obtained from block chain db.
|
|
|
|
// so only accepted registrations are reported (local wallet users are not)
|
|
|
|
// so only accepted registrations are reported (local wallet users are not)
|
|
|
|
// cbFunc is called as cbFunc(cbArg, pubkey)
|
|
|
|
// cbFunc is called as cbFunc(cbReq, pubkey)
|
|
|
|
// if user doesn't exist then pubkey.length == 0
|
|
|
|
// if user doesn't exist then pubkey.length == 0
|
|
|
|
function dumpPubkey(username, cbFunc, cbArg) { |
|
|
|
function dumpPubkey(peerAlias, cbFunc, cbReq) { |
|
|
|
if( username in _pubkeyMap ) { |
|
|
|
if (_pubkeyMap[peerAlias]) { |
|
|
|
if (cbFunc) |
|
|
|
if (cbFunc) |
|
|
|
cbFunc(cbArg, _pubkeyMap[username]); |
|
|
|
cbFunc(cbReq, _pubkeyMap[peerAlias]); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
twisterRpc("dumppubkey", [username], |
|
|
|
twisterRpc('dumppubkey', [peerAlias], |
|
|
|
function(args, ret) { |
|
|
|
function (req, ret) { |
|
|
|
if (ret.length > 0) { |
|
|
|
if (ret.length > 0) { |
|
|
|
_pubkeyMap[username] = ret; |
|
|
|
_pubkeyMap[peerAlias] = ret; |
|
|
|
} |
|
|
|
} |
|
|
|
args.cbFunc(args.cbArg, ret); |
|
|
|
if (req.cbFunc) { |
|
|
|
}, {cbFunc:cbFunc, cbArg:cbArg}, |
|
|
|
req.cbFunc(req.cbReq, ret); |
|
|
|
function(args, ret) { |
|
|
|
} |
|
|
|
alert(polyglot.t("error_connecting_to_daemon")); |
|
|
|
}, {cbFunc: cbFunc, cbReq: cbReq}, |
|
|
|
}, {cbFunc:cbFunc, cbArg:cbArg}); |
|
|
|
function (req, ret) { |
|
|
|
|
|
|
|
console.warn('RPC "dumppubkey" error: ' + (ret && ret.message) ? ret.message : ret); |
|
|
|
|
|
|
|
alert(polyglot.t('error_connecting_to_daemon')); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// privkey is obtained from wallet db
|
|
|
|
// privkey is obtained from wallet db
|
|
|
|
// so privkey is returned even for unsent transactions
|
|
|
|
// so privkey is returned even for unsent transactions
|
|
|
|
function dumpPrivkey(username, cbFunc, cbArg) { |
|
|
|
function dumpPrivkey(peerAlias, cbFunc, cbReq) { |
|
|
|
twisterRpc("dumpprivkey", [username], |
|
|
|
twisterRpc('dumpprivkey', [peerAlias], |
|
|
|
function(args, ret) { |
|
|
|
function(req, ret) { |
|
|
|
args.cbFunc(args.cbArg, ret); |
|
|
|
req.cbFunc(req.cbReq, ret); |
|
|
|
}, {cbFunc:cbFunc, cbArg:cbArg}, |
|
|
|
}, {cbFunc: cbFunc, cbReq: cbReq}, |
|
|
|
function(args, ret) { |
|
|
|
function(req, ret) { |
|
|
|
args.cbFunc(args.cbArg, ""); |
|
|
|
req.cbFunc(req.cbReq, ''); |
|
|
|
console.log("dumpprivkey: user unknown"); |
|
|
|
console.warn('user unknown — RPC "dumppubkey" error: ' + ret.message); |
|
|
|
}, {cbFunc:cbFunc, cbArg:cbArg}); |
|
|
|
}, {cbFunc: cbFunc, cbReq: cbReq} |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|