diff --git a/js/controller/ActivityController.js b/js/controller/ActivityController.js index 3d93c0327..bd09727ca 100644 --- a/js/controller/ActivityController.js +++ b/js/controller/ActivityController.js @@ -56,6 +56,10 @@ class ActivityController { let $target = $('.newCommentForm .message'); this.applyAtWho($target); + + this.activityservice.subscribe(this.$scope, function() { + self.$scope.$apply(); + }) } applyAtWho($target) { diff --git a/js/service/ActivityService.js b/js/service/ActivityService.js index a8cc988e3..19cfbcb57 100644 --- a/js/service/ActivityService.js +++ b/js/service/ActivityService.js @@ -38,6 +38,7 @@ class ActivityService { this.$filter = $filter; this.$http = $http; this.$q = $q; + this.$rootScope = $rootScope; this.data = {}; this.data[DECK_ACTIVITY_TYPE_BOARD] = {}; this.data[DECK_ACTIVITY_TYPE_CARD] = {}; @@ -52,7 +53,7 @@ class ActivityService { let item = this.toEnhanceWithComments[index]; item.commentModel = this.commentCollection.get(item.subject_rich[1].comment); if (typeof item.commentModel !== 'undefined') { - this.toEnhanceWithComments = this.toEnhanceWithComments.filter(entry => entry.id !== item.id); + this.toEnhanceWithComments = this.toEnhanceWithComments.filter(entry => entry.activity_id !== item.activity_id); } } } @@ -60,6 +61,7 @@ class ActivityService { if (typeof firstUnread !== 'undefined') { this.commentCollection.updateReadMarker(); } + this.notify(); }, this); this.commentCollection.on('add', function(model, collection, options) { // we need to update the model, because it consists of client data @@ -76,6 +78,19 @@ class ActivityService { }; } + /** + * We need a event here to properly update scope once the external data from + * the comments backbone js code has changed + */ + subscribe(scope, callback) { + let handler = this.$rootScope.$on('notify-comment-update', callback); + scope.$on('$destroy', handler); + } + + notify() { + this.$rootScope.$emit('notify-comment-update'); + } + static getUrl(type, id, since) { if (type === DECK_ACTIVITY_TYPE_CARD) { return OC.linkToOCS('apps/activity/api/v2/activity', 2) + 'filter?format=json&object_type=deck_card&object_id=' + id + '&limit=' + this.RESULT_PER_PAGE + '&since=' + since; @@ -117,13 +132,16 @@ class ActivityService { } fetchMoreActivities(type, id, success) { + const self = this; this.checkData(type, id); if (this.running === true) { return this.runningPromise; } if (!this.since[type][id].finished) { - this.commentCollection.fetchNext(); this.runningPromise = this.fetchCardActivities(type, id, this.since[type][id].oldest); + this.runningPromise.then(function() { + self.commentCollection.fetchNext(); + }); return this.runningPromise; } return Promise.reject();