Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mtxclient
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
mtxclient
Commits
192ccd81
Commit
192ccd81
authored
7 years ago
by
Konstantinos Sideris
Browse files
Options
Downloads
Patches
Plain Diff
Add field to store the next batch token
parent
05fe996d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/room_feed.cpp
+29
-13
29 additions, 13 deletions
examples/room_feed.cpp
src/client.hpp
+6
-0
6 additions, 0 deletions
src/client.hpp
with
35 additions
and
13 deletions
examples/room_feed.cpp
+
29
−
13
View file @
192ccd81
...
...
@@ -19,6 +19,17 @@ using namespace mtx::events;
using
ErrType
=
experimental
::
optional
<
mtx
::
client
::
errors
::
ClientError
>
;
using
TimelineEvent
=
mtx
::
events
::
collections
::
TimelineEvents
;
void
print_errors
(
ErrType
err
)
{
if
(
err
->
status_code
!=
boost
::
beast
::
http
::
status
::
unknown
)
cout
<<
err
->
status_code
<<
"
\n
"
;
if
(
!
err
->
matrix_error
.
error
.
empty
())
cout
<<
err
->
matrix_error
.
error
<<
"
\n
"
;
if
(
err
->
error_code
)
cout
<<
err
->
error_code
.
message
()
<<
"
\n
"
;
}
// Check if the given event has a textual representation.
bool
is_room_message
(
const
TimelineEvent
&
event
)
...
...
@@ -75,9 +86,15 @@ sync_handler(shared_ptr<Client> client, const mtx::responses::Sync &res, ErrType
{
if
(
err
)
{
cout
<<
"sync error:
\n
"
;
cout
<<
err
->
status_code
<<
"
\n
"
;
cout
<<
err
->
matrix_error
.
error
<<
"
\n
"
;
cout
<<
err
->
error_code
<<
"
\n
"
;
print_errors
(
err
);
client
->
sync
(
""
,
client
->
next_batch_token
(),
false
,
30000
,
std
::
bind
(
&
sync_handler
,
client
,
std
::
placeholders
::
_1
,
std
::
placeholders
::
_2
));
return
;
}
...
...
@@ -86,9 +103,11 @@ sync_handler(shared_ptr<Client> client, const mtx::responses::Sync &res, ErrType
print_message
(
msg
);
}
client
->
set_next_batch_token
(
res
.
next_batch
);
client
->
sync
(
""
,
res
.
next_batch
,
client
->
next_batch
_token
()
,
false
,
30000
,
std
::
bind
(
&
sync_handler
,
client
,
std
::
placeholders
::
_1
,
std
::
placeholders
::
_2
));
...
...
@@ -100,14 +119,9 @@ initial_sync_handler(shared_ptr<Client> client, const mtx::responses::Sync &res,
{
if
(
err
)
{
cout
<<
"error during initial sync:
\n
"
;
if
(
err
->
status_code
!=
boost
::
beast
::
http
::
status
::
unknown
)
cout
<<
err
->
status_code
<<
"
\n
"
;
if
(
!
err
->
matrix_error
.
error
.
empty
())
cout
<<
err
->
matrix_error
.
error
<<
"
\n
"
;
if
(
err
->
error_code
)
cout
<<
err
->
error_code
.
message
()
<<
"
\n
"
;
if
(
err
->
status_code
==
boost
::
beast
::
http
::
status
::
gateway_timeout
)
{
print_errors
(
err
);
if
(
err
->
status_code
!=
boost
::
beast
::
http
::
status
::
ok
)
{
cout
<<
"retrying initial sync ...
\n
"
;
client
->
sync
(
""
,
""
,
...
...
@@ -122,9 +136,11 @@ initial_sync_handler(shared_ptr<Client> client, const mtx::responses::Sync &res,
return
;
}
client
->
set_next_batch_token
(
res
.
next_batch
);
client
->
sync
(
""
,
res
.
next_batch
,
client
->
next_batch
_token
()
,
false
,
30000
,
std
::
bind
(
&
sync_handler
,
client
,
std
::
placeholders
::
_1
,
std
::
placeholders
::
_2
));
...
...
This diff is collapsed.
Click to expand it.
src/client.hpp
+
6
−
0
View file @
192ccd81
...
...
@@ -36,6 +36,10 @@ public:
int
active_sessions
()
const
{
return
active_sessions_
.
size
();
}
//! Add an access token.
void
set_access_token
(
const
std
::
string
&
token
)
{
access_token_
=
token
;
}
//! Update the next batch token.
void
set_next_batch_token
(
const
std
::
string
&
token
)
{
next_batch_token_
=
token
;
}
//! Retrieve the current next batch token.
std
::
string
next_batch_token
()
const
{
return
next_batch_token_
;
}
using
RequestErr
=
std
::
experimental
::
optional
<
mtx
::
client
::
errors
::
ClientError
>
;
...
...
@@ -130,6 +134,8 @@ private:
std
::
string
server_
;
//! The access token that would be used for authentication.
std
::
string
access_token_
;
//! The token that will be used as the 'since' parameter on the next sync request.
std
::
string
next_batch_token_
;
};
}
}
...
...
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