2018-02-14 21:23:20 +01:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
#include "rooms.h"
|
|
|
|
|
2018-02-23 05:46:27 +01:00
|
|
|
using namespace ircd::m;
|
2018-02-14 21:23:20 +01:00
|
|
|
using namespace ircd;
|
|
|
|
|
|
|
|
mapi::header
|
|
|
|
IRCD_MODULE
|
|
|
|
{
|
2018-02-15 22:06:49 +01:00
|
|
|
"Client 7 :Rooms"
|
2018-02-14 21:23:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
resource
|
|
|
|
rooms_resource
|
|
|
|
{
|
|
|
|
"/_matrix/client/r0/rooms/",
|
|
|
|
{
|
2018-02-15 22:06:49 +01:00
|
|
|
"(7.0) Rooms",
|
2018-02-14 21:23:20 +01:00
|
|
|
resource::DIRECTORY,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
resource::response
|
2018-02-23 05:46:27 +01:00
|
|
|
get_rooms(client &client,
|
|
|
|
const resource::request &request)
|
2018-02-14 21:23:20 +01:00
|
|
|
{
|
|
|
|
if(request.parv.size() < 2)
|
2018-02-23 05:46:27 +01:00
|
|
|
throw NEED_MORE_PARAMS
|
2018-02-14 21:23:20 +01:00
|
|
|
{
|
2018-02-15 06:52:19 +01:00
|
|
|
"/rooms command required"
|
2018-02-14 21:23:20 +01:00
|
|
|
};
|
|
|
|
|
2018-02-23 05:46:27 +01:00
|
|
|
room::id::buf room_id
|
2018-02-14 21:23:20 +01:00
|
|
|
{
|
|
|
|
url::decode(request.parv[0], room_id)
|
|
|
|
};
|
|
|
|
|
|
|
|
const string_view &cmd
|
|
|
|
{
|
|
|
|
request.parv[1]
|
|
|
|
};
|
|
|
|
|
|
|
|
if(cmd == "messages")
|
|
|
|
return get__messages(client, request, room_id);
|
|
|
|
|
|
|
|
if(cmd == "state")
|
|
|
|
return get__state(client, request, room_id);
|
|
|
|
|
|
|
|
if(cmd == "members")
|
|
|
|
return get__members(client, request, room_id);
|
|
|
|
|
2018-02-16 21:36:30 +01:00
|
|
|
if(cmd == "joined_members")
|
|
|
|
return get__joined_members(client, request, room_id);
|
|
|
|
|
2018-02-14 21:23:20 +01:00
|
|
|
if(cmd == "context")
|
|
|
|
return get__context(client, request, room_id);
|
|
|
|
|
2018-02-25 13:07:48 +01:00
|
|
|
if(cmd == "initialSync")
|
|
|
|
return get__initialsync(client, request, room_id);
|
|
|
|
|
2018-02-23 05:46:27 +01:00
|
|
|
throw NOT_FOUND
|
2018-02-14 21:23:20 +01:00
|
|
|
{
|
|
|
|
"/rooms command not found"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
resource::method
|
|
|
|
method_get
|
|
|
|
{
|
|
|
|
rooms_resource, "GET", get_rooms
|
|
|
|
};
|
|
|
|
|
|
|
|
resource::response
|
2018-02-23 05:46:27 +01:00
|
|
|
put_rooms(client &client,
|
|
|
|
const resource::request &request)
|
2018-02-14 21:23:20 +01:00
|
|
|
{
|
|
|
|
if(request.parv.size() < 2)
|
2018-02-23 05:46:27 +01:00
|
|
|
throw NEED_MORE_PARAMS
|
2018-02-15 06:52:19 +01:00
|
|
|
{
|
|
|
|
"/rooms command required"
|
|
|
|
};
|
2018-02-14 21:23:20 +01:00
|
|
|
|
2018-02-23 05:46:27 +01:00
|
|
|
room::id::buf room_id
|
2018-02-14 21:23:20 +01:00
|
|
|
{
|
|
|
|
url::decode(request.parv[0], room_id)
|
|
|
|
};
|
|
|
|
|
|
|
|
const string_view &cmd
|
|
|
|
{
|
|
|
|
request.parv[1]
|
|
|
|
};
|
|
|
|
|
|
|
|
if(cmd == "send")
|
|
|
|
return put__send(client, request, room_id);
|
|
|
|
|
2018-02-16 21:43:30 +01:00
|
|
|
if(cmd == "state")
|
|
|
|
return put__state(client, request, room_id);
|
|
|
|
|
2018-02-14 21:23:20 +01:00
|
|
|
if(cmd == "typing")
|
|
|
|
return put__typing(client, request, room_id);
|
|
|
|
|
2018-02-16 01:07:02 +01:00
|
|
|
if(cmd == "redact")
|
|
|
|
return put__redact(client, request, room_id);
|
|
|
|
|
2018-02-23 05:46:27 +01:00
|
|
|
throw NOT_FOUND
|
2018-02-15 06:54:07 +01:00
|
|
|
{
|
|
|
|
"/rooms command not found"
|
|
|
|
};
|
2018-02-14 21:23:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resource::method
|
|
|
|
method_put
|
|
|
|
{
|
|
|
|
rooms_resource, "PUT", put_rooms,
|
|
|
|
{
|
|
|
|
method_put.REQUIRES_AUTH
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
resource::response
|
|
|
|
post_rooms(client &client,
|
|
|
|
const resource::request &request)
|
|
|
|
{
|
|
|
|
if(request.parv.size() < 2)
|
2018-02-23 05:46:27 +01:00
|
|
|
throw NEED_MORE_PARAMS
|
2018-02-15 06:52:19 +01:00
|
|
|
{
|
|
|
|
"/rooms command required"
|
|
|
|
};
|
2018-02-14 21:23:20 +01:00
|
|
|
|
2018-02-23 05:46:27 +01:00
|
|
|
room::id::buf room_id
|
2018-02-14 21:23:20 +01:00
|
|
|
{
|
|
|
|
url::decode(request.parv[0], room_id)
|
|
|
|
};
|
|
|
|
|
|
|
|
const string_view &cmd
|
|
|
|
{
|
|
|
|
request.parv[1]
|
|
|
|
};
|
|
|
|
|
|
|
|
if(cmd == "read_markers")
|
|
|
|
return post__read_markers(client, request, room_id);
|
|
|
|
|
|
|
|
if(cmd == "receipt")
|
|
|
|
return post__receipt(client, request, room_id);
|
|
|
|
|
|
|
|
if(cmd == "join")
|
|
|
|
return post__join(client, request, room_id);
|
|
|
|
|
2018-02-22 00:22:04 +01:00
|
|
|
if(cmd == "invite")
|
|
|
|
return post__invite(client, request, room_id);
|
|
|
|
|
|
|
|
if(cmd == "leave")
|
|
|
|
return post__leave(client, request, room_id);
|
|
|
|
|
|
|
|
if(cmd == "forget")
|
|
|
|
return post__forget(client, request, room_id);
|
|
|
|
|
|
|
|
if(cmd == "kick")
|
|
|
|
return post__kick(client, request, room_id);
|
|
|
|
|
|
|
|
if(cmd == "ban")
|
|
|
|
return post__ban(client, request, room_id);
|
|
|
|
|
|
|
|
if(cmd == "unban")
|
|
|
|
return post__unban(client, request, room_id);
|
|
|
|
|
2018-02-16 01:26:17 +01:00
|
|
|
if(cmd == "redact")
|
|
|
|
return post__redact(client, request, room_id);
|
|
|
|
|
2018-02-23 05:46:27 +01:00
|
|
|
throw NOT_FOUND
|
2018-02-14 21:23:20 +01:00
|
|
|
{
|
2018-02-15 06:54:07 +01:00
|
|
|
"/rooms command not found"
|
2018-02-14 21:23:20 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
resource::method
|
|
|
|
method_post
|
|
|
|
{
|
|
|
|
rooms_resource, "POST", post_rooms,
|
|
|
|
{
|
|
|
|
method_post.REQUIRES_AUTH
|
|
|
|
}
|
|
|
|
};
|
2018-02-23 05:46:27 +01:00
|
|
|
|
|
|
|
extern "C" event::id::buf
|
|
|
|
commit__iov_iov(const room &room,
|
|
|
|
json::iov &event,
|
|
|
|
const json::iov &contents)
|
|
|
|
{
|
|
|
|
const json::iov::push room_id
|
|
|
|
{
|
|
|
|
event, { "room_id", room.room_id }
|
|
|
|
};
|
|
|
|
|
|
|
|
int64_t depth;
|
2018-04-06 06:57:17 +02:00
|
|
|
event::id::buf prev_event_id;
|
2018-04-19 00:04:46 +02:00
|
|
|
std::tie(prev_event_id, depth, std::ignore) = m::top(std::nothrow, room.room_id);
|
2018-02-23 05:46:27 +01:00
|
|
|
|
|
|
|
//TODO: X
|
|
|
|
const json::iov::set_if depth_
|
|
|
|
{
|
|
|
|
event, !event.has("depth"),
|
|
|
|
{
|
|
|
|
"depth", depth + 1
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//TODO: X
|
|
|
|
const string_view auth_events{};
|
|
|
|
|
|
|
|
//TODO: X
|
|
|
|
const string_view prev_state{};
|
|
|
|
|
|
|
|
//TODO: X
|
|
|
|
json::value prev_event0
|
|
|
|
{
|
|
|
|
prev_event_id, json::STRING
|
|
|
|
};
|
|
|
|
|
|
|
|
//TODO: X
|
|
|
|
json::value prev_event
|
|
|
|
{
|
|
|
|
&prev_event0, !empty(prev_event_id)
|
|
|
|
};
|
|
|
|
|
|
|
|
//TODO: X
|
|
|
|
json::value prev_events
|
|
|
|
{
|
|
|
|
&prev_event, !empty(prev_event_id)
|
|
|
|
};
|
|
|
|
|
|
|
|
//TODO: X
|
|
|
|
const json::iov::push prevs[]
|
|
|
|
{
|
|
|
|
{ event, { "auth_events", auth_events } },
|
|
|
|
{ event, { "prev_state", prev_state } },
|
|
|
|
{ event, { "prev_events", prev_events } },
|
|
|
|
};
|
|
|
|
|
2018-04-06 08:07:55 +02:00
|
|
|
const auto &vmopts
|
2018-03-29 04:21:52 +02:00
|
|
|
{
|
2018-04-06 08:07:55 +02:00
|
|
|
room.opts? *room.opts : vm::default_commit_opts
|
2018-03-29 04:21:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return m::vm::commit(event, contents, vmopts);
|
2018-02-23 05:46:27 +01:00
|
|
|
}
|