diff --git a/build.gradle b/build.gradle
index e70da8e..baa14f5 100644
--- a/build.gradle
+++ b/build.gradle
@@ -81,7 +81,7 @@ dependencies {
compile "org.springframework.boot:spring-boot-starter-thymeleaf:1.5.10.RELEASE"
// Matrix Java SDK
- compile 'io.kamax:matrix-java-sdk:0.0.11'
+ compile 'io.kamax:matrix-java-sdk:0.0.14-8-g0e57ec6'
// ed25519 handling
compile 'net.i2p.crypto:eddsa:0.1.0'
diff --git a/docs/features/experimental/application-service.md b/docs/features/experimental/application-service.md
new file mode 100644
index 0000000..114e197
--- /dev/null
+++ b/docs/features/experimental/application-service.md
@@ -0,0 +1,6 @@
+# Integration as an Application Service
+**WARNING: **These features are highly experimental. They can be removed or modified without notice.
+Support is only available via a paid subscription or consultancy.
+
+## 3PID notification for Matrix ID Room invites
+*TBC*
diff --git a/src/main/java/io/kamax/mxisd/as/AppServiceHandler.java b/src/main/java/io/kamax/mxisd/as/AppServiceHandler.java
new file mode 100644
index 0000000..258bb48
--- /dev/null
+++ b/src/main/java/io/kamax/mxisd/as/AppServiceHandler.java
@@ -0,0 +1,89 @@
+/*
+ * mxisd - Matrix Identity Server Daemon
+ * Copyright (C) 2018 Kamax Sarl
+ *
+ * https://www.kamax.io/
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package io.kamax.mxisd.as;
+
+import com.google.gson.JsonObject;
+import io.kamax.matrix.MatrixID;
+import io.kamax.matrix._MatrixID;
+import io.kamax.matrix.event.EventKey;
+import io.kamax.matrix.json.GsonUtil;
+import io.kamax.mxisd.config.MatrixConfig;
+import io.kamax.mxisd.notification.NotificationManager;
+import io.kamax.mxisd.profile.ProfileManager;
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.HashMap;
+import java.util.List;
+
+@Component
+public class AppServiceHandler {
+
+ private final Logger log = LoggerFactory.getLogger(AppServiceHandler.class);
+
+ private MatrixConfig cfg;
+ private ProfileManager profiler;
+ private NotificationManager notif;
+
+ @Autowired
+ public AppServiceHandler(MatrixConfig cfg, ProfileManager profiler, NotificationManager notif) {
+ this.cfg = cfg;
+ this.profiler = profiler;
+ this.notif = notif;
+ }
+
+ public void processTransaction(List eventsJson) {
+ eventsJson.forEach(ev -> {
+ if (!StringUtils.equals("m.room.member", GsonUtil.getStringOrNull(ev, "type"))) {
+ return;
+ }
+
+ if (!StringUtils.equals("invite", GsonUtil.getStringOrNull(ev, "membership"))) {
+ return;
+ }
+
+ String roomId = GsonUtil.getStringOrNull(ev, "room_id");
+ _MatrixID sender = MatrixID.asAcceptable(GsonUtil.getStringOrNull(ev, "sender"));
+ EventKey.StateKey.findString(ev).ifPresent(id -> {
+ log.info("Got invite for {}", id);
+ _MatrixID mxid = MatrixID.asAcceptable(id);
+ if (!StringUtils.equals(mxid.getDomain(), cfg.getDomain())) {
+ log.info("Ignoring invite for {}: not a local user");
+ return;
+ }
+
+ profiler.getThreepids(mxid).forEach(tpid -> {
+ if (!StringUtils.equals("email", tpid.getMedium())) {
+ return;
+ }
+
+ log.info("Found an email address to notify about room invitation: {}", tpid.getAddress());
+ IMatrixIdInvite inv = new MatrixIdInvite(roomId, sender, mxid, tpid.getMedium(), tpid.getAddress(), new HashMap<>());
+ notif.sendForInvite(inv);
+ });
+ });
+ });
+ }
+
+}
diff --git a/src/main/java/io/kamax/mxisd/as/IMatrixIdInvite.java b/src/main/java/io/kamax/mxisd/as/IMatrixIdInvite.java
new file mode 100644
index 0000000..626025d
--- /dev/null
+++ b/src/main/java/io/kamax/mxisd/as/IMatrixIdInvite.java
@@ -0,0 +1,30 @@
+/*
+ * mxisd - Matrix Identity Server Daemon
+ * Copyright (C) 2018 Kamax Sarl
+ *
+ * https://www.kamax.io/
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package io.kamax.mxisd.as;
+
+import io.kamax.matrix._MatrixID;
+import io.kamax.mxisd.invitation.IThreePidInvite;
+
+public interface IMatrixIdInvite extends IThreePidInvite {
+
+ _MatrixID getInvitee();
+
+}
diff --git a/src/main/java/io/kamax/mxisd/as/MatrixIdInvite.java b/src/main/java/io/kamax/mxisd/as/MatrixIdInvite.java
new file mode 100644
index 0000000..1c9d630
--- /dev/null
+++ b/src/main/java/io/kamax/mxisd/as/MatrixIdInvite.java
@@ -0,0 +1,77 @@
+/*
+ * mxisd - Matrix Identity Server Daemon
+ * Copyright (C) 2018 Kamax Sarl
+ *
+ * https://www.kamax.io/
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package io.kamax.mxisd.as;
+
+import io.kamax.matrix._MatrixID;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+public class MatrixIdInvite implements IMatrixIdInvite {
+
+ private String roomId;
+ private _MatrixID sender;
+ private _MatrixID invitee;
+ private String medium;
+ private String address;
+ private Map properties;
+
+ public MatrixIdInvite(String roomId, _MatrixID sender, _MatrixID invitee, String medium, String address, Map properties) {
+ this.roomId = Objects.requireNonNull(roomId);
+ this.sender = Objects.requireNonNull(sender);
+ this.invitee = Objects.requireNonNull(invitee);
+ this.medium = Objects.requireNonNull(medium);
+ this.address = Objects.requireNonNull(address);
+ this.properties = new HashMap<>(Objects.requireNonNull(properties));
+ }
+
+ @Override
+ public _MatrixID getSender() {
+ return sender;
+ }
+
+ @Override
+ public String getMedium() {
+ return medium;
+ }
+
+ @Override
+ public String getAddress() {
+ return address;
+ }
+
+ @Override
+ public _MatrixID getInvitee() {
+ return invitee;
+ }
+
+ @Override
+ public String getRoomId() {
+ return roomId;
+ }
+
+ @Override
+ public Map getProperties() {
+ return properties;
+ }
+
+}
diff --git a/src/main/java/io/kamax/mxisd/config/ListenerConfig.java b/src/main/java/io/kamax/mxisd/config/ListenerConfig.java
new file mode 100644
index 0000000..c3c8b2d
--- /dev/null
+++ b/src/main/java/io/kamax/mxisd/config/ListenerConfig.java
@@ -0,0 +1,108 @@
+/*
+ * mxisd - Matrix Identity Server Daemon
+ * Copyright (C) 2018 Kamax Sarl
+ *
+ * https://www.kamax.io/
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package io.kamax.mxisd.config;
+
+import org.apache.commons.lang.StringUtils;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+import javax.annotation.PostConstruct;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+@Configuration
+@ConfigurationProperties("matrix.listener")
+public class ListenerConfig {
+
+ public static class Token {
+
+ private String as;
+ private String hs;
+
+ public String getAs() {
+ return as;
+ }
+
+ public void setAs(String as) {
+ this.as = as;
+ }
+
+ public String getHs() {
+ return hs;
+ }
+
+ public void setHs(String hs) {
+ this.hs = hs;
+ }
+
+ }
+
+ private transient URL csUrl;
+ private String url;
+ private String localpart;
+ private Token token = new Token();
+
+ public URL getUrl() {
+ return csUrl;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public String getLocalpart() {
+ return localpart;
+ }
+
+ public void setLocalpart(String localpart) {
+ this.localpart = localpart;
+ }
+
+ public Token getToken() {
+ return token;
+ }
+
+ public void setToken(Token token) {
+ this.token = token;
+ }
+
+ @PostConstruct
+ public void build() throws MalformedURLException {
+ if (StringUtils.isBlank(url)) {
+ return;
+ }
+
+ csUrl = new URL(url);
+
+ if (StringUtils.isBlank(getLocalpart())) {
+ throw new IllegalArgumentException("localpart for matrix listener is not set");
+ }
+
+ if (StringUtils.isBlank(getToken().getAs())) {
+ throw new IllegalArgumentException("AS token is not set");
+ }
+
+ if (StringUtils.isBlank(getToken().getHs())) {
+ throw new IllegalArgumentException("HS token is not set");
+ }
+ }
+
+}
diff --git a/src/main/java/io/kamax/mxisd/config/threepid/connector/EmailSendGridConfig.java b/src/main/java/io/kamax/mxisd/config/threepid/connector/EmailSendGridConfig.java
index 6c6c0da..a15c659 100644
--- a/src/main/java/io/kamax/mxisd/config/threepid/connector/EmailSendGridConfig.java
+++ b/src/main/java/io/kamax/mxisd/config/threepid/connector/EmailSendGridConfig.java
@@ -1,8 +1,8 @@
/*
* mxisd - Matrix Identity Server Daemon
- * Copyright (C) 2017 Maxime Dor
+ * Copyright (C) 2017 Kamax Sarl
*
- * https://max.kamax.io/
+ * https://www.kamax.io/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -28,6 +28,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
+import java.util.HashMap;
+import java.util.Map;
@Configuration
@ConfigurationProperties("notification.handlers.sendgrid")
@@ -142,6 +144,15 @@ public class EmailSendGridConfig {
private EmailTemplate invite = new EmailTemplate();
private TemplateSession session = new TemplateSession();
+ private Map generic = new HashMap<>();
+
+ public Map getGeneric() {
+ return generic;
+ }
+
+ public void setGeneric(Map generic) {
+ this.generic = generic;
+ }
public EmailTemplate getInvite() {
return invite;
diff --git a/src/main/java/io/kamax/mxisd/config/threepid/medium/GenericTemplateConfig.java b/src/main/java/io/kamax/mxisd/config/threepid/medium/GenericTemplateConfig.java
index cc848c7..ef15e03 100644
--- a/src/main/java/io/kamax/mxisd/config/threepid/medium/GenericTemplateConfig.java
+++ b/src/main/java/io/kamax/mxisd/config/threepid/medium/GenericTemplateConfig.java
@@ -1,8 +1,8 @@
/*
* mxisd - Matrix Identity Server Daemon
- * Copyright (C) 2017 Maxime Dor
+ * Copyright (C) 2017 Kamax Sarl
*
- * https://max.kamax.io/
+ * https://www.kamax.io/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -22,6 +22,9 @@ package io.kamax.mxisd.config.threepid.medium;
import org.apache.commons.lang.StringUtils;
+import java.util.HashMap;
+import java.util.Map;
+
public class GenericTemplateConfig {
private static final String classpathPrefix = "classpath:";
@@ -73,6 +76,7 @@ public class GenericTemplateConfig {
private String invite;
private Session session = new Session();
+ private Map generic = new HashMap<>();
public String getInvite() {
return invite;
@@ -86,4 +90,12 @@ public class GenericTemplateConfig {
return session;
}
+ public Map getGeneric() {
+ return generic;
+ }
+
+ public void setGeneric(Map generic) {
+ this.generic = generic;
+ }
+
}
diff --git a/src/main/java/io/kamax/mxisd/controller/app/v1/AppServiceController.java b/src/main/java/io/kamax/mxisd/controller/app/v1/AppServiceController.java
new file mode 100644
index 0000000..0bbdaee
--- /dev/null
+++ b/src/main/java/io/kamax/mxisd/controller/app/v1/AppServiceController.java
@@ -0,0 +1,109 @@
+/*
+ * mxisd - Matrix Identity Server Daemon
+ * Copyright (C) 2018 Kamax Sarl
+ *
+ * https://www.kamax.io/
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package io.kamax.mxisd.controller.app.v1;
+
+import com.google.gson.JsonObject;
+import io.kamax.matrix.json.GsonUtil;
+import io.kamax.mxisd.as.AppServiceHandler;
+import io.kamax.mxisd.config.ListenerConfig;
+import io.kamax.mxisd.exception.HttpMatrixException;
+import io.kamax.mxisd.exception.NotAllowedException;
+import io.kamax.mxisd.util.GsonParser;
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.MediaType;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.List;
+
+import static org.springframework.web.bind.annotation.RequestMethod.GET;
+import static org.springframework.web.bind.annotation.RequestMethod.PUT;
+
+@RestController
+@CrossOrigin
+@RequestMapping(path = "/_matrix/app/v1", produces = MediaType.APPLICATION_JSON_VALUE)
+public class AppServiceController {
+
+ private final Logger log = LoggerFactory.getLogger(AppServiceController.class);
+ private final ListenerConfig cfg;
+
+ private final String notFoundBody;
+ private final GsonParser parser;
+ private final AppServiceHandler handler;
+
+ @Autowired
+ public AppServiceController(ListenerConfig cfg, AppServiceHandler handler) {
+ this.notFoundBody = GsonUtil.get().toJson(GsonUtil.makeObj("errcode", "io.kamax.mxisd.AS_NOT_FOUND"));
+ this.parser = new GsonParser();
+
+ this.cfg = cfg;
+ this.handler = handler;
+ }
+
+ private void validateToken(String token) {
+ if (StringUtils.isBlank(token)) {
+ throw new HttpMatrixException(401, "M_UNAUTHORIZED", "No HS token");
+ }
+
+ if (!StringUtils.equals(cfg.getToken().getHs(), token)) {
+ throw new NotAllowedException("Invalid HS token");
+ }
+ }
+
+ @RequestMapping(value = "/rooms/**", method = GET)
+ public String getRoom(HttpServletResponse res, @RequestParam(name = "access_token", required = false) String token) {
+ validateToken(token);
+
+ res.setStatus(404);
+ return notFoundBody;
+ }
+
+ @RequestMapping(value = "/users/**", method = GET)
+ public String getUser(HttpServletResponse res, @RequestParam(name = "access_token", required = false) String token) {
+ validateToken(token);
+
+ res.setStatus(404);
+ return notFoundBody;
+ }
+
+ @RequestMapping(value = "/transactions/{txnId:.+}", method = PUT)
+ public Object getTransaction(
+ HttpServletRequest request,
+ @RequestParam(name = "access_token", required = false) String token,
+ @PathVariable String txnId) {
+ try {
+ validateToken(token);
+
+ log.info("Processing transaction {}", txnId);
+ List events = GsonUtil.asList(GsonUtil.getArray(parser.parse(request.getInputStream()), "events"), JsonObject.class);
+ handler.processTransaction(events);
+ return "{}";
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
diff --git a/src/main/java/io/kamax/mxisd/invitation/InvitationManager.java b/src/main/java/io/kamax/mxisd/invitation/InvitationManager.java
index b8ac621..c185452 100644
--- a/src/main/java/io/kamax/mxisd/invitation/InvitationManager.java
+++ b/src/main/java/io/kamax/mxisd/invitation/InvitationManager.java
@@ -1,8 +1,8 @@
/*
* mxisd - Matrix Identity Server Daemon
- * Copyright (C) 2017 Maxime Dor
+ * Copyright (C) 2017 Kamax Sarl
*
- * https://max.kamax.io/
+ * https://www.kamax.io/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -228,7 +228,7 @@ public class InvitationManager {
log.info("Invite is already pending for {}:{}, returning data", invitation.getMedium(), invitation.getAddress());
if (!StringUtils.equals(invitation.getRoomId(), reply.getInvite().getRoomId())) {
log.info("Sending new notification as new invite room {} is different from the original {}", invitation.getRoomId(), reply.getInvite().getRoomId());
- notifMgr.sendForInvite(new ThreePidInviteReply(reply.getId(), invitation, reply.getToken(), reply.getDisplayName()));
+ notifMgr.sendForReply(new ThreePidInviteReply(reply.getId(), invitation, reply.getToken(), reply.getDisplayName()));
} else {
// FIXME we should check attempt and send if bigger
}
@@ -247,7 +247,7 @@ public class InvitationManager {
reply = new ThreePidInviteReply(invId, invitation, token, displayName);
log.info("Performing invite to {}:{}", invitation.getMedium(), invitation.getAddress());
- notifMgr.sendForInvite(reply);
+ notifMgr.sendForReply(reply);
log.info("Storing invite under ID {}", invId);
storage.insertInvite(reply);
diff --git a/src/main/java/io/kamax/mxisd/notification/INotificationHandler.java b/src/main/java/io/kamax/mxisd/notification/INotificationHandler.java
index 2bfc1e2..ab34c56 100644
--- a/src/main/java/io/kamax/mxisd/notification/INotificationHandler.java
+++ b/src/main/java/io/kamax/mxisd/notification/INotificationHandler.java
@@ -1,8 +1,8 @@
/*
* mxisd - Matrix Identity Server Daemon
- * Copyright (C) 2017 Maxime Dor
+ * Copyright (C) 2017 Kamax Sarl
*
- * https://max.kamax.io/
+ * https://www.kamax.io/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -20,6 +20,7 @@
package io.kamax.mxisd.notification;
+import io.kamax.mxisd.as.IMatrixIdInvite;
import io.kamax.mxisd.invitation.IThreePidInviteReply;
import io.kamax.mxisd.threepid.session.IThreePidSession;
@@ -29,7 +30,9 @@ public interface INotificationHandler {
String getMedium();
- void sendForInvite(IThreePidInviteReply invite);
+ void sendForInvite(IMatrixIdInvite invite);
+
+ void sendForReply(IThreePidInviteReply invite);
void sendForValidation(IThreePidSession session);
diff --git a/src/main/java/io/kamax/mxisd/notification/NotificationManager.java b/src/main/java/io/kamax/mxisd/notification/NotificationManager.java
index 15c9bc2..075c97e 100644
--- a/src/main/java/io/kamax/mxisd/notification/NotificationManager.java
+++ b/src/main/java/io/kamax/mxisd/notification/NotificationManager.java
@@ -1,8 +1,8 @@
/*
* mxisd - Matrix Identity Server Daemon
- * Copyright (C) 2017 Maxime Dor
+ * Copyright (C) 2017 Kamax Sarl
*
- * https://max.kamax.io/
+ * https://www.kamax.io/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -20,6 +20,7 @@
package io.kamax.mxisd.notification;
+import io.kamax.mxisd.as.IMatrixIdInvite;
import io.kamax.mxisd.config.threepid.notification.NotificationConfig;
import io.kamax.mxisd.exception.NotImplementedException;
import io.kamax.mxisd.invitation.IThreePidInviteReply;
@@ -68,8 +69,12 @@ public class NotificationManager {
return handlers.containsKey(medium);
}
- public void sendForInvite(IThreePidInviteReply invite) {
- ensureMedium(invite.getInvite().getMedium()).sendForInvite(invite);
+ public void sendForInvite(IMatrixIdInvite invite) {
+ ensureMedium(invite.getMedium()).sendForInvite(invite);
+ }
+
+ public void sendForReply(IThreePidInviteReply invite) {
+ ensureMedium(invite.getInvite().getMedium()).sendForReply(invite);
}
public void sendForValidation(IThreePidSession session) {
diff --git a/src/main/java/io/kamax/mxisd/threepid/connector/email/EmailSendGridNotificationHandler.java b/src/main/java/io/kamax/mxisd/threepid/connector/email/EmailSendGridNotificationHandler.java
index 1318a1d..a7302be 100644
--- a/src/main/java/io/kamax/mxisd/threepid/connector/email/EmailSendGridNotificationHandler.java
+++ b/src/main/java/io/kamax/mxisd/threepid/connector/email/EmailSendGridNotificationHandler.java
@@ -1,8 +1,8 @@
/*
* mxisd - Matrix Identity Server Daemon
- * Copyright (C) 2017 Maxime Dor
+ * Copyright (C) 2017 Kamax Sarl
*
- * https://max.kamax.io/
+ * https://www.kamax.io/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -23,6 +23,7 @@ package io.kamax.mxisd.threepid.connector.email;
import com.sendgrid.SendGrid;
import com.sendgrid.SendGridException;
import io.kamax.matrix.ThreePidMedium;
+import io.kamax.mxisd.as.IMatrixIdInvite;
import io.kamax.mxisd.config.MatrixConfig;
import io.kamax.mxisd.config.ServerConfig;
import io.kamax.mxisd.config.threepid.connector.EmailSendGridConfig;
@@ -87,13 +88,25 @@ public class EmailSendGridNotificationHandler extends PlaceholderNotificationGen
}
@Override
- public void sendForInvite(IThreePidInviteReply invite) {
- EmailTemplate template = cfg.getTemplates().getInvite();
+ public void sendForInvite(IMatrixIdInvite invite) {
+ EmailTemplate template = cfg.getTemplates().getGeneric().get("matrixId");
+
Email email = getEmail();
email.setSubject(populateForInvite(invite, template.getSubject()));
email.setText(populateForInvite(invite, getFromFile(template.getBody().getText())));
email.setHtml(populateForInvite(invite, getFromFile(template.getBody().getHtml())));
+ send(invite.getAddress(), email);
+ }
+
+ @Override
+ public void sendForReply(IThreePidInviteReply invite) {
+ EmailTemplate template = cfg.getTemplates().getInvite();
+ Email email = getEmail();
+ email.setSubject(populateForReply(invite, template.getSubject()));
+ email.setText(populateForReply(invite, getFromFile(template.getBody().getText())));
+ email.setHtml(populateForReply(invite, getFromFile(template.getBody().getHtml())));
+
send(invite.getInvite().getAddress(), email);
}
diff --git a/src/main/java/io/kamax/mxisd/threepid/notification/GenericNotificationHandler.java b/src/main/java/io/kamax/mxisd/threepid/notification/GenericNotificationHandler.java
index 49a4c06..53dc919 100644
--- a/src/main/java/io/kamax/mxisd/threepid/notification/GenericNotificationHandler.java
+++ b/src/main/java/io/kamax/mxisd/threepid/notification/GenericNotificationHandler.java
@@ -1,8 +1,8 @@
/*
* mxisd - Matrix Identity Server Daemon
- * Copyright (C) 2017 Maxime Dor
+ * Copyright (C) 2017 Kamax Sarl
*
- * https://max.kamax.io/
+ * https://www.kamax.io/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -20,6 +20,7 @@
package io.kamax.mxisd.threepid.notification;
+import io.kamax.mxisd.as.IMatrixIdInvite;
import io.kamax.mxisd.exception.ConfigurationException;
import io.kamax.mxisd.invitation.IThreePidInviteReply;
import io.kamax.mxisd.notification.INotificationHandler;
@@ -55,8 +56,13 @@ public abstract class GenericNotificationHandler