2019-08-26 03:17:00 +02:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2019 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.
|
|
|
|
|
|
|
|
ircd::m::event::id::buf
|
|
|
|
ircd::m::join(const room::alias &room_alias,
|
|
|
|
const user::id &user_id)
|
|
|
|
{
|
|
|
|
if(unlikely(!my(user_id)))
|
|
|
|
throw panic
|
|
|
|
{
|
|
|
|
"Can only join my users."
|
|
|
|
};
|
|
|
|
|
|
|
|
const room::id::buf room_id
|
|
|
|
{
|
|
|
|
m::room_id(room_alias)
|
|
|
|
};
|
|
|
|
|
2020-04-21 08:31:15 +02:00
|
|
|
if(room::bootstrap::required(room_id))
|
2019-08-26 03:17:00 +02:00
|
|
|
{
|
2020-04-22 02:58:32 +02:00
|
|
|
const auto &remote
|
|
|
|
{
|
|
|
|
room_alias.host()
|
|
|
|
};
|
|
|
|
|
2019-08-26 03:17:00 +02:00
|
|
|
m::event::id::buf ret;
|
|
|
|
m::room::bootstrap
|
|
|
|
{
|
2020-04-22 02:58:32 +02:00
|
|
|
ret,
|
|
|
|
room_id,
|
|
|
|
user_id,
|
|
|
|
{ &remote, 1 },
|
2019-08-26 03:17:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
const m::room room
|
|
|
|
{
|
|
|
|
room_id
|
|
|
|
};
|
|
|
|
|
|
|
|
return m::join(room, user_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::m::event::id::buf
|
|
|
|
ircd::m::join(const m::room &room,
|
2020-04-22 02:58:32 +02:00
|
|
|
const m::id::user &user_id,
|
|
|
|
const vector_view<const string_view> &remotes)
|
2019-08-26 03:17:00 +02:00
|
|
|
{
|
|
|
|
if(unlikely(!my(user_id)))
|
|
|
|
throw panic
|
|
|
|
{
|
|
|
|
"Can only join my users."
|
|
|
|
};
|
|
|
|
|
|
|
|
// Branch for when nothing is known about the room.
|
2020-04-21 08:31:15 +02:00
|
|
|
if(room::bootstrap::required(room))
|
2019-08-26 03:17:00 +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.
|
|
|
|
m::event::id::buf ret;
|
|
|
|
m::room::bootstrap
|
|
|
|
{
|
2020-04-22 02:58:32 +02:00
|
|
|
ret,
|
|
|
|
room.room_id,
|
|
|
|
user_id,
|
|
|
|
remotes,
|
2019-08-26 03:17:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(membership(room, user_id, "join"))
|
|
|
|
{
|
|
|
|
const auto &event_idx
|
|
|
|
{
|
|
|
|
room.get(std::nothrow, "m.room.member", user_id)
|
|
|
|
};
|
|
|
|
|
|
|
|
const event::id::buf event_id
|
|
|
|
{
|
|
|
|
event_idx?
|
2020-04-02 00:42:33 +02:00
|
|
|
m::event_id(std::nothrow, event_idx):
|
2019-08-26 03:17:00 +02:00
|
|
|
event::id::buf{}
|
|
|
|
};
|
|
|
|
|
2019-09-06 08:25:19 +02:00
|
|
|
//TODO: check duplicate content
|
|
|
|
//if(event_id)
|
|
|
|
// return event_id;
|
2019-08-26 03:17:00 +02: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" }},
|
|
|
|
};
|
|
|
|
|
|
|
|
const m::user user{user_id};
|
|
|
|
const m::user::profile profile{user};
|
|
|
|
|
|
|
|
char displayname_buf[256];
|
|
|
|
const string_view displayname
|
|
|
|
{
|
|
|
|
profile.get(displayname_buf, "displayname")
|
|
|
|
};
|
|
|
|
|
|
|
|
char avatar_url_buf[256];
|
|
|
|
const string_view avatar_url
|
|
|
|
{
|
|
|
|
profile.get(avatar_url_buf, "avatar_url")
|
|
|
|
};
|
|
|
|
|
|
|
|
const json::iov::add _displayname
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return commit(room, event, content);
|
|
|
|
}
|