@commonpub/layer 0.3.16 → 0.3.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commonpub/layer",
3
- "version": "0.3.16",
3
+ "version": "0.3.17",
4
4
  "type": "module",
5
5
  "main": "./nuxt.config.ts",
6
6
  "files": [
@@ -45,14 +45,14 @@
45
45
  "vue-router": "^4.3.0",
46
46
  "zod": "^4.3.6",
47
47
  "@commonpub/auth": "0.5.0",
48
+ "@commonpub/config": "0.7.0",
48
49
  "@commonpub/docs": "0.5.2",
49
50
  "@commonpub/editor": "0.5.0",
50
- "@commonpub/learning": "0.5.0",
51
51
  "@commonpub/protocol": "0.9.4",
52
- "@commonpub/schema": "0.8.12",
53
- "@commonpub/server": "2.12.0",
54
- "@commonpub/config": "0.7.0",
55
- "@commonpub/ui": "0.7.1"
52
+ "@commonpub/server": "2.12.1",
53
+ "@commonpub/learning": "0.5.0",
54
+ "@commonpub/ui": "0.7.1",
55
+ "@commonpub/schema": "0.8.12"
56
56
  },
57
57
  "scripts": {}
58
58
  }
@@ -358,7 +358,7 @@ useSeoMeta({
358
358
  .cpub-btn-primary:hover:not(:disabled) { opacity: 0.9; }
359
359
  .cpub-btn-primary:disabled { opacity: 0.5; cursor: default; }
360
360
  .cpub-btn-danger { color: var(--red); border-color: var(--red); }
361
- .cpub-btn-danger:hover { background: var(--red); color: white; }
361
+ .cpub-btn-danger:hover { background: var(--red); color: var(--accent-text, #fff); }
362
362
 
363
363
  /* Reply form */
364
364
  .cpub-reply-form { margin-bottom: 16px; }
@@ -5,16 +5,37 @@ const conversationId = route.params.conversationId as string;
5
5
  definePageMeta({ middleware: 'auth' });
6
6
 
7
7
  const { user } = useAuth();
8
+ const toast = useToast();
8
9
 
9
- const { data: convInfo } = useLazyFetch<any>(`/api/messages/${conversationId}/info`, {
10
- default: () => ({ id: conversationId, participants: [] as string[] }),
10
+ interface ConvParticipant {
11
+ id: string;
12
+ displayName?: string;
13
+ username?: string;
14
+ }
15
+
16
+ interface MessageItem {
17
+ id: string;
18
+ senderId: string;
19
+ senderName?: string | null;
20
+ senderAvatarUrl?: string | null;
21
+ body: string;
22
+ createdAt: string;
23
+ }
24
+
25
+ const { data: convInfo } = useLazyFetch<{ id: string; participants: ConvParticipant[] }>(`/api/messages/${conversationId}/info`, {
26
+ default: () => ({ id: conversationId, participants: [] }),
11
27
  });
12
28
 
13
- const { data: initialMessages, refresh } = useLazyFetch<any[]>(`/api/messages/${conversationId}`, {
29
+ const { data: initialMessages, refresh } = useLazyFetch<MessageItem[]>(`/api/messages/${conversationId}`, {
14
30
  default: () => [],
15
31
  });
16
32
 
17
- const messages = ref([...(initialMessages.value ?? [])]);
33
+ const messages = ref<MessageItem[]>([]);
34
+
35
+ // Sync with lazy fetch when it resolves
36
+ watch(initialMessages, (val) => {
37
+ if (val?.length) messages.value = [...val];
38
+ }, { immediate: true });
18
39
 
19
40
  // SSE real-time stream
20
41
  let eventSource: EventSource | null = null;
@@ -51,22 +72,23 @@ const participantLabel = computed(() => {
51
72
  const parts = convInfo.value?.participants ?? [];
52
73
  if (!parts.length) return 'Conversation';
53
74
  const others = parts
54
- .filter((p: any) => typeof p === 'object' ? p.id !== user.value?.id : p !== user.value?.id)
55
- .map((p: any) => typeof p === 'object' ? (p.displayName || p.username) : p);
75
+ .filter((p) => p.id !== user.value?.id)
76
+ .map((p) => p.displayName || p.username || p.id);
56
77
  return others.length > 0 ? others.join(', ') : 'Conversation';
57
78
  });
58
79
 
59
80
  useSeoMeta({ title: () => `Message — ${participantLabel.value}` });
60
81
 
61
82
  async function handleSend(text: string): Promise<void> {
62
- await $fetch(`/api/messages/${conversationId}` as string, {
63
- method: 'POST',
64
- body: { body: text },
65
- });
66
- // SSE will pick up the new message, but also do an immediate refresh for responsiveness
67
- await refresh();
68
- if (initialMessages.value) {
69
- messages.value = [...initialMessages.value];
83
+ try {
84
+ await $fetch(`/api/messages/${conversationId}` as string, {
85
+ method: 'POST',
86
+ body: { body: text },
87
+ });
88
+ // SSE will pick up the new message, but also do an immediate refresh for responsiveness
89
+ await refresh();
90
+ } catch {
91
+ toast.error('Failed to send message');
70
92
  }
71
93
  }
72
94
  </script>
@@ -3,8 +3,7 @@ import { backfillHubFromOutbox, fetchRemoteHubFollowers, repairFederatedHubPostA
3
3
  export default defineEventHandler(async (event) => {
4
4
  requireFeature('federation');
5
5
  requireFeature('federateHubs');
6
- requireAuth(event);
7
- // TODO: admin role check — for now relies on admin layout auth
6
+ requireAdmin(event);
8
7
 
9
8
  const db = useDB();
10
9
  const config = useConfig();