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 00:52:43 +01:00
|
|
|
using namespace ircd::m;
|
2018-02-14 21:23:20 +01:00
|
|
|
using namespace ircd;
|
|
|
|
|
2018-02-23 00:52:43 +01:00
|
|
|
extern "C" event::id::buf
|
|
|
|
join__room_user(const room &room,
|
|
|
|
const id::user &user_id);
|
|
|
|
|
2018-02-14 21:23:20 +01:00
|
|
|
resource::response
|
|
|
|
post__join(client &client,
|
|
|
|
const resource::request &request,
|
2018-02-23 00:52:43 +01:00
|
|
|
const room::id &room_id)
|
2018-02-14 21:23:20 +01:00
|
|
|
{
|
2018-02-22 10:35:00 +01:00
|
|
|
const string_view &third_party_signed
|
|
|
|
{
|
|
|
|
unquote(request["third_party_signed"])
|
|
|
|
};
|
|
|
|
|
2018-02-23 00:52:43 +01:00
|
|
|
join__room_user(room_id, request.user_id);
|
2018-02-14 21:23:20 +01:00
|
|
|
|
|
|
|
return resource::response
|
|
|
|
{
|
|
|
|
client, json::members
|
|
|
|
{
|
|
|
|
{ "room_id", room_id }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2018-02-23 00:52:43 +01:00
|
|
|
|
|
|
|
event::id::buf
|
|
|
|
join__room_user(const room &room,
|
|
|
|
const id::user &user_id)
|
|
|
|
{
|
2018-03-09 01:32:31 +01:00
|
|
|
if(!exists(room))
|
|
|
|
throw m::NOT_FOUND
|
|
|
|
{
|
|
|
|
"Not aware of room %s",
|
|
|
|
string_view{room.room_id}
|
|
|
|
};
|
|
|
|
|
2018-02-23 00:52:43 +01:00
|
|
|
json::iov event;
|
|
|
|
json::iov content;
|
|
|
|
const json::iov::push push[]
|
|
|
|
{
|
|
|
|
{ event, { "type", "m.room.member" }},
|
|
|
|
{ event, { "sender", user_id }},
|
|
|
|
{ event, { "state_key", user_id }},
|
|
|
|
{ event, { "membership", "join" }},
|
|
|
|
{ content, { "membership", "join" }},
|
|
|
|
};
|
|
|
|
|
2018-03-23 00:28:43 +01:00
|
|
|
const m::user user
|
|
|
|
{
|
|
|
|
user_id
|
|
|
|
};
|
|
|
|
|
|
|
|
char displayname_buf[256];
|
|
|
|
const string_view displayname
|
|
|
|
{
|
|
|
|
user.profile(displayname_buf, "displayname")
|
|
|
|
};
|
|
|
|
|
|
|
|
char avatar_url_buf[256];
|
|
|
|
const string_view avatar_url
|
|
|
|
{
|
|
|
|
user.profile(avatar_url_buf, "avatar_url")
|
|
|
|
};
|
|
|
|
|
|
|
|
const json::iov::add_if add_if[]
|
|
|
|
{
|
|
|
|
{ content, !empty(displayname), { "displayname", displayname }},
|
|
|
|
{ content, !empty(avatar_url), { "avatar_url", avatar_url }},
|
|
|
|
};
|
|
|
|
|
2018-02-23 00:52:43 +01:00
|
|
|
return commit(room, event, content);
|
|
|
|
}
|