2018-02-14 21:23:20 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
#include "rooms.h"
|
|
|
|
|
|
|
|
using namespace ircd;
|
|
|
|
|
2018-03-15 01:42:40 +01:00
|
|
|
conf::item<milliseconds>
|
|
|
|
timeout_default
|
|
|
|
{
|
|
|
|
{ "name", "ircd.typing.timeout.default" },
|
|
|
|
{ "default", 30 * 1000L },
|
|
|
|
};
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource::response
|
2018-02-14 21:23:20 +01:00
|
|
|
put__typing(client &client,
|
2019-09-29 01:12:07 +02:00
|
|
|
const m::resource::request &request,
|
2018-02-14 21:23:20 +01:00
|
|
|
const m::room::id &room_id)
|
|
|
|
{
|
|
|
|
if(request.parv.size() < 3)
|
2018-02-15 06:52:19 +01:00
|
|
|
throw m::NEED_MORE_PARAMS
|
|
|
|
{
|
|
|
|
"user_id parameter missing"
|
|
|
|
};
|
2018-02-14 21:23:20 +01:00
|
|
|
|
|
|
|
m::user::id::buf user_id
|
|
|
|
{
|
2018-12-07 01:41:47 +01:00
|
|
|
url::decode(user_id, request.parv[2])
|
2018-02-14 21:23:20 +01:00
|
|
|
};
|
|
|
|
|
2018-03-15 01:42:40 +01:00
|
|
|
if(request.user_id != user_id)
|
|
|
|
throw m::UNSUPPORTED
|
|
|
|
{
|
|
|
|
"Typing as someone else not yet supported"
|
|
|
|
};
|
|
|
|
|
|
|
|
const bool typing
|
2018-02-14 21:23:20 +01:00
|
|
|
{
|
2018-03-15 01:42:40 +01:00
|
|
|
request.get("typing", false)
|
2018-02-14 21:23:20 +01:00
|
|
|
};
|
|
|
|
|
2018-09-17 03:27:43 +02:00
|
|
|
const time_t timeout
|
|
|
|
{
|
|
|
|
request.get("timeout", milliseconds(timeout_default).count())
|
|
|
|
};
|
|
|
|
|
2018-09-13 15:03:09 +02:00
|
|
|
const m::typing event
|
2018-02-14 21:23:20 +01:00
|
|
|
{
|
2018-03-15 01:42:40 +01:00
|
|
|
{ "room_id", room_id },
|
|
|
|
{ "typing", typing },
|
|
|
|
{ "user_id", user_id },
|
2018-09-17 03:27:43 +02:00
|
|
|
{ "timeout", timeout },
|
2018-02-14 21:23:20 +01:00
|
|
|
};
|
|
|
|
|
2018-09-17 03:27:43 +02:00
|
|
|
m::typing::commit
|
2018-02-14 21:23:20 +01:00
|
|
|
{
|
2018-09-17 03:27:43 +02:00
|
|
|
event
|
2018-02-14 21:23:20 +01:00
|
|
|
};
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
return m::resource::response
|
2018-02-14 21:23:20 +01:00
|
|
|
{
|
|
|
|
client, http::OK
|
|
|
|
};
|
|
|
|
}
|