clone

a self-hosted multitenant nostr relay with sites, file storage, git hosting, and inbox and outbox delivery

main
tinyrelay / internal / daemon / rooms.go
rooms.go 2.0K
1package daemon23import (4 "context"5 "time"67 "github.com/FelineStateMachine/tinyrelay/internal/community"8 "github.com/FelineStateMachine/tinyrelay/internal/event"9)1011// roomMessageKinds are the events a room timeline shows: chat, threads and12// their replies, reactions, Buzz rich content and edits, and the relay's13// 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}1516// projectRoom refreshes the relay's records for a room after a durable17// change. The slug room's 39000 to 39002 records come from the tenant18// projection; here it only receives member notices. A room that has been19// 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 err25 }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 err32 }33 }34 if pubkey == "" {35 return nil36 }37 _, err = t.records.RoomNotice(ctx, roomID, pubkey, !removed, now)38 return err39}4041// 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{}, "", errRoomNotFound45 }46 room, err := t.community.Room(ctx, id)47 if err != nil {48 return community.Room{}, "", err49 }50 if !room.Live() {51 return community.Room{}, "", errRoomNotFound52 }53 role, err := t.community.RoomRole(ctx, id, actor)54 if err != nil {55 return community.Room{}, "", err56 }57 if room.Access == community.RoomMembers && role == "" {58 if actor == "" {59 return community.Room{}, "", errRoomAuth60 }61 return community.Room{}, "", errRoomRestricted62 }63 return room, role, nil64}