diff --git a/.forgejo/workflows/docker-publish.yml b/.forgejo/workflows/docker-publish.yml new file mode 100644 index 0000000..80e441e --- /dev/null +++ b/.forgejo/workflows/docker-publish.yml @@ -0,0 +1,36 @@ +# Forgejo Action — build + publish Docker image to Forgejo container registry on merge to main +--- +name: Docker + +on: + push: + branches: [main] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + docker: + runs-on: docker-builder + steps: + - uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Forgejo Container Registry + uses: docker/login-action@v3 + with: + registry: forgejo.lorentz.is + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: | + forgejo.lorentz.is/matt/mailship:${{ github.sha }} + forgejo.lorentz.is/matt/mailship:latest \ No newline at end of file diff --git a/script/render-preview.mjs b/script/render-preview.mjs index e2fec6d..e60011f 100644 --- a/script/render-preview.mjs +++ b/script/render-preview.mjs @@ -24,8 +24,7 @@ const sample = { Icon: 'https://i.pravatar.cc/150?img=32', Name: 'carol', Content: '

Does anyone know how relay-based groups work?

', - Replies: 5, - Reactions: 8, + RelayUrl: 'relay.damus.io', }, { Link: 'https://app.flotilla.social/spaces/nos.lol/community?at=1700000000', @@ -34,8 +33,7 @@ const sample = { Name: 'bob', Content: '

Excited to share our new community space on Flotilla! Check it out.

', - Replies: 14, - Reactions: 32, + RelayUrl: 'nos.lol', }, ], unsubscribeUrl: 'https://app.flotilla.social/unsubscribe?token=abc123', diff --git a/src/digest.ts b/src/digest.ts index c9b2714..3426865 100644 --- a/src/digest.ts +++ b/src/digest.ts @@ -1,6 +1,5 @@ import { neventEncode, decode } from 'nostr-tools/nip19' import { - spec, sortBy, groupBy, displayList, @@ -10,7 +9,6 @@ import { parse, truncate, renderAsHtml } from '@welshman/content' import { TrustedEvent, normalizeRelayUrl, - getParentId, NOTE, COMMENT, REACTION, @@ -50,23 +48,23 @@ export class Digest { const getEventVariables = (event: TrustedEvent) => { const parsed = truncate(parse(event), { minLength: 400, maxLength: 800, mediaLength: 50 }) + const relayUrl = data.relayByEventId.get(event.id) + return { - Link: buildLink(event, handler, data.relayByEventId.get(event.id)), + Link: buildLink(event, handler, relayUrl), Timestamp: formatter.format(secondsToDate(event.created_at)), Icon: profilesByPubkey.get().get(event.pubkey)?.picture, Name: displayProfileByPubkey(event.pubkey), Content: renderAsHtml(parsed, { createElement, renderEntity }).toString(), - Replies: - repliesByParentId.get(event.id)?.filter((e) => [COMMENT, NOTE].includes(e.kind)) - ?.length || 0, - Reactions: repliesByParentId.get(event.id)?.filter(spec({ kind: REACTION }))?.length || 0, + RelayUrl: relayUrl + ? normalizeRelayUrl(relayUrl).replace(/^wss:\/\//, '').replace(/\/$/, '') + : '', } } - const { events, context } = data + const { events } = data const formatter = getFormatter() const handler = await this.loadHandler() - const repliesByParentId = groupBy(getParentId, context) const eventsByPubkey = groupBy((e) => e.pubkey, events) const userProfile = profilesByPubkey.get().get(this.sub.pubkey) const sorted = sortBy((e) => e.created_at, events).slice(0, 100) diff --git a/src/emails/digest.mjml b/src/emails/digest.mjml index 58f5e2d..4cf85f3 100644 --- a/src/emails/digest.mjml +++ b/src/emails/digest.mjml @@ -64,10 +64,7 @@
{{{Content}}}
- {{Replies}} replies - - - {{Reactions}} reactions + Posted to {{RelayUrl}}
diff --git a/test/digest-reply-stats.test.ts b/test/digest-reply-stats.test.ts index 67032cf..faa09e3 100644 --- a/test/digest-reply-stats.test.ts +++ b/test/digest-reply-stats.test.ts @@ -1,6 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' import type { TrustedEvent } from '@welshman/util' -import { spec } from '@welshman/lib' // ── Shared state accessible from both vi.mock factories and test body ────── const mockRepo = vi.hoisted(() => { @@ -159,9 +158,7 @@ describe('digest reply/reaction stats', () => { expect(latest.length).toBeGreaterThanOrEqual(1) const parentEntry = latest[0] - // When context includes reply/reaction events loaded from the repository, - // Replies should be >= 1 and Reactions >= 1 - expect(parentEntry.Replies).toBeGreaterThanOrEqual(1) - expect(parentEntry.Reactions).toBeGreaterThanOrEqual(1) + // RelayUrl should be the relay domain stripped of protocol and trailing slash + expect(parentEntry.RelayUrl).toBe('relay.example.com') }) }) \ No newline at end of file