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;
|
|
|
|
|
|
|
|
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-06-12 09:29:00 +02:00
|
|
|
const string_view &server_name
|
|
|
|
{
|
|
|
|
unquote(request["server_name"])
|
|
|
|
};
|
|
|
|
|
2019-04-22 22:21:05 +02:00
|
|
|
const m::room room
|
|
|
|
{
|
|
|
|
room_id
|
|
|
|
};
|
|
|
|
|
|
|
|
m::join(room, 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
|
2019-04-22 22:21:05 +02:00
|
|
|
IRCD_MODULE_EXPORT
|
|
|
|
ircd::m::join(const room &room,
|
|
|
|
const id::user &user_id)
|
2018-02-23 00:52:43 +01:00
|
|
|
{
|
2019-08-03 10:44:28 +02:00
|
|
|
if(unlikely(!my(user_id)))
|
|
|
|
throw panic
|
|
|
|
{
|
|
|
|
"Can only join my users."
|
|
|
|
};
|
|
|
|
|
|
|
|
// Branch for when nothing is known about the room.
|
2018-03-09 01:32:31 +01:00
|
|
|
if(!exists(room))
|
2018-06-12 09:29:00 +02:00
|
|
|
{
|
2019-08-03 10:44:28 +02:00
|
|
|
// The bootstrap condcts a blocking make_join and issues a join
|
|
|
|
// event, returning the event_id; afterward asynchronously it will
|
|
|
|
// attempt a send_join, and then process the room events.
|
2019-07-24 00:37:32 +02:00
|
|
|
m::event::id::buf ret;
|
|
|
|
m::room::bootstrap
|
|
|
|
{
|
|
|
|
ret, room.room_id, user_id, room.room_id.host() //TODO: host
|
|
|
|
};
|
|
|
|
|
|
|
|
return ret;
|
2018-06-12 09:29:00 +02:00
|
|
|
}
|
2018-03-09 01:32:31 +01:00
|
|
|
|
2019-08-03 10:44:49 +02:00
|
|
|
if(room.membership(user_id, "join"))
|
|
|
|
{
|
|
|
|
const auto &event_idx
|
|
|
|
{
|
|
|
|
room.get(std::nothrow, "m.room.member", user_id)
|
|
|
|
};
|
|
|
|
|
|
|
|
const event::id::buf event_id
|
|
|
|
{
|
|
|
|
event_idx?
|
|
|
|
m::event_id(event_idx, std::nothrow):
|
|
|
|
event::id::buf{}
|
|
|
|
};
|
|
|
|
|
|
|
|
if(event_id)
|
|
|
|
return event_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 }},
|
|
|
|
{ content, { "membership", "join" }},
|
|
|
|
};
|
|
|
|
|
2019-02-21 19:45:37 +01:00
|
|
|
const m::user user{user_id};
|
|
|
|
const m::user::profile profile{user};
|
2018-03-23 00:28:43 +01:00
|
|
|
|
|
|
|
char displayname_buf[256];
|
|
|
|
const string_view displayname
|
|
|
|
{
|
2019-02-21 19:45:37 +01:00
|
|
|
profile.get(displayname_buf, "displayname")
|
2018-03-23 00:28:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
char avatar_url_buf[256];
|
|
|
|
const string_view avatar_url
|
|
|
|
{
|
2019-02-21 19:45:37 +01:00
|
|
|
profile.get(avatar_url_buf, "avatar_url")
|
2018-03-23 00:28:43 +01:00
|
|
|
};
|
|
|
|
|
2018-06-05 20:19:40 +02:00
|
|
|
const json::iov::add _displayname
|
2018-03-23 00:28:43 +01:00
|
|
|
{
|
2018-06-05 20:19:40 +02:00
|
|
|
content, !empty(displayname),
|
|
|
|
{
|
|
|
|
"displayname", [&displayname]() -> json::value
|
|
|
|
{
|
|
|
|
return displayname;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const json::iov::add _avatar_url
|
|
|
|
{
|
|
|
|
content, !empty(avatar_url),
|
|
|
|
{
|
|
|
|
"avatar_url", [&avatar_url]() -> json::value
|
|
|
|
{
|
|
|
|
return avatar_url;
|
|
|
|
}
|
|
|
|
}
|
2018-03-23 00:28:43 +01:00
|
|
|
};
|
|
|
|
|
2018-02-23 00:52:43 +01:00
|
|
|
return commit(room, event, content);
|
|
|
|
}
|
2018-03-27 12:00:09 +02:00
|
|
|
|
|
|
|
event::id::buf
|
2019-04-22 22:21:05 +02:00
|
|
|
IRCD_MODULE_EXPORT
|
|
|
|
ircd::m::join(const m::room::alias &room_alias,
|
|
|
|
const m::user::id &user_id)
|
2018-03-27 12:00:09 +02:00
|
|
|
{
|
2019-08-03 10:44:28 +02:00
|
|
|
if(unlikely(!my(user_id)))
|
|
|
|
throw panic
|
|
|
|
{
|
|
|
|
"Can only join my users."
|
|
|
|
};
|
|
|
|
|
2018-03-27 12:00:09 +02:00
|
|
|
const room::id::buf room_id
|
|
|
|
{
|
|
|
|
m::room_id(room_alias)
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!exists(room_id))
|
2019-06-06 00:57:56 +02:00
|
|
|
{
|
2019-07-24 00:37:32 +02:00
|
|
|
m::event::id::buf ret;
|
|
|
|
m::room::bootstrap
|
2019-06-07 10:57:55 +02:00
|
|
|
{
|
2019-07-24 00:37:32 +02:00
|
|
|
ret, room_id, user_id, room_alias.host()
|
2019-06-06 13:10:56 +02:00
|
|
|
};
|
2018-03-27 12:00:09 +02:00
|
|
|
|
2019-07-24 00:37:32 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2019-06-05 07:41:59 +02:00
|
|
|
|
2019-07-24 00:37:32 +02:00
|
|
|
const m::room room
|
2019-06-05 07:41:59 +02:00
|
|
|
{
|
2019-07-24 00:37:32 +02:00
|
|
|
room_id
|
2019-06-06 00:57:56 +02:00
|
|
|
};
|
2019-06-05 07:41:59 +02:00
|
|
|
|
2019-07-24 00:37:32 +02:00
|
|
|
return m::join(room, user_id);
|
2018-03-27 12:00:09 +02:00
|
|
|
}
|