Skip to content

Commit

Permalink
feat: Suggest Kudos Receiver by default instead of Sender -MEED-7619 -
Browse files Browse the repository at this point in the history
…Meeds-io/meeds#1479 (#537)

Prior to this change, when clicking on 'Kudos' button to send a kudos to
originating Kudos activity receiver, the default behavior was to send
the kudos to the Kudos writer. This change will change it to choose by
default the Kudos Receiver instead.
  • Loading branch information
boubaker authored and exo-swf committed Oct 10, 2024
1 parent ed50ea9 commit af6d219
Showing 1 changed file with 23 additions and 3 deletions.
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

0 comments on commit af6d219

Please sign in to comment.