Small chat scroll tweaks

This commit is contained in:
James Allen 2014-07-16 10:52:06 +01:00
parent e0266e309f
commit 1d7a595c6c
4 changed files with 7 additions and 5 deletions

View file

@ -6,7 +6,7 @@ aside.chat(
infinite-scroll-disabled="chat.loading || chat.atEnd" infinite-scroll-disabled="chat.loading || chat.atEnd"
infinite-scroll-initialize="ui.chatOpen" infinite-scroll-initialize="ui.chatOpen"
infinite-scroll-upwards="true" infinite-scroll-upwards="true"
update-scroll-bottom-on="messages:updated" update-scroll-bottom-on="updateScrollPosition"
) )
.infinite-scroll-inner .infinite-scroll-inner
.loading(ng-show="chat.loading") .loading(ng-show="chat.loading")

View file

@ -1,7 +1,7 @@
define [ define [
"base" "base"
], (App) -> ], (App) ->
App.directive "updateScrollBottomOn", -> App.directive "updateScrollBottomOn", ($timeout) ->
return { return {
restrict: "A" restrict: "A"
link: (scope, element, attrs, ctrls) -> link: (scope, element, attrs, ctrls) ->
@ -29,7 +29,7 @@ define [
scrollBottom = element[0].scrollHeight - element[0].scrollTop - element[0].clientHeight scrollBottom = element[0].scrollHeight - element[0].scrollTop - element[0].clientHeight
scope.$on attrs.updateScrollBottomOn, () -> scope.$on attrs.updateScrollBottomOn, () ->
setTimeout () -> $timeout () ->
element.scrollTop(element[0].scrollHeight - element[0].clientHeight - scrollBottom) element.scrollTop(element[0].scrollHeight - element[0].clientHeight - scrollBottom)
, 0 , 0
} }

View file

@ -7,9 +7,12 @@ define [
$scope.$watch "chat.messages", (messages) -> $scope.$watch "chat.messages", (messages) ->
if messages? if messages?
$scope.$emit "messages:updated" $scope.$emit "updateScrollPosition"
, true # Deep watch , true # Deep watch
$scope.$on "layout:chat:resize", () ->
$scope.$emit "updateScrollPosition"
$scope.sendMessage = -> $scope.sendMessage = ->
chatMessages chatMessages
.sendMessage $scope.newMessageContent .sendMessage $scope.newMessageContent

View file

@ -34,7 +34,6 @@ define [
messages.reverse() messages.reverse()
prependMessages(messages) prependMessages(messages)
chat.state.nextBeforeTimestamp = chat.state.messages[0]?.timestamp chat.state.nextBeforeTimestamp = chat.state.messages[0]?.timestamp
console.log messages, chat.state
TIMESTAMP_GROUP_SIZE = 5 * 60 * 1000 # 5 minutes TIMESTAMP_GROUP_SIZE = 5 * 60 * 1000 # 5 minutes