-
Notifications
You must be signed in to change notification settings - Fork 2
/
notifications.js
executable file
·109 lines (105 loc) · 2.62 KB
/
notifications.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
Notifications = new Mongo.Collection('notifications');
Notifications.allow({
remove: ownsDocument
});
Notifications.deny({
insert: denyPermission,
update: denyPermission
});
Notifications.attachSchema(new SimpleSchema({
/* ID of user A who performed one of the following actions:
* - invited user B
* - commented on Activity Stream Element
* - sent a private message to user B */
userId: {
type: String,
denyUpdate: true,
autoform: {
omit: true
}
},
type: {
type: Number,
denyUpdate: true,
autoform: {
omit: true
}
},
conversationId: {
type: String,
optional: true,
autoform: {
omit: true
},
custom: function () {
return validateIdField(this, 1);
}
},
invitationId: {
type: String,
optional: true,
autoform: {
omit: true
},
custom: function () {
return validateIdField(this, 2);
}
},
commentId: {
type: String,
optional: true,
autoform: {
omit: true
},
custom: function () {
return validateIdField(this, 3);
}
},
productId: {
type: String,
optional: true,
autoform: {
omit: true
}
},
createdAt: {
type: Date,
autoValue: function () {
if (this.isInsert) return new Date;
else if (this.isUpsert) return {$setOnInsert: new Date};
else
/* Prevent user from supplying their own date. */
this.unset();
},
autoform: {
omit: true
}
},
updatedAt: {
type: Date,
autoValue: function () {
if (this.isInsert || this.isUpdate) return new Date;
else if (this.isUpsert) return {$setOnInsert: new Date};
else
/* Prevent user from supplying their own date. */
this.unset();
},
autoform: {
omit: true
}
}
}));
/**
* Returns true if:
* - type argument matches corresponding type field and ID field has been set.
* - type argument does not match corresponding type field and ID has not been set.
*/
function validateIdField(context, type) {
if (context.field('type').value == type) {
if (!context.isSet || context.value === null || context.value === "") return "required";
else return true;
} else {
if (context.isSet || context.value) return "notAllowed";
else return true;
}
}