mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-06 15:12:07 +00:00
Update chat UI immediately
This commit is contained in:
parent
d531e3b393
commit
361fe310ce
1 changed files with 22 additions and 10 deletions
|
@ -14,11 +14,27 @@ define [
|
|||
nextBeforeTimestamp: null
|
||||
newMessage: null
|
||||
}
|
||||
|
||||
|
||||
justSent = false
|
||||
ide.socket.on "new-chat-message", (message) =>
|
||||
ide.$scope.$apply () ->
|
||||
chat.state.newMessage = message
|
||||
appendMessage(message)
|
||||
if message.user.id == ide.$scope.user.id and justSent
|
||||
# Nothing to do
|
||||
else
|
||||
ide.$scope.$apply () ->
|
||||
appendMessage(message)
|
||||
justSent = false
|
||||
|
||||
chat.sendMessage = (message) ->
|
||||
body =
|
||||
content: message
|
||||
_csrf : window.csrfToken
|
||||
justSent = true
|
||||
appendMessage({
|
||||
user: ide.$scope.user
|
||||
content: message
|
||||
timestamp: Date.now()
|
||||
})
|
||||
return $http.post(MESSAGES_URL, body)
|
||||
|
||||
chat.loadMoreMessages = () ->
|
||||
return if chat.state.atEnd
|
||||
|
@ -60,6 +76,8 @@ define [
|
|||
prependMessage(message)
|
||||
|
||||
appendMessage = (message) ->
|
||||
chat.state.newMessage = message
|
||||
|
||||
lastMessage = chat.state.messages[chat.state.messages.length - 1]
|
||||
shouldGroup = lastMessage? and
|
||||
lastMessage.user.id == message.user.id and
|
||||
|
@ -74,10 +92,4 @@ define [
|
|||
contents: [message.content]
|
||||
})
|
||||
|
||||
chat.sendMessage = (message) ->
|
||||
body =
|
||||
content: message
|
||||
_csrf : window.csrfToken
|
||||
return $http.post(MESSAGES_URL, body)
|
||||
|
||||
return chat
|
Loading…
Add table
Reference in a new issue