mirror of
https://github.com/matrix-construct/construct
synced 2024-12-01 19:22:53 +01:00
ircd:Ⓜ️:typing: Add user control over sending and receiving typing events per room.
This commit is contained in:
parent
04b17bc9d7
commit
035dbbab88
3 changed files with 47 additions and 0 deletions
|
@ -40,6 +40,10 @@ struct ircd::m::typing
|
|||
//NOTE: no yielding in this iteration.
|
||||
static bool for_each(const closure &);
|
||||
|
||||
// Get whether a user enabled typing events for a room. The type string
|
||||
// can be "send" or "sync" prevent typing one's events from being sent or
|
||||
// others' from being sync'ed, respectively
|
||||
static bool allow(const id::user &, const id::room &, const string_view &type);
|
||||
|
||||
using edu::m_typing::m_typing;
|
||||
};
|
||||
|
|
|
@ -59,6 +59,10 @@ ircd::m::sync::room_ephemeral_m_typing_linear(data &data)
|
|||
if(json::get<"room_id"_>(*data.event) != user_room.room_id)
|
||||
return false;
|
||||
|
||||
// Check if the user does not want to receive typing events for this room.
|
||||
if(!m::typing::allow(data.user, *data.room, "sync"))
|
||||
return false;
|
||||
|
||||
json::stack::object rooms
|
||||
{
|
||||
*data.out, "rooms"
|
||||
|
|
|
@ -216,6 +216,11 @@ ircd::m::typing::commit::commit(const m::typing &edu)
|
|||
string_view{room.room_id}
|
||||
};
|
||||
|
||||
// If the user does not want to transmit typing events to this room,
|
||||
// bail out here.
|
||||
if(!allow(at<"user_id"_>(edu), room, "send"))
|
||||
return;
|
||||
|
||||
// Clients like Riot will send erroneous and/or redundant typing requests
|
||||
// for example requesting typing=false when the state already =false.
|
||||
// We don't want to tax the vm::eval for this noise so we try to update
|
||||
|
@ -243,6 +248,40 @@ ircd::m::typing::commit::commit(const m::typing &edu)
|
|||
};
|
||||
}
|
||||
|
||||
bool
|
||||
IRCD_MODULE_EXPORT
|
||||
ircd::m::typing::allow(const user::id &user_id,
|
||||
const room::id &room_id,
|
||||
const string_view &allow_type)
|
||||
{
|
||||
const user::room user_room
|
||||
{
|
||||
user_id
|
||||
};
|
||||
|
||||
const room::state state
|
||||
{
|
||||
user_room
|
||||
};
|
||||
|
||||
char buf[event::TYPE_MAX_SIZE+1]
|
||||
{
|
||||
"ircd.typing.disable."
|
||||
};
|
||||
|
||||
const string_view &type
|
||||
{
|
||||
strlcat{buf, allow_type}
|
||||
};
|
||||
|
||||
const string_view &state_key
|
||||
{
|
||||
room_id
|
||||
};
|
||||
|
||||
return !state.has(type, state_key);
|
||||
}
|
||||
|
||||
bool
|
||||
IRCD_MODULE_EXPORT
|
||||
ircd::m::typing::for_each(const closure &closure)
|
||||
|
|
Loading…
Reference in a new issue