Skip to content
This repository was archived by the owner on Feb 15, 2023. It is now read-only.

Commit 75461ef

Browse files
committed
expect mongoose connection to be injected
1 parent 570c3ea commit 75461ef

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

src/FeedManager.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,12 @@ FeedManager.prototype = {
6969
},
7070

7171
activityCreated: function(instance) {
72-
if (this.trackingEnabled(instance)){
72+
if (this.trackingEnabled(instance)) {
7373
var activity = instance.createActivity();
74-
instance.getStreamBackend().serializeActivities([activity]);
74+
var backend = instance.getStreamBackend();
75+
backend.serializeActivities([activity]);
7576
var feedType = instance.activityActorFeed() || this.settings.userFeed;
76-
var userId = instance.activityActorId();
77+
var userId = backend.getIdFromRef(activity.actor);
7778
feed = this.getFeed(feedType, userId);
7879
feed.addActivity(activity, function(err, response, body) {
7980
if (err) console.log('err: ', err);
@@ -82,7 +83,7 @@ FeedManager.prototype = {
8283
},
8384

8485
activityDeleted: function(instance) {
85-
if (this.trackingEnabled(instance)){
86+
if (this.trackingEnabled(instance)) {
8687
var activity = instance.createActivity();
8788
feed = this.getFeed(this.settings.userFeed, activity.actor);
8889
feed.removeActivity({'foreignId': activity.foreign_id}, function(err, response, body) {

src/backends/activity.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@ BaseActivity.methods.activityActor = function() {
2222
return actor;
2323
};
2424

25-
BaseActivity.methods.activityActorId = function() {
26-
var actor = this.activityGetActor();
27-
if (typeof(actor.activityInstanceReference) === 'function') {
28-
return actor.activityInstanceReference(actor);
29-
} else {
30-
return actor;
31-
}
32-
};
33-
3425
BaseActivity.methods.activityObject = function() {
3526
return this;
3627
};

src/backends/mongoose.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
var BaseActivity = require('./activity.js');
22
var util = require("util");
3-
var mongoose = require('mongoose');
43
var stream = require('../index.js');
54

65
function Backend() {}
76

8-
util.inherits(Backend, stream.BaseBackend);
7+
function setupMongoose(m) {
8+
Backend.prototype.getMongoose = function () { return m };
9+
}
910

11+
util.inherits(Backend, stream.BaseBackend);
1012

1113
Backend.prototype.serializeValue = function(value) {
1214
if (typeof(value._id) != "undefined") {
@@ -31,9 +33,14 @@ Backend.prototype.loadFromStorage = function(modelClass, objectsIds, callback) {
3133
};
3234

3335
Backend.prototype.getClassFromRef = function(ref) {
36+
var mongoose = this.getMongoose();
3437
return mongoose.model(ref);
3538
}
3639

40+
Backend.prototype.getIdFromRef = function(ref) {
41+
return ref.split(':')[1];
42+
}
43+
3744
function extendSchema(base, mixin) {
3845
if (typeof base.methods === 'undefined') {
3946
base.methods = {};
@@ -93,3 +100,4 @@ var activitySchema = function(Schema) {
93100

94101
module.exports.activitySchema = activitySchema;
95102
module.exports.Backend = Backend;
103+
module.exports.setupMongoose = setupMongoose;

src/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ var config = require('./config.js');
33
var settings = config();
44
var BaseBackend = require('./backends/base.js');
55

6-
// TODO: make sure this happens only once!
7-
// appears to be happening once only : )
86
module.exports.FeedManager = new FeedManager(settings);
97
module.exports.BaseBackend = BaseBackend;
108
module.exports.mongoose = require('./backends/mongoose.js');
9+
module.exports.settings = settings;

0 commit comments

Comments
 (0)