-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlib.js
67 lines (63 loc) · 1.42 KB
/
lib.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
NotificationsSchema = new SimpleSchema({
notifyType: {
type: String,
denyUpdate: true
},
from: {
type:SimpleSchema.RegEx.Id,
denyUpdate: true
},
to: {
type: SimpleSchema.RegEx.Id,
denyUpdate: true
},
regarding: {
type: SimpleSchema.RegEx.Id,
optional: true,
denyUpdate: true
},
msg: {
type: String,
optional: true
},
fromMsg: {
type: String,
optional: true
},
accepted: {
type: Boolean,
defaultValue: false
},
declined: {
type: Boolean,
defaultValue: false
},
displayed: {
type: Boolean,
defaultValue: false
}
});
Notifications = new Meteor.Collection('Notifications');
Notifications.attachSchema( NotificationsSchema );
Notifications.allow({
'insert': function(userId, doc){
if( doc.accepted === true || doc.declined === true || doc.displayed === true ){
return false;
}
console.log( doc );
return (doc.from === Meteor.userId());
},
'update': function(userId, doc, fields, modifier){
if( modifier.$set.to !== undefined || modifier.$set.from !== undefined ){
return false;
}
return (doc.to === Meteor.userId());
},
'remove': function(userId, doc){
return (doc.from === Meteor.userId());
}
});
Notifications.relatedToUser = function( userId ){
return Notifications.find({$and: [{$or: [{from: userId}, {to: userId}]},{accepted: false,declined: false}] });
};
NotificationSettings = {};