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 IUserSession $ userSession ,
2922 protected IRequest $ request ,
@@ -41,65 +34,48 @@ public function getUser(): ?IUser {
4134 * @return string
4235 */
4336 public function getUserIdentifier () {
44- if ($ this ->identifier !== null ) {
45- return $ this ->identifier ;
46- }
47-
4837 $ uid = $ this ->getUID ();
4938 if ($ uid !== null ) {
50- $ this ->identifier = $ uid ;
51- return $ this ->identifier ;
39+ return $ uid ;
5240 }
5341
5442 $ cloudId = $ this ->getCloudIDFromToken ();
5543 if ($ cloudId !== null ) {
56- $ this ->identifier = $ cloudId ;
57- return $ this ->identifier ;
44+ return $ cloudId ;
5845 }
5946
6047 $ nickname = htmlspecialchars ($ this ->request ->getHeader ('X-NC-Nickname ' ));
6148 if ($ nickname !== '' ) {
62- $ this ->identifier = $ nickname . ' ( ' . $ this ->l10nFactory ->get ('comments ' )->t ('remote user ' ) . ') ' ;
63- return $ this ->identifier ;
49+ return $ nickname . ' ( ' . $ this ->l10nFactory ->get ('comments ' )->t ('remote user ' ) . ') ' ;
6450 }
6551
6652 // Nothing worked, fallback to empty string
67- $ this ->identifier = '' ;
68- return $ this ->identifier ;
53+ return '' ;
6954 }
7055
7156 /**
7257 * Get the current user id from the session
7358 * @return string|null
7459 */
7560 public function getUID () {
76- if ($ this ->sessionUser === false ) {
77- $ user = $ this ->userSession ->getUser ();
78- if ($ user instanceof IUser) {
79- $ this ->sessionUser = $ user ->getUID ();
80- } else {
81- $ this ->sessionUser = null ;
82- }
61+ $ user = $ this ->userSession ->getUser ();
62+ if ($ user instanceof IUser) {
63+ return (string )$ user ->getUID ();
8364 }
84-
85- return $ this ->sessionUser ;
65+ return null ;
8666 }
8767
8868 /**
8969 * Get the current user cloud id from the session
9070 * @return string|null
9171 */
9272 public function getCloudId () {
93- if ($ this ->cloudId === false ) {
94- $ user = $ this ->userSession ->getUser ();
95- if ($ user instanceof IUser) {
96- $ this ->cloudId = (string )$ user ->getCloudId ();
97- } else {
98- $ this ->cloudId = $ this ->getCloudIDFromToken ();
99- }
73+ $ user = $ this ->userSession ->getUser ();
74+ if ($ user instanceof IUser) {
75+ return (string )$ user ->getCloudId ();
76+ } else {
77+ return $ this ->getCloudIDFromToken ();
10078 }
101-
102- return $ this ->cloudId ;
10379 }
10480
10581 /**
0 commit comments