Skip to content

Commit

Permalink
feat: NotificationParams class
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyTubongbanua committed Oct 20, 2022
1 parent 770737d commit 3836d07
Showing 1 changed file with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package org.atsign.client.api.impl.notification;

import java.util.UUID;

import org.atsign.common.AtSign;
import org.atsign.common.KeyBuilders;
import org.atsign.common.NotificationEnums;
import org.atsign.common.Keys.AtKey;
import org.atsign.common.Keys.SharedKey;
import org.atsign.common.NotificationEnums.Operation;


public class NotificationParams {

private String id;
private AtKey atKey;
private String value; // nullable (optional)
private NotificationEnums.Operation operation;
private NotificationEnums.MessageType messageType;
private NotificationEnums.Priority priority;
private NotificationEnums.Strategy strategy;
// private Integer latestN = 1;
// private String notifier = SYSTEM;

/**
*
* @param atKey AtKey object which contains the sharedBy and sharedWith atSign.
* @param value nullable (optional)
* @return NotificationParams object
*/
public static NotificationParams forUpdate(AtKey atKey, String value) {
NotificationParams params = new NotificationParams();
params.id = UUID.randomUUID().toString();
params.atKey = atKey;
params.value = value;
params.operation = Operation.UPDATE;
params.messageType = NotificationEnums.MessageType.KEY;
params.priority = NotificationEnums.Priority.LOW;
params.strategy = NotificationEnums.Strategy.ALL;
return params;
}

public static NotificationParams forDelete(AtKey atKey) {
NotificationParams params = new NotificationParams();
params.id = UUID.randomUUID().toString();
params.atKey = atKey;
params.operation = Operation.DELETE;
params.messageType = NotificationEnums.MessageType.KEY;
params.priority = NotificationEnums.Priority.LOW;
params.strategy = NotificationEnums.Strategy.ALL;
return params;
}

public static NotificationParams forText(String text, String whomToNotify, Boolean shouldEncrypt) {

SharedKey sharedKey = new KeyBuilders.SharedKeyBuilder(
new AtSign(""), new AtSign(whomToNotify)).build();
sharedKey.metadata.isEncrypted = shouldEncrypt;


NotificationParams params = new NotificationParams();
params.id = UUID.randomUUID().toString();
params.atKey = sharedKey;
params.operation = Operation.UPDATE;
params.messageType = NotificationEnums.MessageType.TEXT;
params.priority = NotificationEnums.Priority.LOW;
params.strategy = NotificationEnums.Strategy.ALL;
return params;
}

}

0 comments on commit 3836d07

Please sign in to comment.