Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Suggest Kudos Receiver by default instead of Sender -MEED-7619 - Meeds-io/meeds#1479 #537

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions kudos-webapps/src/main/webapp/vue-app/js/KudosIdentity.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@ export function getReceiver(entityType, entityId) {
entityId = `comment${entityId}`;
}
return getActivityDetails(entityId)
.then((activityDetails) => {
if (activityDetails && activityDetails.owner && activityDetails.owner.href) {
.then(async (activityDetails) => {
if (activityDetails?.type === 'exokudos:activity') {
activityDetails.kudos = await getKudosByActivity(entityId);
}
const kudosReceiverId = activityDetails?.kudos?.receiverId;
if (kudosReceiverId) {
const kudosReceiverType = activityDetails?.kudos?.receiverType;
return getIdentityDetails(kudosReceiverId, kudosReceiverType, kudosReceiverId);
} else if (activityDetails?.owner?.href) {
isSpace = activityDetails.owner.href.indexOf('/spaces/') >= 0;
ownerType = isSpace ? 'space' : 'user';
const remoteId = activityDetails.owner.href.substring(activityDetails.owner.href.lastIndexOf('/') + 1);
Expand Down Expand Up @@ -74,7 +81,7 @@ export function getIdentityDetails(urlId, type, remoteId) {
return ownerDetails;
});
} else {
return fetch(`/portal/rest/v1/social/spaces/${urlId}`, {credentials: 'include'})
return fetch(`/portal/rest/v1/social/spaces/byPrettyName/${urlId}`, {credentials: 'include'})
.then((resp) => resp && resp.ok && resp.json())
.then((identityDetails) => {
if (identityDetails) {
Expand Down Expand Up @@ -110,6 +117,19 @@ export function getActivityDetails(activityId) {
}
}

export function getKudosByActivity(activityId) {
return fetch(`/kudos/rest/kudos/byActivity/${activityId}`, {
method: 'GET',
credentials: 'include',
}).then(resp => {
if (!resp || !resp.ok) {
throw new Error('Response code indicates a server error', resp);
} else {
return resp.json();
}
});
}

/*
* Search spaces from eXo Platform, used for suggester
*/
Expand Down