mirror of
https://github.com/block/buzz.git
synced 2026-10-28 21:11:48 +00:00
feat(relay): channel labels as t tags on group-state events
A channel can carry up to 8 labels that group channels across channel types. kind:9007 sets them with ["t", <label>] tags. On kind:9002 the t tags replace the whole set, a lone ["t", ""] clears it, and an edit without t tags leaves the set unchanged. Only an owner or admin may change labels. The relay refuses, before storage, a label that is not 1-64 characters from a-z, 0-9, '.', ':' and '-', a label equal to a channel type name, an empty label mixed with other labels, and more than 8 distinct labels. Migration 0061 adds channels.labels (TEXT[], default empty, at most 8). The relay publishes each label as a t tag after the channel type tag on kinds 39000, 39001 and 39002, and buzz-admin reconcile does the same. Clients read the first t value as the type; the CLI and buzz-acp parsers used the last one and now use the first. Signed-off-by: Logan Johnson <loganj@squareup.com> Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz>
This commit is contained in:
@@ -192,7 +192,8 @@ impl ChannelSummary {
|
||||
match key {
|
||||
"d" => channel_id = val.map(str::to_string),
|
||||
"name" => name = val.map(str::to_string),
|
||||
"t" => channel_type = val.map(str::to_string),
|
||||
// The first `t` is the channel type; later `t` tags are labels.
|
||||
"t" if channel_type.is_none() => channel_type = val.map(str::to_string),
|
||||
// NIP-29 emits both `private` and `public` (Buzz adds the latter).
|
||||
// The presence of either tag is the source of truth; tag value is unused.
|
||||
"private" => visibility = Some("private".to_string()),
|
||||
@@ -2008,6 +2009,19 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_event_reads_the_type_from_the_first_t_tag() {
|
||||
let ev = event(json!([
|
||||
["d", "11111111-1111-1111-1111-111111111111"],
|
||||
["name", "labeled"],
|
||||
["t", "forum"],
|
||||
["t", "workspace"],
|
||||
["P", "ab".repeat(32)],
|
||||
]));
|
||||
let s = ChannelSummary::from_event(&ev).expect("parse");
|
||||
assert_eq!(s.channel_type.as_deref(), Some("forum"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_event_extracts_known_tags() {
|
||||
let ev = event(json!([
|
||||
|
||||
Reference in New Issue
Block a user