0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-10-01 05:08:59 +02:00

ircd:Ⓜ️:device: Simplify del method.

This commit is contained in:
Jason Volk 2020-03-31 10:54:34 -07:00
parent 5d685e6b40
commit cde3c10a08

View file

@ -98,39 +98,32 @@ ircd::m::device::set(const m::user &user,
return true; return true;
} }
/// To delete a device we iterate the user's room state for all types matching
/// ircd.device.* (and ircd.device) which have a state_key of the device_id.
/// Those events are redacted which removes them from appearing in the state.
bool bool
ircd::m::device::del(const m::user &user, ircd::m::device::del(const m::user &user,
const string_view &id) const string_view &id)
{ {
const user::room user_room{user}; const user::room user_room
const room::state state{user_room};
const room::state::type_prefix type
{ {
"ircd.device." user
}; };
state.for_each(type, [&user, &id, &user_room, &state] const auto event_idx
(const string_view &type, const string_view &, const event::idx &)
{ {
const auto event_idx user_room.get("ircd.device.device_id", id)
{ };
state.get(std::nothrow, type, id)
};
const auto event_id if(!event_idx)
{ return false;
m::event_id(event_idx, std::nothrow)
};
if(event_id) const auto event_id
m::redact(user_room, user, event_id, "deleted"); {
m::event_id(event_idx, std::nothrow)
};
return true; if(!event_id)
}); return false;
m::redact(user_room, user_room.user, event_id, "deleted");
return true; return true;
} }