I came across the strange behavior of meteors in a collection subscription. I have one abstract route mailbox and there are three routes below this. Inbox, sent and singleMail (which shows the details of one mail from both). Now the problem is when I solve a collection of mail messages on one email route, it links the same collection of letters for both incoming and sent, despite the fact that I publish another collection for both. Note: it works perfect until I switch to one mail route from both. for example, when I click on any mail from the Inbox or send it, it will be sent to one mail route and show the details of the email. and when back. this is where the problem begins. he signs a collection of letters for both. that is, if in the folder "Inbox "6 and 3 sent, they will display 9. I tried the clock, but I’m out of luck. Any help is really appreciated! I insert a lot of code to solve my exact problem. Here is mail.js on the server
Meteor.publish("mails", function (obj) {
isAuth(this);
var query = {identity:this.userId};
if (obj) {
query[obj.condition] = obj.id;
}
return Mails.find(query);
});
Meteor.publish("mailsTo", function (options) {
isAuth(this);
Counts.publish(this, 'countOfNewMails', Mails.find({identity: this.userId, 'to.id': this.userId, unread: true}));
Counts.publish(this, 'countOfToMails', Mails.find({identity: this.userId, 'to.id': this.userId}), { noReady: true });
return Mails.find({identity: this.userId, 'to.id': this.userId}, options);
});
Meteor.publish("mailsFrom", function (options) {
isAuth(this);
Counts.publish(this, 'countOfFromMails', Mails.find({identity: this.userId, from: this.userId}), { noReady: true });
return Mails.find({identity: this.userId, from: this.userId}, options);
});
route.js
angular.module('Secret')
.config(['$urlRouterProvider', '$stateProvider', '$locationProvider',
function($urlRouterProvider, $stateProvider, $locationProvider){
$locationProvider.html5Mode(true);
$stateProvider
.state('home', {
url: '/home',
templateUrl: 'client/home/views/home.ng.html',
controller: 'homeCtrl'
})
.state('login', {
url: '/homes/:id/login',
templateUrl: 'client/login/views/login.ng.html',
controller: 'loginCtrl'
})
.state('signup', {
url: '/homes/:id/signup',
templateUrl: 'client/signup/views/signup.ng.html',
controller: 'signupCtrl'
})
.state('forgotPassword', {
url: '/homes/:id/forgot-password',
templateUrl: 'client/forgotPassword/views/forgotPassword.ng.html',
controller: 'forgotPasswordCtrl'
})
.state('profile', {
url: '/profile',
templateUrl: 'client/profile/views/profile.ng.html',
controller: 'profile'
})
.state('mailbox', {
url: '/mailbox',
templateUrl: 'client/mailBox/views/mailbox.ng.html',
controller: 'mailboxCtrl',
abstract: true
})
.state('mailbox.inbox', {
url: '/inbox',
templateUrl: 'client/inbox/views/inbox.ng.html',
controller: 'inboxCtrl',
resolve: {
"currentUser": ["$meteor", function($meteor){
return $meteor.requireUser();
}]
}
})
.state('mailbox.sent', {
url: '/sent',
templateUrl: 'client/sent/views/sent.ng.html',
controller: 'sentCtrl'
})
.state('mailbox.singleMail', {
url: '/:folder/:id',
params: {
hasnext: null
},
templateUrl: 'client/singleMail/views/single.ng.html',
controller: 'singleCtrl',
resolve: {
"currentUser": ["$meteor", function($meteor){
return $meteor.requireUser();
}],
statesSub: ['$meteor', '$stateParams', function($meteor, $stateParams) {
return $meteor.subscribe('mails', $stateParams.id);
}]
}
})
.state('mailbox.compose', {
url: '/compose/:r/:mailId',
templateUrl: 'client/compose/views/compose.ng.html',
controller: 'composeCtrl'
})
$urlRouterProvider.otherwise("/home");
}])
.run(['$rootScope', '$state',
function($rootScope, $state){
$rootScope.$on("$stateChangeError", function(event, next, previous, error) {
$state.go("home");
});
}]);
- SentCtrl
$scope.page = 1;
$scope.perPage = 50;
$scope.sort = { createdAt: -1 };
$meteor.autorun($scope, function() {
$scope.mails = $scope.$meteorCollection(Mails).subscribe('mailsFrom',{
limit: parseInt($scope.getReactively('perPage')),
skip: (parseInt($scope.getReactively('page')) - 1) * parseInt($scope.getReactively('perPage')),
sort: $scope.getReactively('sort')
})
})
InboxCtrl
$scope.page = 1;
$scope.perPage = 50;
$scope.sort = { createdAt: -1 };
$scope.pagechanged = function(sign){
sign ? $scope.page++ : $scope.page--;
}
$meteor.autorun($scope, function() {
$scope.inbox = $scope.$meteorCollection(Mails).subscribe('mailsTo',{
limit: parseInt($scope.getReactively('perPage')),
skip: (parseInt($scope.getReactively('page')) - 1) * parseInt($scope.getReactively('perPage')),
sort: $scope.getReactively('sort')
})
})
$scope.currentMail = $meteor.object(Mails, $stateParams.id);