Skip to content

Commit

Permalink
Merge pull request #189 from GetStream/fix/sign-activities-copy
Browse files Browse the repository at this point in the history
Don't modify original activities when signing
  • Loading branch information
ruggi committed Aug 8, 2018
2 parents d9c7831 + 88dd62e commit 4025a6b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
27 changes: 15 additions & 12 deletions src/lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,23 +424,26 @@ StreamClient.prototype = {
return activities;
}

var signedActivities = [];
for (var i = 0; i < activities.length; i++) {
var activity = activities[i];
var activity = Object.assign({}, activities[i]);
var to = activity.to || [];
var signedTo = [];
for (var j = 0; j < to.length; j++) {
var feedId = to[j];
var feedSlug = feedId.split(':')[0];
var userId = feedId.split(':')[1];
var token = this.feed(feedSlug, userId).token;
var signedFeed = feedId + ' ' + token;
signedTo.push(signedFeed);
if (to.length > 0) {
var signedTo = [];
for (var j = 0; j < to.length; j++) {
var feedId = to[j];
var feedSlug = feedId.split(':')[0];
var userId = feedId.split(':')[1];
var token = this.feed(feedSlug, userId).token;
var signedFeed = feedId + ' ' + token;
signedTo.push(signedFeed);
}
activity.to = signedTo;
}

activity.to = signedTo;
signedActivities.push(activity);
}

return activities;
return signedActivities;
},

getFayeAuthorization: function() {
Expand Down
3 changes: 2 additions & 1 deletion test/unit/common/client_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,14 +331,15 @@ describe('[UNIT] Stream Client (Common)', function() {

var output = this.client.signActivities(activities);

expect(output).to.equal(activities);
expect(output).to.eql(activities);
});

it('(2) with to', function() {
var activities = [{ object: 0, actor: 'matthisk', verb: 'tweet', to: ['global:feed'] }];

var output = this.client.signActivities(activities);

expect(activities[0].to).to.eql(['global:feed'])
expect(output[0].to[0].split(' ')[0]).to.be('global:feed');

if (this.client.apiSecret) {
Expand Down

0 comments on commit 4025a6b

Please sign in to comment.