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
7157d957
Commit
7157d957
authored
7 years ago
by
Konstantinos Sideris
Browse files
Options
Downloads
Patches
Plain Diff
Implement /join with an alias or room id
fixes #2
parent
2b47a737
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
src/client.cpp
+9
-0
9 additions, 0 deletions
src/client.cpp
src/client.hpp
+3
-0
3 additions, 0 deletions
src/client.hpp
src/utils.cpp
+8
-5
8 additions, 5 deletions
src/utils.cpp
src/utils.hpp
+1
-1
1 addition, 1 deletion
src/utils.hpp
tests/client_api.cpp
+12
-4
12 additions, 4 deletions
tests/client_api.cpp
with
33 additions
and
10 deletions
src/client.cpp
+
9
−
0
View file @
7157d957
...
...
@@ -254,6 +254,15 @@ Client::join_room(const mtx::identifiers::Room &room_id,
post
<
std
::
string
,
nlohmann
::
json
>
(
api_path
,
""
,
callback
);
}
void
Client
::
join_room
(
const
std
::
string
&
room
,
std
::
function
<
void
(
const
nlohmann
::
json
&
,
RequestErr
)
>
callback
)
{
auto
api_path
=
"/join/"
+
room
;
post
<
std
::
string
,
nlohmann
::
json
>
(
api_path
,
""
,
callback
);
}
void
Client
::
leave_room
(
const
mtx
::
identifiers
::
Room
&
room_id
,
std
::
function
<
void
(
const
nlohmann
::
json
&
,
RequestErr
)
>
callback
)
...
...
This diff is collapsed.
Click to expand it.
src/client.hpp
+
3
−
0
View file @
7157d957
...
...
@@ -54,6 +54,9 @@ public:
//! Join a room by its room_id.
void
join_room
(
const
mtx
::
identifiers
::
Room
&
room_id
,
std
::
function
<
void
(
const
nlohmann
::
json
&
res
,
RequestErr
err
)
>
);
//! Join a room by an alias or a room_id.
void
join_room
(
const
std
::
string
&
room
,
std
::
function
<
void
(
const
nlohmann
::
json
&
res
,
RequestErr
err
)
>
);
//! Leave a room by its room_id.
void
leave_room
(
const
mtx
::
identifiers
::
Room
&
room_id
,
std
::
function
<
void
(
const
nlohmann
::
json
&
res
,
RequestErr
err
)
>
);
...
...
This diff is collapsed.
Click to expand it.
src/utils.cpp
+
8
−
5
View file @
7157d957
...
...
@@ -4,12 +4,15 @@
#include
<boost/random/uniform_int_distribution.hpp>
std
::
string
mtx
::
client
::
utils
::
random_token
(
uint8_t
len
)
mtx
::
client
::
utils
::
random_token
(
uint8_t
len
,
bool
with_symbols
)
{
std
::
string
chars
(
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"1234567890"
"!@#$%^&*()"
);
std
::
string
symbols
=
"!@#$%^&*()"
;
std
::
string
alphanumberic
(
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"1234567890"
);
const
auto
chars
=
with_symbols
?
alphanumberic
+
symbols
:
alphanumberic
;
boost
::
random
::
random_device
rng
;
boost
::
random
::
uniform_int_distribution
<>
index_dist
(
0
,
chars
.
size
()
-
1
);
...
...
This diff is collapsed.
Click to expand it.
src/utils.hpp
+
1
−
1
View file @
7157d957
...
...
@@ -9,7 +9,7 @@ namespace utils {
//! Generates a random string of the given size.
std
::
string
random_token
(
uint8_t
len
=
12
);
random_token
(
uint8_t
len
=
12
,
bool
with_symbols
=
true
);
//! Construct query string from the given parameter pairs.
std
::
string
query_params
(
const
std
::
map
<
std
::
string
,
std
::
string
>
&
params
);
...
...
This diff is collapsed.
Click to expand it.
tests/client_api.cpp
+
12
−
4
View file @
7157d957
...
...
@@ -169,11 +169,16 @@ TEST(ClientAPI, JoinRoom)
// Waiting for the previous requests to complete.
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
seconds
(
3
));
// Creating a random room alias.
// TODO: add a type for room aliases.
const
auto
alias
=
utils
::
random_token
(
20
,
false
);
mtx
::
requests
::
CreateRoom
req
;
req
.
name
=
"Name"
;
req
.
topic
=
"Topic"
;
req
.
invite
=
{
"@bob:localhost"
};
alice
->
create_room
(
req
,
[
bob
](
const
mtx
::
responses
::
CreateRoom
&
res
,
ErrType
err
)
{
req
.
name
=
"Name"
;
req
.
topic
=
"Topic"
;
req
.
invite
=
{
"@bob:localhost"
};
req
.
room_alias_name
=
alias
;
alice
->
create_room
(
req
,
[
bob
,
alias
](
const
mtx
::
responses
::
CreateRoom
&
res
,
ErrType
err
)
{
ASSERT_FALSE
(
err
);
auto
room_id
=
res
.
room_id
;
...
...
@@ -188,6 +193,9 @@ TEST(ClientAPI, JoinRoom)
"M_UNRECOGNIZED"
);
});
// Join the room using an alias.
bob
->
join_room
(
"#"
+
alias
+
":localhost"
,
[](
const
nlohmann
::
json
&
,
ErrType
err
)
{
ASSERT_FALSE
(
err
);
});
});
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