forked from cesarve77/simple-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmethods.js
39 lines (37 loc) · 1.17 KB
/
methods.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
import {Meteor} from 'meteor/meteor'
import {check} from 'meteor/check'
import {Match} from 'meteor/check'
import {Chats} from './collections'
import {SimpleChat} from './config'
Meteor.methods({
"SimpleChat.newMessage": function (message, roomId, username, avatar, name, custom) {
check(message, String);
check(roomId, String);
check(username, Match.Maybe(String));
check(avatar, Match.Maybe(String));
check(name, Match.Maybe(String));
check(custom, Match.Any );
this.unblock()
if (!SimpleChat.options.allow.call(this, message, roomId, username, avatar, name))
throw new Meteor.Error(403, "Access deny")
message=_.escape(message)
const msg={
message,
roomId,
username,
name,
sent: !this.isSimulation,
receivedBy: [],
receivedAll: false,
viewedBy: [],
viewedAll: false,
userId: this.userId,
avatar,
custom,
date: new Date()
}
msg._id=Chats.insert(msg)
SimpleChat.options.onNewMessage(msg)
return msg
}
});