From 2a1e82ce46905d7b8bd05d98f67aa4885288d57c Mon Sep 17 00:00:00 2001 From: James Allen Date: Thu, 15 Dec 2016 15:30:00 +0000 Subject: [PATCH 1/4] Delete unused public dir --- services/chat/public/app.build.js | 25 - services/chat/public/coffee/chat.coffee | 109 - .../coffee/collections/connectedUsers.coffee | 9 - .../public/coffee/collections/messages.coffee | 45 - .../chat/public/coffee/models/message.coffee | 5 - .../chat/public/coffee/models/room.coffee | 85 - .../chat/public/coffee/models/user.coffee | 13 - .../public/coffee/utils/staticLoader.coffee | 10 - .../public/coffee/views/chatWindowView.coffee | 219 - .../coffee/views/timeMessageBlockView.coffee | 40 - .../coffee/views/userMessageBlockView.coffee | 64 - services/chat/public/jade/templates.jade | 24 - services/chat/public/js/libs/backbone.js | 1571 - services/chat/public/js/libs/jquery.js | 9478 ------ .../chat/public/js/libs/jquery.storage.js | 85 - services/chat/public/js/libs/moment.js | 6 - services/chat/public/js/libs/underscore.js | 1227 - services/chat/public/js/r.js | 26058 ---------------- services/chat/public/js/text.js | 373 - services/chat/public/less/chat.less | 198 - 20 files changed, 39644 deletions(-) delete mode 100644 services/chat/public/app.build.js delete mode 100644 services/chat/public/coffee/chat.coffee delete mode 100644 services/chat/public/coffee/collections/connectedUsers.coffee delete mode 100644 services/chat/public/coffee/collections/messages.coffee delete mode 100644 services/chat/public/coffee/models/message.coffee delete mode 100644 services/chat/public/coffee/models/room.coffee delete mode 100644 services/chat/public/coffee/models/user.coffee delete mode 100644 services/chat/public/coffee/utils/staticLoader.coffee delete mode 100644 services/chat/public/coffee/views/chatWindowView.coffee delete mode 100644 services/chat/public/coffee/views/timeMessageBlockView.coffee delete mode 100644 services/chat/public/coffee/views/userMessageBlockView.coffee delete mode 100644 services/chat/public/jade/templates.jade delete mode 100644 services/chat/public/js/libs/backbone.js delete mode 100644 services/chat/public/js/libs/jquery.js delete mode 100644 services/chat/public/js/libs/jquery.storage.js delete mode 100644 services/chat/public/js/libs/moment.js delete mode 100644 services/chat/public/js/libs/underscore.js delete mode 100644 services/chat/public/js/r.js delete mode 100644 services/chat/public/js/text.js delete mode 100644 services/chat/public/less/chat.less diff --git a/services/chat/public/app.build.js b/services/chat/public/app.build.js deleted file mode 100644 index 1614b5cb7b..0000000000 --- a/services/chat/public/app.build.js +++ /dev/null @@ -1,25 +0,0 @@ -requirejs.config({ - baseUrl: "./build", - out: "./build/chat.js", - inlineText:true, - preserveLicenseComments:false, - shim: { - "libs/underscore": { - init: function() { - return _.noConflict(); - } - }, - "libs/backbone": { - deps: ["libs/underscore"], - init: function() { - return Backbone.noConflict(); - } - } - }, - paths: { - "moment": "libs/moment", - }, - name:"chat", - optimize: 'none', - skipDirOptimize: true -}) \ No newline at end of file diff --git a/services/chat/public/coffee/chat.coffee b/services/chat/public/coffee/chat.coffee deleted file mode 100644 index 473c916f83..0000000000 --- a/services/chat/public/coffee/chat.coffee +++ /dev/null @@ -1,109 +0,0 @@ -define [ - "utils/staticLoader" - "libs/underscore" - "libs/backbone" - "libs/jquery.storage" - "models/room" - "models/user" - "views/chatWindowView" - -], (staticLoader, _, Backbone, jqueryStorage, Room, User, ChatWindowView) -> - - staticLoader.appendAssets() - _.templateSettings = escape : /\{\{(.+?)\}\}/g - - class GlobalNotificationManager - constructor: (@chat) -> - @focussed = true - $(window).on "focus", () => - @clearNewMessageNotification() - @focussed = true - $(window).on "blur", () => @focussed = false - - @chat.on "joinedRoom", (room) => - notifyIfAppropriate = (message) => - if message.get("user") != @chat.user and !message.get("preloaded") - @notifyAboutNewMessage() - - room.get("messages").on "add", notifyIfAppropriate - room.on "disconnect", () -> - room.get("messages").off "add", notifyIfAppropriate - - notifyAboutNewMessage: () -> - if !@focussed and !@newMessageNotificationTimeout? - @originalTitle ||= window.document.title - do changeTitle = () => - if window.document.title == @originalTitle - window.document.title = "New Message" - else - window.document.title = @originalTitle - @newMessageNotificationTimeout = setTimeout changeTitle, 800 - - clearNewMessageNotification: () -> - clearTimeout @newMessageNotificationTimeout - delete @newMessageNotificationTimeout - if @originalTitle? - window.document.title = @originalTitle - - class Chat - constructor: (options) -> - _.extend(@, Backbone.Events) - window.chat = @ - @rooms = {} - project_id = window.location.pathname.split( '/' )[2] - @socket = socket = io.connect options.url, { - resource: "chat/socket.io", - "force new connection": true - query:"project_id=#{project_id}" - } - - @socket.on "connect", () => - @connected = true - @getAuthToken (error, auth_token) => - return @handleError(error) if error? - @socket.emit "auth", {auth_token: auth_token}, (error, user_info) => - return @handleError(error) if error? - @user = User.findOrCreate(user_info) - @joinProjectRoom(options.room.project_id) - @trigger "authed" - - @socket.on "disconnect", () => - @connected = false - @trigger "disconnected" - - @socket.on "messageReceived", (data) => - @getRoom(data.message.room.id)?.onMessageReceived(data) - - @socket.on "userJoined", (data) => - @getRoom(data.room.id).addConnectedUser(data.user) - - @socket.on "userLeft", (data) => - @getRoom(data.room.id)?.removeConnectedUser(data.user) - - @globalNotificationManager = new GlobalNotificationManager(@) - - getRoom: (room_id) -> - @rooms[room_id] - - joinProjectRoom: (project_id) -> - if !@room? - @room = new Room( - project_id: project_id - chat: @ - ) - @window = new ChatWindowView({ - room: @room - chat: @ - }) - @room.on "joined", => @trigger("joinedRoom", @room) - - getAuthToken: (callback = (error, auth_token) ->) -> - $.ajax "/user/auth_token", { - success: (data, status, xhr) -> - callback null, data - error: (xhr, status, error) -> - callback error - } - - handleError: (error) -> - console.error error diff --git a/services/chat/public/coffee/collections/connectedUsers.coffee b/services/chat/public/coffee/collections/connectedUsers.coffee deleted file mode 100644 index eee80e014c..0000000000 --- a/services/chat/public/coffee/collections/connectedUsers.coffee +++ /dev/null @@ -1,9 +0,0 @@ -define [ - "libs/backbone" - "models/user" -], (Backbone, User) -> - ConnectedUsers = Backbone.Collection.extend - model: User - - initialize: (models, options) -> - {@chat, @room} = options diff --git a/services/chat/public/coffee/collections/messages.coffee b/services/chat/public/coffee/collections/messages.coffee deleted file mode 100644 index d054df89f2..0000000000 --- a/services/chat/public/coffee/collections/messages.coffee +++ /dev/null @@ -1,45 +0,0 @@ -define [ - "libs/backbone" - "models/message" - "models/user" - -], (Backbone, Message, User) -> - - Messages = Backbone.Collection.extend - model: Message - - initialize: (models, options) -> - {@chat, @room} = options - - fetchMoreMessages: (options = { preloading: false }, callback = (error) ->) -> - limit = Messages.DEFAULT_MESSAGE_LIMIT - - @room.fetchMessages @_buildMessagesQuery(limit), (error, messages) => - if error? - callback(error) - return @chat.handleError(error) - if messages.length < limit - @trigger "noMoreMessages" - @_parseAndAddMessages(messages, options) - callback() - - _parseAndAddMessages: (messages, options) -> - for message in messages - user = User.findOrCreate message.user - @add new Message( - content : message.content - timestamp : message.timestamp - user : user - preloaded : !!options.preloading - ), at: 0 - - _buildMessagesQuery: (limit) -> - query = - limit: limit - firstMessage = @at(0) - if firstMessage? - query.before = firstMessage.get("timestamp") - return query - Messages.DEFAULT_MESSAGE_LIMIT = 50 - - return Messages \ No newline at end of file diff --git a/services/chat/public/coffee/models/message.coffee b/services/chat/public/coffee/models/message.coffee deleted file mode 100644 index 5b83fe686a..0000000000 --- a/services/chat/public/coffee/models/message.coffee +++ /dev/null @@ -1,5 +0,0 @@ -define [ - "libs/backbone" -], (Backbone) -> - - Message = Backbone.Model.extend {} \ No newline at end of file diff --git a/services/chat/public/coffee/models/room.coffee b/services/chat/public/coffee/models/room.coffee deleted file mode 100644 index df51bb57e1..0000000000 --- a/services/chat/public/coffee/models/room.coffee +++ /dev/null @@ -1,85 +0,0 @@ -define [ - "libs/underscore" - "libs/backbone" - "collections/messages" - "collections/connectedUsers" - "models/user" - "models/message" -], (_, Backbone, Messages, ConnectedUsers, User, Message) -> - - - Room = Backbone.Model.extend - initialize: () -> - @chat = @get("chat") - @set "messages", new Messages([], chat: @chat, room: @) - @set "connectedUsers", new ConnectedUsers([], chat: @chat, room: @) - - @get("connectedUsers").on "change", () -> - @get("connectedUsers").on "add", () -> - @get("connectedUsers").on "remove", () -> - - @connected = false - - @chat.on "authed", () => @join() - @chat.on "disconnected", () => @_onDisconnect() - - join: () -> - @chat.socket.emit "joinRoom", room: project_id: @get("project_id"), (error, data) => - return @chat.handleError(error) if error? - room = data.room - @set("id", room.id) - @chat.rooms[room.id] = @ - @addConnectedUsers(room.connectedUsers) - @_onJoin() - - _onJoin: () -> - @trigger "joined" - @connected = true - - if @get("messages").models.length == 0 - @get("messages").fetchMoreMessages preloading: true, () => - @trigger("afterMessagesPreloaded") - - _onDisconnect: () -> - @trigger "disconnected" - @connected = false - - addConnectedUsers: (users) -> - for user in users - @addConnectedUser(user) - - addConnectedUser: (user) -> - if user not instanceof User - user = User.findOrCreate(user) - @get("connectedUsers").add user - - removeConnectedUser: (user) -> - if user not instanceof User - user = User.findOrCreate(user) - @get("connectedUsers").remove user - - sendMessage: (content, callback = (error) ->) -> - if !@connected - return callback(new Error("Not connected")) - @chat.socket.emit "sendMessage", { - message: - content: content - room: - id: @get("id") - } - - fetchMessages: (query, callback = (error, messages) ->) -> - if !@connected - return callback(new Error("Not connected")) - query.room = id: @get("id") - @chat.socket.emit "getMessages", query, callback - - onMessageReceived: (data) -> - message = data.message - user = User.findOrCreate message.user - message = new Message( - content : data.message.content - timestamp : data.message.timestamp - user : user - ) - @get("messages").add message \ No newline at end of file diff --git a/services/chat/public/coffee/models/user.coffee b/services/chat/public/coffee/models/user.coffee deleted file mode 100644 index 103e9c9c5f..0000000000 --- a/services/chat/public/coffee/models/user.coffee +++ /dev/null @@ -1,13 +0,0 @@ -define [ - "libs/backbone" -], (Backbone, room) -> - - User = Backbone.Model.extend {}, - findOrCreate: (attributes) -> - User.cache ||= {} - if User.cache[attributes.id]? - return User.cache[attributes.id] - else - user = new User(attributes) - User.cache[attributes.id] = user - return user \ No newline at end of file diff --git a/services/chat/public/coffee/utils/staticLoader.coffee b/services/chat/public/coffee/utils/staticLoader.coffee deleted file mode 100644 index 763f322087..0000000000 --- a/services/chat/public/coffee/utils/staticLoader.coffee +++ /dev/null @@ -1,10 +0,0 @@ -define [ - "text!html/templates.html" - "text!css/chat.css" -], (templates, css)-> - - appendAssets : -> - $(document.body).append($(templates)) - style = $("