Skip to content
This repository has been archived by the owner on May 4, 2020. It is now read-only.
/ scenic Public archive

Commit

Permalink
Serve the current picture on channel join.
Browse files Browse the repository at this point in the history
If the current picture is set with the last image in the channel.
When a picture uploaded, the current picture is changed with it.
If there's no picture in the channel, serve null.
  • Loading branch information
HyeonJe Jun committed Nov 17, 2012
1 parent 3c0db1d commit eca5544
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
8 changes: 8 additions & 0 deletions client/js/socket.js
Expand Up @@ -51,6 +51,14 @@ function Socket(channel) {
window.chat_view.onChatInput(function(msg) {
_this.io.emit('chat', {msg: msg});
});

// load image
if(data.picture !== null) {
window.app_view.main_view.render(data.picture.id, {width: data.picture.width, height: data.picture.height});
}
else {
window.app_view.main_view.render();
}
});

this.io.on('chat', function(data) {
Expand Down
21 changes: 18 additions & 3 deletions server/classes.js
Expand Up @@ -10,7 +10,17 @@ module.exports = {
this.channel = channel;
this.channel.addUser(this);
this.channel.notice(this.nick+" has joined.");
this.socket.emit('channel_joined', {nick:this.nick, channel: channel.model.name});

var picture = null;
if(this.channel.current_picture) {
picture = {
id: this.channel.current_picture._id,
width: this.channel.current_picture.width,
height: this.channel.current_picture.height
};
}

this.socket.emit('channel_joined', {nick:this.nick, channel: channel.model.name, picture: picture});
this.channel.updateUserlist();
};

Expand Down Expand Up @@ -44,7 +54,12 @@ module.exports = {
Channel: function(model) {
this.model = model;
this.users = [];
this.current_picture = null;
if(this.model.pictures.length > 0) {
this.current_picture = _.last(this.model.pictures);
}
else {
this.current_picture = null;
}

this.addUser = function(user) {
this.preventNickDuplication(user);
Expand Down Expand Up @@ -106,7 +121,7 @@ module.exports = {
};

this.changePicture = function(picture) {
this.current_picture = picture._id;
this.current_picture = picture;
_.each(this.users, function(user) {
user.socket.emit('picture_changed', {pid: picture._id, width: picture.width, height: picture.height});
});
Expand Down

0 comments on commit eca5544

Please sign in to comment.