1212use OCA \Files_Trashbin \Helper ;
1313use OCA \Files_Trashbin \Storage ;
1414use OCA \Files_Trashbin \Trashbin ;
15+ use OCP \Federation \ICloudIdManager ;
1516use OCP \Files \FileInfo ;
1617use OCP \Files \Folder ;
1718use OCP \Files \IRootFolder ;
@@ -28,6 +29,7 @@ class LegacyTrashBackend implements ITrashBackend {
2829 public function __construct (
2930 private readonly IRootFolder $ rootFolder ,
3031 private readonly IUserManager $ userManager ,
32+ private readonly ICloudIdManager $ cloudIdManager ,
3133 ) {
3234 }
3335
@@ -40,7 +42,7 @@ private function mapTrashItem(FileInfo $file, IUser $user, ?ITrashItem $parent =
4042 $ originalLocation = $ file ->getName ();
4143 }
4244 /** @psalm-suppress UndefinedInterfaceMethod */
43- $ deletedBy = $ this ->userManager -> get ($ file ['deletedBy ' ]) ?? $ parent ?->getDeletedBy();
45+ $ deletedBy = $ this ->resolveDeletedBy ($ file ['deletedBy ' ]) ?? $ parent ?->getDeletedBy();
4446 $ trashFilename = Trashbin::getTrashFilename ($ file ->getName (), $ file ->getMtime ());
4547 return new TrashItem (
4648 $ this ,
@@ -127,4 +129,29 @@ public function getTrashNodeById(IUser $user, int $fileId): ?Node {
127129 return null ;
128130 }
129131 }
132+
133+ /**
134+ * Resolve the user that deleted a trash item. Files deleted by a federated share
135+ * recipient only carry the recipient's remote cloud ID, which no local IUserManager
136+ * backend can resolve, so fall back to a display-only user for the cloud ID in that
137+ * case instead of leaving the item without an "Unknown" deleted by user.
138+ */
139+ private function resolveDeletedBy (?string $ uid ): ?IUser {
140+ if (!$ uid ) {
141+ return null ;
142+ }
143+
144+ $ user = $ this ->userManager ->get ($ uid );
145+ if ($ user !== null ) {
146+ return $ user ;
147+ }
148+
149+ try {
150+ $ cloudId = $ this ->cloudIdManager ->resolveCloudId ($ uid );
151+ } catch (\InvalidArgumentException $ e ) {
152+ return null ;
153+ }
154+
155+ return $ this ->userManager ->getFederatedUser ($ cloudId );
156+ }
130157}
0 commit comments