1717
1818class CurrentUser {
1919
20- /** @var string|null */
21- protected $ identifier = null ;
22- /** @var string|false|null */
23- protected $ cloudId = false ;
24- /** @var string|false|null */
25- protected $ sessionUser = false ;
26-
2720 public function __construct (
2821 protected readonly IUserSession $ userSession ,
2922 protected readonly IRequest $ request ,
@@ -40,63 +33,46 @@ public function getUser(): ?IUser {
4033 * Get an identifier for the user, session or token
4134 */
4235 public function getUserIdentifier (): string {
43- if ($ this ->identifier !== null ) {
44- return $ this ->identifier ;
45- }
46-
4736 $ uid = $ this ->getUID ();
4837 if ($ uid !== null ) {
49- $ this ->identifier = $ uid ;
50- return $ this ->identifier ;
38+ return $ uid ;
5139 }
5240
5341 $ cloudId = $ this ->getCloudIDFromToken ();
5442 if ($ cloudId !== null ) {
55- $ this ->identifier = $ cloudId ;
56- return $ this ->identifier ;
43+ return $ cloudId ;
5744 }
5845
5946 $ nickname = htmlspecialchars ($ this ->request ->getHeader ('X-NC-Nickname ' ));
6047 if ($ nickname !== '' ) {
61- $ this ->identifier = $ nickname . ' ( ' . $ this ->l10nFactory ->get ('comments ' )->t ('remote user ' ) . ') ' ;
62- return $ this ->identifier ;
48+ return $ nickname . ' ( ' . $ this ->l10nFactory ->get ('comments ' )->t ('remote user ' ) . ') ' ;
6349 }
6450
6551 // Nothing worked, fallback to empty string
66- $ this ->identifier = '' ;
67- return $ this ->identifier ;
52+ return '' ;
6853 }
6954
7055 /**
7156 * Get the current user id from the session
7257 */
7358 public function getUID (): ?string {
74- if ($ this ->sessionUser === false ) {
75- $ user = $ this ->userSession ->getUser ();
76- if ($ user instanceof IUser) {
77- $ this ->sessionUser = (string )$ user ->getUID ();
78- } else {
79- $ this ->sessionUser = null ;
80- }
59+ $ user = $ this ->userSession ->getUser ();
60+ if ($ user instanceof IUser) {
61+ return $ user ->getUID ();
8162 }
82-
83- return $ this ->sessionUser ;
63+ return null ;
8464 }
8565
8666 /**
8767 * Get the current user cloud id from the session
8868 */
8969 public function getCloudId (): ?string {
90- if ($ this ->cloudId === false ) {
91- $ user = $ this ->userSession ->getUser ();
92- if ($ user instanceof IUser) {
93- $ this ->cloudId = (string )$ user ->getCloudId ();
94- } else {
95- $ this ->cloudId = $ this ->getCloudIDFromToken ();
96- }
70+ $ user = $ this ->userSession ->getUser ();
71+ if ($ user instanceof IUser) {
72+ return $ user ->getCloudId ();
73+ } else {
74+ return $ this ->getCloudIDFromToken ();
9775 }
98-
99- return $ this ->cloudId ;
10076 }
10177
10278 /**
0 commit comments