Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
ulakbus-ui
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ulakbus
ulakbus-ui
Commits
d0781023
Commit
d0781023
authored
Aug 09, 2016
by
Vladimir Baranov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rref #5392. Stop loading if all messages loaded, keep scroll position when new messages loaded
parent
4e1ce1bd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
5 deletions
+30
-5
messaging.js
app/components/messaging/messaging.js
+29
-5
messaging_service.js
app/components/messaging/messaging_service.js
+1
-0
No files found.
app/components/messaging/messaging.js
View file @
d0781023
...
@@ -45,6 +45,7 @@ angular.module("ulakbus.messaging")
...
@@ -45,6 +45,7 @@ angular.module("ulakbus.messaging")
function
reset
(){
function
reset
(){
iScope
.
selectedChannel
=
null
;
iScope
.
selectedChannel
=
null
;
iScope
.
allMessagesLoaded
=
false
;
iScope
.
publicChannels
=
[];
iScope
.
publicChannels
=
[];
iScope
.
notificationsChannel
=
[];
iScope
.
notificationsChannel
=
[];
iScope
.
directChannels
=
[];
iScope
.
directChannels
=
[];
...
@@ -270,6 +271,8 @@ angular.module("ulakbus.messaging")
...
@@ -270,6 +271,8 @@ angular.module("ulakbus.messaging")
}
}
iScope
.
selectChannel
=
function
(
channel
,
silent
){
iScope
.
selectChannel
=
function
(
channel
,
silent
){
// enable channel history loading
iScope
.
allMessagesLoaded
=
false
;
var
channelKey
=
getKey
(
channel
);
var
channelKey
=
getKey
(
channel
);
selectChannel
(
channelKey
,
silent
).
then
(
function
(
result
){
selectChannel
(
channelKey
,
silent
).
then
(
function
(
result
){
iScope
.
selectedChannel
=
result
;
iScope
.
selectedChannel
=
result
;
...
@@ -367,11 +370,18 @@ angular.module("ulakbus.messaging")
...
@@ -367,11 +370,18 @@ angular.module("ulakbus.messaging")
};
};
iScope
.
loadMore
=
function
(){
iScope
.
loadMore
=
function
(){
if
(
iScope
.
allMessagesLoaded
)
return
;
if
(
iScope
.
selectedChannel
.
messages
.
length
>
0
){
if
(
iScope
.
selectedChannel
.
messages
.
length
>
0
){
var
first
=
iScope
.
selectedChannel
.
messages
[
0
];
var
first
=
iScope
.
selectedChannel
.
messages
[
0
];
return
MessagingService
.
channel_history
(
iScope
.
selectedChannel
,
first
.
timestamp
)
return
MessagingService
.
channel_history
(
getKey
(
iScope
.
selectedChannel
)
,
first
.
timestamp
)
.
then
(
function
(
result
){
.
then
(
function
(
result
){
console
.
error
(
"RES: "
,
result
);
var
messages
=
iScope
.
selectedChannel
.
messages
;
if
(
result
.
messages
.
length
==
0
){
iScope
.
allMessagesLoaded
=
true
;
return
;
}
// prepend loaded messages to current channel messages list
messages
.
unshift
.
apply
(
messages
,
result
.
messages
);
});
});
}
}
};
};
...
@@ -433,6 +443,7 @@ angular.module("ulakbus.messaging")
...
@@ -433,6 +443,7 @@ angular.module("ulakbus.messaging")
})
})
.
directive
(
"loadMoreTop"
,
function
(
$compile
,
$timeout
,
$q
)
{
.
directive
(
"loadMoreTop"
,
function
(
$compile
,
$timeout
,
$q
)
{
// centered loader
var
loaderTpl
=
$compile
(
'<div class="loader" style="float: none; margin: auto; margin-top: 10px;" ng-show="loading"></div>'
);
var
loaderTpl
=
$compile
(
'<div class="loader" style="float: none; margin: auto; margin-top: 10px;" ng-show="loading"></div>'
);
return
{
return
{
scope
:
{
scope
:
{
...
@@ -442,18 +453,31 @@ angular.module("ulakbus.messaging")
...
@@ -442,18 +453,31 @@ angular.module("ulakbus.messaging")
var
elem
=
$
(
iElem
);
var
elem
=
$
(
iElem
);
iElem
.
prepend
(
angular
.
element
(
loaderTpl
(
iScope
)));
iElem
.
prepend
(
angular
.
element
(
loaderTpl
(
iScope
)));
iScope
.
loading
=
false
;
iScope
.
loading
=
false
;
elem
.
scroll
(
function
(
e
){
function
onScroll
(){
var
scrollTop
=
elem
.
scrollTop
();
var
scrollTop
=
elem
.
scrollTop
();
if
(
scrollTop
<=
0
&&
!
iScope
.
loading
){
if
(
scrollTop
<=
0
&&
!
iScope
.
loading
){
if
(
iScope
.
loadMoreCallback
){
if
(
iScope
.
loadMoreCallback
){
// save last top element with id position
var
id
=
elem
.
find
(
"[id]"
).
first
().
attr
(
'id'
);
$timeout
(
function
(){
iScope
.
loading
=
true
});
$timeout
(
function
(){
iScope
.
loading
=
true
});
$q
.
when
(
iScope
.
loadMoreCallback
())
$q
.
when
(
iScope
.
loadMoreCallback
())
.
finally
(
function
(){
.
finally
(
function
(){
$timeout
(
function
(){
iScope
.
loading
=
false
});
$timeout
(
function
(){
iScope
.
loading
=
false
;
// try to restore last scroll position;
var
lastTopElem
=
elem
.
find
(
"#"
+
id
);
if
(
lastTopElem
){
var
top
=
lastTopElem
.
offset
().
top
-
elem
.
offset
().
top
-
100
;
elem
.
scrollTop
(
top
);
}
});
})
})
}
}
}
}
});
}
elem
.
scroll
(
onScroll
);
}
}
}
}
})
})
...
...
app/components/messaging/messaging_service.js
View file @
d0781023
...
@@ -343,6 +343,7 @@ angular.module('ulakbus.messaging', ['ui.bootstrap'])
...
@@ -343,6 +343,7 @@ angular.module('ulakbus.messaging', ['ui.bootstrap'])
};
};
return
wsRequest
(
outgoing
).
then
(
function
(
result
){
return
wsRequest
(
outgoing
).
then
(
function
(
result
){
$log
.
info
(
"Load channel "
,
channelKey
,
"history: "
,
result
);
$log
.
info
(
"Load channel "
,
channelKey
,
"history: "
,
result
);
prepareMessages
(
result
.
messages
);
return
result
;
return
result
;
})
})
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment