diff --git a/api/controllers/ApiController.js b/api/controllers/ApiController.js index 64b02ac..dc078fb 100644 --- a/api/controllers/ApiController.js +++ b/api/controllers/ApiController.js @@ -12,7 +12,7 @@ module.exports = { var index = recentlyLeft.indexOf(username); if (index === -1) { - ChatService.addMachineMessage(users[id] + ' entered the room', username); + ChatService.addMachineMessage(users[id] + ' entered the room', username, 'userEnter'); } else { recentlyLeft.splice(index, 1); } @@ -100,7 +100,11 @@ module.exports = { subscribeVideos: function(req, res) { Video.watch(req.socket); - Video.find().exec(function(err, videos) { + Video.find({ + createdAt: { + '>=': new Date(Date.now() - 24 * 3600 * 1000) + } + }).exec(function(err, videos) { Video.subscribe(req.socket, videos); }); }, @@ -125,7 +129,7 @@ function userDisconnected(username) { var index = recentlyLeft.indexOf(username); if (index !== -1) { recentlyLeft.splice(index, 1); - ChatService.addMachineMessage(username + ' left the room'); + ChatService.addMachineMessage(username + ' left the room', username, 'userLeft'); emitListeners(); if (Object.keys(users).length === 0) { SyncService.setAutoplay(false); diff --git a/api/services/ChatService.js b/api/services/ChatService.js index 715c6ad..e247075 100644 --- a/api/services/ChatService.js +++ b/api/services/ChatService.js @@ -9,7 +9,11 @@ module.exports = { }; function getChats() { - return Chat.find(); + return Chat.find({ + createdAt: { + '>=': new Date(Date.now() - 24 * 3600 * 1000) + } + }); } function addUserMessage(chat) { @@ -17,20 +21,20 @@ function addUserMessage(chat) { addMessage(chat); } -function addMachineMessage(message, username) { +function addMachineMessage(message, username, type='machine') { var chat = { message: message, - type: 'machine', + type: type, username: username, time: new Date().toISOString() }; addMessage(chat); } -function addVideoMessage(message) { +function addVideoMessage(message, type) { var chat = { message: message, - type: 'video', + type: type, time: new Date().toISOString() }; addMessage(chat); @@ -41,5 +45,5 @@ function addMessage(chat) { .then((c) => { sails.io.sockets.in('chatting').emit('chat', c); }) - .catch((e) => logger.warning(e)); + .catch((e) => logger.warn(e)); } diff --git a/api/services/SyncService.js b/api/services/SyncService.js index 59e857c..33019d0 100644 --- a/api/services/SyncService.js +++ b/api/services/SyncService.js @@ -63,7 +63,7 @@ function addPlaylist(videos) { function sendAddMessages(video) { return new Promise(function(resolve, reject) { Video.publishCreate(video); - ChatService.addVideoMessage(video.title + ' was added to the playlist by ' + video.user); + ChatService.addVideoMessage(video.title + ' was added to the playlist by ' + video.user, 'addVideo'); if (slack && sails.config.globals.slackSongPlaying && sails.config.globals.slackSongAdded) { sendSlackAddedNotification(video).then(function() { resolve(video); @@ -86,7 +86,7 @@ function sendPlaylistAddMessages(videos) { return new Promise((resolve, reject) => { Video.publishCreate(videos); if (videos.length !== 0) { - ChatService.addVideoMessage(videos.length + ' videos were added to the playlist by ' + videos[0].user); + ChatService.addVideoMessage(videos.length + ' videos were added to the playlist by ' + videos[0].user, 'addVideo'); if (slack && sails.config.globals.slackSongAdded) { sendSlackAddedNotification(videos).then(function() { resolve(); @@ -110,7 +110,7 @@ function endCurrentVideo(username) { playing: true }).exec(function(err, current) { if (username) { - ChatService.addMachineMessage(username + ' skipped ' + current.title, username); + ChatService.addMachineMessage(username + ' skipped ' + current.title, username, 'videoSkipped'); } current.playing = false; current.save(function() { @@ -143,7 +143,7 @@ function startVideo(video) { videoTimeout = setTimeout(endCurrentVideo, video.duration); video.save(() => { Video.publishUpdate(video.id, video); - ChatService.addVideoMessage(video.title + ' is now playing'); + ChatService.addVideoMessage(video.title + ' is now playing', 'videoPlaying'); if (slack && sails.config.globals.slackSongPlaying) { sendSlackPlayingNotification(video).then(function() { logger.info('Started playing video ' + video.key); diff --git a/api/services/YouTubeService.js b/api/services/YouTubeService.js index c3bba69..3290bd2 100644 --- a/api/services/YouTubeService.js +++ b/api/services/YouTubeService.js @@ -53,7 +53,7 @@ function parseYouTubeVideo(data, user) { key: item.id, duration: moment.duration(item.contentDetails.duration).asMilliseconds(), user: user, - thumbnail: item.snippet.thumbnails.default.url, + thumbnail: item.snippet.thumbnails ? item.snippet.thumbnails.default.url : null, title: item.snippet.title }); } diff --git a/assets/components/chat.html b/assets/components/chat.html index 7273e71..d0d3771 100644 --- a/assets/components/chat.html +++ b/assets/components/chat.html @@ -11,7 +11,7 @@

Chat

-
+
@@ -20,10 +20,20 @@

Chat

+ + + + + {{chat.message}}
+ + + + + {{chat.message}}
diff --git a/assets/components/playlist.html b/assets/components/playlist.html index e84f5e7..495d064 100644 --- a/assets/components/playlist.html +++ b/assets/components/playlist.html @@ -11,7 +11,7 @@

Videos

-
+
diff --git a/assets/js/components/chat.js b/assets/js/components/chat.js index 4e2c378..183f8da 100644 --- a/assets/js/components/chat.js +++ b/assets/js/components/chat.js @@ -17,6 +17,10 @@ function ChatController($rootScope, $scope, $http, $notification, $storage) { this.typers = ''; this.notifications = $storage.get('chat-notifications') === 'true' || !$storage.get('chat-notifications'); + this.getChats = function() { + return this.chats.filter(function(chat) { return new Date(chat.createdAt) >= new Date(Date.now() - 24 * 3600 * 1000); }); + }; + this.getUsername = function() { return self.username || 'Anonymous'; }; @@ -70,7 +74,7 @@ function ChatController($rootScope, $scope, $http, $notification, $storage) { io.socket.on('chat', (c) => { this.chats.push(c); - if (c.username !== this.getUsername() && this.notifications && c.type !== 'video') { + if (c.username !== this.getUsername() && this.notifications && c.type !== 'addVideo' && c.type !== 'videoSkipped' && c.type !== 'videoPlaying') { let notification = $notification(c.username || 'JukeBot', { body: c.message, delay: 4000, diff --git a/package.json b/package.json index 5317b52..c7c3832 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "JukeBot", - "version": "1.3.0", + "version": "1.3.1", "description": "Slack-Enabled Syncronized Music Listening", "keywords": [], "dependencies": { diff --git a/views/partials/header.ejs b/views/partials/header.ejs index 684a7de..cc3759c 100644 --- a/views/partials/header.ejs +++ b/views/partials/header.ejs @@ -24,5 +24,8 @@ JukeBot v<%= sails.config.globals.version %> + + +