From be915aed947a6d38e5f26f0a7834d12e3a0799f2 Mon Sep 17 00:00:00 2001 From: Edgars Voroboks Date: Thu, 9 Jan 2020 20:14:56 +0200 Subject: [PATCH] Remove duplicates from identity store before email notifications I use LDAP for user store. I have set up "mail" and "otherMailbox" as threepid email attributes. When people get invited to rooms, they receive 2 (sometimes 3) invitation e-mails if they have the same e-mail address in LDAP "mail" and "otherMailbox" fields. I think it's a good idea to check identity store for duplicates before sending invitation e-mails. --- .../as/processor/event/MembershipEventProcessor.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/kamax/mxisd/as/processor/event/MembershipEventProcessor.java b/src/main/java/io/kamax/mxisd/as/processor/event/MembershipEventProcessor.java index 5963dce..b57f79b 100644 --- a/src/main/java/io/kamax/mxisd/as/processor/event/MembershipEventProcessor.java +++ b/src/main/java/io/kamax/mxisd/as/processor/event/MembershipEventProcessor.java @@ -144,7 +144,13 @@ public class MembershipEventProcessor implements EventTypeProcessor { .collect(Collectors.toList()); log.info("Found {} email(s) in identity store for {}", tpids.size(), inviteeId); - for (_ThreePid tpid : tpids) { + log.info("Removing duplicates from identity store"); + List<_ThreePid> uniqueTpids = tpids.stream() + .distinct() + .collect(Collectors.toList()); + log.info("There are {} unique email(s) in identity store for {}", uniqueTpids.size(), inviteeId); + + for (_ThreePid tpid : uniqueTpids) { log.info("Found Email to notify about room invitation: {}", tpid.getAddress()); Map properties = new HashMap<>(); profiler.getDisplayName(sender).ifPresent(name -> properties.put("sender_display_name", name));