1- use crate :: constants:: inner_constants:: {
2- PodcastType , BASIC_AUTH , COMMON_USER_AGENT , DEFAULT_IMAGE_URL , ENVIRONMENT_SERVICE , OIDC_AUTH ,
3- } ;
1+ use crate :: constants:: inner_constants:: { PodcastType , BASIC_AUTH , COMMON_USER_AGENT , DEFAULT_IMAGE_URL , ENVIRONMENT_SERVICE , MAIN_ROOM , OIDC_AUTH } ;
42use crate :: models:: dto_models:: PodcastFavorUpdateModel ;
53use crate :: models:: misc_models:: { PodcastAddModel , PodcastInsertModel } ;
64use crate :: models:: opml_model:: OpmlModel ;
75use crate :: models:: search_type:: SearchType :: { ITunes , Podindex } ;
8- use crate :: models:: web_socket_message:: Lobby ;
96use crate :: service:: environment_service:: EnvironmentService ;
107use crate :: service:: mapping_service:: MappingService ;
118use crate :: service:: podcast_episode_service:: PodcastEpisodeService ;
129use crate :: service:: rust_service:: PodcastService ;
1310use crate :: { get_default_image, unwrap_string, DbPool } ;
14- use actix:: Addr ;
1511use actix_web:: dev:: PeerAddr ;
1612use actix_web:: http:: Method ;
1713use actix_web:: web:: { Data , Json , Path } ;
@@ -239,7 +235,7 @@ tag="podcasts"
239235#[ post( "/podcast/itunes" ) ]
240236pub async fn add_podcast (
241237 track_id : web:: Json < PodcastAddModel > ,
242- lobby : Data < Addr < Lobby > > ,
238+ lobby : Data < ChatServerHandle > ,
243239 conn : Data < DbPool > ,
244240 requester : Option < web:: ReqData < User > > ,
245241) -> Result < HttpResponse , CustomError > {
@@ -290,7 +286,7 @@ tag="podcasts"
290286#[ post( "/podcast/feed" ) ]
291287pub async fn add_podcast_by_feed (
292288 rss_feed : web:: Json < PodcastRSSAddModel > ,
293- lobby : Data < Addr < Lobby > > ,
289+ lobby : Data < ChatServerHandle > ,
294290 podcast_service : Data < Mutex < PodcastService > > ,
295291 conn : Data < DbPool > ,
296292 requester : Option < web:: ReqData < User > > ,
@@ -349,7 +345,7 @@ tag="podcasts"
349345#[ post( "/podcast/opml" ) ]
350346pub async fn import_podcasts_from_opml (
351347 opml : web:: Json < OpmlModel > ,
352- lobby : Data < Addr < Lobby > > ,
348+ lobby : Data < ChatServerHandle > ,
353349 conn : Data < DbPool > ,
354350 requester : Option < web:: ReqData < User > > ,
355351) -> Result < HttpResponse , CustomError > {
@@ -388,7 +384,7 @@ tag="podcasts"
388384#[ post( "/podcast/podindex" ) ]
389385pub async fn add_podcast_from_podindex (
390386 id : web:: Json < PodcastAddModel > ,
391- lobby : Data < Addr < Lobby > > ,
387+ lobby : Data < ChatServerHandle > ,
392388 conn : Data < DbPool > ,
393389 requester : Option < web:: ReqData < User > > ,
394390) -> Result < HttpResponse , CustomError > {
@@ -424,7 +420,7 @@ pub async fn add_podcast_from_podindex(
424420
425421fn start_download_podindex (
426422 id : i32 ,
427- lobby : Data < Addr < Lobby > > ,
423+ lobby : Data < ChatServerHandle > ,
428424 conn : & mut DbConnection ,
429425) -> Result < Podcast , CustomError > {
430426 let rt = tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ;
@@ -464,7 +460,7 @@ tag="podcasts"
464460) ]
465461#[ post( "/podcast/all" ) ]
466462pub async fn refresh_all_podcasts (
467- lobby : Data < Addr < Lobby > > ,
463+ lobby : Data < ChatServerHandle > ,
468464 podcast_service : Data < Mutex < PodcastService > > ,
469465 conn : Data < DbPool > ,
470466 requester : Option < web:: ReqData < User > > ,
@@ -485,13 +481,13 @@ pub async fn refresh_all_podcasts(
485481 conn. get ( ) . map_err ( map_r2d2_error) . unwrap ( ) . deref_mut ( ) ,
486482 )
487483 . unwrap ( ) ;
488- lobby. clone ( ) . do_send ( BroadcastMessage {
484+ lobby. send_broadcast_sync ( MAIN_ROOM . parse ( ) . unwrap ( ) , serde_json :: to_string ( & BroadcastMessage {
489485 podcast_episode : None ,
490486 type_of : PodcastType :: RefreshPodcast ,
491487 message : format ! ( "Refreshed podcast: {}" , podcast. name) ,
492488 podcast : Option :: from ( podcast. clone ( ) ) ,
493489 podcast_episodes : None ,
494- } ) ;
490+ } ) . unwrap ( ) ) ;
495491 }
496492 } ) ;
497493 Ok ( HttpResponse :: Ok ( ) . into ( ) )
@@ -506,7 +502,7 @@ tag="podcasts"
506502#[ post( "/podcast/{id}/refresh" ) ]
507503pub async fn download_podcast (
508504 id : Path < String > ,
509- lobby : Data < Addr < Lobby > > ,
505+ lobby : Data < ChatServerHandle > ,
510506 podcast_service : Data < Mutex < PodcastService > > ,
511507 conn : Data < DbPool > ,
512508 requester : Option < web:: ReqData < User > > ,
@@ -621,7 +617,7 @@ pub async fn update_active_podcast(
621617async fn insert_outline (
622618 podcast : Outline ,
623619 client : Client ,
624- lobby : Data < Addr < Lobby > > ,
620+ lobby : Data < ChatServerHandle > ,
625621 mut rng : ThreadRng ,
626622 environment : EnvironmentService ,
627623 conn : Data < DbPool > ,
@@ -647,13 +643,13 @@ async fn insert_outline(
647643
648644 let feed_response = client. get ( feed_url. unwrap ( ) ) . send ( ) . await ;
649645 if feed_response. is_err ( ) {
650- lobby. do_send ( BroadcastMessage {
646+ lobby. send_broadcast ( MAIN_ROOM . parse ( ) . unwrap ( ) , serde_json :: to_string ( & BroadcastMessage {
651647 type_of : PodcastType :: OpmlErrored ,
652648 message : feed_response. err ( ) . unwrap ( ) . to_string ( ) ,
653649 podcast : None ,
654650 podcast_episodes : None ,
655651 podcast_episode : None ,
656- } ) ;
652+ } ) . unwrap ( ) ) . await ;
657653 return ;
658654 }
659655 let content = feed_response. unwrap ( ) . bytes ( ) . await . unwrap ( ) ;
@@ -689,35 +685,43 @@ async fn insert_outline(
689685 )
690686 . await ;
691687 match inserted_podcast {
692- Ok ( podcast) => lobby. do_send ( BroadcastMessage {
693- type_of : PodcastType :: OpmlAdded ,
694- message : "Refreshed podcasts" . to_string ( ) ,
695- podcast : Option :: from ( podcast) ,
696- podcast_episodes : None ,
697- podcast_episode : None ,
698- } ) ,
699- Err ( e) => lobby. do_send ( BroadcastMessage {
700- type_of : PodcastType :: OpmlErrored ,
701- message : e. to_string ( ) ,
702- podcast : None ,
703- podcast_episodes : None ,
704- podcast_episode : None ,
705- } ) ,
688+ Ok ( podcast) => {
689+
690+ let _ = lobby. send_broadcast ( MAIN_ROOM . parse ( ) . unwrap ( ) , serde_json:: to_string ( & BroadcastMessage {
691+ type_of : PodcastType :: OpmlAdded ,
692+ message : "Refreshed podcasts" . to_string ( ) ,
693+ podcast : Option :: from ( podcast) ,
694+ podcast_episodes : None ,
695+ podcast_episode : None ,
696+ } ) . unwrap ( ) ) . await ;
697+ } ,
698+ Err ( e) => {
699+ let _ = lobby. send_broadcast ( MAIN_ROOM . parse ( ) . unwrap ( ) , serde_json:: to_string ( & BroadcastMessage {
700+ type_of : PodcastType :: OpmlErrored ,
701+ message : e. to_string ( ) ,
702+ podcast : None ,
703+ podcast_episodes : None ,
704+ podcast_episode : None ,
705+ } ) . unwrap ( ) ) . await ;
706+ } ,
706707 }
707708 }
708- Err ( e) => lobby. do_send ( BroadcastMessage {
709- type_of : PodcastType :: OpmlErrored ,
710- message : e. to_string ( ) ,
711- podcast : None ,
712- podcast_episodes : None ,
713- podcast_episode : None ,
714- } ) ,
709+ Err ( e) => {
710+ let _ = lobby. send_broadcast ( MAIN_ROOM . parse ( ) . unwrap ( ) , serde_json:: to_string ( & BroadcastMessage {
711+ type_of : PodcastType :: OpmlErrored ,
712+ message : e. to_string ( ) ,
713+ podcast : None ,
714+ podcast_episodes : None ,
715+ podcast_episode : None ,
716+ } ) . unwrap ( ) ) . await ;
717+ } ,
715718 }
716719}
717720use crate :: models:: episode:: Episode ;
718721use utoipa:: ToSchema ;
719722
720723use crate :: controllers:: podcast_episode_controller:: EpisodeFormatDto ;
724+ use crate :: controllers:: server:: ChatServerHandle ;
721725use crate :: controllers:: websocket_controller:: RSSAPiKey ;
722726use crate :: models:: podcast_settings:: PodcastSetting ;
723727use crate :: models:: settings:: Setting ;
0 commit comments