Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
TheConnMan committed Jan 13, 2017
2 parents b317cd7 + b88d058 commit da085dd
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 18 deletions.
10 changes: 7 additions & 3 deletions api/controllers/ApiController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
});
},
Expand All @@ -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);
Expand Down
16 changes: 10 additions & 6 deletions api/services/ChatService.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,32 @@ module.exports = {
};

function getChats() {
return Chat.find();
return Chat.find({
createdAt: {
'>=': new Date(Date.now() - 24 * 3600 * 1000)
}
});
}

function addUserMessage(chat) {
chat.time = new Date(chat.time).toISOString();
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);
Expand All @@ -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));
}
8 changes: 4 additions & 4 deletions api/services/SyncService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand All @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion api/services/YouTubeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}
Expand Down
12 changes: 11 additions & 1 deletion assets/components/chat.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h2 class="ui dividing header">Chat
</div>
</h2>
<div id="chat-list" class="ui feed fg-1" style="overflow-y: auto; word-break: break-word;">
<div class="event" ng-repeat="chat in $ctrl.chats | orderBy: time track by $index">
<div class="event" ng-repeat="chat in $ctrl.getChats() | orderBy: time track by $index">
<div class="content" ng-if="$ctrl.showUsername($index)">
<div class="summary">
<div class="user">
Expand All @@ -20,10 +20,20 @@ <h2 class="ui dividing header">Chat
<div am-time-ago="{{$ctrl.getTime(chat)}}" class="date"></div>
</div>
<div class="extra text chat {{chat.type === 'user' ? '' : 'content minimal'}}">
<i class="plus icon" ng-if="chat.type === 'addVideo'"></i>
<i class="play icon" ng-if="chat.type === 'videoPlaying'"></i>
<i class="fast forward icon" ng-if="chat.type === 'videoSkipped'"></i>
<i class="user icon" ng-if="chat.type === 'userEnter'"></i>
<i class="eject icon" ng-if="chat.type === 'userLeft'"></i>
{{chat.message}}
</div>
</div>
<div class="content color-black chat {{chat.type === 'user' ? '' : 'content minimal'}}" ng-if="!$ctrl.showUsername($index)">
<i class="plus icon" ng-if="chat.type === 'addVideo'"></i>
<i class="play icon" ng-if="chat.type === 'videoPlaying'"></i>
<i class="fast forward icon" ng-if="chat.type === 'videoSkipped'"></i>
<i class="user icon" ng-if="chat.type === 'userEnter'"></i>
<i class="eject icon" ng-if="chat.type === 'userLeft'"></i>
{{chat.message}}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion assets/components/playlist.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h2 class="ui dividing header">Videos
</h2>
<div id="video-list" ng-if="$ctrl.getVideos().length > 0" class="ui items">
<div class="item" ng-repeat="video in $ctrl.getVideos() | orderBy: createdAt track by video.id">
<div class="ui image">
<div class="ui image" ng-if="video.thumbnail">
<img ng-src="{{video.thumbnail}}">
</div>
<div class="content">
Expand Down
6 changes: 5 additions & 1 deletion assets/js/components/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
};
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "JukeBot",
"version": "1.3.0",
"version": "1.3.1",
"description": "Slack-Enabled Syncronized Music Listening",
"keywords": [],
"dependencies": {
Expand Down
3 changes: 3 additions & 0 deletions views/partials/header.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@
<a class="ui item">
JukeBot v<%= sails.config.globals.version %>
</a>
<a class="icon item" href="https://github.com/TheConnMan/jukebot/issues" target="_blank" title="Open an Issue">
<i class="large github icon"></i>
</a>
</div>
</div>

0 comments on commit da085dd

Please sign in to comment.