mirror of
https://github.com/matrix-construct/construct
synced 2025-02-18 01:30:12 +01:00
modules: Stub m.device_list_update edu handler; json schema.
This commit is contained in:
parent
0efd723edb
commit
d5e8bbbf4a
5 changed files with 121 additions and 0 deletions
|
@ -15,6 +15,7 @@ namespace ircd::m
|
|||
{
|
||||
struct device;
|
||||
struct device_keys;
|
||||
struct device_list_update;
|
||||
}
|
||||
|
||||
struct ircd::m::device_keys
|
||||
|
@ -55,6 +56,45 @@ struct ircd::m::device_keys
|
|||
using super_type::operator=;
|
||||
};
|
||||
|
||||
struct ircd::m::device_list_update
|
||||
:json::tuple
|
||||
<
|
||||
/// Required. The user ID who owns this device.
|
||||
json::property<name::user_id, json::string>,
|
||||
|
||||
/// Required. The ID of the device whose details are changing.
|
||||
json::property<name::device_id, json::string>,
|
||||
|
||||
/// The public human-readable name of this device. Will be absent if
|
||||
/// the device has no name.
|
||||
json::property<name::device_display_name, json::string>,
|
||||
|
||||
/// Required. An ID sent by the server for this update, unique
|
||||
/// for a given user_id. Used to identify any gaps in the sequence
|
||||
/// of m.device_list_update EDUs broadcast by a server.
|
||||
json::property<name::stream_id, long>,
|
||||
|
||||
/// The stream_ids of any prior m.device_list_update EDUs sent for this
|
||||
/// user which have not been referred to already in an EDU's prev_id
|
||||
/// field. If the receiving server does not recognise any of the prev_ids,
|
||||
/// it means an EDU has been lost and the server should query a snapshot
|
||||
/// of the device list via /user/keys/query in order to correctly interpret
|
||||
/// future m.device_list_update EDUs. May be missing or empty for the
|
||||
/// first EDU in a sequence.
|
||||
json::property<name::prev_id, json::array>,
|
||||
|
||||
/// True if the server is announcing that this device has been deleted.
|
||||
json::property<name::deleted, bool>,
|
||||
|
||||
/// The updated identity keys (if any) for this device. May be absent
|
||||
/// if the device has no E2E keys defined.
|
||||
json::property<name::keys, json::object>
|
||||
>
|
||||
{
|
||||
using super_type::tuple;
|
||||
using super_type::operator=;
|
||||
};
|
||||
|
||||
struct ircd::m::device
|
||||
:json::tuple
|
||||
<
|
||||
|
|
|
@ -159,4 +159,8 @@ struct ircd::m::name
|
|||
|
||||
static constexpr const char *const message_id {"message_id"};
|
||||
static constexpr const char *const messages {"messages"};
|
||||
|
||||
static constexpr const char *const stream_id {"stream_id"};
|
||||
static constexpr const char *const prev_id {"prev_id"};
|
||||
static constexpr const char *const deleted {"deleted"};
|
||||
};
|
||||
|
|
|
@ -138,3 +138,7 @@ constexpr const char *const ircd::m::name::algorithms;
|
|||
|
||||
constexpr const char *const ircd::m::name::message_id;
|
||||
constexpr const char *const ircd::m::name::messages;
|
||||
|
||||
constexpr const char *const ircd::m::name::stream_id;
|
||||
constexpr const char *const ircd::m::name::prev_id;
|
||||
constexpr const char *const ircd::m::name::deleted;
|
||||
|
|
|
@ -107,6 +107,7 @@ m_typing_la_SOURCES = m_typing.cc
|
|||
m_receipt_la_SOURCES = m_receipt.cc
|
||||
m_presence_la_SOURCES = m_presence.cc
|
||||
m_direct_to_device_la_SOURCES = m_direct_to_device.cc
|
||||
m_device_list_update_la_SOURCES = m_device_list_update.cc
|
||||
m_state_la_SOURCES = m_state.cc
|
||||
m_rooms_la_SOURCES = m_rooms.cc
|
||||
m_room_la_SOURCES = m_room.cc
|
||||
|
@ -128,6 +129,7 @@ m_module_LTLIBRARIES = \
|
|||
m_receipt.la \
|
||||
m_presence.la \
|
||||
m_direct_to_device.la \
|
||||
m_device_list_update.la \
|
||||
m_state.la \
|
||||
m_rooms.la \
|
||||
m_room.la \
|
||||
|
|
71
modules/m_device_list_update.cc
Normal file
71
modules/m_device_list_update.cc
Normal file
|
@ -0,0 +1,71 @@
|
|||
// Matrix Construct
|
||||
//
|
||||
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
||||
// Copyright (C) 2016-2019 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.
|
||||
|
||||
using namespace ircd;
|
||||
|
||||
mapi::header
|
||||
IRCD_MODULE
|
||||
{
|
||||
"Matrix Device List Update"
|
||||
};
|
||||
|
||||
static void
|
||||
handle_edu_m_device_list_update(const m::event &,
|
||||
m::vm::eval &);
|
||||
|
||||
const m::hookfn<m::vm::eval &>
|
||||
_m_device_list_update_eval
|
||||
{
|
||||
handle_edu_m_device_list_update,
|
||||
{
|
||||
{ "_site", "vm.eval" },
|
||||
{ "type", "m.device_list_update" },
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
handle_edu_m_device_list_update(const m::event &event,
|
||||
m::vm::eval &eval)
|
||||
try
|
||||
{
|
||||
if(m::my_host(at<"origin"_>(event)))
|
||||
return;
|
||||
|
||||
const json::object &content
|
||||
{
|
||||
at<"content"_>(event)
|
||||
};
|
||||
|
||||
const m::device_list_update update
|
||||
{
|
||||
content
|
||||
};
|
||||
|
||||
log::info
|
||||
{
|
||||
m::log, "Device list update from :%s by %s for '%s' sid:%lu %s",
|
||||
json::get<"origin"_>(event),
|
||||
json::get<"user_id"_>(update),
|
||||
json::get<"device_id"_>(update),
|
||||
json::get<"stream_id"_>(update),
|
||||
json::get<"deleted"_>(update)?
|
||||
"[deleted]"_sv:
|
||||
string_view{}
|
||||
};
|
||||
}
|
||||
catch(const std::exception &e)
|
||||
{
|
||||
log::derror
|
||||
{
|
||||
m::log, "m.device_list_update from %s :%s",
|
||||
json::get<"origin"_>(event),
|
||||
e.what(),
|
||||
};
|
||||
}
|
Loading…
Add table
Reference in a new issue