0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-29 08:54:02 +01:00
construct/matrix/user_pushers.cc

153 lines
2.6 KiB
C++
Raw Normal View History

2020-03-21 19:14:21 +01:00
// The Construct
//
// Copyright (C) The Construct Developers, Authors & Contributors
// Copyright (C) 2016-2020 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.
bool
ircd::m::user::pushers::del(const string_view &key)
const
{
const m::user::room user_room
{
user
};
static const auto &type
{
push::pusher::type_prefix
};
const event::idx &event_idx
{
user_room.get(type, key)
};
const m::event::id::buf event_id
{
m::event_id(std::nothrow, event_idx)
2020-03-21 19:14:21 +01:00
};
if(!event_id)
return false;
const auto redact_id
{
m::redact(user_room, user, event_id, "deleted")
};
return true;
}
bool
ircd::m::user::pushers::set(const json::object &content)
const
{
const json::string &key
{
content.at("pushkey")
};
const json::string &kind
{
content.at("kind")
};
if(kind == "null")
return del(key);
const m::user::room user_room
{
user
};
static const auto &type
{
push::pusher::type_prefix
};
const auto pusher_event_id
{
m::send(user_room, user, type, key, content)
};
return true;
}
void
ircd::m::user::pushers::get(const string_view &key,
const closure &closure)
const
{
if(!get(std::nothrow, key, closure))
throw m::NOT_FOUND
{
"pusher '%s' for user %s not found",
key,
string_view{user.user_id}
};
}
bool
ircd::m::user::pushers::get(std::nothrow_t,
const string_view &key,
const closure &closure)
const
{
const m::user::room user_room
{
user
};
static const auto &type
{
push::pusher::type_prefix
};
const event::idx &event_idx
{
user_room.get(type, key)
};
return m::get(std::nothrow, event_idx, "content", [&key, &closure, &event_idx]
2020-03-21 19:14:21 +01:00
(const json::object &content)
{
closure(event_idx, key, content);
2020-03-21 19:14:21 +01:00
});
}
bool
ircd::m::user::pushers::for_each(const closure_bool &closure)
const
{
const user::room user_room
{
user
};
const room::state state
{
user_room
};
static const auto &type
{
push::pusher::type_prefix
};
return state.for_each(type, room::state::closure_bool{[&closure]
(const string_view &_type, const string_view &state_key, const m::event::idx &event_idx)
{
assert(type == _type);
return m::query<bool>(std::nothrow, event_idx, "content", true, [&]
2020-03-21 19:14:21 +01:00
(const json::object &content)
{
return closure(event_idx, state_key, content);
2020-03-21 19:14:21 +01:00
});
}});
}