mirror of
https://github.com/overte-org/overte.git
synced 2025-07-24 01:23:55 +02:00
Fix the bugs, add the feature
This commit is contained in:
parent
713ddd5cef
commit
cf3c10c5b1
2 changed files with 40 additions and 19 deletions
|
@ -844,7 +844,7 @@ Rectangle {
|
||||||
boxSize: 24;
|
boxSize: 24;
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var newValue = model.connection !== "friend";
|
var newValue = model.connection !== "friend";
|
||||||
connectionsUserModel.setProperty(model.userIndex, styleData.role, newValue);
|
connectionsUserModel.setProperty(model.userIndex, styleData.role, (newValue ? "friend" : "connection"));
|
||||||
connectionsUserModelData[model.userIndex][styleData.role] = newValue; // Defensive programming
|
connectionsUserModelData[model.userIndex][styleData.role] = newValue; // Defensive programming
|
||||||
pal.sendToScript({method: newValue ? 'addFriend' : 'removeFriend', params: model.userName});
|
pal.sendToScript({method: newValue ? 'addFriend' : 'removeFriend', params: model.userName});
|
||||||
|
|
||||||
|
|
|
@ -268,7 +268,7 @@ function fromQml(message) { // messages are {method, params}, like json-rpc. See
|
||||||
break;
|
break;
|
||||||
case 'refreshConnections':
|
case 'refreshConnections':
|
||||||
print('Refreshing Connections...');
|
print('Refreshing Connections...');
|
||||||
getConnectionData();
|
getConnectionData(false);
|
||||||
UserActivityLogger.palAction("refresh_connections", "");
|
UserActivityLogger.palAction("refresh_connections", "");
|
||||||
break;
|
break;
|
||||||
case 'removeConnection':
|
case 'removeConnection':
|
||||||
|
@ -281,25 +281,27 @@ function fromQml(message) { // messages are {method, params}, like json-rpc. See
|
||||||
print("Error: unable to remove connection", connectionUserName, error || response.status);
|
print("Error: unable to remove connection", connectionUserName, error || response.status);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
getConnectionData();
|
getConnectionData(false);
|
||||||
});
|
});
|
||||||
break
|
break
|
||||||
|
|
||||||
case 'removeFriend':
|
case 'removeFriend':
|
||||||
friendUserName = message.params;
|
friendUserName = message.params;
|
||||||
|
print("Removing " + friendUserName + " from friends.");
|
||||||
request({
|
request({
|
||||||
uri: METAVERSE_BASE + '/api/v1/user/friends/' + friendUserName,
|
uri: METAVERSE_BASE + '/api/v1/user/friends/' + friendUserName,
|
||||||
method: 'DELETE'
|
method: 'DELETE'
|
||||||
}, function (error, response) {
|
}, function (error, response) {
|
||||||
if (error || (response.status !== 'success')) {
|
if (error || (response.status !== 'success')) {
|
||||||
print("Error: unable to unfriend", friendUserName, error || response.status);
|
print("Error: unable to unfriend " + friendUserName, error || response.status);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
getConnectionData();
|
getConnectionData(friendUserName);
|
||||||
});
|
});
|
||||||
break
|
break
|
||||||
case 'addFriend':
|
case 'addFriend':
|
||||||
friendUserName = message.params;
|
friendUserName = message.params;
|
||||||
|
print("Adding " + friendUserName + " to friends.");
|
||||||
request({
|
request({
|
||||||
uri: METAVERSE_BASE + '/api/v1/user/friends',
|
uri: METAVERSE_BASE + '/api/v1/user/friends',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
@ -312,7 +314,7 @@ function fromQml(message) { // messages are {method, params}, like json-rpc. See
|
||||||
print("Error: unable to friend " + friendUserName, error || response.status);
|
print("Error: unable to friend " + friendUserName, error || response.status);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
getConnectionData(); // For now, just refresh all connection data. Later, just refresh the one friended row.
|
getConnectionData(friendUserName);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
@ -360,8 +362,6 @@ function getProfilePicture(username, callback) { // callback(url) if successfull
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function getAvailableConnections(domain, callback) { // callback([{usename, location}...]) if successfull. (Logs otherwise)
|
function getAvailableConnections(domain, callback) { // callback([{usename, location}...]) if successfull. (Logs otherwise)
|
||||||
// The back end doesn't do user connections yet. Fake it by getting all users that have made themselves accessible to us,
|
|
||||||
// and pretending that they are all connections.
|
|
||||||
url = METAVERSE_BASE + '/api/v1/users?'
|
url = METAVERSE_BASE + '/api/v1/users?'
|
||||||
if (domain) {
|
if (domain) {
|
||||||
url += 'status=' + domain.slice(1, -1); // without curly braces
|
url += 'status=' + domain.slice(1, -1); // without curly braces
|
||||||
|
@ -372,8 +372,19 @@ function getAvailableConnections(domain, callback) { // callback([{usename, loca
|
||||||
callback(connectionsData.users);
|
callback(connectionsData.users);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
function getInfoAboutUser(specificUsername, callback) {
|
||||||
function getConnectionData(domain) { // Update all the usernames that I am entitled to see, using my login but not dependent on canKick.
|
url = METAVERSE_BASE + '/api/v1/users?filter=connections'
|
||||||
|
requestJSON(url, function (connectionsData) {
|
||||||
|
for (user in connectionsData.users) {
|
||||||
|
if (connectionsData.users[user].username === specificUsername) {
|
||||||
|
callback(connectionsData.users[user]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
callback(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function getConnectionData(specificUsername, domain) { // Update all the usernames that I am entitled to see, using my login but not dependent on canKick.
|
||||||
function frob(user) { // get into the right format
|
function frob(user) { // get into the right format
|
||||||
var formattedSessionId = user.location.node_id || '';
|
var formattedSessionId = user.location.node_id || '';
|
||||||
if (formattedSessionId !== '' && formattedSessionId.indexOf("{") != 0) {
|
if (formattedSessionId !== '' && formattedSessionId.indexOf("{") != 0) {
|
||||||
|
@ -387,6 +398,15 @@ function getConnectionData(domain) { // Update all the usernames that I am entit
|
||||||
placeName: (user.location.root || user.location.domain || {}).name || ''
|
placeName: (user.location.root || user.location.domain || {}).name || ''
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
if (specificUsername) {
|
||||||
|
getInfoAboutUser(specificUsername, function (user) {
|
||||||
|
if (user) {
|
||||||
|
updateUser(frob(user));
|
||||||
|
} else {
|
||||||
|
print('Error: Unable to find information about ' + specificUsername + ' in connectionsData!');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
getAvailableConnections(domain, function (users) {
|
getAvailableConnections(domain, function (users) {
|
||||||
if (domain) {
|
if (domain) {
|
||||||
users.forEach(function (user) {
|
users.forEach(function (user) {
|
||||||
|
@ -396,6 +416,7 @@ function getConnectionData(domain) { // Update all the usernames that I am entit
|
||||||
sendToQml({ method: 'connections', params: users.map(frob) });
|
sendToQml({ method: 'connections', params: users.map(frob) });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -472,7 +493,7 @@ function populateNearbyUserList(selectData, oldAudioData) {
|
||||||
data.push(avatarPalDatum);
|
data.push(avatarPalDatum);
|
||||||
print('PAL data:', JSON.stringify(avatarPalDatum));
|
print('PAL data:', JSON.stringify(avatarPalDatum));
|
||||||
});
|
});
|
||||||
getConnectionData(location.domainId); // Even admins don't get relationship data in requestUsernameFromID (which is still needed for admin status, which comes from domain).
|
getConnectionData(false, location.domainId); // Even admins don't get relationship data in requestUsernameFromID (which is still needed for admin status, which comes from domain).
|
||||||
conserveResources = Object.keys(avatarsOfInterest).length > 20;
|
conserveResources = Object.keys(avatarsOfInterest).length > 20;
|
||||||
sendToQml({ method: 'nearbyUsers', params: data });
|
sendToQml({ method: 'nearbyUsers', params: data });
|
||||||
if (selectData) {
|
if (selectData) {
|
||||||
|
|
Loading…
Reference in a new issue