Add support for 3PID notification for Matrix ID room invites
- Experimental feature - Via AS API
This commit is contained in:
@@ -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'
|
||||
|
6
docs/features/experimental/application-service.md
Normal file
6
docs/features/experimental/application-service.md
Normal file
@@ -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*
|
89
src/main/java/io/kamax/mxisd/as/AppServiceHandler.java
Normal file
89
src/main/java/io/kamax/mxisd/as/AppServiceHandler.java
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<JsonObject> 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);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
30
src/main/java/io/kamax/mxisd/as/IMatrixIdInvite.java
Normal file
30
src/main/java/io/kamax/mxisd/as/IMatrixIdInvite.java
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.as;
|
||||
|
||||
import io.kamax.matrix._MatrixID;
|
||||
import io.kamax.mxisd.invitation.IThreePidInvite;
|
||||
|
||||
public interface IMatrixIdInvite extends IThreePidInvite {
|
||||
|
||||
_MatrixID getInvitee();
|
||||
|
||||
}
|
77
src/main/java/io/kamax/mxisd/as/MatrixIdInvite.java
Normal file
77
src/main/java/io/kamax/mxisd/as/MatrixIdInvite.java
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<String, String> properties;
|
||||
|
||||
public MatrixIdInvite(String roomId, _MatrixID sender, _MatrixID invitee, String medium, String address, Map<String, String> 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<String, String> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
}
|
108
src/main/java/io/kamax/mxisd/config/ListenerConfig.java
Normal file
108
src/main/java/io/kamax/mxisd/config/ListenerConfig.java
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -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<String, EmailTemplate> generic = new HashMap<>();
|
||||
|
||||
public Map<String, EmailTemplate> getGeneric() {
|
||||
return generic;
|
||||
}
|
||||
|
||||
public void setGeneric(Map<String, EmailTemplate> generic) {
|
||||
this.generic = generic;
|
||||
}
|
||||
|
||||
public EmailTemplate getInvite() {
|
||||
return invite;
|
||||
|
@@ -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<String, String> generic = new HashMap<>();
|
||||
|
||||
public String getInvite() {
|
||||
return invite;
|
||||
@@ -86,4 +90,12 @@ public class GenericTemplateConfig {
|
||||
return session;
|
||||
}
|
||||
|
||||
public Map<String, String> getGeneric() {
|
||||
return generic;
|
||||
}
|
||||
|
||||
public void setGeneric(Map<String, String> generic) {
|
||||
this.generic = generic;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<JsonObject> events = GsonUtil.asList(GsonUtil.getArray(parser.parse(request.getInputStream()), "events"), JsonObject.class);
|
||||
handler.processTransaction(events);
|
||||
return "{}";
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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) {
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -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<A extends IThreePidConnector, B
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendForInvite(IThreePidInviteReply invite) {
|
||||
send(connector, invite.getInvite().getAddress(), generator.getForInvite(invite));
|
||||
public void sendForInvite(IMatrixIdInvite invite) {
|
||||
send(connector, invite.getAddress(), generator.getForInvite(invite));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendForReply(IThreePidInviteReply invite) {
|
||||
send(connector, invite.getInvite().getAddress(), generator.getForReply(invite));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -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.config.MatrixConfig;
|
||||
import io.kamax.mxisd.config.ServerConfig;
|
||||
import io.kamax.mxisd.config.threepid.medium.GenericTemplateConfig;
|
||||
@@ -65,9 +66,15 @@ public abstract class GenericTemplateNotificationGenerator extends PlaceholderNo
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getForInvite(IThreePidInviteReply invite) {
|
||||
public String getForInvite(IMatrixIdInvite invite) {
|
||||
log.info("Generating notification content for Matrix ID invite");
|
||||
return populateForInvite(invite, getTemplateContent(cfg.getGeneric().get("matrixId")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getForReply(IThreePidInviteReply invite) {
|
||||
log.info("Generating notification content for 3PID invite");
|
||||
return populateForInvite(invite, getTemplateContent(cfg.getInvite()));
|
||||
return populateForReply(invite, getTemplateContent(cfg.getInvite()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -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.invitation.IThreePidInviteReply;
|
||||
import io.kamax.mxisd.threepid.session.IThreePidSession;
|
||||
|
||||
@@ -29,7 +30,9 @@ public interface INotificationGenerator {
|
||||
|
||||
String getMedium();
|
||||
|
||||
String getForInvite(IThreePidInviteReply invite);
|
||||
String getForInvite(IMatrixIdInvite invite);
|
||||
|
||||
String getForReply(IThreePidInviteReply invite);
|
||||
|
||||
String getForValidation(IThreePidSession session);
|
||||
|
||||
|
@@ -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
|
||||
@@ -21,6 +21,7 @@
|
||||
package io.kamax.mxisd.threepid.notification;
|
||||
|
||||
import io.kamax.matrix.ThreePid;
|
||||
import io.kamax.mxisd.as.IMatrixIdInvite;
|
||||
import io.kamax.mxisd.config.MatrixConfig;
|
||||
import io.kamax.mxisd.config.ServerConfig;
|
||||
import io.kamax.mxisd.controller.identity.v1.IdentityAPIv1;
|
||||
@@ -39,7 +40,7 @@ public abstract class PlaceholderNotificationGenerator {
|
||||
this.srvCfg = srvCfg;
|
||||
}
|
||||
|
||||
protected String populateForCommon(String input, ThreePid recipient) {
|
||||
protected String populateForCommon(ThreePid recipient, String input) {
|
||||
String domainPretty = WordUtils.capitalizeFully(mxCfg.getDomain());
|
||||
|
||||
return input
|
||||
@@ -49,7 +50,14 @@ public abstract class PlaceholderNotificationGenerator {
|
||||
.replace("%RECIPIENT_ADDRESS%", recipient.getAddress());
|
||||
}
|
||||
|
||||
protected String populateForInvite(IThreePidInviteReply invite, String input) {
|
||||
protected String populateForInvite(IMatrixIdInvite invite, String input) {
|
||||
return populateForCommon(new ThreePid(invite.getMedium(), invite.getAddress()), input)
|
||||
.replace("%SENDER_ID%", invite.getSender().getId())
|
||||
.replace("%RECIPIENT_ID%", invite.getInvitee().getId())
|
||||
.replace("%ROOM_ID%", invite.getRoomId());
|
||||
}
|
||||
|
||||
protected String populateForReply(IThreePidInviteReply invite, String input) {
|
||||
ThreePid tpid = new ThreePid(invite.getInvite().getMedium(), invite.getInvite().getAddress());
|
||||
|
||||
String senderName = invite.getInvite().getProperties().getOrDefault("sender_display_name", "");
|
||||
@@ -57,7 +65,7 @@ public abstract class PlaceholderNotificationGenerator {
|
||||
String roomName = invite.getInvite().getProperties().getOrDefault("room_name", "");
|
||||
String roomNameOrId = StringUtils.defaultIfBlank(roomName, invite.getInvite().getRoomId());
|
||||
|
||||
return populateForCommon(input, tpid)
|
||||
return populateForCommon(tpid, input)
|
||||
.replace("%SENDER_ID%", invite.getInvite().getSender().getId())
|
||||
.replace("%SENDER_NAME%", senderName)
|
||||
.replace("%SENDER_NAME_OR_ID%", senderNameOrId)
|
||||
@@ -76,7 +84,7 @@ public abstract class PlaceholderNotificationGenerator {
|
||||
session.getToken()
|
||||
);
|
||||
|
||||
return populateForCommon(input, session.getThreePid())
|
||||
return populateForCommon(session.getThreePid(), input)
|
||||
.replace("%VALIDATION_LINK%", validationLink)
|
||||
.replace("%VALIDATION_TOKEN%", session.getToken())
|
||||
.replace("%NEXT_URL%", validationLink);
|
||||
|
@@ -46,8 +46,8 @@ public class EmailNotificationGenerator extends GenericTemplateNotificationGener
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String populateForCommon(String body, ThreePid recipient) {
|
||||
body = super.populateForCommon(body, recipient);
|
||||
protected String populateForCommon(ThreePid recipient, String body) {
|
||||
body = super.populateForCommon(recipient, body);
|
||||
body = body.replace("%FROM_EMAIL%", cfg.getIdentity().getFrom());
|
||||
body = body.replace("%FROM_NAME%", cfg.getIdentity().getName());
|
||||
return body;
|
||||
|
@@ -26,6 +26,12 @@ matrix:
|
||||
servers:
|
||||
matrix-org:
|
||||
- 'https://matrix.org'
|
||||
listener:
|
||||
url: ''
|
||||
localpart: ''
|
||||
token:
|
||||
as: ''
|
||||
hs: ''
|
||||
|
||||
lookup:
|
||||
recursive:
|
||||
|
Reference in New Issue
Block a user