0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-26 18:38:52 +02:00

ircd:Ⓜ️ Move and relink all the state/non-state sends()/message();

modules/client/rooms/state: reorg / renamespacing.
modules/client/rooms/send: renamespacing.
This commit is contained in:
Jason Volk 2018-02-22 20:16:12 -08:00
parent 44ff77a03f
commit 7d4d88de73
5 changed files with 246 additions and 204 deletions

View file

@ -52,7 +52,6 @@ namespace ircd::m
event::id::buf redact(const room &, const m::id::user &sender, const m::id::event &, const string_view &reason);
event::id::buf message(const room &, const m::id::user &sender, const json::members &content);
event::id::buf message(const room &, const m::id::user &sender, const string_view &body, const string_view &msgtype = "m.text");
event::id::buf membership(const room &, const m::id::user &, const string_view &membership);
event::id::buf leave(const room &, const m::id::user &);
event::id::buf join(const room &, const m::id::user &);

View file

@ -344,3 +344,103 @@ ircd::m::redact(const room &room,
return function(room, sender, event_id, reason);
}
ircd::m::event::id::buf
ircd::m::message(const room &room,
const m::id::user &sender,
const string_view &body,
const string_view &msgtype)
{
return message(room, sender,
{
{ "body", { body, json::STRING } },
{ "msgtype", { msgtype, json::STRING } },
});
}
ircd::m::event::id::buf
ircd::m::message(const room &room,
const m::id::user &sender,
const json::members &contents)
{
return send(room, sender, "m.room.message", contents);
}
ircd::m::event::id::buf
ircd::m::send(const room &room,
const m::id::user &sender,
const string_view &type,
const string_view &state_key,
const json::members &contents)
{
json::iov _content;
json::iov::push content[contents.size()];
return send(room, sender, type, state_key, make_iov(_content, content, contents.size(), contents));
}
ircd::m::event::id::buf
ircd::m::send(const room &room,
const m::id::user &sender,
const string_view &type,
const string_view &state_key,
const json::object &contents)
{
json::iov _content;
json::iov::push content[contents.size()];
return send(room, sender, type, state_key, make_iov(_content, content, contents.size(), contents));
}
ircd::m::event::id::buf
ircd::m::send(const room &room,
const m::id::user &sender,
const string_view &type,
const string_view &state_key,
const json::iov &content)
{
using prototype = event::id::buf (const m::room &, const id::user &, const string_view &, const string_view &, const json::iov &);
static import<prototype> function
{
"client_rooms", "state__iov"
};
return function(room, sender, type, state_key, content);
}
ircd::m::event::id::buf
ircd::m::send(const room &room,
const m::id::user &sender,
const string_view &type,
const json::members &contents)
{
json::iov _content;
json::iov::push content[contents.size()];
return send(room, sender, type, make_iov(_content, content, contents.size(), contents));
}
ircd::m::event::id::buf
ircd::m::send(const room &room,
const m::id::user &sender,
const string_view &type,
const json::object &contents)
{
json::iov _content;
json::iov::push content[contents.count()];
return send(room, sender, type, make_iov(_content, content, contents.count(), contents));
}
ircd::m::event::id::buf
ircd::m::send(const room &room,
const m::id::user &sender,
const string_view &type,
const json::iov &content)
{
using prototype = event::id::buf (const m::room &, const id::user &, const string_view &, const json::iov &);
static import<prototype> function
{
"client_rooms", "send__iov"
};
return function(room, sender, type, content);
}

View file

@ -10,126 +10,6 @@
#include <ircd/m/m.h>
ircd::m::event::id::buf
ircd::m::membership(const room &room,
const m::id::user &user_id,
const string_view &membership)
{
json::iov event;
json::iov content;
json::iov::push push[]
{
{ event, { "type", "m.room.member" }},
{ event, { "sender", user_id }},
{ event, { "state_key", user_id }},
{ event, { "membership", membership }},
{ content, { "membership", membership }},
};
return commit(room, event, content);
}
ircd::m::event::id::buf
ircd::m::message(const room &room,
const m::id::user &sender,
const string_view &body,
const string_view &msgtype)
{
return message(room, sender,
{
{ "body", { body, json::STRING } },
{ "msgtype", { msgtype, json::STRING } },
});
}
ircd::m::event::id::buf
ircd::m::message(const room &room,
const m::id::user &sender,
const json::members &contents)
{
return send(room, sender, "m.room.message", contents);
}
ircd::m::event::id::buf
ircd::m::send(const room &room,
const m::id::user &sender,
const string_view &type,
const string_view &state_key,
const json::members &contents)
{
json::iov _content;
json::iov::push content[contents.size()];
return send(room, sender, type, state_key, make_iov(_content, content, contents.size(), contents));
}
ircd::m::event::id::buf
ircd::m::send(const room &room,
const m::id::user &sender,
const string_view &type,
const string_view &state_key,
const json::object &contents)
{
json::iov _content;
json::iov::push content[contents.size()];
return send(room, sender, type, state_key, make_iov(_content, content, contents.size(), contents));
}
ircd::m::event::id::buf
ircd::m::send(const room &room,
const m::id::user &sender,
const string_view &type,
const string_view &state_key,
const json::iov &content)
{
json::iov event;
const json::iov::push push[]
{
{ event, { "sender", sender }},
{ event, { "type", type }},
{ event, { "state_key", state_key }},
};
return commit(room, event, content);
}
ircd::m::event::id::buf
ircd::m::send(const room &room,
const m::id::user &sender,
const string_view &type,
const json::members &contents)
{
json::iov _content;
json::iov::push content[contents.size()];
return send(room, sender, type, make_iov(_content, content, contents.size(), contents));
}
ircd::m::event::id::buf
ircd::m::send(const room &room,
const m::id::user &sender,
const string_view &type,
const json::object &contents)
{
json::iov _content;
json::iov::push content[contents.count()];
return send(room, sender, type, make_iov(_content, content, contents.count(), contents));
}
ircd::m::event::id::buf
ircd::m::send(const room &room,
const m::id::user &sender,
const string_view &type,
const json::iov &content)
{
json::iov event;
const json::iov::push push[]
{
{ event, { "sender", sender }},
{ event, { "type", type }},
};
return commit(room, event, content);
}
ircd::m::event::id::buf
ircd::m::commit(const room &room,
json::iov &event,

View file

@ -10,15 +10,16 @@
#include "rooms.h"
using namespace ircd::m;
using namespace ircd;
resource::response
put__send(client &client,
const resource::request &request,
const m::room::id &room_id)
const room::id &room_id)
{
if(request.parv.size() < 3)
throw m::NEED_MORE_PARAMS
throw NEED_MORE_PARAMS
{
"type parameter missing"
};
@ -29,7 +30,7 @@ put__send(client &client,
};
if(request.parv.size() < 4)
throw m::NEED_MORE_PARAMS
throw NEED_MORE_PARAMS
{
"txnid parameter missing"
};
@ -39,7 +40,7 @@ put__send(client &client,
request.parv[3]
};
m::room room
room room
{
room_id
};
@ -62,3 +63,19 @@ put__send(client &client,
}
};
}
extern "C" event::id::buf
send__iov(const room &room,
const id::user &sender,
const string_view &type,
const json::iov &content)
{
json::iov event;
const json::iov::push push[]
{
{ event, { "sender", sender }},
{ event, { "type", type }},
};
return commit(room, event, content);
}

View file

@ -10,100 +10,41 @@
#include "rooms.h"
using namespace ircd::m;
using namespace ircd;
static resource::response
get__state(client &client,
const resource::request &request,
const m::room::id &room_id,
const string_view &event_id)
{
const m::room::state state
{
m::room{room_id, event_id}
};
std::vector<json::value> ret;
ret.reserve(32);
state.for_each([&ret]
(const m::event &event)
{
ret.emplace_back(event);
});
return resource::response
{
client, json::value
{
ret.data(), ret.size()
}
};
}
extern "C" event::id::buf
state__iov(const room &room,
const id::user &sender,
const string_view &type,
const string_view &state_key,
const json::iov &content);
static resource::response
get__state(client &client,
const resource::request &request,
const m::room::id &room_id,
const room::id &room_id,
const string_view &event_id);
static resource::response
get__state(client &client,
const resource::request &request,
const room::id &room_id,
const string_view &event_id,
const string_view &type)
{
const m::room::state state
{
m::room{room_id, event_id}
};
std::vector<json::value> ret;
ret.reserve(32);
state.for_each(type, [&ret]
(const m::event &event)
{
//TODO: Fix conversion derpage
ret.emplace_back(event);
});
return resource::response
{
client, json::value
{
ret.data(), ret.size()
}
};
}
const string_view &type);
static resource::response
get__state(client &client,
const resource::request &request,
const m::room::id &room_id,
const room::id &room_id,
const string_view &event_id,
const string_view &type,
const string_view &state_key)
{
const m::room::state state
{
m::room{room_id, event_id}
};
std::array<json::value, 1> ret;
const bool i{state.get(std::nothrow, type, state_key, [&ret]
(const m::event &event)
{
ret[0] = event;
})};
return resource::response
{
client, json::value
{
ret.data(), i
}
};
}
const string_view &state_key);
resource::response
get__state(client &client,
const resource::request &request,
const m::room::id &room_id)
const room::id &room_id)
{
char type_buf[uint(256 * 1.34 + 1)];
const string_view &type
@ -137,7 +78,7 @@ get__state(client &client,
resource::response
put__state(client &client,
const resource::request &request,
const m::room::id &room_id)
const room::id &room_id)
{
char type_buf[uint(256 * 1.34 + 1)];
const string_view &type
@ -158,7 +99,7 @@ put__state(client &client,
const auto event_id
{
m::send(room_id, request.user_id, type, state_key, content)
send(room_id, request.user_id, type, state_key, content)
};
return resource::response
@ -169,3 +110,108 @@ put__state(client &client,
}
};
}
resource::response
get__state(client &client,
const resource::request &request,
const room::id &room_id,
const string_view &event_id)
{
const room::state state
{
room{room_id, event_id}
};
std::vector<json::value> ret;
ret.reserve(32);
state.for_each([&ret]
(const event &event)
{
ret.emplace_back(event);
});
return resource::response
{
client, json::value
{
ret.data(), ret.size()
}
};
}
resource::response
get__state(client &client,
const resource::request &request,
const room::id &room_id,
const string_view &event_id,
const string_view &type)
{
const room::state state
{
room{room_id, event_id}
};
std::vector<json::value> ret;
ret.reserve(32);
state.for_each(type, [&ret]
(const event &event)
{
ret.emplace_back(event);
});
return resource::response
{
client, json::value
{
ret.data(), ret.size()
}
};
}
resource::response
get__state(client &client,
const resource::request &request,
const room::id &room_id,
const string_view &event_id,
const string_view &type,
const string_view &state_key)
{
const room::state state
{
room{room_id, event_id}
};
std::array<json::value, 1> ret;
const bool i{state.get(std::nothrow, type, state_key, [&ret]
(const event &event)
{
ret[0] = event;
})};
return resource::response
{
client, json::value
{
ret.data(), i
}
};
}
event::id::buf
state__iov(const room &room,
const id::user &sender,
const string_view &type,
const string_view &state_key,
const json::iov &content)
{
json::iov event;
const json::iov::push push[]
{
{ event, { "sender", sender }},
{ event, { "type", type }},
{ event, { "state_key", state_key }},
};
return commit(room, event, content);
}