This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function unixTimestampSeconds() { | |
return Math.floor(Date.now() / 1000); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function messageData () { | |
var fiveHoursAgo = unixTimestampSeconds() - 5 * 60 * 60; | |
return Messages.find({unixTimestamp: {$gte: fiveHoursAgo}}); | |
} | |
function userData () { | |
return Meteor.users.find({}, {fields: {'status.online': 1, username: 1}}); | |
} | |
if (Meteor.isServer) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In `meteor shell`: | |
> new Mongo.Collection("messages") | |
Error: A method named '/messages/insert' is already defined | |
at packages/ddp/livedata_server.js:1461:1 | |
at Function._.each._.forEach (packages/underscore/underscore.js:113:1) | |
at [object Object]._.extend.methods (packages/ddp/livedata_server.js:1459:1) | |
at [object Object].Mongo.Collection._defineMutationMethods (packages/mongo/collection.js:904:1) | |
at new Mongo.Collection (packages/mongo/collection.js:209:1) | |
at [object Object].ns.Collection (packages/lai:collection-extensions/collection-extensions.js:71:1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> Rooms.findOne({name: 'linux'}) | |
{ _id: 'QrBSYEy4PQL9e6svb', | |
name: 'linux', | |
unixTimestamp: 1428397795, | |
joinedUsers: [ 'JNkrbokz2393fLDjg' ] } | |
> Rooms.findOne({name: "doesn't exist"}) | |
> x = Rooms.findOne({name: "doesn't exist"}) | |
> x | |
> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Template.body.helpers({ | |
messages: function () { | |
return Messages.find({room: $('#joined-rooms').val()}); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (Meteor.isServer) { | |
function onlineUsers () { | |
return function () { | |
return Meteor.users.find({'status.online': true}, {fields: {'status.online': 1, username: 1}}); | |
} | |
} | |
Meteor.publish("onlineUsers", onlineUsers); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<section id="users"> | |
{{#with room}} | |
{{#each joinedUsers}} | |
<div class="user">{{this}}</div> | |
{{/each} | |
{{/each}} | |
</section> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template name="roomsList"> | |
<div class="modal fade"> | |
<div class="modal-dialog"> | |
<div class="modal-content"> | |
<div class="modal-header"> | |
<h4 class="modal-title">Rooms List</h4> | |
</div> | |
<div class="modal-body"> | |
<table> | |
{{#each rooms}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'click #join-room': function (event) { | |
bootbox.prompt("Enter the name of the room you want to join.", function(roomName) { | |
if (roomName !== null) { | |
joinRoom(roomName); | |
$('#joined-rooms').val(roomName); // this is the line that isn't working. | |
} | |
}); | |
}, |