2727
2828namespace OC \Core \Controller ;
2929
30-
30+ use EmailAction ;
3131use OCP \Accounts \IAccountManager ;
3232use OCP \AppFramework \Http \TemplateResponse ;
3333use OCP \AppFramework \Services \IInitialState ;
3434use OCP \IL10N ;
3535use OCP \IRequest ;
3636use OCP \IUserSession ;
3737use OCP \UserStatus \IManager ;
38- use OCP \UserStatus \IUserStatus ;
3938use OCP \Accounts \IAccount ;
4039use OCP \Accounts \IAccountProperty ;
4140use OCP \App \IAppManager ;
41+ use OCP \IUserManager ;
42+ use OCP \Profile \IActionManager ;
4243
4344class ProfileController extends \OCP \AppFramework \Controller {
4445
4546 /** @var IL10N */
4647 private $ l10n ;
48+
4749 /** @var IUserSession */
4850 private $ userSession ;
51+
52+ /** @var IUserManager */
53+ private $ userManager ;
54+
4955 /** @var IAccountManager */
5056 private $ accountManager ;
57+
5158 /** @var IInitialState */
5259 private $ initialStateService ;
60+
5361 /** @var IAppManager */
5462 private $ appManager ;
5563
64+ /** @var IManager */
65+ private $ userStatusManager ;
66+
67+ /** @var IActionManager */
68+ // private $actionManager;
69+
5670 public function __construct (
5771 $ appName ,
5872 IRequest $ request ,
5973 IL10N $ l10n ,
6074 IUserSession $ userSession ,
75+ IUserManager $ userManager ,
6176 IAccountManager $ accountManager ,
6277 IInitialState $ initialStateService ,
63- IAppManager $ appManager
78+ IAppManager $ appManager ,
79+ IManager $ userStatusManager ,
80+ // IActionManager $actionManager
6481 ) {
6582 parent ::__construct ($ appName , $ request );
6683 $ this ->l10n = $ l10n ;
6784 $ this ->userSession = $ userSession ;
85+ $ this ->userManager = $ userManager ;
6886 $ this ->accountManager = $ accountManager ;
6987 $ this ->initialStateService = $ initialStateService ;
7088 $ this ->appManager = $ appManager ;
89+ $ this ->userStatusManager = $ userStatusManager ;
90+ // $this->actionManager = $actionManager;
7191 }
7292
93+ public const PROPERTY_ACTIONS = [
94+ IAccountManager::PROPERTY_EMAIL ,
95+ IAccountManager::PROPERTY_PHONE ,
96+ IAccountManager::PROPERTY_WEBSITE ,
97+ IAccountManager::PROPERTY_TWITTER ,
98+ ];
99+
73100 /**
74101 * @NoCSRFRequired
75102 * @UseSession
76103 * FIXME Public page annotation blocks the user session somehow
77104 */
78105 public function index (string $ userId = null ): TemplateResponse {
79106 $ isLoggedIn = $ this ->userSession ->isLoggedIn ();
80- $ account = $ this ->accountManager ->getAccount (\ OC :: $ server -> getUserManager () ->get ($ userId ));
107+ $ account = $ this ->accountManager ->getAccount ($ this -> userManager ->get ($ userId ));
81108
82109 $ profileEnabled = filter_var (
83110 $ account ->getProperty (IAccountManager::PROPERTY_PROFILE_ENABLED )->getValue (),
@@ -95,8 +122,7 @@ public function index(string $userId = null): TemplateResponse {
95122 );
96123 }
97124
98- $ status = \OC ::$ server ->get (IManager::class);
99- $ status = $ status ->getUserStatuses ([$ userId ]);
125+ $ status = $ this ->userStatusManager ->getUserStatuses ([$ userId ]);
100126 $ status = array_pop ($ status );
101127
102128 if ($ status ) {
@@ -158,4 +184,35 @@ function (IAccountProperty $property) {
158184
159185 return $ profileParameters ;
160186 }
187+
188+ protected function initActions (IAccount $ account ) {
189+ foreach (self ::PROPERTY_ACTIONS as $ property ) {
190+ $ scope = $ account ->getProperty ($ property )->getScope ();
191+ $ value = $ account ->getProperty ($ property )->getValue ();
192+
193+ // TODO: handle talk verification
194+ if ($ scope === IAccountManager::SCOPE_PRIVATE ) {
195+ return ;
196+ }
197+
198+ // User is not logged in, we don't display the action
199+ if ($ scope === IAccountManager::SCOPE_LOCAL && !$ this ->userSession ->isLoggedIn ()) {
200+ return ;
201+ }
202+
203+ // TODO: handle federation verification
204+ if ($ scope === IAccountManager::SCOPE_FEDERATED && false ) {
205+ return ;
206+ }
207+
208+ switch ($ property ) {
209+ case IAccountManager::PROPERTY_EMAIL :
210+ // $this->actionManager->registerAction(new EmailAction($value));
211+ break ;
212+
213+ default :
214+ break ;
215+ }
216+ }
217+ }
161218}
0 commit comments