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
4614aad1
Commit
4614aad1
authored
7 years ago
by
Konstantinos Sideris
Browse files
Options
Downloads
Patches
Plain Diff
Implement endpoints for typing notifications
parent
3f82edb5
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
+27
-0
27 additions, 0 deletions
src/client.cpp
src/client.hpp
+7
-0
7 additions, 0 deletions
src/client.hpp
tests/client_api.cpp
+60
-0
60 additions, 0 deletions
tests/client_api.cpp
with
95 additions
and
1 deletion
cmake/MatrixStructs.cmake
+
1
−
1
View file @
4614aad1
...
...
@@ -13,7 +13,7 @@ ExternalProject_Add(
MatrixStructs
GIT_REPOSITORY https://github.com/mujx/matrix-structs
GIT_TAG
0659554443a98bd018691337c8cfc11bfe909007
GIT_TAG
42c2279914fd6806d74e8490e692a3b4c4a975c0
BUILD_IN_SOURCE 1
SOURCE_DIR
${
MATRIX_STRUCTS_ROOT
}
...
...
This diff is collapsed.
Click to expand it.
src/client.cpp
+
27
−
0
View file @
4614aad1
...
...
@@ -389,3 +389,30 @@ Client::download(const std::string &server,
callback
(
res
,
content_type
,
original_filename
,
err
);
});
}
void
Client
::
start_typing
(
const
mtx
::
identifiers
::
Room
&
room_id
,
uint64_t
timeout
,
std
::
function
<
void
(
RequestErr
)
>
callback
)
{
const
auto
api_path
=
"/client/r0/rooms/"
+
room_id
.
toString
()
+
"/typing/"
+
user_id_
.
toString
();
mtx
::
requests
::
TypingNotification
req
;
req
.
typing
=
true
;
req
.
timeout
=
timeout
;
put
<
mtx
::
requests
::
TypingNotification
>
(
api_path
,
req
,
callback
);
}
void
Client
::
stop_typing
(
const
mtx
::
identifiers
::
Room
&
room_id
,
std
::
function
<
void
(
RequestErr
)
>
callback
)
{
const
auto
api_path
=
"/client/r0/rooms/"
+
room_id
.
toString
()
+
"/typing/"
+
user_id_
.
toString
();
mtx
::
requests
::
TypingNotification
req
;
req
.
typing
=
false
;
put
<
mtx
::
requests
::
TypingNotification
>
(
api_path
,
req
,
callback
);
}
This diff is collapsed.
Click to expand it.
src/client.hpp
+
7
−
0
View file @
4614aad1
...
...
@@ -97,6 +97,13 @@ public:
const
std
::
string
&
content_type
,
const
std
::
string
&
original_filename
,
RequestErr
err
)
>
cb
);
//! Send typing notifications to the room.
void
start_typing
(
const
mtx
::
identifiers
::
Room
&
room_id
,
uint64_t
timeout
,
std
::
function
<
void
(
RequestErr
err
)
>
cb
);
//! Remove typing notifications from the room.
void
stop_typing
(
const
mtx
::
identifiers
::
Room
&
room_id
,
std
::
function
<
void
(
RequestErr
err
)
>
cb
);
/* void download_room_avatar(); */
/* void download_user_avatar(); */
/* void download_media(); */
...
...
This diff is collapsed.
Click to expand it.
tests/client_api.cpp
+
60
−
0
View file @
4614aad1
#include
<atomic>
#include
<chrono>
#include
<iostream>
#include
<thread>
...
...
@@ -517,3 +518,62 @@ TEST(ClientAPI, Versions)
mtx_client
->
close
();
}
TEST
(
ClientAPI
,
Typing
)
{
auto
alice
=
std
::
make_shared
<
Client
>
(
"localhost"
);
alice
->
login
(
"alice"
,
"secret"
,
[](
const
mtx
::
responses
::
Login
&
,
ErrType
err
)
{
ASSERT_FALSE
(
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
)
{
ASSERT_FALSE
(
err
);
alice
->
start_typing
(
res
.
room_id
,
10000
,
[
alice
,
res
](
ErrType
err
)
{
ASSERT_FALSE
(
err
);
const
auto
room_id
=
res
.
room_id
.
toString
();
atomic_bool
can_continue
=
false
;
alice
->
sync
(
""
,
""
,
false
,
0
,
[
room_id
,
&
can_continue
](
const
mtx
::
responses
::
Sync
&
res
,
ErrType
err
)
{
ASSERT_FALSE
(
err
);
can_continue
=
true
;
auto
room
=
res
.
rooms
.
join
.
at
(
room_id
);
EXPECT_EQ
(
room
.
ephemeral
.
typing
.
size
(),
1
);
EXPECT_EQ
(
room
.
ephemeral
.
typing
.
front
(),
"@alice:localhost"
);
});
while
(
!
can_continue
)
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
100
));
alice
->
stop_typing
(
res
.
room_id
,
[
alice
,
room_id
](
ErrType
err
)
{
ASSERT_FALSE
(
err
);
alice
->
sync
(
""
,
""
,
false
,
0
,
[
room_id
](
const
mtx
::
responses
::
Sync
&
res
,
ErrType
err
)
{
ASSERT_FALSE
(
err
);
auto
room
=
res
.
rooms
.
join
.
at
(
room_id
);
EXPECT_EQ
(
room
.
ephemeral
.
typing
.
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