-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample-chat.js
More file actions
42 lines (34 loc) · 966 Bytes
/
sample-chat.js
File metadata and controls
42 lines (34 loc) · 966 Bytes
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
Messages = new Mongo.Collection("messages");
if (Meteor.isClient) {
Template.message_list.helpers({
messages: function () {
var filter = {}
var sort = {
sort: {createdAt: -1}
}
return Messages.find(filter, sort);
}
});
Template.submit_text.events({
"submit form": function (event) {
// Prevent default browser form submit
event.preventDefault();
// Get value from form element
var msg = event.target.message.value;
// Insert a task into the collection
Messages.insert({
text: msg,
createdAt: new Date(), // current time
owner: Meteor.userId(), // _id of logged in user
username: Meteor.user().username // username of logged in user
});
// Clear form
event.target.message.value = "";
}
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
}