mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
f1b42a3d0d
Chat reactification GitOrigin-RevId: ee1268b412513a8656703257febad4975adb74e7
42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
import App from '../../../base'
|
|
import { react2angular } from 'react2angular'
|
|
import ChatPane from '../components/chat-pane'
|
|
|
|
App.controller('ReactChatController', function($scope, chatMessages, ide) {
|
|
ide.$scope.$on('chat:more-messages-loaded', onMoreMessagesLoaded)
|
|
function onMoreMessagesLoaded(e, chat) {
|
|
ide.$scope.$applyAsync(() => {
|
|
$scope.atEnd = chatMessages.state.atEnd
|
|
$scope.loading = chat.state.loading
|
|
$scope.messages = chat.state.messages.slice(0) // passing a new reference to trigger a prop update on react
|
|
})
|
|
}
|
|
|
|
ide.$scope.$on('chat:more-messages-loading', onMoreMessagesLoading)
|
|
function onMoreMessagesLoading(e, chat) {
|
|
ide.$scope.$applyAsync(() => {
|
|
$scope.loading = true
|
|
})
|
|
}
|
|
|
|
function sendMessage(message) {
|
|
if (message) {
|
|
chatMessages.sendMessage(message)
|
|
ide.$scope.$broadcast('chat:newMessage', message)
|
|
}
|
|
}
|
|
|
|
function resetUnreadMessages() {
|
|
ide.$scope.$broadcast('chat:resetUnreadMessages')
|
|
}
|
|
|
|
$scope.atEnd = chatMessages.state.atEnd
|
|
$scope.loading = chatMessages.state.loading
|
|
$scope.loadMoreMessages = chatMessages.loadMoreMessages
|
|
$scope.messages = chatMessages.state.messages
|
|
$scope.resetUnreadMessages = resetUnreadMessages
|
|
$scope.sendMessage = sendMessage
|
|
$scope.userId = ide.$scope.user.id
|
|
})
|
|
|
|
App.component('chat', react2angular(ChatPane))
|