Browse Source

rewrite getFullname()

readme-update
Simon Grim 9 years ago
parent
commit
606dd0ad67
  1. 91
      js/twister_io.js

91
js/twister_io.js

@ -204,52 +204,55 @@ function getProfileResource( username, resource, item, cbFunc, cbArg ){
} }
} }
// get fullname and store it in item.text // get fullname and store it in elem.text
function getFullname( username, item ){ function getFullname(peerAlias, elem) {
// Set the username first in case the profile has no fullname elem.text(peerAlias); // fallback: set the peerAlias first in case the profile has no fullname
item.text(username); getProfileResource(peerAlias, 'fullname', undefined,
getProfileResource( username, "fullname", undefined, function(req, name) {
function(args, value) { if (name && (name = name.trim()))
if( value ) { req.elem.text(name);
value.replace(/^\s+|\s+$/g, '');
if( value.length ) if (typeof twisterFollowingO !== 'undefined' && // FIXME delete this check when you fix client init sequence
args.item.text(value); ($.Options.isFollowingMe.val === 'everywhere' || req.elem.hasClass('profile-name'))) {
} // here we try to detect if peer follows us and then display it
}, {item: item} ); if (twisterFollowingO.knownFollowers.indexOf(req.peerAlias) > -1) {
if (typeof(twisterFollowingO) !== 'undefined' && req.elem.addClass('isFollowing');
($.Options.isFollowingMe.val === 'everywhere' || item.hasClass('profile-name'))) { req.elem.attr('title', polyglot.t('follows you'));
if (twisterFollowingO.knownFollowers.indexOf(username) > -1) { } else if (twisterFollowingO.notFollowers.indexOf(req.peerAlias) === -1) {
item.addClass('isFollowing'); if (twisterFollowingO.followingsFollowings[req.peerAlias] &&
item.attr("title", polyglot.t("follows you")); twisterFollowingO.followingsFollowings[req.peerAlias].following) {
} else if (twisterFollowingO.notFollowers.indexOf(username) === -1) { if (twisterFollowingO.followingsFollowings[req.peerAlias].following.indexOf(defaultScreenName) > -1) {
if (typeof(twisterFollowingO.followingsFollowings[username]) !== 'undefined' && if (twisterFollowingO.knownFollowers.indexOf(req.peerAlias) === -1) {
typeof(twisterFollowingO.followingsFollowings[username]["following"]) !== 'undefined') { twisterFollowingO.knownFollowers.push(req.peerAlias);
if (twisterFollowingO.followingsFollowings[username]["following"].indexOf(defaultScreenName) > -1) { twisterFollowingO.save();
twisterFollowingO.knownFollowers.push(username); addPeerToFollowersList(getElem('.followers-modal .followers-list'), req.peerAlias, true);
addPeerToFollowersList(getElem('.followers-modal .followers-list'), username, true); $('.open-followers').attr('title', twisterFollowingO.knownFollowers.length.toString());
twisterFollowingO.save(); }
item.addClass('isFollowing'); req.elem.addClass('isFollowing');
item.attr("title", polyglot.t("follows you")); req.elem.attr('title', polyglot.t('follows you'));
}
} else {
loadFollowingFromDht(username, 1, [], 0, function (args, following, seqNum) {
if (following.indexOf(args.user) > -1) {
item.addClass('isFollowing');
item.attr("title", polyglot.t("follows you"));
if (twisterFollowingO.knownFollowers.indexOf(args.username) < 0) {
twisterFollowingO.knownFollowers.push(args.username);
addPeerToFollowersList(getElem('.followers-modal .followers-list'), args.username, true);
} }
} else } else {
twisterFollowingO.notFollowers.push(args.username); loadFollowingFromDht(req.peerAlias, 1, [], 0,
function (req, following, seqNum) {
twisterFollowingO.save(); if (following.indexOf(defaultScreenName) > -1) {
}, {"user": defaultScreenName, "item": item, "username": username}); if (twisterFollowingO.knownFollowers.indexOf(req.peerAlias) === -1) {
twisterFollowingO.knownFollowers.push(req.peerAlias);
addPeerToFollowersList(getElem('.followers-modal .followers-list'), req.peerAlias, true);
$('.open-followers').attr('title', twisterFollowingO.knownFollowers.length.toString());
}
req.elem.addClass('isFollowing');
req.elem.attr('title', polyglot.t('follows you'));
} else if (twisterFollowingO.notFollowers.indexOf(req.peerAlias) === -1)
twisterFollowingO.notFollowers.push(req.peerAlias);
twisterFollowingO.save();
}, {elem: req.elem, peerAlias: req.peerAlias}
);
}
}
} }
} }, {elem: elem, peerAlias: peerAlias}
);
$(".open-followers").attr("title", twisterFollowingO.knownFollowers.length.toString());
}
} }
// get bio, format it as post message and store result to elem // get bio, format it as post message and store result to elem

Loading…
Cancel
Save