Add various Notification template generator improvements
- Add ability to set arbitrary value for some placeholders (Fix #133) - More Unit tests - Improve doc
This commit is contained in:
@@ -77,6 +77,7 @@ public class GenericTemplateConfig {
|
||||
private String invite;
|
||||
private Session session = new Session();
|
||||
private Map<String, String> generic = new HashMap<>();
|
||||
private Map<String, String> placeholder = new HashMap<>();
|
||||
|
||||
public String getInvite() {
|
||||
return invite;
|
||||
@@ -98,4 +99,12 @@ public class GenericTemplateConfig {
|
||||
this.generic = generic;
|
||||
}
|
||||
|
||||
public Map<String, String> getPlaceholder() {
|
||||
return placeholder;
|
||||
}
|
||||
|
||||
public void setPlaceholder(Map<String, String> placeholder) {
|
||||
this.placeholder = placeholder;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -68,6 +68,7 @@ public abstract class GenericTemplateNotificationGenerator extends PlaceholderNo
|
||||
@Override
|
||||
public String getForReply(IThreePidInviteReply invite) {
|
||||
log.info("Generating notification content for 3PID invite");
|
||||
invite.getInvite().getProperties().putAll(cfg.getPlaceholder());
|
||||
return populateForReply(invite, getTemplateContent(cfg.getInvite()));
|
||||
}
|
||||
|
||||
|
@@ -35,6 +35,8 @@ import static io.kamax.mxisd.http.io.identity.StoreInviteRequest.Keys.SenderDisp
|
||||
|
||||
public abstract class PlaceholderNotificationGenerator {
|
||||
|
||||
public static final String RegisterUrl = "REGISTER_URL";
|
||||
|
||||
private MatrixConfig mxCfg;
|
||||
private ServerConfig srvCfg;
|
||||
|
||||
@@ -76,8 +78,10 @@ public abstract class PlaceholderNotificationGenerator {
|
||||
String senderNameOrId = StringUtils.defaultIfBlank(senderName, invite.getInvite().getSender().getId());
|
||||
String roomName = invite.getInvite().getProperties().getOrDefault(RoomName, "");
|
||||
String roomNameOrId = StringUtils.defaultIfBlank(roomName, invite.getInvite().getRoomId());
|
||||
String registerUrl = StringUtils.defaultIfBlank(invite.getInvite().getProperties().get(RegisterUrl), "https://" + mxCfg.getDomain());
|
||||
|
||||
return populateForCommon(tpid, input)
|
||||
.replace("%" + RegisterUrl + "%", registerUrl)
|
||||
.replace("%SENDER_ID%", invite.getInvite().getSender().getId())
|
||||
.replace("%SENDER_NAME%", senderName)
|
||||
.replace("%SENDER_NAME_OR_ID%", senderNameOrId)
|
||||
@@ -102,10 +106,6 @@ public abstract class PlaceholderNotificationGenerator {
|
||||
.replace("%NEXT_URL%", validationLink);
|
||||
}
|
||||
|
||||
protected String populateForRemoteValidation(IThreePidSession session, String input) {
|
||||
return populateForValidation(session, input);
|
||||
}
|
||||
|
||||
protected String populateForFraudulentUndind(ThreePid tpid, String input) {
|
||||
return populateForCommon(tpid, input);
|
||||
}
|
||||
|
Reference in New Issue
Block a user