Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nheko
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nheko Reborn
nheko
Commits
5af6f652
Commit
5af6f652
authored
5 years ago
by
Nicolas Werner
Browse files
Options
Downloads
Patches
Plain Diff
Use fetchMore for native lazy loading of item model data
parent
946ab4d0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
resources/qml/TimelineView.qml
+1
-5
1 addition, 5 deletions
resources/qml/TimelineView.qml
src/timeline/TimelineModel.cpp
+44
-31
44 additions, 31 deletions
src/timeline/TimelineModel.cpp
src/timeline/TimelineModel.h
+3
-1
3 additions, 1 deletion
src/timeline/TimelineModel.h
with
48 additions
and
37 deletions
resources/qml/TimelineView.qml
+
1
−
5
View file @
5af6f652
...
...
@@ -93,13 +93,9 @@ Item {
currentIndex
=
newIndex
model
.
currentIndex
=
newIndex
}
if
(
contentHeight
<
height
&&
model
)
{
model
.
fetchHistory
();
}
}
onAtYBeginningChanged
:
if
(
atYBeginning
)
{
chat
.
model
.
currentIndex
=
0
;
chat
.
currentIndex
=
0
;
model
.
fetchHistory
();
}
onAtYBeginningChanged
:
if
(
atYBeginning
)
{
chat
.
model
.
currentIndex
=
0
;
chat
.
currentIndex
=
0
;
}
function
updatePosition
()
{
for
(
var
y
=
chat
.
contentY
+
chat
.
height
;
y
>
chat
.
height
;
y
-=
9
)
{
...
...
This diff is collapsed.
Click to expand it.
src/timeline/TimelineModel.cpp
+
44
−
31
View file @
5af6f652
...
...
@@ -349,6 +349,50 @@ TimelineModel::data(const QModelIndex &index, int role) const
}
}
bool
TimelineModel
::
canFetchMore
(
const
QModelIndex
&
)
const
{
if
(
eventOrder
.
empty
())
return
true
;
if
(
!
std
::
holds_alternative
<
mtx
::
events
::
StateEvent
<
mtx
::
events
::
state
::
Create
>>
(
events
[
eventOrder
.
back
()]))
return
true
;
else
return
false
;
}
void
TimelineModel
::
fetchMore
(
const
QModelIndex
&
)
{
if
(
paginationInProgress
)
{
nhlog
::
ui
()
->
warn
(
"Already loading older messages"
);
return
;
}
paginationInProgress
=
true
;
mtx
::
http
::
MessagesOpts
opts
;
opts
.
room_id
=
room_id_
.
toStdString
();
opts
.
from
=
prev_batch_token_
.
toStdString
();
nhlog
::
ui
()
->
debug
(
"Paginationg room {}"
,
opts
.
room_id
);
http
::
client
()
->
messages
(
opts
,
[
this
,
opts
](
const
mtx
::
responses
::
Messages
&
res
,
mtx
::
http
::
RequestErr
err
)
{
if
(
err
)
{
nhlog
::
net
()
->
error
(
"failed to call /messages ({}): {} - {}"
,
opts
.
room_id
,
mtx
::
errors
::
to_string
(
err
->
matrix_error
.
errcode
),
err
->
matrix_error
.
error
);
paginationInProgress
=
false
;
return
;
}
emit
oldMessagesRetrieved
(
std
::
move
(
res
));
paginationInProgress
=
false
;
});
}
void
TimelineModel
::
addEvents
(
const
mtx
::
responses
::
Timeline
&
timeline
)
{
...
...
@@ -465,37 +509,6 @@ TimelineModel::internalAddEvents(
return
ids
;
}
void
TimelineModel
::
fetchHistory
()
{
if
(
paginationInProgress
)
{
nhlog
::
ui
()
->
warn
(
"Already loading older messages"
);
return
;
}
paginationInProgress
=
true
;
mtx
::
http
::
MessagesOpts
opts
;
opts
.
room_id
=
room_id_
.
toStdString
();
opts
.
from
=
prev_batch_token_
.
toStdString
();
nhlog
::
ui
()
->
info
(
"Paginationg room {}"
,
opts
.
room_id
);
http
::
client
()
->
messages
(
opts
,
[
this
,
opts
](
const
mtx
::
responses
::
Messages
&
res
,
mtx
::
http
::
RequestErr
err
)
{
if
(
err
)
{
nhlog
::
net
()
->
error
(
"failed to call /messages ({}): {} - {}"
,
opts
.
room_id
,
mtx
::
errors
::
to_string
(
err
->
matrix_error
.
errcode
),
err
->
matrix_error
.
error
);
paginationInProgress
=
false
;
return
;
}
emit
oldMessagesRetrieved
(
std
::
move
(
res
));
paginationInProgress
=
false
;
});
}
void
TimelineModel
::
setCurrentIndex
(
int
index
)
{
...
...
This diff is collapsed.
Click to expand it.
src/timeline/TimelineModel.h
+
3
−
1
View file @
5af6f652
...
...
@@ -154,6 +154,9 @@ public:
int
rowCount
(
const
QModelIndex
&
parent
=
QModelIndex
())
const
override
;
QVariant
data
(
const
QModelIndex
&
index
,
int
role
=
Qt
::
DisplayRole
)
const
override
;
bool
canFetchMore
(
const
QModelIndex
&
)
const
override
;
void
fetchMore
(
const
QModelIndex
&
)
override
;
Q_INVOKABLE
QColor
userColor
(
QString
id
,
QColor
background
);
Q_INVOKABLE
QString
displayName
(
QString
id
)
const
;
Q_INVOKABLE
QString
avatarUrl
(
QString
id
)
const
;
...
...
@@ -175,7 +178,6 @@ public:
void
sendMessage
(
const
T
&
msg
);
public
slots
:
void
fetchHistory
();
void
setCurrentIndex
(
int
index
);
int
currentIndex
()
const
{
return
idToIndex
(
currentId
);
}
void
markEventsAsRead
(
const
std
::
vector
<
QString
>
&
event_ids
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment