~ knotless Search/
↑↓ move↵ open⇧↵ all results

zat.dev/jetstream

jetstream client · mirror of https://tangled.org/zat.dev/jetstream

0
0
main
28 lines · 1.2 KB Raw History
const std = @import("std");
const livedecode = @import("livedecode.zig");

pub fn collectionMatches(collections: []const []const u8, collection: []const u8) bool {
    if (collections.len == 0 or collection.len == 0) return true;
    for (collections) |pattern| {
        if (std.mem.eql(u8, pattern, collection)) return true;
        // Keep the dot: app.bsky.graph.* must not match app.bsky.graphient.
        if (std.mem.endsWith(u8, pattern, ".*") and
            std.mem.startsWith(u8, collection, pattern[0 .. pattern.len - 1])) return true;
    }
    return false;
}

pub fn wants(event: livedecode.Event, kinds: []const livedecode.Kind, dids: []const []const u8, collections: []const []const u8) bool {
    if (kinds.len > 0) {
        for (kinds) |kind| {
            if (kind == std.meta.activeTag(event.payload)) break;
        } else return false;
    }
    if (dids.len > 0) {
        for (dids) |did| {
            if (std.mem.eql(u8, did, event.did)) break;
        } else return false;
    }
    // DID-level markers remain visible under collection filters.
    return event.payload != .commit or collectionMatches(collections, event.payload.commit.collection);
}