- commit
- 21f001fee928acb3999e5a8b91285aa02c74bda2
- parent
- 7f1e36443f5032d4390c4fbf27fadfb285893ca2
- author
- Dami <dami.etoile@gmail.com>
| M | docs/ | 2 | +- |
| M | internal/ | 11 | ++++++++--- |
| M | internal/ | 2 | +- |
| M | scripts/ | 4 | ++++ |
@@ -57,7 +57,7 @@ Room events reach device notifications and relay push callbacks the same way as
5757 5858 ## In the web UI5959 60-**Rooms** in the relay navigation lists the rooms you can see with their access rule, member count and last message. Signed-in members create a room at the bottom of the list: the name becomes the room id, lowercased with punctuation replaced by hyphens, and the room opens once the relay accepts it.60+**Rooms** in the relay navigation lists the rooms you can see with their access rule, member count and last message. Signed-in members create a room at the bottom of the list: the name becomes the room id, lowercased with punctuation replaced by hyphens, unless the **Id** field names one, and the room opens once the relay accepts it. Give the id yourself when a client expects a particular shape, such as a Buzz gateway that wants a UUID.6161 6262 Open a room to read its messages, oldest first. Each message shows the author's key, their room role and the time; messages from agents carry an agent marker. Links open in place and `nostr:` links resolve through the relay. A thread shows how many replies it has and opens on its own page, where replies read in order. Reactions appear under the message they answer. Choose **load earlier** for older messages.6363 @@ -754,8 +754,13 @@
754754 // RoomCreate signs a NIP-29 create (kind 9007) with an id derived from the755755 // name, then opens the new room.756756 class RoomCreate extends FormElement {757- event({name = "", about = "", access = "open"} = {}) {758- const title = String(name).trim(), id = roomID(title);757+ // event builds the kind 9007 room creation. The id comes from the name758+ // unless one is given, so a client that wants a fixed id, such as a Buzz759+ // gateway that expects a UUID, can ask for it.760+ event({name = "", id = "", about = "", access = "open"} = {}) {761+ const title = String(name).trim(), given = String(id).trim().toLowerCase();762+ if (given && !/^[a-z0-9_-]{1,64}$/.test(given)) throw Error("Room ids use 1 to 64 lowercase letters, digits, hyphens or underscores.");763+ id = given || roomID(title);759764 if (!id) throw Error("Enter a name with letters or digits.");760765 const tags = [["h", id], ["name", title]];761766 if (String(about).trim()) tags.push(["about", String(about).trim()]);@@ -765,7 +770,7 @@
765770 766771 async submit(form) {767772 const value = name => form.elements[name]?.value || "";768- const {id, event} = this.event({name: value("name"), about: value("about"), access: value("access")});773+ const {id, event} = this.event({name: value("name"), id: value("id"), about: value("about"), access: value("access")});769774 this.report("Signing…");770775 await signAndPublish(event);771776 this.report("Created #" + id + ".");@@ -11,7 +11,7 @@
1111 {{else}}<p>No rooms yet.</p>1212 {{end}}{{with (asMap .Event).next_cursor}}<p id="pages"><a href="{{browsePageURL "/rooms" $.Query "cursor" .}}">next page</a></p>1313 {{end}}{{if .Actor}}<h2 id="new-room">New room</h2>14-<room-create><label>Name <input name="name" required maxlength="200" placeholder="build"></label><label>Access <select name="access"><option value="open">open</option><option value="members">members only</option></select></label><label>About <textarea name="about" maxlength="2000"></textarea></label><button>Create room</button></room-create>14+<room-create><label>Name <input name="name" required maxlength="200" placeholder="build"></label><label>Id <input name="id" maxlength="64" pattern="[a-z0-9_-]{1,64}" placeholder="from the name"></label><label>Access <select name="access"><option value="open">open</option><option value="members">members only</option></select></label><label>About <textarea name="about" maxlength="2000"></textarea></label><button>Create room</button></room-create>1515 <noscript><p>Creating a room needs JavaScript and a connected signer.</p></noscript>1616 {{else}}<p><a href="/signin">Sign in</a> to create a room.</p>1717 {{end}}</section>@@ -142,6 +142,10 @@ test("room-create derives the id from the name and signs 9007 before opening the
142142 same(event.tags, [["h", "build-release"], ["name", "Build & Release"], ["about", "nightly"], ["visibility", "members"]]);143143 same(create.event({name: "general"}).event.tags, [["h", "general"], ["name", "general"], ["visibility", "open"]]);144144 assert.throws(() => create.event({name: "!!!"}), /letters or digits/);145+ const fixed = create.event({name: "Hermes", id: " 9782AFBD-88c9-43b1-8b3a-5a68e99d3c52 "});146+ assert.equal(fixed.id, "9782afbd-88c9-43b1-8b3a-5a68e99d3c52");147+ same(fixed.event.tags, [["h", "9782afbd-88c9-43b1-8b3a-5a68e99d3c52"], ["name", "Hermes"], ["visibility", "open"]]);148+ assert.throws(() => create.event({name: "Hermes", id: "not valid!"}), /lowercase letters/);145149 await create.submit(s.form({name: "Build", about: "", access: "open"}));146150 assert.equal(s.sent[0].event.kind, 9007);147151 assert.equal(verifyEvent(s.sent[0].event), true);