handle group/{id}/id links

This commit is contained in:
Hannes Mannerheim 2015-09-21 02:00:03 +02:00
parent dcd4f55c69
commit d8abe400a7
3 changed files with 72 additions and 11 deletions

View File

@ -193,6 +193,29 @@ function getNicknameByUserIdFromAPI(id, callback) {
}
/* ·
·
· Get group nickname by group id
·
· @param id: local group id
· @param callback: function to invoke when done
·
· · · · · · · · · · · · · */
function getNicknameByGroupIdFromAPI(id, callback) {
display_spinner();
getFromAPI('statusnet/groups/show/' + id + '.json', function(data){
remove_spinner();
if(data && typeof data.nickname != 'undefined') {
callback(data.nickname);
}
else {
callback(false);
}
});
}
/* ·
·
· Update the bookmarks

View File

@ -438,7 +438,6 @@ function groupProfileCard(groupAlias) {
// add card to DOM
$('#feed').siblings('.profile-card').remove(); // remove any old profile card
console.log(data);
$('#feed').before(' <div class="profile-card group">\
<div class="profile-header-inner" style="background-image:url(' + data.original_logo + ')">\
<div class="profile-header-inner-overlay"></div>\
@ -584,22 +583,35 @@ function setNewCurrentStream(streamObject,setLocation,fallbackId,actionOnSuccess
return;
}
// if we have a fallbackId and a userArray, and the userArray's is is not equal to
// if we have a fallbackId and a userArray, and the userArray's id is not equal to
// the fallackId, this is the wrong stream! we need to re-invoke setNewCurrentStream()
// with the correct and up-to-date nickname (maybe best not to send a fallbackId here not
// to risk getting into an infinite loop caused by bad data)
// also, we do the same thing if getting the stream fails, but we have a fallback id
if((userArray && fallbackId && userArray.id != fallbackId)
|| (queet_data === false && fallbackId)) {
getNicknameByUserIdFromAPI(fallbackId,function(nickname) {
if(nickname) {
setNewCurrentStream(pathToStreamRouter(nickname),true,false,actionOnSuccess);
}
else {
// redirect to front page if everything fails
setNewCurrentStream(pathToStreamRouter('/'),true,false,actionOnSuccess);
}
});
if(streamObject.name == 'profile') {
getNicknameByUserIdFromAPI(fallbackId,function(nickname) {
if(nickname) {
setNewCurrentStream(pathToStreamRouter(nickname),true,false,actionOnSuccess);
}
else {
// redirect to front page if everything fails
setNewCurrentStream(pathToStreamRouter('/'),true,false,actionOnSuccess);
}
});
}
else if(streamObject.name == 'group notice stream') {
getNicknameByGroupIdFromAPI(fallbackId,function(nickname) {
if(nickname) {
setNewCurrentStream(pathToStreamRouter('group/' + nickname),true,false,actionOnSuccess);
}
else {
// redirect to front page if everything fails
setNewCurrentStream(pathToStreamRouter('/'),true,false,actionOnSuccess);
}
});
}
}
// getting stream failed, and we don't have a fallback id, redirect to front page

View File

@ -1331,6 +1331,32 @@ $('body').on('click','a', function(e) {
});
}
}
// same with group/{id}/id links
else if(streamObject.name == 'group notice stream by id') {
// we might be member of the group and thereby already know its nickname
if (typeof window.groupMemberships != 'undefined' && typeof window.groupMemberships[streamObject.id] != 'undefined') {
setNewCurrentStream(pathToStreamRouter('group/' + window.groupMemberships[streamObject.id].username),true,streamObject.id);
}
// if the text() of the clicked element looks like a group nickname, use that (but send id to setNewCurrentStream() in case this is bad data)
else if(/^![a-zA-Z0-9]+$/.test($(e.target).text()) || /^[a-zA-Z0-9]+$/.test($(e.target).text())) {
var nickname = $(e.target).text();
if(nickname.indexOf('!') == 0) {
nickname = nickname.substring(1); // remove any starting !
}
setNewCurrentStream(pathToStreamRouter('group/' + nickname),true,streamObject.id);
}
// if we can't figure out or guess a nickname, query the server for it
else {
getNicknameByGroupIdFromAPI(streamObject.id,function(nickname) {
if(nickname) {
setNewCurrentStream(pathToStreamRouter('group/' + nickname),true,false);
}
else {
alert('group not found');
}
});
}
}
// all other links that qvitter can handle
else {
setNewCurrentStream(streamObject,true,false);