Skip to content

Commit

Permalink
DS-370: Add silent message update support (#663)
Browse files Browse the repository at this point in the history
- Update Symphony APIs spec version

 - Add silent flag support according to the new spec.
   When silent is true, the new updated message is marked as read, otherwise is unread.
   True is the default value.
  • Loading branch information
yinan-symphony authored May 25, 2022
1 parent d8ff672 commit ea96560
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion symphony-bdk-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ dependencies {
}

// OpenAPI code generation
def apiBaseUrl = "https://raw.githubusercontent.com/finos/symphony-api-spec/136b530512eea112de73591906051871d034750a"
def apiBaseUrl = "https://raw.githubusercontent.com/finos/symphony-api-spec/46abc03ad7225ebc32439c06920019c9d0fb0814"
def generatedFolder = "$buildDir/generated/openapi"
def apisToGenerate = [
Agent: 'agent/agent-api-public-deprecated.yaml',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ private Map<String, Object> getForm(Message message) {
form.put("message", message.getContent());
form.put("data", message.getData());
form.put("version", message.getVersion());
form.put("silent", message.getSilent());
form.put("attachment", toApiClientBodyParts(message.getAttachments()));
form.put("preview", toApiClientBodyParts(message.getPreviews()));
return form;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,20 @@ public class Message {
* Optional message version in the format "major.minor". If empty, defaults to the latest supported version.
*/
private final String version;
/**
* Optional boolean flag. Used in message update api only.
* If true, the message is updated as read already, otherwise it is unread. The default value is true.
* @since Agent 20.14
*/
private final Boolean silent;

Message(final MessageBuilder builder) {
this.content = builder.content();
this.version = builder.version();
this.data = builder.data();
this.attachments = builder.attachments();
this.previews = builder.previews();
this.silent = builder.silent();
}

/**
Expand Down Expand Up @@ -86,6 +93,7 @@ public static class MessageBuilder {
private String version = "2.0";
private String content;
private String data;
private Boolean silent = Boolean.TRUE;
private List<Attachment> attachments = new ArrayList<>();
@Setter(value = AccessLevel.PRIVATE) private List<Attachment> previews = new ArrayList<>();

Expand Down Expand Up @@ -136,6 +144,11 @@ public MessageBuilder data(@Nonnull Object data) {
}
}

public MessageBuilder silent(@Nonnull Boolean silent) {
this.silent = silent;
return this;
}

/**
* Add attachment to the message.
* @param content Attachment content.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,19 @@ void testMessageUpdate() throws IOException {
assertEquals(1599659432867L, updateMessage.getInitialTimestamp());
}

@Test
void testMessageSilentUpdate() throws IOException {
mockApiClient.onPost(V4_STREAM_MESSAGE_UPDATE.replace("{sid}", STREAM_ID).replace("{mid}", MESSAGE_ID),
JsonHelper.readFromClasspath("/message/update_message.json"));

final V4Message messageToUpdate = new V4Message().stream(new V4Stream().streamId(STREAM_ID)).messageId(MESSAGE_ID);
final Message content = Message.builder().content("This is a message update with silent flag as false").silent(false).build();
final V4Message updateMessage = this.messageService.update(messageToUpdate, content);

assertEquals(MESSAGE_ID, updateMessage.getMessageId());
assertEquals(false, updateMessage.getSilent());
}

@Test
void testGetAttachment() throws ApiException {
final String attachmentId = "attachmentId";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,14 @@ void checkMessageMLAppendedToContentIfNotSet() {
void checkMessageMLNotAppendedToContentIfSet() {
assertEquals("<messageML>hello</messageML>", Message.builder().content("<messageML>hello</messageML>").build().getContent());
}

@Test
void checkMessageSilentValueIfSet() {
assertEquals(Boolean.FALSE, Message.builder().content("<messageML>hello</messageML>").silent(Boolean.FALSE).build().getSilent());
}

@Test
void checkMessageSilentDefaultValue() {
assertEquals(Boolean.TRUE, Message.builder().content("<messageML>hello</messageML>").build().getSilent());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
"sid": "6ca2b92d-f198-4059-9073-9701c26ab5f3",
"initialMessageId": "vanscOQk6IJXm-6XAN3B33___oiRvNNKdA",
"initialTimestamp": 1599659432867,
"silent": false,
"replacing": "j7-VAoCY_1pGAYSye_MtI3___oPXo8VHbQ"
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private static void startTheShow(SymphonyBdk bdk, String streamId) {
for (int i = 0; i < 10; i++) {
Thread.sleep((long) (Math.random() * (5000L - 500L)));
String mml = "<emoji shortcode=\"" + pickEmoji.apply(i) + "\" /><br/><br/>Update <b>#" + (i + 1) + "</b>";
previousMessage = bdk.messages().update(previousMessage, Message.builder().content(mml).build());
previousMessage = bdk.messages().update(previousMessage, Message.builder().content(mml).silent(false).build());
}
}

Expand Down

0 comments on commit ea96560

Please sign in to comment.