From 79a11a604c5e2aa7d34ecb00697a1abe55e1bf86 Mon Sep 17 00:00:00 2001 From: Rasmus Steine Olsen <111959793+olsenrasmus@users.noreply.github.com> Date: Fri, 25 Oct 2024 10:23:10 +0200 Subject: [PATCH 01/11] Refakturering av varsler med ny melding --- .../classes/HOT_MessagesNotification.cls | 180 +++++++++--------- .../sms/classes/HOT_ReminderSMSService.cls | 25 +-- 2 files changed, 103 insertions(+), 102 deletions(-) diff --git a/force-app/main/default/classes/HOT_MessagesNotification.cls b/force-app/main/default/classes/HOT_MessagesNotification.cls index 91d6209682..b69254503b 100644 --- a/force-app/main/default/classes/HOT_MessagesNotification.cls +++ b/force-app/main/default/classes/HOT_MessagesNotification.cls @@ -1,4 +1,33 @@ public without sharing class HOT_MessagesNotification { + public static HOT_Notification__c newMessageNotificationPush(Id accountId, Thread__c thread, String type) { + HOT_Notification__c notification = new HOT_Notification__c(); + notification.HOT_Account__c = accountId; + notification.HOT_NotificationChannel__c = 'Push-varsel i appen'; + notification.HOT_Subject__c = 'Ny melding fra Tolketjenesten'; + notification.HOT_NotificationText__c = 'Du har fått en melding fra Tolketjenesten.'; + notification.HOT_RelatedObject__c = thread.Id; + notification.HOT_RelatedObjectType__c = type; + return notification; + } + public static HOT_Notification__c newMessageNotificationSMS(Id accountId, Thread__c thread, String type) { + HOT_Notification__c notification = new HOT_Notification__c(); + notification.HOT_Account__c = accountId; + notification.HOT_NotificationChannel__c = 'SMS'; + notification.HOT_Subject__c = 'Ny melding fra Tolketjenesten'; + notification.HOT_NotificationText__c = 'Du har fått en melding fra Tolketjenesten.'; + notification.HOT_RelatedObject__c = thread.Id; + notification.HOT_RelatedObjectType__c = type; + return notification; + } + private static void insertNotifications(List notifications) { + try { + HOT_NotificationCentreController.createNotification(notifications); + } catch (Exception e) { + LoggerUtility logger = new LoggerUtility(); + logger.exception(e, CRM_ApplicationDomain.Domain.HOT); + logger.publish(); + } + } public static void NotifyDispatcher(List threadIds) { List threads = [ SELECT Id, Name, OwnerId, HOT_Dispatcher__c, HOT_Subject__c @@ -67,7 +96,7 @@ public without sharing class HOT_MessagesNotification { for (User user : users) { userIdByAccountId.put(user.AccountId, user.Id); } - //creating notification object list + //LAGER VARSLINGSOBJEKT LISTE TIL INSETTING SENERE List notificationList = new List(); if (!threads.isEmpty()) { @@ -83,6 +112,7 @@ public without sharing class HOT_MessagesNotification { } } if (recipients.size() > 0) { + //FØRST MÅ MAN FINNE UT AV OM DET ER EN TOLKE SAMTALE ELLER EN SAMTALE SOM BRUKER, OG BASERT PÅ DET BRUKE BRUKEREN ELLER TOLKEN SIN VARSLINGSMETODE if ( (thread.CRM_Thread_Type__c == 'HOT_TOLK-FORMIDLER' || thread.CRM_Thread_Type__c == 'HOT_TOLK-RESSURSKONTOR' && @@ -94,29 +124,25 @@ public without sharing class HOT_MessagesNotification { thread.CRM_Thread_Type__c == 'HOT_TOLK-RESSURSKONTOR' || thread.CRM_Thread_Type__c == 'HOT_TOLK-FORMIDLER' ) { - //creating notification object - HOT_Notification__c notification = new HOT_Notification__c(); - notification.HOT_Account__c = thread.CRM_Account__c; - notification.HOT_NotificationChannel__c = 'Push-varsel i appen'; - notification.HOT_Subject__c = 'Ny melding fra Tolketjenesten'; - notification.HOT_NotificationText__c = 'Du har fått en melding fra Tolketjenesten.'; - notification.HOT_RelatedObject__c = thread.Id; - notification.HOT_RelatedObjectType__c = 'threadInterpreter'; - - notificationList.add(notification); + //BETYR AT VARSELET SKAL LINKE TIL TOLKE SAMTALER. SAMTALER MELLOM RESSURSKONTOR OG EN TIL EN MED FORMIDLER + //LAGER NOTIFIKASJONSOBJEKTET + HOT_Notification__c newNotification = newMessageNotificationPush( + thread.CRM_Account__c, + thread, + 'threadInterpreter' + ); + notificationList.add(newNotification); } else { - //creating notification object - HOT_Notification__c notification = new HOT_Notification__c(); - notification.HOT_Account__c = thread.CRM_Account__c; - notification.HOT_NotificationChannel__c = 'Push-varsel i appen'; - notification.HOT_Subject__c = 'Ny melding fra Tolketjenesten'; - notification.HOT_NotificationText__c = 'Du har fått en melding fra Tolketjenesten.'; - notification.HOT_RelatedObject__c = thread.Id; - notification.HOT_RelatedObjectType__c = 'threadUser'; - - notificationList.add(notification); + //BETYR AT VARSELET SKAL LINKE TIL SAMTALE HVOR BRUKEREN IKKE ER TOLK + //LAGER NOTIFIKASJONSOBJEKTET + HOT_Notification__c newNotification = newMessageNotificationPush( + thread.CRM_Account__c, + thread, + 'threadUser' + ); + notificationList.add(newNotification); } - + //SENDER UT PUSHVARSEL HOT_UserNotificationService.newMessageNotification( getCustomNotificationType('HOT_NotifyUser'), thread, @@ -130,50 +156,33 @@ public without sharing class HOT_MessagesNotification { thread.CRM_Thread_Type__c == 'HOT_TOLK-RESSURSKONTOR' || thread.CRM_Thread_Type__c == 'HOT_TOLK-FORMIDLER' ) { - //creating notification object - HOT_Notification__c notification = new HOT_Notification__c(); - notification.HOT_Account__c = thread.CRM_Account__c; - notification.HOT_NotificationChannel__c = 'SMS'; - notification.HOT_Subject__c = 'Ny melding fra Tolketjenesten'; - notification.HOT_NotificationText__c = - 'INFO Du har fått en melding fra tolketjenesten.\nFor mer informasjon, se tolkebestilling.nav.no.\n' + - 'Du kan ikke svare på denne meldingen.\n' + - 'Mvh tolketjenesten i Nav'; - notification.HOT_RelatedObject__c = thread.Id; - notification.HOT_RelatedObjectType__c = 'threadInterpreter'; - - notificationList.add(notification); + //BETYR AT VARSELET SKAL LINKE TIL TOLKE SAMTALER. SAMTALER MELLOM RESSURSKONTOR OG EN TIL EN MED FORMIDLER + //LAGER NOTIFIKASJONSOBJEKTET + HOT_Notification__c newNotification = newMessageNotificationSMS( + thread.CRM_Account__c, + thread, + 'threadInterpreter' + ); + notificationList.add(newNotification); } else { - //creating notification object - HOT_Notification__c notification = new HOT_Notification__c(); - notification.HOT_Account__c = thread.CRM_Account__c; - notification.HOT_NotificationChannel__c = 'SMS'; - notification.HOT_Subject__c = 'Ny melding fra Tolketjenesten'; - notification.HOT_NotificationText__c = - 'INFO Du har fått en melding fra tolketjenesten.\nFor mer informasjon, se tolkebestilling.nav.no.\n' + - 'Du kan ikke svare på denne meldingen.\n' + - 'Mvh tolketjenesten i Nav'; - notification.HOT_RelatedObject__c = thread.Id; - notification.HOT_RelatedObjectType__c = 'threadUser'; - - notificationList.add(notification); + //BETYR AT VARSELET SKAL LINKE TIL SAMTALE HVOR BRUKEREN IKKE ER TOLK + //LAGER NOTIFIKASJONSOBJEKTET + HOT_Notification__c newNotification = newMessageNotificationSMS( + thread.CRM_Account__c, + thread, + 'threadUser' + ); + notificationList.add(newNotification); } HOT_ReminderSMSService.sendSMSOnNewMessage(threadList); } } } - //inserting notifications - try { - HOT_NotificationCentreController.createNotification(notificationList); - } catch (Exception e) { - LoggerUtility logger = new LoggerUtility(); - logger.exception(e, CRM_ApplicationDomain.Domain.HOT); - logger.publish(); - } + //INSERTE NOTIFIKASJONSRECORD TIL VARSLINGSSENTERET + insertNotifications(notificationList); } } - @Future public static void NotifyInterpreter(List threadIds) { List threads = [ SELECT @@ -236,6 +245,7 @@ public without sharing class HOT_MessagesNotification { } } } + Map userIdToThreadMapSMS = new Map(); for (User user : userIdToThreadMap.keySet()) { String notificationChannel = user.ServiceResources[0].HOT_NotificationChannel__c; Thread__c thread = userIdToThreadMap.get(user); @@ -249,11 +259,12 @@ public without sharing class HOT_MessagesNotification { notification.setTargetId(thread.Id); // send med parameter for denne HOT_NotificationHandler.sendNotification(notification, recipients, (SObject) thread); // send med parameter for denne } else { - Set threadList = new Set(); - threadList.add(thread.Id); - HOT_ReminderSMSService.sendSMSOnNewMessageInterpreter(user.Id, thread.Id); + userIdToThreadMapSMS.put(user, thread); } } + if (!userIdToThreadMapSMS.isEmpty()) { + HOT_ReminderSMSService.sendSMSOnNewMessageInterpreter(userIdToThreadMapSMS); + } } //FRILANSTOLKER VARSEL @@ -282,7 +293,7 @@ public without sharing class HOT_MessagesNotification { } //creating notification object list List notificationList = new List(); - + Map userIdToThreadMapSMS = new Map(); for (User user : userIdToThreadMap.keySet()) { Set recipients = new Set(); String notificationChannel = user.ServiceResources[0].HOT_NotificationChannel__c; @@ -295,15 +306,12 @@ public without sharing class HOT_MessagesNotification { if (recipients.size() > 0) { if (notificationChannel.contains('Push')) { //creating notification object - HOT_Notification__c notification = new HOT_Notification__c(); - notification.HOT_Account__c = user.AccountId; - notification.HOT_NotificationChannel__c = 'Push-varsel i appen'; - notification.HOT_Subject__c = 'Ny melding fra Tolketjenesten'; - notification.HOT_NotificationText__c = 'Du har fått en melding fra Tolketjenesten.'; - notification.HOT_RelatedObject__c = thread.Id; - notification.HOT_RelatedObjectType__c = 'threadInterpreter'; - - notificationList.add(notification); + HOT_Notification__c newNotification = newMessageNotificationPush( + user.AccountId, + thread, + 'threadInterpreter' + ); + notificationList.add(newNotification); HOT_UserNotificationService.newMessageNotification( getCustomNotificationType('HOT_NotifyUser'), thread, @@ -311,33 +319,23 @@ public without sharing class HOT_MessagesNotification { recipients ); } else { - Set threadList = new Set(); - threadList.add(thread.Id); //creating notification object - HOT_Notification__c notification = new HOT_Notification__c(); - notification.HOT_Account__c = user.AccountId; - notification.HOT_NotificationChannel__c = 'SMS'; - notification.HOT_Subject__c = 'Ny melding fra Tolketjenesten'; - notification.HOT_NotificationText__c = - 'INFO Du har fått en melding fra tolketjenesten. \nFor mer informasjon, se tolkebestilling.nav.no.\n' + - 'Du kan ikke svare på denne meldingen.\n' + - 'Mvh tolketjenesten i Nav'; - notification.HOT_RelatedObject__c = thread.Id; - notification.HOT_RelatedObjectType__c = 'threadInterpreter'; + HOT_Notification__c newNotification = newMessageNotificationSMS( + user.AccountId, + thread, + 'threadInterpreter' + ); + notificationList.add(newNotification); - notificationList.add(notification); - HOT_ReminderSMSService.sendSMSOnNewMessageInterpreter(user.Id, thread.Id); + userIdToThreadMapSMS.put(user, thread); } } } - //inserting notifications - try { - HOT_NotificationCentreController.createNotification(notificationList); - } catch (Exception e) { - LoggerUtility logger = new LoggerUtility(); - logger.exception(e, CRM_ApplicationDomain.Domain.HOT); - logger.publish(); + if (!userIdToThreadMapSMS.isEmpty()) { + HOT_ReminderSMSService.sendSMSOnNewMessageInterpreter(userIdToThreadMapSMS); } + //INSERTE NOTIFIKASJONSRECORD TIL VARSLINGSSENTERET + insertNotifications(notificationList); } } } diff --git a/force-app/main/sms/classes/HOT_ReminderSMSService.cls b/force-app/main/sms/classes/HOT_ReminderSMSService.cls index 8aab59b6d9..3de59849d1 100644 --- a/force-app/main/sms/classes/HOT_ReminderSMSService.cls +++ b/force-app/main/sms/classes/HOT_ReminderSMSService.cls @@ -283,19 +283,22 @@ public without sharing class HOT_ReminderSMSService { } } - public static void sendSMSOnNewMessageInterpreter(String userId, String threadId) { - User user = [SELECT Id, AccountId FROM User WHERE Id = :userId]; + public static void sendSMSOnNewMessageInterpreter(Map userIdToThreadMap) { List smsList = new List(); + for (User user : userIdToThreadMap.keySet()) { + Thread__c thread = userIdToThreadMap.get(user); - SMS__c sms = new SMS__c(); - sms.Domain__c = 'HOT'; - sms.Type__c = 'Message'; - sms.Account__c = user.AccountId; - sms.Thread__c = threadId; - sms.Recipient__c = getRecipientPhoneNumberInterpreter(userId); - sms.Message__c = constructOnNewMessage(); - if (SMS.Recipient__c != null) { - smsList.add(sms); + SMS__c sms = new SMS__c(); + sms.Domain__c = 'HOT'; + sms.Type__c = 'Message'; + sms.Account__c = user.AccountId; + sms.Thread__c = thread.Id; + sms.Recipient__c = getRecipientPhoneNumberInterpreter(user.Id); + sms.Message__c = constructOnNewMessage(); + + if (sms.Recipient__c != null) { + smsList.add(sms); + } } try { From 4c511fce39fa97a58730158dcf83888c62d925b9 Mon Sep 17 00:00:00 2001 From: Rasmus Steine Olsen <111959793+olsenrasmus@users.noreply.github.com> Date: Fri, 25 Oct 2024 10:24:43 +0200 Subject: [PATCH 02/11] Fjerner merkelige kommentarer --- .../main/default/classes/HOT_MessagesNotification.cls | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/force-app/main/default/classes/HOT_MessagesNotification.cls b/force-app/main/default/classes/HOT_MessagesNotification.cls index b69254503b..bf16d88929 100644 --- a/force-app/main/default/classes/HOT_MessagesNotification.cls +++ b/force-app/main/default/classes/HOT_MessagesNotification.cls @@ -50,10 +50,10 @@ public without sharing class HOT_MessagesNotification { } Messaging.CustomNotification notification = new Messaging.CustomNotification(); notification.setTitle('Ny melding'); - notification.setBody(thread.HOT_Subject__c); // send med parameter for denne - notification.setNotificationTypeId(getCustomNotificationType('HOT_NotifyDispatcher').Id); // send med parameter for denne - notification.setTargetId(thread.Id); // send med parameter for denne - HOT_NotificationHandler.sendNotification(notification, recipients, (SObject) thread); // send med parameter for denne + notification.setBody(thread.HOT_Subject__c); + notification.setNotificationTypeId(getCustomNotificationType('HOT_NotifyDispatcher').Id); + notification.setTargetId(thread.Id); + HOT_NotificationHandler.sendNotification(notification, recipients, (SObject) thread); } } From b3ad181c5c07b83dffcaa6eaac838fc0faaa10c3 Mon Sep 17 00:00:00 2001 From: Rasmus Steine Olsen <111959793+olsenrasmus@users.noreply.github.com> Date: Fri, 25 Oct 2024 10:30:00 +0200 Subject: [PATCH 03/11] =?UTF-8?q?Legger=20p=C3=A5=20forklarende=20kommenta?= =?UTF-8?q?rer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../classes/HOT_MessagesNotification.cls | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/force-app/main/default/classes/HOT_MessagesNotification.cls b/force-app/main/default/classes/HOT_MessagesNotification.cls index bf16d88929..568526e7d1 100644 --- a/force-app/main/default/classes/HOT_MessagesNotification.cls +++ b/force-app/main/default/classes/HOT_MessagesNotification.cls @@ -96,7 +96,7 @@ public without sharing class HOT_MessagesNotification { for (User user : users) { userIdByAccountId.put(user.AccountId, user.Id); } - //LAGER VARSLINGSOBJEKT LISTE TIL INSETTING SENERE + //LAGER VARSLINGS LISTE TIL INSETTING SENERE List notificationList = new List(); if (!threads.isEmpty()) { @@ -125,7 +125,7 @@ public without sharing class HOT_MessagesNotification { thread.CRM_Thread_Type__c == 'HOT_TOLK-FORMIDLER' ) { //BETYR AT VARSELET SKAL LINKE TIL TOLKE SAMTALER. SAMTALER MELLOM RESSURSKONTOR OG EN TIL EN MED FORMIDLER - //LAGER NOTIFIKASJONSOBJEKTET + //LAGER NOTIFIKASJON HOT_Notification__c newNotification = newMessageNotificationPush( thread.CRM_Account__c, thread, @@ -134,7 +134,7 @@ public without sharing class HOT_MessagesNotification { notificationList.add(newNotification); } else { //BETYR AT VARSELET SKAL LINKE TIL SAMTALE HVOR BRUKEREN IKKE ER TOLK - //LAGER NOTIFIKASJONSOBJEKTET + //LAGER NOTIFIKASJON HOT_Notification__c newNotification = newMessageNotificationPush( thread.CRM_Account__c, thread, @@ -142,7 +142,7 @@ public without sharing class HOT_MessagesNotification { ); notificationList.add(newNotification); } - //SENDER UT PUSHVARSEL + //SENDER UT PUSHVARSEL TIL MOBIL HOT_UserNotificationService.newMessageNotification( getCustomNotificationType('HOT_NotifyUser'), thread, @@ -174,7 +174,7 @@ public without sharing class HOT_MessagesNotification { ); notificationList.add(newNotification); } - + //SENDER SMS HOT_ReminderSMSService.sendSMSOnNewMessage(threadList); } } @@ -250,18 +250,21 @@ public without sharing class HOT_MessagesNotification { String notificationChannel = user.ServiceResources[0].HOT_NotificationChannel__c; Thread__c thread = userIdToThreadMap.get(user); if (notificationChannel.contains('Push')) { + //PUSHVARSEL TIL MOBIL Set recipients = new Set(); recipients.add(user.Id); Messaging.CustomNotification notification = new Messaging.CustomNotification(); notification.setTitle('Ny melding'); - notification.setBody(thread.HOT_Subject__c); // send med parameter for denne - notification.setNotificationTypeId(getCustomNotificationType('HOT_NotifyInterpreter').Id); // send med parameter for denne - notification.setTargetId(thread.Id); // send med parameter for denne - HOT_NotificationHandler.sendNotification(notification, recipients, (SObject) thread); // send med parameter for denne + notification.setBody(thread.HOT_Subject__c); + notification.setNotificationTypeId(getCustomNotificationType('HOT_NotifyInterpreter').Id); + notification.setTargetId(thread.Id); + HOT_NotificationHandler.sendNotification(notification, recipients, (SObject) thread); } else { + //SMS userIdToThreadMapSMS.put(user, thread); } } + //SENDER SMS if (!userIdToThreadMapSMS.isEmpty()) { HOT_ReminderSMSService.sendSMSOnNewMessageInterpreter(userIdToThreadMapSMS); } @@ -291,7 +294,7 @@ public without sharing class HOT_MessagesNotification { } } } - //creating notification object list + //LAGER VARSLINGS LISTE TIL INSETTING SENERE List notificationList = new List(); Map userIdToThreadMapSMS = new Map(); for (User user : userIdToThreadMap.keySet()) { @@ -305,7 +308,8 @@ public without sharing class HOT_MessagesNotification { if (recipients.size() > 0) { if (notificationChannel.contains('Push')) { - //creating notification object + //PUSHVARSEL TIL MOBIL + //LAGER NOTIFIKASJON HOT_Notification__c newNotification = newMessageNotificationPush( user.AccountId, thread, @@ -319,19 +323,20 @@ public without sharing class HOT_MessagesNotification { recipients ); } else { - //creating notification object + //LAGER NOTIFIKASJON HOT_Notification__c newNotification = newMessageNotificationSMS( user.AccountId, thread, 'threadInterpreter' ); + //SMS notificationList.add(newNotification); - userIdToThreadMapSMS.put(user, thread); } } } if (!userIdToThreadMapSMS.isEmpty()) { + //SENDER SMS HOT_ReminderSMSService.sendSMSOnNewMessageInterpreter(userIdToThreadMapSMS); } //INSERTE NOTIFIKASJONSRECORD TIL VARSLINGSSENTERET From b809a1f14d940fd52d6d971cf6a48d9105083631 Mon Sep 17 00:00:00 2001 From: Rasmus Steine Olsen <111959793+olsenrasmus@users.noreply.github.com> Date: Fri, 25 Oct 2024 10:42:45 +0200 Subject: [PATCH 04/11] Oppdaterer test --- force-app/main/sms/classes/HOT_ReminderSMSServiceTest.cls | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/force-app/main/sms/classes/HOT_ReminderSMSServiceTest.cls b/force-app/main/sms/classes/HOT_ReminderSMSServiceTest.cls index 19138ac1e8..08470dcdc8 100644 --- a/force-app/main/sms/classes/HOT_ReminderSMSServiceTest.cls +++ b/force-app/main/sms/classes/HOT_ReminderSMSServiceTest.cls @@ -177,7 +177,9 @@ private class HOT_ReminderSMSServiceTest { FROM ServiceResource WHERE RelatedRecordId = :currentUser.Id ]; - HOT_ReminderSMSService.sendSMSOnNewMessageInterpreter(currentUser.Id, thread.Id); + Map userIdToThreadMapSMS = new Map(); + userIdToThreadMapSMS.put(currentUser, thread); + HOT_ReminderSMSService.sendSMSOnNewMessageInterpreter(userIdToThreadMapSMS); Test.stopTest(); List smsList = [SELECT Id, Message__c FROM SMS__c]; System.assertEquals(1, smsList.size(), 'Could not create sms-record'); From f24cbb535236039416bae2dc3492918ab5b481d0 Mon Sep 17 00:00:00 2001 From: Rasmus Steine Olsen <111959793+olsenrasmus@users.noreply.github.com> Date: Fri, 25 Oct 2024 11:40:41 +0200 Subject: [PATCH 05/11] . --- .../main/default/classes/HOT_MessagesNotification.cls | 8 ++++---- force-app/main/sms/classes/HOT_ReminderSMSService.cls | 6 +++--- force-app/main/sms/classes/HOT_ReminderSMSServiceTest.cls | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/force-app/main/default/classes/HOT_MessagesNotification.cls b/force-app/main/default/classes/HOT_MessagesNotification.cls index 568526e7d1..26baae785f 100644 --- a/force-app/main/default/classes/HOT_MessagesNotification.cls +++ b/force-app/main/default/classes/HOT_MessagesNotification.cls @@ -245,7 +245,7 @@ public without sharing class HOT_MessagesNotification { } } } - Map userIdToThreadMapSMS = new Map(); + Map userIdToThreadMapSMS = new Map(); for (User user : userIdToThreadMap.keySet()) { String notificationChannel = user.ServiceResources[0].HOT_NotificationChannel__c; Thread__c thread = userIdToThreadMap.get(user); @@ -261,7 +261,7 @@ public without sharing class HOT_MessagesNotification { HOT_NotificationHandler.sendNotification(notification, recipients, (SObject) thread); } else { //SMS - userIdToThreadMapSMS.put(user, thread); + userIdToThreadMapSMS.put(thread, user); } } //SENDER SMS @@ -296,7 +296,7 @@ public without sharing class HOT_MessagesNotification { } //LAGER VARSLINGS LISTE TIL INSETTING SENERE List notificationList = new List(); - Map userIdToThreadMapSMS = new Map(); + Map userIdToThreadMapSMS = new Map(); for (User user : userIdToThreadMap.keySet()) { Set recipients = new Set(); String notificationChannel = user.ServiceResources[0].HOT_NotificationChannel__c; @@ -331,7 +331,7 @@ public without sharing class HOT_MessagesNotification { ); //SMS notificationList.add(newNotification); - userIdToThreadMapSMS.put(user, thread); + userIdToThreadMapSMS.put(thread, user); } } } diff --git a/force-app/main/sms/classes/HOT_ReminderSMSService.cls b/force-app/main/sms/classes/HOT_ReminderSMSService.cls index 3de59849d1..9a5d125f49 100644 --- a/force-app/main/sms/classes/HOT_ReminderSMSService.cls +++ b/force-app/main/sms/classes/HOT_ReminderSMSService.cls @@ -283,10 +283,10 @@ public without sharing class HOT_ReminderSMSService { } } - public static void sendSMSOnNewMessageInterpreter(Map userIdToThreadMap) { + public static void sendSMSOnNewMessageInterpreter(Map userIdToThreadMap) { List smsList = new List(); - for (User user : userIdToThreadMap.keySet()) { - Thread__c thread = userIdToThreadMap.get(user); + for (Thread__c thread : userIdToThreadMap.keySet()) { + User user = userIdToThreadMap.get(thread); SMS__c sms = new SMS__c(); sms.Domain__c = 'HOT'; diff --git a/force-app/main/sms/classes/HOT_ReminderSMSServiceTest.cls b/force-app/main/sms/classes/HOT_ReminderSMSServiceTest.cls index 08470dcdc8..5f42e64841 100644 --- a/force-app/main/sms/classes/HOT_ReminderSMSServiceTest.cls +++ b/force-app/main/sms/classes/HOT_ReminderSMSServiceTest.cls @@ -177,8 +177,8 @@ private class HOT_ReminderSMSServiceTest { FROM ServiceResource WHERE RelatedRecordId = :currentUser.Id ]; - Map userIdToThreadMapSMS = new Map(); - userIdToThreadMapSMS.put(currentUser, thread); + Map userIdToThreadMapSMS = new Map(); + userIdToThreadMapSMS.put(thread, currentUser); HOT_ReminderSMSService.sendSMSOnNewMessageInterpreter(userIdToThreadMapSMS); Test.stopTest(); List smsList = [SELECT Id, Message__c FROM SMS__c]; From 440b2b5b745bceaabe73b547408eb739cebb6c90 Mon Sep 17 00:00:00 2001 From: Rasmus Steine Olsen <111959793+olsenrasmus@users.noreply.github.com> Date: Fri, 25 Oct 2024 12:35:52 +0200 Subject: [PATCH 06/11] Bare fikser testen --- force-app/main/sms/classes/HOT_ReminderSMSServiceTest.cls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/force-app/main/sms/classes/HOT_ReminderSMSServiceTest.cls b/force-app/main/sms/classes/HOT_ReminderSMSServiceTest.cls index 5f42e64841..87175b87dc 100644 --- a/force-app/main/sms/classes/HOT_ReminderSMSServiceTest.cls +++ b/force-app/main/sms/classes/HOT_ReminderSMSServiceTest.cls @@ -177,7 +177,7 @@ private class HOT_ReminderSMSServiceTest { FROM ServiceResource WHERE RelatedRecordId = :currentUser.Id ]; - Map userIdToThreadMapSMS = new Map(); + Map userIdToThreadMapSMS = new Map(); userIdToThreadMapSMS.put(thread, currentUser); HOT_ReminderSMSService.sendSMSOnNewMessageInterpreter(userIdToThreadMapSMS); Test.stopTest(); From 786d1dc7d6193e9d4900dff884c5822717e8f215 Mon Sep 17 00:00:00 2001 From: Eugenijus Date: Fri, 25 Oct 2024 14:28:45 +0200 Subject: [PATCH 07/11] fix take all threads into account --- .../classes/HOT_MessagesNotification.cls | 121 +++++++++--------- .../sms/classes/HOT_ReminderSMSService.cls | 27 ++-- .../classes/HOT_ReminderSMSServiceTest.cls | 5 +- 3 files changed, 80 insertions(+), 73 deletions(-) diff --git a/force-app/main/default/classes/HOT_MessagesNotification.cls b/force-app/main/default/classes/HOT_MessagesNotification.cls index 26baae785f..dcb2a6b631 100644 --- a/force-app/main/default/classes/HOT_MessagesNotification.cls +++ b/force-app/main/default/classes/HOT_MessagesNotification.cls @@ -196,9 +196,8 @@ public without sharing class HOT_MessagesNotification { WHERE Id IN :threadIds ]; - Set participantIdsSet = new Set(); if (!threads.isEmpty()) { - Map interpretersOnThreadMap = new Map(); + Map> interpretersOnThreadMap = new Map>(); for (Thread__c t : threads) { String[] participantIds = t.HOT_ParticipantIds__c.split(', '); @@ -206,21 +205,25 @@ public without sharing class HOT_MessagesNotification { for (String participantId : participantIds) { participantId = participantId.trim(); - if (participantId != '') { - interpretersOnThreadMap.put(participantId, t); - participantIdsSet.add(participantId); + if (participantId == '') { + continue; + } + if(interpretersOnThreadMap.containsKey(participantId)){ + interpretersOnThreadMap.get(participantId).add(t); + }else{ + interpretersOnThreadMap.put(participantId, new List{t}); } } } List employeeServiceresource = [ SELECT Id, RelatedRecordId, HOT_NotificationChannel__c FROM ServiceResource - WHERE RelatedRecordId IN :participantIdsSet AND HOT_IsEmployedInterpreter__c = TRUE + WHERE RelatedRecordId IN :interpretersOnThreadMap.keySet() AND HOT_IsEmployedInterpreter__c = TRUE ]; List freelanceServiceresource = [ SELECT Id, AccountId, HOT_NotificationChannel__c FROM ServiceResource - WHERE RelatedRecordId IN :participantIdsSet AND HOT_IsFreelanceInterpreter__c = TRUE + WHERE RelatedRecordId IN :interpretersOnThreadMap.keySet() AND HOT_IsFreelanceInterpreter__c = TRUE ]; //ANSATTOLKER VARSEL @@ -230,38 +233,43 @@ public without sharing class HOT_MessagesNotification { employeeUserIds.add(sr.RelatedRecordId); } - List users = [ + Map userMap = new Map([ SELECT Id, AccountId, (SELECT Id, HOT_NotificationChannel__c FROM ServiceResources) FROM User WHERE Id IN :employeeUserIds - ]; + ]); - Map userIdToThreadMap = new Map(); + Map> userIdToThreadMap = new Map>(); for (Id participantId : interpretersOnThreadMap.keySet()) { - Thread__c threadId = interpretersOnThreadMap.get(participantId); - for (User user : users) { - if (participantId == user.Id && threadId.LastModifiedById != user.Id) { - userIdToThreadMap.put(User, threadId); + if(!userMap.containsKey(participantId)){ + continue; + } + for(Thread__c thread: interpretersOnThreadMap.get(participantId)){ + if(thread.LastModifiedById == participantId){ + continue; + } + if(userIdToThreadMap.containsKey(userMap.get(participantId))){ + userIdToThreadMap.get(userMap.get(participantId)).add(thread); + }else{ + userIdToThreadMap.put(userMap.get(participantId), new List{thread}); } } } - Map userIdToThreadMapSMS = new Map(); + Map> userIdToThreadMapSMS = new Map>(); for (User user : userIdToThreadMap.keySet()) { - String notificationChannel = user.ServiceResources[0].HOT_NotificationChannel__c; - Thread__c thread = userIdToThreadMap.get(user); - if (notificationChannel.contains('Push')) { - //PUSHVARSEL TIL MOBIL - Set recipients = new Set(); - recipients.add(user.Id); - Messaging.CustomNotification notification = new Messaging.CustomNotification(); - notification.setTitle('Ny melding'); - notification.setBody(thread.HOT_Subject__c); - notification.setNotificationTypeId(getCustomNotificationType('HOT_NotifyInterpreter').Id); - notification.setTargetId(thread.Id); - HOT_NotificationHandler.sendNotification(notification, recipients, (SObject) thread); - } else { - //SMS - userIdToThreadMapSMS.put(thread, user); + if(user.ServiceResources[0].HOT_NotificationChannel__c.contains('Push')){ + for (Thread__c thread : userIdToThreadMap.get(user)) { + Set recipients = new Set(); + recipients.add(user.Id); + Messaging.CustomNotification notification = new Messaging.CustomNotification(); + notification.setTitle('Ny melding'); + notification.setBody(thread.HOT_Subject__c); + notification.setNotificationTypeId(getCustomNotificationType('HOT_NotifyInterpreter').Id); + notification.setTargetId(thread.Id); + HOT_NotificationHandler.sendNotification(notification, recipients, (SObject) thread); + } + }else{ + userIdToThreadMapSMS.put(user, userIdToThreadMap.get(user)); } } //SENDER SMS @@ -277,39 +285,34 @@ public without sharing class HOT_MessagesNotification { for (ServiceResource sr : freelanceServiceresource) { freelanceAccountIds.add(sr.AccountId); } - - List users = [ + Map userMap = new Map([ SELECT Id, AccountId, (SELECT Id, HOT_NotificationChannel__c FROM ServiceResources) FROM User - WHERE AccountId IN :freelanceAccountIds - ]; + WHERE Id IN :freelanceAccountIds + ]); - Map userIdToThreadMap = new Map(); + Map> userIdToThreadMap = new Map>(); for (Id participantId : interpretersOnThreadMap.keySet()) { - Thread__c threadId = interpretersOnThreadMap.get(participantId); - - for (User user : users) { - if (participantId == user.Id) { - userIdToThreadMap.put(User, threadId); + if(!userMap.containsKey(participantId)){ + continue; + } + for(Thread__c thread: interpretersOnThreadMap.get(participantId)){ + if(thread.LastModifiedById == participantId){ + continue; + } + if(userIdToThreadMap.containsKey(userMap.get(participantId))){ + userIdToThreadMap.get(userMap.get(participantId)).add(thread); + }else{ + userIdToThreadMap.put(userMap.get(participantId), new List{thread}); } } } //LAGER VARSLINGS LISTE TIL INSETTING SENERE List notificationList = new List(); - Map userIdToThreadMapSMS = new Map(); + Map> userIdToThreadMapSMS = new Map>(); for (User user : userIdToThreadMap.keySet()) { - Set recipients = new Set(); - String notificationChannel = user.ServiceResources[0].HOT_NotificationChannel__c; - Thread__c thread = userIdToThreadMap.get(user); - - if (user.Id != thread.LastModifiedById) { - recipients.add(user.Id); - } - - if (recipients.size() > 0) { - if (notificationChannel.contains('Push')) { - //PUSHVARSEL TIL MOBIL - //LAGER NOTIFIKASJON + if (user.ServiceResources[0].HOT_NotificationChannel__c.contains('Push')) { + for(Thread__c thread : userIdToThreadMap.get(user)){ HOT_Notification__c newNotification = newMessageNotificationPush( user.AccountId, thread, @@ -320,19 +323,21 @@ public without sharing class HOT_MessagesNotification { getCustomNotificationType('HOT_NotifyUser'), thread, true, - recipients + new Set{user.Id} ); - } else { - //LAGER NOTIFIKASJON - HOT_Notification__c newNotification = newMessageNotificationSMS( + } + } else { + for(Thread__c thread : userIdToThreadMap.get(user)){ + HOT_Notification__c newNotification = newMessageNotificationSMS( user.AccountId, thread, 'threadInterpreter' ); //SMS notificationList.add(newNotification); - userIdToThreadMapSMS.put(thread, user); } + //SMS + userIdToThreadMapSMS.put(user, userIdToThreadMap.get(user)); } } if (!userIdToThreadMapSMS.isEmpty()) { diff --git a/force-app/main/sms/classes/HOT_ReminderSMSService.cls b/force-app/main/sms/classes/HOT_ReminderSMSService.cls index 9a5d125f49..7f779ffb4b 100644 --- a/force-app/main/sms/classes/HOT_ReminderSMSService.cls +++ b/force-app/main/sms/classes/HOT_ReminderSMSService.cls @@ -282,22 +282,22 @@ public without sharing class HOT_ReminderSMSService { handleException(e); } } - - public static void sendSMSOnNewMessageInterpreter(Map userIdToThreadMap) { + + public static void sendSMSOnNewMessageInterpreter(Map> userIdToThreadMap) { List smsList = new List(); - for (Thread__c thread : userIdToThreadMap.keySet()) { - User user = userIdToThreadMap.get(thread); - - SMS__c sms = new SMS__c(); - sms.Domain__c = 'HOT'; - sms.Type__c = 'Message'; - sms.Account__c = user.AccountId; - sms.Thread__c = thread.Id; - sms.Recipient__c = getRecipientPhoneNumberInterpreter(user.Id); - sms.Message__c = constructOnNewMessage(); + for(User user : userIdToThreadMap.keySet()){ + for(Thread__c thread : userIdToThreadMap.get(user)){ + SMS__c sms = new SMS__c(); + sms.Domain__c = 'HOT'; + sms.Type__c = 'Message'; + sms.Account__c = user.AccountId; + sms.Thread__c = thread.Id; + sms.Recipient__c = getRecipientPhoneNumberInterpreter(user.Id); + sms.Message__c = constructOnNewMessage(); - if (sms.Recipient__c != null) { + if (sms.Recipient__c != null) { smsList.add(sms); + } } } @@ -307,6 +307,7 @@ public without sharing class HOT_ReminderSMSService { handleException(e); } } + public static void sendSMSOnNewWantedSR(Set wantedIRIds) { List smsList = new List(); List wantedIRList = [ diff --git a/force-app/main/sms/classes/HOT_ReminderSMSServiceTest.cls b/force-app/main/sms/classes/HOT_ReminderSMSServiceTest.cls index 87175b87dc..513bdbe897 100644 --- a/force-app/main/sms/classes/HOT_ReminderSMSServiceTest.cls +++ b/force-app/main/sms/classes/HOT_ReminderSMSServiceTest.cls @@ -177,8 +177,9 @@ private class HOT_ReminderSMSServiceTest { FROM ServiceResource WHERE RelatedRecordId = :currentUser.Id ]; - Map userIdToThreadMapSMS = new Map(); - userIdToThreadMapSMS.put(thread, currentUser); + Map> userIdToThreadMapSMS = new Map>{ + currentUser => new List{thread} + }; HOT_ReminderSMSService.sendSMSOnNewMessageInterpreter(userIdToThreadMapSMS); Test.stopTest(); List smsList = [SELECT Id, Message__c FROM SMS__c]; From e0011f926209dcf5dc5959a849ca7f9f1fbd7e8c Mon Sep 17 00:00:00 2001 From: Eugenijus Date: Fri, 25 Oct 2024 16:04:53 +0200 Subject: [PATCH 08/11] fix freelance user soql --- force-app/main/default/classes/HOT_MessagesNotification.cls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/force-app/main/default/classes/HOT_MessagesNotification.cls b/force-app/main/default/classes/HOT_MessagesNotification.cls index dcb2a6b631..24cc55c544 100644 --- a/force-app/main/default/classes/HOT_MessagesNotification.cls +++ b/force-app/main/default/classes/HOT_MessagesNotification.cls @@ -288,7 +288,7 @@ public without sharing class HOT_MessagesNotification { Map userMap = new Map([ SELECT Id, AccountId, (SELECT Id, HOT_NotificationChannel__c FROM ServiceResources) FROM User - WHERE Id IN :freelanceAccountIds + WHERE AccountId IN :freelanceAccountIds ]); Map> userIdToThreadMap = new Map>(); From b02b1c50588a908d8c22c82d258a494be3fd1e92 Mon Sep 17 00:00:00 2001 From: Eugenijus Date: Mon, 28 Oct 2024 07:30:30 +0100 Subject: [PATCH 09/11] prettier --- .../classes/HOT_MessagesNotification.cls | 66 ++++++++++--------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/force-app/main/default/classes/HOT_MessagesNotification.cls b/force-app/main/default/classes/HOT_MessagesNotification.cls index 24cc55c544..fe27a9ccab 100644 --- a/force-app/main/default/classes/HOT_MessagesNotification.cls +++ b/force-app/main/default/classes/HOT_MessagesNotification.cls @@ -208,10 +208,10 @@ public without sharing class HOT_MessagesNotification { if (participantId == '') { continue; } - if(interpretersOnThreadMap.containsKey(participantId)){ + if (interpretersOnThreadMap.containsKey(participantId)) { interpretersOnThreadMap.get(participantId).add(t); - }else{ - interpretersOnThreadMap.put(participantId, new List{t}); + } else { + interpretersOnThreadMap.put(participantId, new List{ t }); } } } @@ -233,31 +233,33 @@ public without sharing class HOT_MessagesNotification { employeeUserIds.add(sr.RelatedRecordId); } - Map userMap = new Map([ - SELECT Id, AccountId, (SELECT Id, HOT_NotificationChannel__c FROM ServiceResources) - FROM User - WHERE Id IN :employeeUserIds - ]); + Map userMap = new Map( + [ + SELECT Id, AccountId, (SELECT Id, HOT_NotificationChannel__c FROM ServiceResources) + FROM User + WHERE Id IN :employeeUserIds + ] + ); Map> userIdToThreadMap = new Map>(); for (Id participantId : interpretersOnThreadMap.keySet()) { - if(!userMap.containsKey(participantId)){ + if (!userMap.containsKey(participantId)) { continue; } - for(Thread__c thread: interpretersOnThreadMap.get(participantId)){ - if(thread.LastModifiedById == participantId){ + for (Thread__c thread : interpretersOnThreadMap.get(participantId)) { + if (thread.LastModifiedById == participantId) { continue; } - if(userIdToThreadMap.containsKey(userMap.get(participantId))){ + if (userIdToThreadMap.containsKey(userMap.get(participantId))) { userIdToThreadMap.get(userMap.get(participantId)).add(thread); - }else{ - userIdToThreadMap.put(userMap.get(participantId), new List{thread}); + } else { + userIdToThreadMap.put(userMap.get(participantId), new List{ thread }); } } } Map> userIdToThreadMapSMS = new Map>(); for (User user : userIdToThreadMap.keySet()) { - if(user.ServiceResources[0].HOT_NotificationChannel__c.contains('Push')){ + if (user.ServiceResources[0].HOT_NotificationChannel__c.contains('Push')) { for (Thread__c thread : userIdToThreadMap.get(user)) { Set recipients = new Set(); recipients.add(user.Id); @@ -268,7 +270,7 @@ public without sharing class HOT_MessagesNotification { notification.setTargetId(thread.Id); HOT_NotificationHandler.sendNotification(notification, recipients, (SObject) thread); } - }else{ + } else { userIdToThreadMapSMS.put(user, userIdToThreadMap.get(user)); } } @@ -285,25 +287,27 @@ public without sharing class HOT_MessagesNotification { for (ServiceResource sr : freelanceServiceresource) { freelanceAccountIds.add(sr.AccountId); } - Map userMap = new Map([ - SELECT Id, AccountId, (SELECT Id, HOT_NotificationChannel__c FROM ServiceResources) - FROM User - WHERE AccountId IN :freelanceAccountIds - ]); + Map userMap = new Map( + [ + SELECT Id, AccountId, (SELECT Id, HOT_NotificationChannel__c FROM ServiceResources) + FROM User + WHERE AccountId IN :freelanceAccountIds + ] + ); Map> userIdToThreadMap = new Map>(); for (Id participantId : interpretersOnThreadMap.keySet()) { - if(!userMap.containsKey(participantId)){ + if (!userMap.containsKey(participantId)) { continue; } - for(Thread__c thread: interpretersOnThreadMap.get(participantId)){ - if(thread.LastModifiedById == participantId){ + for (Thread__c thread : interpretersOnThreadMap.get(participantId)) { + if (thread.LastModifiedById == participantId) { continue; } - if(userIdToThreadMap.containsKey(userMap.get(participantId))){ + if (userIdToThreadMap.containsKey(userMap.get(participantId))) { userIdToThreadMap.get(userMap.get(participantId)).add(thread); - }else{ - userIdToThreadMap.put(userMap.get(participantId), new List{thread}); + } else { + userIdToThreadMap.put(userMap.get(participantId), new List{ thread }); } } } @@ -312,7 +316,7 @@ public without sharing class HOT_MessagesNotification { Map> userIdToThreadMapSMS = new Map>(); for (User user : userIdToThreadMap.keySet()) { if (user.ServiceResources[0].HOT_NotificationChannel__c.contains('Push')) { - for(Thread__c thread : userIdToThreadMap.get(user)){ + for (Thread__c thread : userIdToThreadMap.get(user)) { HOT_Notification__c newNotification = newMessageNotificationPush( user.AccountId, thread, @@ -323,12 +327,12 @@ public without sharing class HOT_MessagesNotification { getCustomNotificationType('HOT_NotifyUser'), thread, true, - new Set{user.Id} + new Set{ user.Id } ); } } else { - for(Thread__c thread : userIdToThreadMap.get(user)){ - HOT_Notification__c newNotification = newMessageNotificationSMS( + for (Thread__c thread : userIdToThreadMap.get(user)) { + HOT_Notification__c newNotification = newMessageNotificationSMS( user.AccountId, thread, 'threadInterpreter' From 9a75d283d6be8a2e7b9144666e3e5534daf65a01 Mon Sep 17 00:00:00 2001 From: Rasmus Steine Olsen <111959793+olsenrasmus@users.noreply.github.com> Date: Mon, 28 Oct 2024 07:57:13 +0100 Subject: [PATCH 10/11] Update HOT_MessagesNotification.cls --- .../classes/HOT_MessagesNotification.cls | 74 ++++++++++--------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/force-app/main/default/classes/HOT_MessagesNotification.cls b/force-app/main/default/classes/HOT_MessagesNotification.cls index 24cc55c544..027373ed8e 100644 --- a/force-app/main/default/classes/HOT_MessagesNotification.cls +++ b/force-app/main/default/classes/HOT_MessagesNotification.cls @@ -114,11 +114,11 @@ public without sharing class HOT_MessagesNotification { if (recipients.size() > 0) { //FØRST MÅ MAN FINNE UT AV OM DET ER EN TOLKE SAMTALE ELLER EN SAMTALE SOM BRUKER, OG BASERT PÅ DET BRUKE BRUKEREN ELLER TOLKEN SIN VARSLINGSMETODE if ( - (thread.CRM_Thread_Type__c == 'HOT_TOLK-FORMIDLER' || - thread.CRM_Thread_Type__c == 'HOT_TOLK-RESSURSKONTOR' && + (thread.CRM_Thread_Type__c == 'HOT_TOLK-RESSURSKONTOR' && userToServiceResource.get(userIdByAccountId.get(thread.CRM_Account__c)) - .HOT_NotificationChannel__c.contains('Push')) || - thread.CRM_Account__r.CRM_Person__r.HOT_NotificationChannel__c.contains('Push') + ?.HOT_NotificationChannel__c.contains('Push')) || + (thread.CRM_Thread_Type__c == 'HOT_TOLK-FORMIDLER' && + thread.CRM_Account__r.CRM_Person__r.HOT_NotificationChannel__c.contains('Push')) ) { if ( thread.CRM_Thread_Type__c == 'HOT_TOLK-RESSURSKONTOR' || @@ -208,10 +208,10 @@ public without sharing class HOT_MessagesNotification { if (participantId == '') { continue; } - if(interpretersOnThreadMap.containsKey(participantId)){ + if (interpretersOnThreadMap.containsKey(participantId)) { interpretersOnThreadMap.get(participantId).add(t); - }else{ - interpretersOnThreadMap.put(participantId, new List{t}); + } else { + interpretersOnThreadMap.put(participantId, new List{ t }); } } } @@ -233,31 +233,33 @@ public without sharing class HOT_MessagesNotification { employeeUserIds.add(sr.RelatedRecordId); } - Map userMap = new Map([ - SELECT Id, AccountId, (SELECT Id, HOT_NotificationChannel__c FROM ServiceResources) - FROM User - WHERE Id IN :employeeUserIds - ]); + Map userMap = new Map( + [ + SELECT Id, AccountId, (SELECT Id, HOT_NotificationChannel__c FROM ServiceResources) + FROM User + WHERE Id IN :employeeUserIds + ] + ); Map> userIdToThreadMap = new Map>(); for (Id participantId : interpretersOnThreadMap.keySet()) { - if(!userMap.containsKey(participantId)){ + if (!userMap.containsKey(participantId)) { continue; } - for(Thread__c thread: interpretersOnThreadMap.get(participantId)){ - if(thread.LastModifiedById == participantId){ + for (Thread__c thread : interpretersOnThreadMap.get(participantId)) { + if (thread.LastModifiedById == participantId) { continue; } - if(userIdToThreadMap.containsKey(userMap.get(participantId))){ + if (userIdToThreadMap.containsKey(userMap.get(participantId))) { userIdToThreadMap.get(userMap.get(participantId)).add(thread); - }else{ - userIdToThreadMap.put(userMap.get(participantId), new List{thread}); + } else { + userIdToThreadMap.put(userMap.get(participantId), new List{ thread }); } } } Map> userIdToThreadMapSMS = new Map>(); for (User user : userIdToThreadMap.keySet()) { - if(user.ServiceResources[0].HOT_NotificationChannel__c.contains('Push')){ + if (user.ServiceResources[0].HOT_NotificationChannel__c.contains('Push')) { for (Thread__c thread : userIdToThreadMap.get(user)) { Set recipients = new Set(); recipients.add(user.Id); @@ -268,7 +270,7 @@ public without sharing class HOT_MessagesNotification { notification.setTargetId(thread.Id); HOT_NotificationHandler.sendNotification(notification, recipients, (SObject) thread); } - }else{ + } else { userIdToThreadMapSMS.put(user, userIdToThreadMap.get(user)); } } @@ -285,25 +287,27 @@ public without sharing class HOT_MessagesNotification { for (ServiceResource sr : freelanceServiceresource) { freelanceAccountIds.add(sr.AccountId); } - Map userMap = new Map([ - SELECT Id, AccountId, (SELECT Id, HOT_NotificationChannel__c FROM ServiceResources) - FROM User - WHERE AccountId IN :freelanceAccountIds - ]); + Map userMap = new Map( + [ + SELECT Id, AccountId, (SELECT Id, HOT_NotificationChannel__c FROM ServiceResources) + FROM User + WHERE AccountId IN :freelanceAccountIds + ] + ); Map> userIdToThreadMap = new Map>(); for (Id participantId : interpretersOnThreadMap.keySet()) { - if(!userMap.containsKey(participantId)){ + if (!userMap.containsKey(participantId)) { continue; } - for(Thread__c thread: interpretersOnThreadMap.get(participantId)){ - if(thread.LastModifiedById == participantId){ + for (Thread__c thread : interpretersOnThreadMap.get(participantId)) { + if (thread.LastModifiedById == participantId) { continue; } - if(userIdToThreadMap.containsKey(userMap.get(participantId))){ + if (userIdToThreadMap.containsKey(userMap.get(participantId))) { userIdToThreadMap.get(userMap.get(participantId)).add(thread); - }else{ - userIdToThreadMap.put(userMap.get(participantId), new List{thread}); + } else { + userIdToThreadMap.put(userMap.get(participantId), new List{ thread }); } } } @@ -312,7 +316,7 @@ public without sharing class HOT_MessagesNotification { Map> userIdToThreadMapSMS = new Map>(); for (User user : userIdToThreadMap.keySet()) { if (user.ServiceResources[0].HOT_NotificationChannel__c.contains('Push')) { - for(Thread__c thread : userIdToThreadMap.get(user)){ + for (Thread__c thread : userIdToThreadMap.get(user)) { HOT_Notification__c newNotification = newMessageNotificationPush( user.AccountId, thread, @@ -323,12 +327,12 @@ public without sharing class HOT_MessagesNotification { getCustomNotificationType('HOT_NotifyUser'), thread, true, - new Set{user.Id} + new Set{ user.Id } ); } } else { - for(Thread__c thread : userIdToThreadMap.get(user)){ - HOT_Notification__c newNotification = newMessageNotificationSMS( + for (Thread__c thread : userIdToThreadMap.get(user)) { + HOT_Notification__c newNotification = newMessageNotificationSMS( user.AccountId, thread, 'threadInterpreter' From 42c8588306d96c514e1291cc1925beb3ced189af Mon Sep 17 00:00:00 2001 From: Eugenijus Date: Mon, 28 Oct 2024 08:07:30 +0100 Subject: [PATCH 11/11] prettier --- force-app/main/sms/classes/HOT_ReminderSMSService.cls | 8 ++++---- force-app/main/sms/classes/HOT_ReminderSMSServiceTest.cls | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/force-app/main/sms/classes/HOT_ReminderSMSService.cls b/force-app/main/sms/classes/HOT_ReminderSMSService.cls index 7f779ffb4b..0c69b74be3 100644 --- a/force-app/main/sms/classes/HOT_ReminderSMSService.cls +++ b/force-app/main/sms/classes/HOT_ReminderSMSService.cls @@ -282,11 +282,11 @@ public without sharing class HOT_ReminderSMSService { handleException(e); } } - + public static void sendSMSOnNewMessageInterpreter(Map> userIdToThreadMap) { List smsList = new List(); - for(User user : userIdToThreadMap.keySet()){ - for(Thread__c thread : userIdToThreadMap.get(user)){ + for (User user : userIdToThreadMap.keySet()) { + for (Thread__c thread : userIdToThreadMap.get(user)) { SMS__c sms = new SMS__c(); sms.Domain__c = 'HOT'; sms.Type__c = 'Message'; @@ -296,7 +296,7 @@ public without sharing class HOT_ReminderSMSService { sms.Message__c = constructOnNewMessage(); if (sms.Recipient__c != null) { - smsList.add(sms); + smsList.add(sms); } } } diff --git a/force-app/main/sms/classes/HOT_ReminderSMSServiceTest.cls b/force-app/main/sms/classes/HOT_ReminderSMSServiceTest.cls index 513bdbe897..a3d5a74018 100644 --- a/force-app/main/sms/classes/HOT_ReminderSMSServiceTest.cls +++ b/force-app/main/sms/classes/HOT_ReminderSMSServiceTest.cls @@ -178,7 +178,7 @@ private class HOT_ReminderSMSServiceTest { WHERE RelatedRecordId = :currentUser.Id ]; Map> userIdToThreadMapSMS = new Map>{ - currentUser => new List{thread} + currentUser => new List{ thread } }; HOT_ReminderSMSService.sendSMSOnNewMessageInterpreter(userIdToThreadMapSMS); Test.stopTest();