0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-10 14:08:56 +02:00

ircd:Ⓜ️:v1: Add invite requestor.

This commit is contained in:
Jason Volk 2018-04-03 12:58:18 -07:00
parent b90d4230ca
commit 1755ca55da
3 changed files with 101 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_INVITE_H
namespace ircd::m::v1
{
struct invite;
};
struct ircd::m::v1::invite
:server::request
{
struct opts;
explicit operator json::array() const
{
return json::array{in.content};
}
invite(const room::id &, const id::event &, const json::object &, const mutable_buffer &, opts);
invite() = default;
};
struct ircd::m::v1::invite::opts
{
net::hostport remote;
m::request request;
server::out out;
server::in in;
const struct server::request::opts *sopts {nullptr};
};

View file

@ -16,6 +16,7 @@
#include "user.h"
#include "make_join.h"
#include "send_join.h"
#include "invite.h"
#include "event.h"
#include "state.h"
#include "backfill.h"

View file

@ -407,6 +407,66 @@ ircd::m::v1::event::event(const m::event::id &event_id,
{
}
///////////////////////////////////////////////////////////////////////////////
//
// v1/invite.h
//
ircd::m::v1::invite::invite(const room::id &room_id,
const id::event &event_id,
const json::object &content,
const mutable_buffer &buf,
opts opts)
:server::request{[&]
{
assert(!!opts.remote);
assert(!size(opts.out.content));
opts.out.content = content;
assert(!defined(json::get<"content"_>(opts.request)));
json::get<"content"_>(opts.request) = json::object{opts.out.content};
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) = host(opts.remote);
if(!defined(json::get<"uri"_>(opts.request)))
{
thread_local char urlbuf[2048], ridbuf[768], eidbuf[768];
json::get<"uri"_>(opts.request) = fmt::sprintf
{
urlbuf, "/_matrix/federation/v1/invite/%s/%s",
url::encode(room_id, ridbuf),
url::encode(event_id, eidbuf)
};
}
json::get<"method"_>(opts.request) = "PUT";
opts.out.head = opts.request(buf);
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 = mutable_buffer{};
}
return server::request
{
opts.remote, std::move(opts.out), std::move(opts.in), opts.sopts
};
}()}
{
}
///////////////////////////////////////////////////////////////////////////////
//
// v1/send_join.h