46
46
use OCP \Files \Lock \OwnerLockedException ;
47
47
use OCP \Files \NotFoundException ;
48
48
use OCP \IL10N ;
49
+ use OCP \IRequest ;
49
50
use OCP \IUserManager ;
50
51
use OCP \IUserSession ;
51
52
@@ -65,6 +66,7 @@ class LockService {
65
66
private IAppManager $ appManager ;
66
67
private IEventDispatcher $ eventDispatcher ;
67
68
private IUserSession $ userSession ;
69
+ private IRequest $ request ;
68
70
69
71
70
72
private array $ locks = [];
@@ -83,6 +85,7 @@ public function __construct(
83
85
IAppManager $ appManager ,
84
86
IEventDispatcher $ eventDispatcher ,
85
87
IUserSession $ userSession ,
88
+ IRequest $ request ,
86
89
) {
87
90
$ this ->l10n = $ l10n ;
88
91
$ this ->userManager = $ userManager ;
@@ -92,6 +95,7 @@ public function __construct(
92
95
$ this ->appManager = $ appManager ;
93
96
$ this ->eventDispatcher = $ eventDispatcher ;
94
97
$ this ->userSession = $ userSession ;
98
+ $ this ->request = $ request ;
95
99
96
100
$ this ->setup ('app ' , 'files_lock ' );
97
101
}
@@ -184,9 +188,9 @@ public function lock(LockContext $lockScope): FileLock {
184
188
$ this ->generateToken ($ lock );
185
189
$ lock ->setCreation (time ());
186
190
$ this ->notice ('locking file ' , false , ['fileLock ' => $ lock ]);
191
+ $ this ->injectMetadata ($ lock );
187
192
$ this ->locksRequest ->save ($ lock );
188
193
$ this ->propagateEtag ($ lockScope );
189
- $ this ->injectMetadata ($ lock );
190
194
return $ lock ;
191
195
}
192
196
}
@@ -339,7 +343,11 @@ public function injectMetadata(FileLock $lock): FileLock {
339
343
$ displayName = $ this ->getAppName ($ lock ->getOwner ()) ?? null ;
340
344
}
341
345
if ($ lock ->getType () === ILock::TYPE_TOKEN ) {
342
- $ displayName = $ this ->userManager ->getDisplayName ($ lock ->getOwner ()) ?? $ lock ->getDisplayName ();
346
+ $ clientHint = $ this ->getClientHint ();
347
+ $ displayName = $ lock ->getDisplayName () ?: (
348
+ $ this ->userManager ->getDisplayName ($ lock ->getOwner ()) . ' ' .
349
+ ($ clientHint ? ('( ' . $ clientHint . ') ' ) : '' )
350
+ );
343
351
}
344
352
345
353
if ($ displayName ) {
@@ -348,6 +356,22 @@ public function injectMetadata(FileLock $lock): FileLock {
348
356
return $ lock ;
349
357
}
350
358
359
+ private function getClientHint (): ?string {
360
+ if ($ this ->request ->isUserAgent ([IRequest::USER_AGENT_CLIENT_DESKTOP ])) {
361
+ return $ this ->l10n ->t ('Desktop client ' );
362
+ }
363
+
364
+ if ($ this ->request ->isUserAgent ([IRequest::USER_AGENT_CLIENT_IOS ])) {
365
+ return $ this ->l10n ->t ('iOS client ' );
366
+ }
367
+
368
+ if ($ this ->request ->isUserAgent ([IRequest::USER_AGENT_CLIENT_ANDROID ])) {
369
+ return $ this ->l10n ->t ('Android client ' );
370
+ }
371
+
372
+ return null ;
373
+ }
374
+
351
375
/**
352
376
* @param FileLock $lock
353
377
*/
0 commit comments