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
1eef8082
Commit
1eef8082
authored
7 years ago
by
ajberchek
Committed by
mujx
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Adds functionality to invite a user to a room (#20)
fixes #1
parent
4feb4d89
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
cmake/MatrixStructs.cmake
+1
-1
1 addition, 1 deletion
cmake/MatrixStructs.cmake
src/client.cpp
+13
-0
13 additions, 0 deletions
src/client.cpp
src/client.hpp
+4
-1
4 additions, 1 deletion
src/client.hpp
tests/client_api.cpp
+86
-0
86 additions, 0 deletions
tests/client_api.cpp
with
104 additions
and
2 deletions
cmake/MatrixStructs.cmake
+
1
−
1
View file @
1eef8082
...
...
@@ -13,7 +13,7 @@ ExternalProject_Add(
MatrixStructs
GIT_REPOSITORY https://github.com/mujx/matrix-structs
GIT_TAG
a84b37215ead77620dcddc0789c4b9b443757a1
7
GIT_TAG
0659554443a98bd018691337c8cfc11bfe90900
7
BUILD_IN_SOURCE 1
SOURCE_DIR
${
MATRIX_STRUCTS_ROOT
}
...
...
This diff is collapsed.
Click to expand it.
src/client.cpp
+
13
−
0
View file @
1eef8082
...
...
@@ -306,6 +306,19 @@ Client::leave_room(const mtx::identifiers::Room &room_id,
post
<
std
::
string
,
nlohmann
::
json
>
(
api_path
,
""
,
callback
);
}
void
Client
::
invite_user
(
const
mtx
::
identifiers
::
Room
&
room_id
,
const
std
::
string
&
user_id
,
std
::
function
<
void
(
const
mtx
::
responses
::
RoomInvite
&
,
RequestErr
)
>
callback
)
{
mtx
::
requests
::
RoomInvite
req
;
req
.
user_id
=
user_id
;
auto
api_path
=
"/client/r0/rooms/"
+
room_id
.
toString
()
+
"/invite"
;
post
<
mtx
::
requests
::
RoomInvite
,
mtx
::
responses
::
RoomInvite
>
(
api_path
,
req
,
callback
);
}
void
Client
::
sync
(
const
std
::
string
&
filter
,
const
std
::
string
&
since
,
...
...
This diff is collapsed.
Click to expand it.
src/client.hpp
+
4
−
1
View file @
1eef8082
...
...
@@ -67,7 +67,10 @@ public:
void
leave_room
(
const
mtx
::
identifiers
::
Room
&
room_id
,
std
::
function
<
void
(
const
nlohmann
::
json
&
res
,
RequestErr
err
)
>
);
//! Invite a user to a room.
/* void invite_user(); */
void
invite_user
(
const
mtx
::
identifiers
::
Room
&
room_id
,
const
std
::
string
&
user_id
,
std
::
function
<
void
(
const
mtx
::
responses
::
RoomInvite
&
res
,
RequestErr
err
)
>
);
//! Perform sync.
void
sync
(
const
std
::
string
&
filter
,
const
std
::
string
&
since
,
...
...
This diff is collapsed.
Click to expand it.
tests/client_api.cpp
+
86
−
0
View file @
1eef8082
...
...
@@ -385,6 +385,92 @@ TEST(ClientAPI, LeaveRoom)
bob
->
close
();
}
TEST
(
ClientAPI
,
InviteRoom
)
{
auto
alice
=
std
::
make_shared
<
Client
>
(
"localhost"
);
auto
bob
=
std
::
make_shared
<
Client
>
(
"localhost"
);
alice
->
login
(
"alice"
,
"secret"
,
[
alice
](
const
mtx
::
responses
::
Login
&
res
,
ErrType
err
)
{
boost
::
ignore_unused
(
res
);
ASSERT_FALSE
(
err
);
});
bob
->
login
(
"bob"
,
"secret"
,
[
bob
](
const
mtx
::
responses
::
Login
&
res
,
ErrType
err
)
{
boost
::
ignore_unused
(
res
);
ASSERT_FALSE
(
err
);
});
// Waiting for the previous requests to complete.
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
seconds
(
3
));
mtx
::
requests
::
CreateRoom
req
;
req
.
name
=
"Name"
;
req
.
topic
=
"Topic"
;
req
.
invite
=
{};
alice
->
create_room
(
req
,
[
alice
,
bob
](
const
mtx
::
responses
::
CreateRoom
&
res
,
ErrType
err
)
{
ASSERT_FALSE
(
err
);
auto
room_id
=
res
.
room_id
;
alice
->
invite_user
(
room_id
,
"@bob:localhost"
,
[
room_id
,
bob
](
const
mtx
::
responses
::
Empty
&
,
ErrType
err
)
{
ASSERT_FALSE
(
err
);
if
(
err
)
{
std
::
cout
<<
"Received error when inviting user"
<<
std
::
endl
;
}
bob
->
join_room
(
room_id
,
[](
const
nlohmann
::
json
&
,
ErrType
err
)
{
ASSERT_FALSE
(
err
);
});
});
});
alice
->
close
();
bob
->
close
();
}
TEST
(
ClientAPI
,
InvalidInvite
)
{
auto
alice
=
std
::
make_shared
<
Client
>
(
"localhost"
);
auto
bob
=
std
::
make_shared
<
Client
>
(
"localhost"
);
alice
->
login
(
"alice"
,
"secret"
,
[
alice
](
const
mtx
::
responses
::
Login
&
res
,
ErrType
err
)
{
boost
::
ignore_unused
(
res
);
ASSERT_FALSE
(
err
);
});
bob
->
login
(
"bob"
,
"secret"
,
[
bob
](
const
mtx
::
responses
::
Login
&
res
,
ErrType
err
)
{
boost
::
ignore_unused
(
res
);
ASSERT_FALSE
(
err
);
});
// Waiting for the previous requests to complete.
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
seconds
(
3
));
mtx
::
requests
::
CreateRoom
req
;
req
.
name
=
"Name"
;
req
.
topic
=
"Topic"
;
req
.
invite
=
{};
alice
->
create_room
(
req
,
[
alice
,
bob
](
const
mtx
::
responses
::
CreateRoom
&
res
,
ErrType
err
)
{
ASSERT_FALSE
(
err
);
auto
room_id
=
res
.
room_id
;
bob
->
invite_user
(
room_id
,
"@carl:localhost"
,
[
room_id
,
bob
](
const
mtx
::
responses
::
Empty
&
,
ErrType
err
)
{
ASSERT_TRUE
(
err
);
EXPECT_EQ
(
mtx
::
errors
::
to_string
(
err
->
matrix_error
.
errcode
),
"M_FORBIDDEN"
);
});
});
alice
->
close
();
bob
->
close
();
}
TEST
(
ClientAPI
,
Sync
)
{
std
::
shared_ptr
<
Client
>
mtx_client
=
std
::
make_shared
<
Client
>
(
"localhost"
);
...
...
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