Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TypingNotification options for setting SenderDisplayName #22351

Merged
merged 6 commits into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/communication/azure-communication-chat/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Added method `ChatThreadAsyncClient.listParticipants(ListParticipantsOptions listParticipantsOptions)`
- Added method `ChatThreadAsyncClient.listReadReceipts(ListReadReceiptOptions listReadReceiptOptions)`
- Added support for metadata in messages.
- Added options class `SendTypingNotificationOptions` for setting `SenderDisplayName` of the notification sender.

## 1.0.1 (2021-05-27)
- Dependency versions updated.
Expand Down
9 changes: 7 additions & 2 deletions sdk/communication/azure-communication-chat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,15 @@ readReceiptsResponse.iterableByPage().forEach(resp -> {
#### Send typing notification

Use `sendTypingNotification` method to post a typing notification event to a chat thread, on behalf of a user.
`typingNotificationOptions` is used to describe the typing notification request.

<!-- embedme ./src/samples/java/com/azure/communication/chat/ReadmeSamples.java#L275-L275 -->
- Use `senderDisplayName` to set the display name of the notification sender;

<!-- embedme ./src/samples/java/com/azure/communication/chat/ReadmeSamples.java#L276-L278 -->
```Java
chatThreadClient.sendTypingNotification();
TypingNotificationOptions options = new TypingNotificationOptions();
options.setSenderDisplayName("Sender Display Name");
chatThreadClient.sendTypingNotification(options);
```


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.azure.communication.chat.models.ListReadReceiptOptions;
import com.azure.communication.chat.models.SendChatMessageOptions;
import com.azure.communication.chat.models.SendChatMessageResult;
import com.azure.communication.chat.models.TypingNotificationOptions;
import com.azure.communication.chat.models.UpdateChatMessageOptions;
import com.azure.communication.chat.models.UpdateChatThreadOptions;
import com.azure.communication.common.CommunicationIdentifier;
Expand Down Expand Up @@ -734,7 +735,8 @@ Mono<Response<Void>> deleteMessage(String chatMessageId, Context context) {
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Void> sendTypingNotification() {
try {
return withContext(context -> sendTypingNotification(context)
TypingNotificationOptions options = new TypingNotificationOptions();
return withContext(context -> sendTypingNotification(options, context)
.flatMap((Response<Void> res) -> {
return Mono.empty();
}));
Expand All @@ -753,7 +755,8 @@ public Mono<Void> sendTypingNotification() {
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<Void>> sendTypingNotificationWithResponse() {
try {
return withContext(context -> sendTypingNotification(context));
TypingNotificationOptions options = new TypingNotificationOptions();
return withContext(context -> sendTypingNotification(options, context));
} catch (RuntimeException ex) {
return monoError(logger, ex);
}
Expand All @@ -762,13 +765,54 @@ public Mono<Response<Void>> sendTypingNotificationWithResponse() {
/**
* Posts a typing event to a thread, on behalf of a user.
*
* @param options Options for sending the typing notification.
angiurgiu marked this conversation as resolved.
Show resolved Hide resolved
* @throws ChatErrorResponseException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the completion.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Void> sendTypingNotification(TypingNotificationOptions options) {
try {
Objects.requireNonNull(options, "'options' cannot be null.");
return withContext(context -> sendTypingNotification(options, context)
.flatMap((Response<Void> res) -> {
return Mono.empty();
}));
} catch (RuntimeException ex) {
return monoError(logger, ex);
}
}

/**
* Posts a typing event to a thread, on behalf of a user.
*
* @param options Options for sending the typing notification.
angiurgiu marked this conversation as resolved.
Show resolved Hide resolved
* @throws ChatErrorResponseException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the completion.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<Void>> sendTypingNotificationWithResponse(TypingNotificationOptions options) {
try {
Objects.requireNonNull(options, "'options' cannot be null.");
return withContext(context -> sendTypingNotification(options, context));
} catch (RuntimeException ex) {
return monoError(logger, ex);
}
}

/**
* Posts a typing event to a thread, on behalf of a user.
*
* @param options Options for sending the typing notification.
* @param context The context to associate with this operation.
* @return the completion.
*/
Mono<Response<Void>> sendTypingNotification(Context context) {
Mono<Response<Void>> sendTypingNotification(TypingNotificationOptions options, Context context) {
context = context == null ? Context.NONE : context;
try {
return this.chatThreadClient.sendTypingNotificationWithResponseAsync(chatThreadId, context)
Objects.requireNonNull(options, "'options' cannot be null.");
return this.chatThreadClient.sendTypingNotificationWithResponseAsync(chatThreadId, options, context)
.onErrorMap(CommunicationErrorResponseException.class, e -> translateException(e));
} catch (RuntimeException ex) {
return monoError(logger, ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.azure.communication.chat.models.ListReadReceiptOptions;
import com.azure.communication.chat.models.SendChatMessageOptions;
import com.azure.communication.chat.models.SendChatMessageResult;
import com.azure.communication.chat.models.TypingNotificationOptions;
import com.azure.communication.chat.models.UpdateChatMessageOptions;
import com.azure.communication.common.CommunicationIdentifier;
import com.azure.core.annotation.ReturnType;
Expand Down Expand Up @@ -350,8 +351,8 @@ public void deleteMessage(String chatMessageId) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<Void> sendTypingNotificationWithResponse(Context context) {

return this.client.sendTypingNotification(context).block();
TypingNotificationOptions options = new TypingNotificationOptions();
return this.client.sendTypingNotification(options, context).block();
}

/**
Expand All @@ -365,6 +366,32 @@ public void sendTypingNotification() {
this.client.sendTypingNotification().block();
}

/**
* Posts a typing event to a thread, on behalf of a user.
*
* @param options Options for sending the typing notification.
* @param context The context to associate with this operation.
* @throws ChatErrorResponseException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the completion.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<Void> sendTypingNotificationWithResponse(TypingNotificationOptions options, Context context) {
return this.client.sendTypingNotification(options, context).block();
}

/**
* Posts a typing event to a thread, on behalf of a user.
*
* @param options Options for sending the typing notification.
* @throws ChatErrorResponseException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public void sendTypingNotification(TypingNotificationOptions options) {
this.client.sendTypingNotification(options).block();
}

/**
* Posts a read receipt event to a thread, on behalf of a user.
*
Expand Down
Loading