Add support for 3PID notification for Matrix ID room invites
- Experimental feature - Via AS API
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user