1313namespace OCA \Maps \Controller ;
1414
1515use OCA \Files \Event \LoadSidebar ;
16+ use OCA \Maps \Service \MyMapsService ;
1617use OCA \Viewer \Event \LoadViewer ;
1718use OCP \AppFramework \Controller ;
19+ use OCP \AppFramework \Http \RedirectResponse ;
1820use OCP \AppFramework \Http \TemplateResponse ;
21+ use OCP \AppFramework \Services \IInitialState ;
1922use OCP \EventDispatcher \IEventDispatcher ;
2023use OCP \IConfig ;
21- use OCP \IInitialStateService ;
2224use OCP \IRequest ;
25+ use OCP \IURLGenerator ;
2326
2427class PageController extends Controller {
2528
2629 public function __construct (
2730 string $ appName ,
2831 IRequest $ request ,
32+ private string $ userId ,
2933 private IEventDispatcher $ eventDispatcher ,
3034 private IConfig $ config ,
31- private IInitialStateService $ initialStateService ,
32- private string $ userId ,
35+ private IInitialState $ initialState ,
36+ private IURLGenerator $ urlGenerator ,
3337 ) {
3438 parent ::__construct ($ appName , $ request );
3539 }
@@ -50,7 +54,7 @@ public function index(): TemplateResponse {
5054 $ this ->eventDispatcher ->dispatch (LoadViewer::class, new LoadViewer ());
5155
5256 $ params = ['user ' => $ this ->userId ];
53- $ this ->initialStateService ->provideInitialState ($ this -> appName , 'photos ' , $ this ->config ->getAppValue ('photos ' , 'enabled ' , 'no ' ) === 'yes ' );
57+ $ this ->initialState ->provideInitialState ('photos ' , $ this ->config ->getAppValue ('photos ' , 'enabled ' , 'no ' ) === 'yes ' );
5458 $ response = new TemplateResponse ('maps ' , 'main ' , $ params );
5559
5660 $ this ->addCsp ($ response );
@@ -62,12 +66,21 @@ public function index(): TemplateResponse {
6266 * @NoAdminRequired
6367 * @NoCSRFRequired
6468 */
65- public function indexMyMap ($ myMapId ): TemplateResponse {
69+ public function indexMyMap (int $ myMapId , MyMapsService $ service ): TemplateResponse |RedirectResponse {
70+ $ map = $ service ->getMyMap ($ myMapId , $ this ->userId );
71+ if ($ map !== null && $ map ['id ' ] !== $ myMapId ) {
72+ // Instead of the id of the map containing folder the '.index.maps' file id was passed so redirect
73+ // this happens if coming from the files app integration
74+ return new RedirectResponse (
75+ $ this ->urlGenerator ->linkToRouteAbsolute ('maps.page.indexMyMap ' , ['myMapId ' => $ map ['id ' ]]),
76+ );
77+ }
78+
6679 $ this ->eventDispatcher ->dispatch (LoadSidebar::class, new LoadSidebar ());
6780 $ this ->eventDispatcher ->dispatch (LoadViewer::class, new LoadViewer ());
6881
6982 $ params = ['user ' => $ this ->userId ];
70- $ this ->initialStateService ->provideInitialState ($ this -> appName , 'photos ' , $ this ->config ->getAppValue ('photos ' , 'enabled ' , 'no ' ) === 'yes ' );
83+ $ this ->initialState ->provideInitialState ('photos ' , $ this ->config ->getAppValue ('photos ' , 'enabled ' , 'no ' ) === 'yes ' );
7184 $ response = new TemplateResponse ('maps ' , 'main ' , $ params );
7285
7386 $ this ->addCsp ($ response );
0 commit comments