Repository navigation
Expand file tree
/
Copy pathcallbacks.js
More file actions
173 lines (136 loc) · 5.13 KB
/
Copy pathcallbacks.js
File metadata and controls
173 lines (136 loc) · 5.13 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import Users from 'meteor/vulcan:users';
import Posts from 'meteor/vulcan:posts';
import { addCallback, removeCallback, getSetting, Utils } from 'meteor/vulcan:core';
import { createNotification } from 'meteor/vulcan:notifications';
import marked from 'marked';
removeCallback('categories.parameters', 'CategoriesAscOrderSorting');
const CategoriesDescOrderSorting = (parameters, terms) => {
parameters.options.sort = {order: -1};
return parameters;
};
addCallback('categories.parameters', CategoriesDescOrderSorting);
const CategoriesFilterVisible = (parameters, terms) => {
if (terms.onlyVisible) {
parameters.selector.visible = true;
}
return parameters;
};
addCallback('categories.parameters', CategoriesFilterVisible);
// only show sticky posts when filtering posts list by categorie
const PostsShowStickyOnlyOnCategories = (parameters, terms) => {
if (!terms.cat) {
parameters.selector.sticky = {$ne: true};
}
return parameters;
};
addCallback('posts.parameters', PostsShowStickyOnlyOnCategories);
const WiresNewAssignAdminRecipient = wire => {
const [ firstAdmin ] = Users.adminUsers({});
return {
...wire,
recipientId: firstAdmin._id,
};
};
addCallback('wires.new.sync', WiresNewAssignAdminRecipient);
removeCallback('wires.new.async', 'WiresNewSendEmailAsync');
const WiresNewSendFeedback = wire => {
const { senderId, recipientId, htmlBody, createdAt, reaction, parentComponentName, location, context } = wire;
const { email: senderEmail, slug: senderSlug, displayName: senderName } = Users.findOne({_id: senderId});
const { email: recipientEmail } = Users.findOne({_id: recipientId});
const notificationData = {
// email sender
senderEmail,
senderName,
senderProfile: `${Utils.getSiteUrl()}users/${senderSlug}`,
//email recipient
recipientEmail,
// email body
htmlBody,
createdAt,
reaction,
// parentComponentName,
location,
context,
};
createNotification(recipientId, 'newFeedback', notificationData);
};
addCallback('wires.new.async', WiresNewSendFeedback);
removeCallback('comments.new.sync', 'CommentsNewGenerateHTMLBody');
const CommentsNewGenerateHTMLBodyWithEmoji = (comment, user) => {
comment.htmlBody = Utils.sanitize(Utils.replaceEmojis(marked(comment.body)));
return comment;
}
addCallback("comments.new.sync", CommentsNewGenerateHTMLBodyWithEmoji);
removeCallback("comments.edit.sync", 'CommentsEditGenerateHTMLBody');
const CommentsEditGenerateHTMLBodyWithEmoji = (modifier, comment, user) => {
// if body is being modified, update htmlBody too
if (modifier.$set && modifier.$set.body) {
modifier.$set.htmlBody = Utils.sanitize(Utils.replaceEmojis(marked(modifier.$set.body)));
}
return modifier;
}
addCallback("comments.edit.sync", CommentsEditGenerateHTMLBodyWithEmoji);
removeCallback("posts.new.sync", "PostsNewHTMLContent")
const PostsNewHTMLContentWithEmoji = post => {
if (post.body) {
// excerpt length is configurable via the settings (30 words by default, ~255 characters)
const excerptLength = getSetting('postExcerptLength', 30);
// extend the post document
post = {
...post,
htmlBody: Utils.sanitize(Utils.replaceEmojis(marked(post.body))),
excerpt: Utils.trimHTML(Utils.sanitize(Utils.replaceEmojis(marked(post.body))), excerptLength),
};
}
return post;
}
addCallback("posts.new.sync", PostsNewHTMLContentWithEmoji);
removeCallback("posts.edit.sync", "PostsEditHTMLContent");
const PostsEditHTMLContentWithEmoji = (modifier, post) => {
if (modifier.$set && typeof modifier.$set.body !== 'undefined') {
// excerpt length is configurable via the settings (30 words by default, ~255 characters)
const excerptLength = getSetting('postExcerptLength', 30);
// extend the modifier
modifier.$set = {
...modifier.$set,
htmlBody: Utils.sanitize(Utils.replaceEmojis(marked(modifier.$set.body))),
excerpt: Utils.trimHTML(Utils.sanitize(Utils.replaceEmojis(marked(modifier.$set.body))), excerptLength),
};
} else if (modifier.$unset && modifier.$unset.body) {
// extend the modifier
modifier.$unset = {
...modifier.$unset,
htmlBody: true,
excerpt: true,
};
}
return modifier;
}
addCallback("posts.edit.sync", PostsEditHTMLContentWithEmoji);
removeCallback("posts.new.sync", "PostsNewSlugify");
/**
* @summary Set the post's slug based on its title
*/
const PostsNewSlugifyNoRepeat = post => {
let slug = Utils.slugify(post.title);
post.slug = Utils.getUnusedSlug(Posts, slug)
return post;
}
addCallback('posts.new.sync', PostsNewSlugifyNoRepeat);
removeCallback("posts.edit.sync", "PostsEditSlugify");
/**
* @summary If title is changing, return new slug
*/
const PostsEditSlugifyNoRepeat = (modifier, post) => {
if (modifier.$set && modifier.$set.title) {
let slug = Utils.slugify(modifier.$set.title);
modifier.$set.slug = Utils.getUnusedSlug(Posts, slug);
}
return modifier;
}
addCallback('posts.edit.sync', PostsEditSlugifyNoRepeat)
const TrophiesDescOrderSorting = (parameters, terms) => {
parameters.options.sort = {value: -1};
return parameters;
}
addCallback('trophies.parameters', TrophiesDescOrderSorting);