@@ -11,6 +11,7 @@ const privileges = require('../privileges');
1111const activitypub = require ( '../activitypub' ) ;
1212const utils = require ( '../utils' ) ;
1313const translate = require ( '../translate' ) ;
14+ const websockets = require ( '../socket.io' ) ;
1415
1516module . exports = function ( Posts ) {
1617 Posts . create = async function ( data ) {
@@ -36,14 +37,21 @@ module.exports = function (Posts) {
3637 let postData = { pid, uid, tid, content, sourceContent, timestamp, isEnglish, translatedContent } ;
3738
3839 // Start translation in background (non-blocking)
39- translate . translate ( data ) . then ( ( [ detected , translated ] ) => {
40+ translate . translate ( data ) . then ( async ( [ detected , translated ] ) => {
4041 // Update post asynchronously when translation completes
41- Posts . setPostFields ( pid , {
42+ await Posts . setPostFields ( pid , {
4243 isEnglish : detected ,
4344 translatedContent : translated ,
44- } ) . catch ( ( err ) => {
45- // Silent fail - post already created successfully
46- console . error ( '[translator] Failed to update translation:' , err . message ) ;
45+ } ) ;
46+
47+ // Emit socket event to notify clients of translation update
48+ websockets . in ( `topic_${ tid } ` ) . emit ( 'event:post_edited' , {
49+ post : {
50+ pid : pid ,
51+ isEnglish : detected ,
52+ translatedContent : translated ,
53+ } ,
54+ topic : { tid : tid } ,
4755 } ) ;
4856 } ) . catch ( ( err ) => {
4957 // Translation failed - post already created with English defaults
0 commit comments