ircd:Ⓜ️ Add convenience interface for querying m.replace relation.

This commit is contained in:
Jason Volk 2023-04-18 11:47:49 -07:00
parent 02e09728a5
commit fa0365fa31
3 changed files with 85 additions and 5 deletions

View File

@ -89,6 +89,7 @@ namespace ircd::m
#include "direct_to_device.h"
#include "visible.h"
#include "redacted.h"
#include "replaced.h"
#include "feds.h"
#include "app.h"
#include "bridge.h"

80
include/ircd/m/replaced.h Normal file
View File

@ -0,0 +1,80 @@
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2023 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_REPLACED_H
namespace ircd::m
{
struct replaced;
}
class ircd::m::replaced
:public returns<event::idx>
{
m::relates relates;
public:
IRCD_OVERLOAD(latest);
replaced(const event::idx &, latest_t);
replaced(const event::idx &);
replaced(const event::id &, latest_t);
replaced(const event::id &);
explicit replaced(const event &, latest_t);
explicit replaced(const event &);
};
inline
ircd::m::replaced::replaced(const event &event)
:replaced{event.event_id}
{}
inline
ircd::m::replaced::replaced(const event &event,
latest_t)
:replaced{event.event_id, latest}
{}
inline
ircd::m::replaced::replaced(const event::id &event_id)
:replaced{index(std::nothrow, event_id)}
{}
inline
ircd::m::replaced::replaced(const event::id &event_id,
latest_t)
:replaced{index(std::nothrow, event_id), latest}
{}
inline
ircd::m::replaced::replaced(const event::idx &event_idx)
:relates
{
.refs = event_idx,
.match_sender = true,
}
{
this->returns::ret = relates.has("m.replace")? -1UL: 0UL;
}
inline
ircd::m::replaced::replaced(const event::idx &event_idx,
latest_t)
:relates
{
.refs = event_idx,
.match_sender = true,
}
{
this->returns::ret = relates.latest("m.replace");
}

View File

@ -54,15 +54,14 @@ ircd::m::replace(room::message &msg,
const event::idx &event_idx)
{
// Find the latest edit of this; otherwise stick with the original.
const m::relates relates
const m::replaced replaced
{
.refs = event_idx,
.match_sender = true,
event_idx, m::replaced::latest
};
const event::idx replace_idx
const event::idx &replace_idx
{
relates.latest("m.replace")
replaced
};
if(!replace_idx)