0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2025-01-13 16:33:53 +01:00

modules/client/rooms/leave: Add missing m::leave definition.

This commit is contained in:
Jason Volk 2019-04-22 13:28:22 -07:00
parent fd9097cfd4
commit 4d491340b6
2 changed files with 59 additions and 1 deletions

View file

@ -4545,7 +4545,7 @@ ircd::m::leave(const room &room,
static mods::import<prototype> function
{
"client_rooms", "leave__room_user"
"client_rooms", "ircd::m::leave"
};
return function(room, user_id);

View file

@ -39,3 +39,61 @@ post__leave(client &client,
}
};
}
event::id::buf
IRCD_MODULE_EXPORT
ircd::m::leave(const room &room,
const id::user &user_id)
{
if(!exists(room))
return {};
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", "leave" }},
};
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);
}