linkspace/commons/
reply.rs

1use crate::prelude::*;
2
3pub fn lkc_reply_query(
4    point: &dyn Point,
5    subset: &[u8],
6    pubkey: Option<PubKey>,
7) -> LkResult<query::LkQuery> {
8    let mut q = if subset.is_empty() {
9        lkq_new(
10            &r#":scan
11           :watch +reply.[hash]
12           domain = [domain]
13           group = [group]
14           prefix = /@/[hash]
15           "#,
16            &point,
17        )
18    } else {
19        lkq_new(
20            &r#":scan
21           :watch +reply.[hash].[0]
22           domain = [domain]
23           group = [group]
24           prefix = /@/[hash]/[0]
25           "#,
26            &(point, &[subset] as &[&[u8]]),
27        )
28    }?;
29    if let Some(key) = pubkey {
30        lkq_insert_mut(&mut q, "pubkey", "=", &*key)?;
31    }
32    Ok(q)
33}
34
35/// Create a new point that is a reply to a previous point, optionally under a given path segm.
36pub fn lkc_reply(
37    point: &dyn Point,
38    subset: &[u8],
39    key: Option<&LkIdentity>,
40    data: &[u8],
41    links: &[Link],
42    not_replacable: bool,
43) -> LkResult<PointArc> {
44    lkc_reply_at(
45        point.hash_ref(),
46        point.get_domain(),
47        point.get_group(),
48        subset,
49        key,
50        data,
51        links,
52        not_replacable,
53    )
54}
55
56#[doc(hidden)]
57#[allow(clippy::too_many_arguments)]
58pub fn lkc_reply_at(
59    hash: &LkHash,
60    domain: &Domain,
61    group: &GroupID,
62    subset: &[u8],
63    key: Option<&LkIdentity>,
64    data: &[u8],
65    links: &[Link],
66    not_replacable: bool,
67) -> LkResult<PointArc> {
68    let mut path = lkpath(&[b"@", &**hash]);
69    if !subset.is_empty() {
70        let _ = path.push(subset);
71    }
72    let mut point = crate::point::lk_point_ref(key, *domain, *group, &path, data, links, now())?;
73    if !not_replacable {
74        point.update_xheader(&XFlags::REPLACABLE);
75    }
76    Ok(point.as_arc())
77}