Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

feat: useWorkspaceEcho / usePostEcho composables and realtime list refresh

Paulo Castellano554b86d22327
diff --git a/resources/js/components/NotificationBell.vue b/resources/js/components/NotificationBell.vue
index 17182e9bf..527c48254 100644
--- a/resources/js/components/NotificationBell.vue
+++ b/resources/js/components/NotificationBell.vue
@@ -44,7 +44,7 @@ const channelName = computed(() =>
);
if (channelName.value) {
- useEcho(channelName.value, '.NotificationCreated', (e: { notification: Notification }) => {
+ useEcho(channelName.value, '.notification.created', (e: { notification: Notification }) => {
const exists = notifications.value.some((n) => n.id === e.notification.id);
if (exists) return;
diff --git a/resources/js/components/posts/ai/AiGenerateDialog.vue b/resources/js/components/posts/ai/AiGenerateDialog.vue
index f081de887..788190c1b 100644
--- a/resources/js/components/posts/ai/AiGenerateDialog.vue
+++ b/resources/js/components/posts/ai/AiGenerateDialog.vue
@@ -6,7 +6,7 @@ import { Button } from '@/components/ui/button';
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog';
import { Label } from '@/components/ui/label';
import { Textarea } from '@/components/ui/textarea';
-import { useAiStream } from '@/composables/useAiStream';
+import { useAiStream } from '@/composables/echo/useAiStream';
import { generate as generatePostAi } from '@/routes/app/posts/ai';
const props = defineProps<{
diff --git a/resources/js/components/posts/create/AiPostWizard.vue b/resources/js/components/posts/create/AiPostWizard.vue
index 86dea0052..8770abed7 100644
--- a/resources/js/components/posts/create/AiPostWizard.vue
+++ b/resources/js/components/posts/create/AiPostWizard.vue
@@ -229,7 +229,7 @@ const subscribeToCreation = (userId: string, creationId: string) => {
const channelName = `users.${userId}.ai-creation.${creationId}`;
subscribedChannelName = channelName;
- echoChannel = echo().private(channelName).listen('.PostCreationReady', (e: any) => {
+ echoChannel = echo().private(channelName).listen('.ai.creation.completed', (e: any) => {
if (e.error) {
previewStatus.value = 'error';
previewError.value = e.error;
diff --git a/resources/js/composables/echo/usePostEcho.ts b/resources/js/composables/echo/usePostEcho.ts
new file mode 100644
index 000000000..8daa46ac6
--- /dev/null
+++ b/resources/js/composables/echo/usePostEcho.ts
@@ -0,0 +1,9 @@
+import { useEcho } from '@laravel/echo-vue';
+
+export const usePostEcho = <T = unknown>(
+ postId: string,
+ event: string | string[],
+ callback: (payload: T) => void,
+) => {
+ return useEcho<T>(`post.${postId}`, event, callback);
+};
diff --git a/resources/js/composables/echo/useWorkspaceEcho.ts b/resources/js/composables/echo/useWorkspaceEcho.ts
new file mode 100644
index 000000000..51ce7d87c
--- /dev/null
+++ b/resources/js/composables/echo/useWorkspaceEcho.ts
@@ -0,0 +1,18 @@
+import { usePage } from '@inertiajs/vue3';
+import { useEcho } from '@laravel/echo-vue';
+
+import type { Auth } from '@/types';
+
+export const useWorkspaceEcho = <T = unknown>(
+ event: string | string[],
+ callback: (payload: T) => void,
+) => {
+ const page = usePage();
+ const workspaceId = (page.props.auth as Auth | undefined)?.currentWorkspace?.id;
+
+ if (!workspaceId) {
+ return;
+ }
+
+ return useEcho<T>(`workspace.${workspaceId}`, event, callback);
+};
diff --git a/resources/js/pages/posts/Edit.vue b/resources/js/pages/posts/Edit.vue
index 250258493..1ca1b2935 100644
--- a/resources/js/pages/posts/Edit.vue
+++ b/resources/js/pages/posts/Edit.vue
@@ -1,6 +1,5 @@
<script setup lang="ts">
import { Head, router } from '@inertiajs/vue3';
-import { useEcho } from '@laravel/echo-vue';
import {
IconCalendar,
IconCircleCheck,
@@ -18,6 +17,7 @@ import PostEditorSidebar from '@/components/posts/editor/PostEditorSidebar.vue';
import PickTimePopover from '@/components/posts/PickTimePopover.vue';
import { Button } from '@/components/ui/button';
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
+import { usePostEcho } from '@/composables/echo/usePostEcho';
import { getMediaItemIssue } from '@/composables/useMedia';
import { getMediaRulesForContentType } from '@/composables/useMediaRules';
import dayjs from '@/dayjs';
@@ -422,13 +422,13 @@ const unschedulePost = () => {
// Event fires when any post_platform completes publishing (success or fail).
// Full reload of the post prop so the new status + post_platforms propagate and
// the overlay dismisses.
-useEcho(`post.${post.value.id}`, '.PostPlatformStatusUpdated', () => {
+usePostEcho(post.value.id, '.post.platform.status.updated', () => {
router.reload({ only: ['post'] });
});
// Echo: listen for real-time comments
-useEcho(`post.${post.value.id}`, '.PostCommentCreated', (e: any) => {
+usePostEcho(post.value.id, '.post.comment.created', (e: any) => {
if (e.mentioned_users) {
editorSidebarRef.value?.registerMentionedUsers(e.mentioned_users);
}
diff --git a/resources/js/pages/posts/Index.vue b/resources/js/pages/posts/Index.vue
index 68ac246d5..cd0a009cb 100644
--- a/resources/js/pages/posts/Index.vue
+++ b/resources/js/pages/posts/Index.vue
@@ -29,6 +29,7 @@ import {
TableRow,
} from '@/components/ui/table';
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
+import { useWorkspaceEcho } from '@/composables/echo/useWorkspaceEcho';
import { getPlatformLabel, getPlatformLogo } from '@/composables/usePlatformLogo';
import { getPostStatusConfig } from '@/composables/usePostStatus';
import dayjs from '@/dayjs';
@@ -143,6 +144,16 @@ const handleDuplicate = (post: Post) => {
const handleCopyId = (post: Post) => copyToClipboard(post.id, trans('posts.actions.copied'));
const hasActiveSearch = computed(() => Boolean(searchQuery.value?.trim()));
+
+// `reset: ['posts']` forces a replace on the InfiniteScroll merge prop —
+// without it, every broadcast would append a fresh page 1 onto the
+// existing list and produce duplicates.
+const refreshPosts = () => router.reload({ only: ['posts'], reset: ['posts'] });
+
+useWorkspaceEcho(
+ ['.post.created', '.post.deleted', '.post.platform.status.updated'],
+ refreshPosts,
+);
</script>
<template>
diff --git a/resources/js/pages/posts/Show.vue b/resources/js/pages/posts/Show.vue
index 2900876b4..2b3db05e3 100644
--- a/resources/js/pages/posts/Show.vue
+++ b/resources/js/pages/posts/Show.vue
@@ -1,6 +1,5 @@
<script setup lang="ts">
import { Head, Link, router } from '@inertiajs/vue3';
-import { useEcho } from '@laravel/echo-vue';
import { IconArrowLeft, IconCalendar, IconExternalLink, IconLoader2, IconX } from '@tabler/icons-vue';
import { trans } from 'laravel-vue-i18n';
import { computed, ref } from 'vue';
@@ -12,6 +11,7 @@ import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import { Card, CardContent } from '@/components/ui/card';
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
+import { usePostEcho } from '@/composables/echo/usePostEcho';
import { getPlatformLabel, getPlatformLogo } from '@/composables/usePlatformLogo';
import { getPlatformStatusConfig, getPostStatusConfig } from '@/composables/usePostStatus';
import dayjs from '@/dayjs';
@@ -104,7 +104,7 @@ const openLightbox = (i: number) => {
lightboxOpen.value = true;
};
-useEcho(`post.${props.post.id}`, '.PostPlatformStatusUpdated', () => {
+usePostEcho(props.post.id, '.post.platform.status.updated', () => {
router.reload({ only: ['post'] });
});
</script>