Skip to content

Commit

Permalink
Merge pull request #7096 from RocketChat/convert-livechat-to-js
Browse files Browse the repository at this point in the history
Convert Livechat from Coffeescript to JavaScript
  • Loading branch information
sampaiodiego authored May 26, 2017
2 parents abcc585 + 883db06 commit e3945d0
Show file tree
Hide file tree
Showing 33 changed files with 983 additions and 652 deletions.
2 changes: 1 addition & 1 deletion packages/rocketchat-lib/server/functions/sendMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RocketChat.sendMessage = function(user, message, room, upsert = false) {
message.msg = '';
}
message.rid = room._id;
if (room.usernames || room.usernames.length === 0) {
if (!room.usernames || room.usernames.length === 0) {
const updated_room = RocketChat.models.Rooms.findOneById(room._id);
if (updated_room != null) {
room = updated_room;
Expand Down
1 change: 0 additions & 1 deletion packages/rocketchat-livechat/app/.meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ underscore@1.0.10
jquery@1.11.10
random@1.0.10
ejson@1.0.13
coffeescript
rocketchat:streamer
kadira:flow-router
kadira:blaze-layout
Expand Down
57 changes: 0 additions & 57 deletions packages/rocketchat-livechat/app/client/lib/_visitor.coffee

This file was deleted.

66 changes: 66 additions & 0 deletions packages/rocketchat-livechat/app/client/lib/_visitor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* globals Commands */
const msgStream = new Meteor.Streamer('room-messages');

this.visitor = new class {
constructor() {
this.token = new ReactiveVar(null);
this.room = new ReactiveVar(null);
this.roomToSubscribe = new ReactiveVar(null);
this.roomSubscribed = null;
}

register() {
if (!localStorage.getItem('visitorToken')) {
localStorage.setItem('visitorToken', Random.id());
}

this.token.set(localStorage.getItem('visitorToken'));
}

getToken() {
return this.token.get();
}

setRoom(rid) {
this.room.set(rid);
}

getRoom(createOnEmpty = false) {
let roomId = this.room.get();
if (!roomId && createOnEmpty) {
roomId = Random.id();
this.room.set(roomId);
}

return roomId;
}

isSubscribed(roomId) {
return this.roomSubscribed === roomId;
}

subscribeToRoom(roomId) {
if (this.roomSubscribed && this.roomSubscribed === roomId) {
return;
}

this.roomSubscribed = roomId;

msgStream.on(roomId, (msg) => {
if (msg.t === 'command') {
Commands[msg.msg] && Commands[msg.msg]();
} else if (msg.t !== 'livechat_video_call') {
ChatMessage.upsert({ _id: msg._id }, msg);

if (msg.t === 'livechat-close') {
parentCall('callback', 'chat-ended');
}

// notification sound
if (Session.equals('sound', true) && msg.u._id !== Meteor.userId()) {
$('#chatAudioNotification')[0].play();
}
}
});
}
};
220 changes: 0 additions & 220 deletions packages/rocketchat-livechat/app/client/lib/chatMessages.coffee

This file was deleted.

Loading

0 comments on commit e3945d0

Please sign in to comment.