tinyrelayfile
tinyrelay/internal/daemon/rooms.go/

internal/daemon/rooms.go raw
1package daemon
2
3import (
4 "context"
5 "time"
6
7 "github.com/FelineStateMachine/tinyrelay/internal/community"
8 "github.com/FelineStateMachine/tinyrelay/internal/event"
9)
10
11// roomMessageKinds are the events a room timeline shows: chat, threads and
12// their replies, reactions, Buzz rich content and edits, and the relay's
13// member notices.
14var roomMessageKinds = []int{event.KIND_CHAT, event.KIND_THREAD, event.KIND_THREAD_REPLY, 7, event.KIND_RICH_CONTENT, event.KIND_CONTENT_EDIT, event.KIND_ROOM_MEMBER_ADDED, event.KIND_ROOM_MEMBER_REMOVED}
15
16// projectRoom refreshes the relay's records for a room after a durable
17// change. The slug room's 39000 to 39002 records come from the tenant
18// projection; here it only receives member notices. A room that has been
19// deleted since the change was queued has its records retired instead.
20func (t *Tenant) projectRoom(ctx context.Context, roomID, pubkey string, removed, deleted bool) error {
21 now := time.Now().Unix()
22 room, err := t.community.Room(ctx, roomID)
23 if err != nil {
24 return err
25 }
26 if deleted || !room.Live() {
27 return t.records.RetireRoom(ctx, roomID)
28 }
29 if roomID != t.meta.Name {
30 if _, err := t.records.PublishRoom(ctx, roomID, now); err != nil {
31 return err
32 }
33 }
34 if pubkey == "" {
35 return nil
36 }
37 _, err = t.records.RoomNotice(ctx, roomID, pubkey, !removed, now)
38 return err
39}
40
41// roomFor loads a live room the actor may see, or explains why not.
42func (t *Tenant) roomFor(ctx context.Context, actor, id string) (community.Room, string, error) {
43 if !community.ValidRoomID(id) {
44 return community.Room{}, "", errRoomNotFound
45 }
46 room, err := t.community.Room(ctx, id)
47 if err != nil {
48 return community.Room{}, "", err
49 }
50 if !room.Live() {
51 return community.Room{}, "", errRoomNotFound
52 }
53 role, err := t.community.RoomRole(ctx, id, actor)
54 if err != nil {
55 return community.Room{}, "", err
56 }
57 if room.Access == community.RoomMembers && role == "" {
58 if actor == "" {
59 return community.Room{}, "", errRoomAuth
60 }
61 return community.Room{}, "", errRoomRestricted
62 }
63 return room, role, nil
64}

About

ownerc01503e8035f
visibilitypublic
headd730679639bf

Maintainers

  • c01503e8035f owner
  • ba1b5beed5b5 agent hermes

Clone

  • https://012.run/npub1cq2s86qrtadf36eqq3epm38wmhdynrrcwxf84eldk3f94dkv7ttsrulrz5/tinyrelay.git

Refs