2525 */
2626namespace OCA \ContactsInteraction \Listeners ;
2727
28+ use OCA \ContactsInteraction \AppInfo \Application ;
2829use OCA \ContactsInteraction \Db \CardSearchDao ;
2930use OCA \ContactsInteraction \Db \RecentContact ;
3031use OCA \ContactsInteraction \Db \RecentContactMapper ;
3334use OCP \Contacts \Events \ContactInteractedWithEvent ;
3435use OCP \EventDispatcher \Event ;
3536use OCP \EventDispatcher \IEventListener ;
37+ use OCP \IConfig ;
3638use OCP \IDBConnection ;
3739use OCP \IL10N ;
3840use OCP \IUserManager ;
@@ -46,28 +48,14 @@ class ContactInteractionListener implements IEventListener {
4648
4749 use TTransactional;
4850
49- private RecentContactMapper $ mapper ;
50- private CardSearchDao $ cardSearchDao ;
51- private IUserManager $ userManager ;
52- private IDBConnection $ dbConnection ;
53- private ITimeFactory $ timeFactory ;
54- private IL10N $ l10n ;
55- private LoggerInterface $ logger ;
56-
57- public function __construct (RecentContactMapper $ mapper ,
58- CardSearchDao $ cardSearchDao ,
59- IUserManager $ userManager ,
60- IDBConnection $ connection ,
61- ITimeFactory $ timeFactory ,
62- IL10N $ l10nFactory ,
63- LoggerInterface $ logger ) {
64- $ this ->mapper = $ mapper ;
65- $ this ->cardSearchDao = $ cardSearchDao ;
66- $ this ->userManager = $ userManager ;
67- $ this ->dbConnection = $ connection ;
68- $ this ->timeFactory = $ timeFactory ;
69- $ this ->l10n = $ l10nFactory ;
70- $ this ->logger = $ logger ;
51+ public function __construct (private RecentContactMapper $ mapper ,
52+ private CardSearchDao $ cardSearchDao ,
53+ private IUserManager $ userManager ,
54+ private IDBConnection $ connection ,
55+ private ITimeFactory $ timeFactory ,
56+ private IL10N $ l10n ,
57+ private IConfig $ config ,
58+ private LoggerInterface $ logger ) {
7159 }
7260
7361 public function handle (Event $ event ): void {
@@ -85,6 +73,11 @@ public function handle(Event $event): void {
8573 return ;
8674 }
8775
76+ if ($ this ->config ->getUserValue ($ event ->getActor ()->getUID (), Application::APP_ID , 'generateContactsInteraction ' , 'yes ' ) === 'no ' ) {
77+ $ this ->logger ->debug ("Ignoring contact interaction as it's disabled for this user " );
78+ return ;
79+ }
80+
8881 $ this ->atomic (function () use ($ event ) {
8982 $ uid = $ event ->getUid ();
9083 $ email = $ event ->getEmail ();
@@ -96,9 +89,9 @@ public function handle(Event $event): void {
9689 $ federatedCloudId
9790 );
9891 if (!empty ($ existing )) {
99- $ now = $ this ->timeFactory ->getTime ();
92+ $ now = $ this ->timeFactory ->now ();
10093 foreach ($ existing as $ c ) {
101- $ c ->setLastContact ($ now );
94+ $ c ->setLastContact ($ now-> getTimestamp () );
10295 $ this ->mapper ->update ($ c );
10396 }
10497
@@ -116,7 +109,7 @@ public function handle(Event $event): void {
116109 if ($ federatedCloudId !== null ) {
117110 $ contact ->setFederatedCloudId ($ federatedCloudId );
118111 }
119- $ contact ->setLastContact ($ this ->timeFactory ->getTime ());
112+ $ contact ->setLastContact ($ this ->timeFactory ->now ()-> getTimestamp ());
120113
121114 $ copy = $ this ->cardSearchDao ->findExisting (
122115 $ event ->getActor (),
@@ -141,7 +134,7 @@ public function handle(Event $event): void {
141134 $ contact ->setCard ($ this ->generateCard ($ contact ));
142135 }
143136 $ this ->mapper ->insert ($ contact );
144- }, $ this ->dbConnection );
137+ }, $ this ->connection );
145138 }
146139
147140 private function getDisplayName (?string $ uid ): ?string {
0 commit comments