1010use OCP \IRequest ;
1111use OCP \IUser ;
1212use OCP \IUserSession ;
13+ use OCP \L10N \IFactory ;
1314use OCP \Share \Exceptions \ShareNotFound ;
1415use OCP \Share \IManager ;
1516use OCP \Share \IShare ;
1617
1718class CurrentUser {
1819
19- /** @var string */
20- protected $ identifier ;
2120 /** @var string|null */
22- protected $ cloudId ;
21+ protected $ identifier = null ;
2322 /** @var string|false|null */
24- protected $ sessionUser ;
23+ protected $ cloudId = false ;
24+ /** @var string|false|null */
25+ protected $ sessionUser = false ;
2526
26- /**
27- * @param IUserSession $userSession
28- * @param IRequest $request
29- * @param IManager $shareManager
30- */
3127 public function __construct (
3228 protected IUserSession $ userSession ,
3329 protected IRequest $ request ,
3430 protected IManager $ shareManager ,
31+ protected IFactory $ l10nFactory ,
3532 ) {
36- $ this ->cloudId = false ;
37- $ this ->sessionUser = false ;
3833 }
3934
4035 public function getUser (): ?IUser {
@@ -46,19 +41,30 @@ public function getUser(): ?IUser {
4641 * @return string
4742 */
4843 public function getUserIdentifier () {
49- if ($ this ->identifier === null ) {
50- $ this ->identifier = $ this ->getUID ();
44+ if ($ this ->identifier !== null ) {
45+ return $ this ->identifier ;
46+ }
5147
52- if ($ this ->identifier === null ) {
53- $ this ->identifier = $ this ->getCloudIDFromToken ();
48+ $ uid = $ this ->getUID ();
49+ if ($ uid !== null ) {
50+ $ this ->identifier = $ uid ;
51+ return $ this ->identifier ;
52+ }
5453
55- if ($ this ->identifier === null ) {
56- // Nothing worked, fallback to empty string
57- $ this ->identifier = '' ;
58- }
59- }
54+ $ cloudId = $ this ->getCloudIDFromToken ();
55+ if ($ cloudId !== null ) {
56+ $ this ->identifier = $ cloudId ;
57+ return $ this ->identifier ;
58+ }
59+
60+ $ nickname = $ this ->request ->getHeader ('X-NC-Nickname ' );
61+ if ($ nickname !== '' ) {
62+ $ this ->identifier = $ nickname . ' ( ' . $ this ->l10nFactory ->get ('comments ' )->t ('remote user ' ) . ') ' ;
63+ return $ this ->identifier ;
6064 }
6165
66+ // Nothing worked, fallback to empty string
67+ $ this ->identifier = '' ;
6268 return $ this ->identifier ;
6369 }
6470
0 commit comments