0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 16:22:35 +01:00

ircd:Ⓜ️ Add v1::groups namespace; add publicised requestor.

This commit is contained in:
Jason Volk 2018-03-28 01:00:08 -07:00
parent 28c7494acb
commit 14b540c6a8
3 changed files with 102 additions and 0 deletions

View file

@ -0,0 +1,40 @@
// 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.
#pragma once
#define HAVE_IRCD_M_V1_GROUPS_H
namespace ircd::m::v1::groups
{
struct publicised;
};
struct ircd::m::v1::groups::publicised
:server::request
{
struct opts;
operator json::object() const
{
return json::object{in.content};
}
publicised(const id::node &, const vector_view<const user::id> &, const mutable_buffer &, opts);
publicised() = default;
};
struct ircd::m::v1::groups::publicised::opts
{
net::hostport remote;
m::request request;
server::out out;
server::in in;
const struct server::request::opts *sopts {nullptr};
};

View file

@ -19,3 +19,4 @@
#include "state.h"
#include "backfill.h"
#include "send.h"
#include "groups.h"

View file

@ -10,6 +10,67 @@
#include <ircd/m/m.h>
///////////////////////////////////////////////////////////////////////////////
//
// v1/groups.h
//
ircd::m::v1::groups::publicised::publicised(const id::node &node,
const vector_view<const user::id> &user_ids,
const mutable_buffer &buf_,
opts opts)
:server::request{[&]
{
if(!opts.remote)
opts.remote = node.host();
if(!defined(json::get<"origin"_>(opts.request)))
json::get<"origin"_>(opts.request) = my_host();
if(!defined(json::get<"destination"_>(opts.request)))
json::get<"destination"_>(opts.request) = node.host();
if(!defined(json::get<"uri"_>(opts.request)))
json::get<"uri"_>(opts.request) = "/_matrix/federation/v1/get_groups_publicised";
json::get<"method"_>(opts.request) = "POST";
mutable_buffer buf{buf_};
const string_view user_ids_
{
json::stringify(buf, user_ids.data(), user_ids.data() + user_ids.size())
};
assert(!defined(json::get<"content"_>(opts.request)));
json::get<"content"_>(opts.request) = stringify(buf, json::members
{
{ "user_ids", user_ids_ }
});
// (front of buf was advanced by stringify)
opts.out.head = opts.request(buf);
opts.out.content = json::get<"content"_>(opts.request);
if(!size(opts.in))
{
const auto in_max
{
std::max(ssize_t(size(buf) - size(opts.out.head)), ssize_t(0))
};
assert(in_max >= ssize_t(size(buf) / 2));
opts.in.head = { data(buf) + size(opts.out.head), size_t(in_max) };
opts.in.content = opts.in.head;
}
return server::request
{
opts.remote, std::move(opts.out), std::move(opts.in), opts.sopts
};
}()}
{
}
///////////////////////////////////////////////////////////////////////////////
//
// v1/send.h