Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Step 12.24: Add after hook for user modification
- Loading branch information
1 parent
3af2783
commit d68c948
Showing
1 changed file
with
11 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
import { MongoObservable } from 'meteor-rxjs'; | ||
import { Meteor } from 'meteor/meteor'; | ||
import { User } from '../models'; | ||
import { Pictures } from './pictures'; | ||
|
||
export const Users = MongoObservable.fromExisting<User>(Meteor.users); | ||
export const Users = MongoObservable.fromExisting<User>(Meteor.users); | ||
|
||
// Dispose unused profile pictures | ||
Meteor.users.after.update(function (userId, doc, fieldNames, modifier, options) { | ||
if (!doc.profile) return; | ||
if (!this.previous.profile) return; | ||
if (doc.profile.pictureId == this.previous.profile.pictureId) return; | ||
|
||
Pictures.collection.remove({ _id: doc.profile.pictureId }); | ||
}, { fetchPrevious: true }); |