@@ -3131,6 +3131,52 @@ function post_comment_file(id, comment_str) {
31313131 } ) ;
31323132}
31333133
3134+ function delete_comment_file ( id , comment_id ) {
3135+ const json = {
3136+ file_identifier : id ,
3137+ comment_identifier : comment_id
3138+ } ;
3139+
3140+ fetch ( '/api/delete_comment_file' , {
3141+ method : 'POST' ,
3142+ headers : {
3143+ 'Content-Type' : 'application/json' ,
3144+ } ,
3145+ body : JSON . stringify ( json ) ,
3146+ } )
3147+ . then ( response => {
3148+ if ( response . status === 204 ) {
3149+ show_file ( id ) ;
3150+ }
3151+ } )
3152+ . catch ( ( error ) => {
3153+ console . error ( 'Error:' , error ) ;
3154+ } ) ;
3155+ }
3156+
3157+ function delete_comment_forwarder ( id , comment_id ) {
3158+ const json = {
3159+ forwarder_identifier : id ,
3160+ comment_identifier : comment_id
3161+ } ;
3162+
3163+ fetch ( '/api/delete_comment_forwarder' , {
3164+ method : 'POST' ,
3165+ headers : {
3166+ 'Content-Type' : 'application/json' ,
3167+ } ,
3168+ body : JSON . stringify ( json ) ,
3169+ } )
3170+ . then ( response => {
3171+ if ( response . status === 204 ) {
3172+ show_forwarder ( id ) ;
3173+ }
3174+ } )
3175+ . catch ( ( error ) => {
3176+ console . error ( 'Error:' , error ) ;
3177+ } ) ;
3178+ }
3179+
31343180function update_stars_for_file ( id , stars ) {
31353181 const json = {
31363182 file_identifier : id ,
@@ -3745,7 +3791,7 @@ async function draw_article(type, forwarder, id) {
37453791 const next = reviews . slice ( index , index + bsize ) ;
37463792 index += bsize ;
37473793
3748- for ( const review of next ) {
3794+ for ( const [ comment_id , review ] of next . entries ( ) ) {
37493795 const profile = await get_profile_for_user ( review . username ) ;
37503796
37513797 const comment_div = document . createElement ( 'div' ) ;
@@ -3774,6 +3820,20 @@ async function draw_article(type, forwarder, id) {
37743820 comment_author . className = 'view_floating_window_comment_author' ;
37753821 comment_author . innerHTML = `<strong>${ review . username } </strong>` ;
37763822
3823+ if ( comment_author === get_cookie ( "username" ) || get_cookie ( "user_type" ) === '1' ) {
3824+ const delete_button = document . createElement ( 'button' ) ;
3825+ delete_button . className = 'view_floating_window_comment_delete' ;
3826+ delete_button . innerHTML = '<i class="fa-solid fa-trash"></i>' ;
3827+ delete_button . onclick = ( ) => {
3828+ if ( type === Forwarder ) {
3829+ delete_comment_forwarder ( id , comment_id ) ;
3830+ } else {
3831+ delete_comment_file ( id , comment_id ) ;
3832+ }
3833+ } ;
3834+ comment_author . appendChild ( delete_button ) ;
3835+ }
3836+
37773837 const comment_date = document . createElement ( 'span' ) ;
37783838 comment_date . className = 'view_floating_window_comment_date' ;
37793839 comment_date . textContent = new Date ( review . timestamp ) . toLocaleString ( ) ;
0 commit comments