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
477e4d41
Commit
477e4d41
authored
7 years ago
by
Konstantinos Sideris
Browse files
Options
Downloads
Patches
Plain Diff
Implement /messages endpoint
fixes #7
parent
209c8ac6
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
src/client.cpp
+30
-0
30 additions, 0 deletions
src/client.cpp
src/client.hpp
+24
-7
24 additions, 7 deletions
src/client.hpp
tests/client_api.cpp
+49
-0
49 additions, 0 deletions
tests/client_api.cpp
with
103 additions
and
7 deletions
src/client.cpp
+
30
−
0
View file @
477e4d41
...
...
@@ -455,3 +455,33 @@ Client::stop_typing(const mtx::identifiers::Room &room_id, std::function<void(Re
put
<
mtx
::
requests
::
TypingNotification
>
(
api_path
,
req
,
callback
);
}
void
Client
::
messages
(
const
mtx
::
identifiers
::
Room
&
room_id
,
const
std
::
string
&
from
,
const
std
::
string
&
to
,
PaginationDirection
dir
,
uint16_t
limit
,
const
std
::
string
&
filter
,
std
::
function
<
void
(
const
mtx
::
responses
::
Messages
&
res
,
RequestErr
err
)
>
callback
)
{
std
::
map
<
std
::
string
,
std
::
string
>
params
;
params
.
emplace
(
"from"
,
from
);
params
.
emplace
(
"dir"
,
to_string
(
dir
));
if
(
!
to
.
empty
())
params
.
emplace
(
"to"
,
to
);
if
(
limit
>
0
)
params
.
emplace
(
"limit"
,
std
::
to_string
(
limit
));
if
(
!
filter
.
empty
())
params
.
emplace
(
"filter"
,
filter
);
const
auto
api_path
=
"/client/r0/rooms/"
+
room_id
.
toString
()
+
"/messages?"
+
utils
::
query_params
(
params
);
get
<
mtx
::
responses
::
Messages
>
(
api_path
,
[
callback
](
const
mtx
::
responses
::
Messages
&
res
,
HeaderFields
,
RequestErr
err
)
{
callback
(
res
,
err
);
});
}
This diff is collapsed.
Click to expand it.
src/client.hpp
+
24
−
7
View file @
477e4d41
...
...
@@ -20,6 +20,21 @@
namespace
mtx
{
namespace
client
{
enum
class
PaginationDirection
{
Backwards
,
Forwards
,
};
inline
std
::
string
to_string
(
PaginationDirection
dir
)
{
if
(
dir
==
PaginationDirection
::
Backwards
)
return
"b"
;
return
"f"
;
}
//! The main object that the user will interact.
class
Client
:
public
std
::
enable_shared_from_this
<
Client
>
{
...
...
@@ -89,9 +104,16 @@ public:
bool
full_state
,
uint16_t
timeout
,
std
::
function
<
void
(
const
mtx
::
responses
::
Sync
&
res
,
RequestErr
err
)
>
);
//! Paginate through room messages.
/* void get_messages(); */
//! Send a message into a room.
void
messages
(
const
mtx
::
identifiers
::
Room
&
room_id
,
const
std
::
string
&
from
,
const
std
::
string
&
to
,
PaginationDirection
dir
,
uint16_t
limit
,
const
std
::
string
&
filter
,
std
::
function
<
void
(
const
mtx
::
responses
::
Messages
&
res
,
RequestErr
err
)
>
);
//! Get the supported versions from the server.
void
versions
(
std
::
function
<
void
(
const
mtx
::
responses
::
Versions
&
res
,
RequestErr
err
)
>
);
...
...
@@ -140,13 +162,8 @@ public:
const
mtx
::
identifiers
::
Room
&
room_id
,
Payload
payload
,
std
::
function
<
void
(
const
mtx
::
responses
::
EventId
&
,
RequestErr
)
>
callback
);
/* void download_room_avatar(); */
/* void download_media(); */
/* void upload_filter(); */
/* void send_typing_notification(); */
/* void remove_typing_notification(); */
/* void read_event(); */
private
:
...
...
This diff is collapsed.
Click to expand it.
tests/client_api.cpp
+
49
−
0
View file @
477e4d41
...
...
@@ -809,3 +809,52 @@ TEST(ClientAPI, SendStateEvents)
alice
->
close
();
bob
->
close
();
}
TEST
(
ClientAPI
,
Pagination
)
{
auto
alice
=
std
::
make_shared
<
Client
>
(
"localhost"
);
alice
->
login
(
"alice"
,
"secret"
,
[
alice
](
const
mtx
::
responses
::
Login
&
,
ErrType
err
)
{
check_error
(
err
);
});
while
(
alice
->
access_token
().
empty
())
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
100
));
mtx
::
requests
::
CreateRoom
req
;
alice
->
create_room
(
req
,
[
alice
](
const
mtx
::
responses
::
CreateRoom
&
res
,
ErrType
err
)
{
check_error
(
err
);
auto
room_id
=
res
.
room_id
;
alice
->
messages
(
res
.
room_id
,
""
,
// from
""
,
// to
PaginationDirection
::
Backwards
,
30
,
// limit. Just enough messages so can fetch the whole history on
// this newly created room.
""
,
// filter
[
room_id
,
alice
](
const
mtx
::
responses
::
Messages
&
res
,
ErrType
err
)
{
check_error
(
err
);
ASSERT_TRUE
(
res
.
chunk
.
size
()
>
5
);
ASSERT_NE
(
res
.
start
,
res
.
end
);
alice
->
messages
(
room_id
,
res
.
end
,
""
,
PaginationDirection
::
Backwards
,
30
,
""
,
[](
const
mtx
::
responses
::
Messages
&
res
,
ErrType
err
)
{
check_error
(
err
);
// We reached the start of the timeline.
EXPECT_EQ
(
res
.
start
,
res
.
end
);
EXPECT_EQ
(
res
.
chunk
.
size
(),
0
);
});
});
});
alice
->
close
();
}
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