Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Konheko
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
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
Konheko
Commits
ad388ea7
Commit
ad388ea7
authored
5 years ago
by
Nicolas Werner
Browse files
Options
Downloads
Patches
Plain Diff
Add sync loop on worker thread
parent
8c51dfeb
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/harbour-spoon.cpp
+2
-1
2 additions, 1 deletion
src/harbour-spoon.cpp
src/sync.cpp
+41
-4
41 additions, 4 deletions
src/sync.cpp
src/sync.h
+22
-3
22 additions, 3 deletions
src/sync.h
with
65 additions
and
8 deletions
src/harbour-spoon.cpp
+
2
−
1
View file @
ad388ea7
...
...
@@ -47,9 +47,10 @@ int main(int argc, char *argv[]) {
RoomModel
rooms
;
Sync
sync
(
rooms
,
&
login
);
QObject
::
connect
(
&
login
,
&
Login
::
loginSuccess
,
&
sync
,
&
Sync
::
startSync
);
QObject
::
connect
(
&
login
,
&
Login
::
loginSuccess
,
&
sync
,
&
Sync
::
startSync
,
Qt
::
QueuedConnection
);
QObject
::
connect
(
&
sync
,
&
Sync
::
newRoom
,
&
rooms
,
&
RoomModel
::
addRoom
,
Qt
::
QueuedConnection
);
QObject
::
connect
(
&
sync
,
&
Sync
::
newInvite
,
&
rooms
,
&
RoomModel
::
addInvite
,
Qt
::
QueuedConnection
);
QObject
::
connect
(
app
.
data
(),
&
QGuiApplication
::
aboutToQuit
,
&
sync
,
&
Sync
::
stopSync
,
Qt
::
QueuedConnection
);
QSharedPointer
<
Room
>
a
=
QSharedPointer
<
Room
>
(
new
Room
);
a
->
tag
=
"group"
;
...
...
This diff is collapsed.
Click to expand it.
src/sync.cpp
+
41
−
4
View file @
ad388ea7
...
...
@@ -6,10 +6,45 @@
#include
"debug_out.h"
void
Sync
::
startSync
()
{
qDebug
()
<<
"trying initial sync"
;
if
(
!
isRunning
())
{
start
(
LowPriority
);
}
else
{
stop
=
false
;
condition
.
wakeOne
();
}
}
Sync
::~
Sync
()
{
stopSync
();
}
void
Sync
::
stopSync
()
{
this
->
exit
=
true
;
this
->
stop
=
true
;
http
::
client
().
shutdown
();
condition
.
wakeOne
();
wait
();
}
void
Sync
::
run
()
{
emit
nextSync
();
}
void
Sync
::
sync
()
{
qDebug
()
<<
"sync"
;
if
(
this
->
stop
)
{
if
(
this
->
exit
)
{
qDebug
()
<<
"sync exiting"
;
return
;
}
else
{
qDebug
()
<<
"sync pausing"
;
mutex
.
lock
();
this
->
condition
.
wait
(
&
mutex
);
mutex
.
unlock
();
}
}
mtx
::
http
::
SyncOpts
opts
=
{};
opts
.
timeout
=
0
;
opts
.
since
=
since
;
http
::
client
().
sync
(
opts
,
[
this
](
const
mtx
::
responses
::
Sync
&
res
,
mtx
::
http
::
RequestErr
err
)
{
if
(
err
)
{
qDebug
()
<<
"Failed sync"
;
...
...
@@ -17,6 +52,8 @@ void Sync::startSync() {
return
;
}
this
->
since
=
res
.
next_batch
;
for
(
const
std
::
pair
<
std
::
string
,
mtx
::
responses
::
JoinedRoom
>
&
join
:
res
.
rooms
.
join
)
{
const
mtx
::
responses
::
JoinedRoom
&
r
=
join
.
second
;
...
...
@@ -25,8 +62,6 @@ void Sync::startSync() {
room
->
name
=
join
.
first
;
qDebug
()
<<
QString
::
fromStdString
(
room
->
name
);
// room.picture = r.avatar();
// room.tag = r.account_data.events.back(;
room
->
unreadNotifications
=
r
.
unread_notifications
.
highlight_count
;
emit
newRoom
(
room
);
}
...
...
@@ -41,5 +76,7 @@ void Sync::startSync() {
qDebug
()
<<
QString
::
fromStdString
(
room
->
name
);
emit
newInvite
(
room
);
}
emit
nextSync
();
});
}
This diff is collapsed.
Click to expand it.
src/sync.h
+
22
−
3
View file @
ad388ea7
#pragma once
#include
<QObject>
#include
<atomic>
#include
<QMutex>
#include
<QThread>
#include
<QWaitCondition>
#include
"login.h"
#include
"models/roommodel.h"
class
Sync
:
public
Q
Object
{
class
Sync
:
public
Q
Thread
{
Q_OBJECT
public:
Sync
(
RoomModel
&
rooms
,
Login
*
login
)
:
rooms
(
rooms
)
{}
Sync
(
RoomModel
&
rooms
,
Login
*
login
,
QObject
*
parent
=
0
)
:
QThread
(
parent
),
rooms
(
rooms
),
stop
(
false
),
exit
(
false
)
{
connect
(
this
,
&
Sync
::
nextSync
,
this
,
&
Sync
::
sync
);
}
~
Sync
();
void
run
();
public
slots
:
void
startSync
();
void
stopSync
();
private
slots
:
void
sync
();
signals
:
void
newRoom
(
QSharedPointer
<
Room
>
room
);
void
newInvite
(
QSharedPointer
<
Room
>
room
);
void
nextSync
();
private
:
RoomModel
&
rooms
;
QWaitCondition
condition
;
QMutex
mutex
;
std
::
atomic
<
bool
>
stop
,
exit
;
std
::
string
since
;
};
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