overleaf/services/web/public/coffee/ide/chat/controllers/ChatController.coffee
2015-02-07 16:15:33 +00:00

36 lines
No EOL
918 B
CoffeeScript

define [
"base"
"libs/autolinker"
"ide/chat/services/chatMessages"
], (App, autolinker) ->
App.controller "ChatController", ($scope, chatMessages, ide, $location) ->
$scope.chat = chatMessages.state
$scope.$watch "chat.messages", (messages) ->
if messages?
$scope.$emit "updateScrollPosition"
, true # Deep watch
$scope.$on "layout:chat:resize", () ->
$scope.$emit "updateScrollPosition"
$scope.$watch "chat.newMessage", (message) ->
if message?
ide.$scope.$broadcast "chat:newMessage", message
$scope.resetUnreadMessages = () ->
ide.$scope.$broadcast "chat:resetUnreadMessages"
$scope.sendMessage = ->
message = $scope.newMessageContent
$scope.newMessageContent = ""
chatMessages
.sendMessage message
$scope.loadMoreMessages = ->
chatMessages.loadMoreMessages()
$scope.linkify = (message)->
return autolinker.link(message)