0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-16 08:58:20 +02:00

ircd:Ⓜ️:user: Add interface to im.vector.riot.breadcrumb_rooms.

This commit is contained in:
Jason Volk 2019-07-08 03:22:36 -07:00
parent 93b82445d9
commit d5c035693c
5 changed files with 133 additions and 0 deletions

View file

@ -34,3 +34,4 @@ namespace ircd::m
#include "user/filter.h"
#include "user/ignores.h"
#include "user/highlight.h"
#include "user/breadcrumb_rooms.h"

View file

@ -0,0 +1,36 @@
// 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.
#pragma once
#define HAVE_IRCD_M_USER_BREADCRUMB_ROOMS_H
struct ircd::m::user::breadcrumb_rooms
{
using closure = std::function<void (const string_view &)>;
using closure_bool = std::function<bool (const string_view &)>;
using sort_closure = std::function<bool (const string_view &, const string_view &)>;
m::user::account_data account_data;
public:
bool get(std::nothrow_t, const closure &) const;
void get(const closure &) const;
bool for_each(const closure_bool &) const;
event::id::buf set(const json::array &value) const;
event::id::buf sort(const sort_closure &) const;
event::id::buf add(const string_view &) const;
event::id::buf del(const string_view &) const;
breadcrumb_rooms(const m::user &user)
:account_data{user}
{}
};

View file

@ -24,6 +24,7 @@ struct ircd::m::user
struct filter;
struct ignores;
struct highlight;
struct breadcrumb_rooms;
using id = m::id::user;
using closure = std::function<void (const user &)>;

View file

@ -10852,6 +10852,34 @@ console_cmd__user__ignores(opt &out, const string_view &line)
return true;
}
bool
console_cmd__user__breadcrumb_rooms(opt &out, const string_view &line)
{
const params param{line, " ",
{
"user_id"
}};
const m::user::id &user_id
{
param.at("user_id")
};
const m::user::breadcrumb_rooms breadcrumb_rooms
{
user_id
};
breadcrumb_rooms.for_each([&out]
(const string_view &room_id)
{
out << room_id << std::endl;
return true;
});
return true;
}
//
// users
//

View file

@ -44,6 +44,73 @@ user_create(const m::user::id &user_id,
return user;
}
///////////////////////////////////////////////////////////////////////////////
//
// m/user/breadcrumb_rooms.h
//
ircd::m::event::id::buf
ircd::m::user::breadcrumb_rooms::set(const json::array &rooms)
const
{
const json::strung object
{
json::members
{
{ "rooms", rooms }
}
};
return account_data.set("im.vector.riot.breadcrumb_rooms", object);
}
bool
ircd::m::user::breadcrumb_rooms::for_each(const closure_bool &closure)
const
{
bool ret{true};
get(std::nothrow, [&closure, &ret]
(const json::array &rooms)
{
for(const json::string &room : rooms)
if(!closure(room))
{
ret = false;
break;
}
});
return ret;
}
void
ircd::m::user::breadcrumb_rooms::get(const closure &closure)
const
{
if(!get(std::nothrow, closure))
throw m::NOT_FOUND
{
"User has no breadcrumb_rooms set in their account_data."
};
}
bool
ircd::m::user::breadcrumb_rooms::get(std::nothrow_t,
const closure &closure)
const
{
return account_data.get(std::nothrow, "im.vector.riot.breadcrumb_rooms", [&closure]
(const string_view &key, const json::object &object)
{
const json::array &rooms
{
object["rooms"]
};
closure(rooms);
});
}
///////////////////////////////////////////////////////////////////////////////
//
// m/user/highlight.h