From dc2059b2cecda215d92e4ce63817e331f8d31a86 Mon Sep 17 00:00:00 2001 From: Vince Jerald Villamora Date: Thu, 3 Nov 2022 18:52:10 +0800 Subject: [PATCH] feat(typing): expose API for typing indicators (#8) --- .../fpi/msgr/controller/MsgrReqResource.java | 17 +++++++++++++++++ .../abavilla/fpi/msgr/service/MsgrReqSvc.java | 6 ++++++ .../abavilla/fpi/msgr/ext/rest/MsgrReqApi.java | 9 +++++++++ 3 files changed, 32 insertions(+) diff --git a/fpi-msgr-api-core/src/main/java/com/abavilla/fpi/msgr/controller/MsgrReqResource.java b/fpi-msgr-api-core/src/main/java/com/abavilla/fpi/msgr/controller/MsgrReqResource.java index c153ff7..4a75af6 100644 --- a/fpi-msgr-api-core/src/main/java/com/abavilla/fpi/msgr/controller/MsgrReqResource.java +++ b/fpi-msgr-api-core/src/main/java/com/abavilla/fpi/msgr/controller/MsgrReqResource.java @@ -21,6 +21,7 @@ import javax.ws.rs.HeaderParam; import javax.ws.rs.POST; import javax.ws.rs.Path; +import javax.ws.rs.PathParam; import com.abavilla.fpi.fw.controller.AbsBaseResource; import com.abavilla.fpi.fw.dto.IDto; @@ -33,6 +34,7 @@ import com.abavilla.fpi.msgr.ext.dto.MsgrMsgReqDto; import com.abavilla.fpi.msgr.service.MsgrReqSvc; import io.smallrye.mutiny.Uni; +import org.apache.commons.lang3.BooleanUtils; import org.jboss.resteasy.reactive.RestResponse; import org.jboss.resteasy.reactive.server.ServerExceptionMapper; @@ -51,6 +53,21 @@ public Uni> sendMsg( }); } + @POST + @Path("typing/{recipient}/{isTyping}") + public Uni> toggleTyping( + @PathParam("recipient") String recipient, + @PathParam("isTyping") String isTypingParam) { + boolean isTyping = BooleanUtils.toBoolean(isTypingParam); + return service.toggleTyping(recipient, isTyping).map(svcResp -> { + var resp = new RespDto(); + resp.setResp(svcResp); + resp.setTimestamp(DateUtil.nowAsStr()); + resp.setStatus("%s typing indicator for %s".formatted(isTyping ? "Activated" : "Deactivated", recipient)); + return resp; + }); + } + /** * {@inheritDoc} */ diff --git a/fpi-msgr-api-core/src/main/java/com/abavilla/fpi/msgr/service/MsgrReqSvc.java b/fpi-msgr-api-core/src/main/java/com/abavilla/fpi/msgr/service/MsgrReqSvc.java index 05cbb2a..8b1b47e 100644 --- a/fpi-msgr-api-core/src/main/java/com/abavilla/fpi/msgr/service/MsgrReqSvc.java +++ b/fpi-msgr-api-core/src/main/java/com/abavilla/fpi/msgr/service/MsgrReqSvc.java @@ -76,4 +76,10 @@ public Uni postMsg(MsgrMsgReqDto msgReq, String appSource) { }); } + public Uni toggleTyping(String recipient, boolean isTyping) { + return metaMsgrApiSvc.sendTypingIndicator(recipient, isTyping) + .onFailure().recoverWithUni(ex-> Uni.createFrom().failure( + new FPISvcEx("Failed to update typing status", ex))); + } + } diff --git a/fpi-msgr-api-lib/src/main/java/com/abavilla/fpi/msgr/ext/rest/MsgrReqApi.java b/fpi-msgr-api-lib/src/main/java/com/abavilla/fpi/msgr/ext/rest/MsgrReqApi.java index c1ac401..f9b12e4 100644 --- a/fpi-msgr-api-lib/src/main/java/com/abavilla/fpi/msgr/ext/rest/MsgrReqApi.java +++ b/fpi-msgr-api-lib/src/main/java/com/abavilla/fpi/msgr/ext/rest/MsgrReqApi.java @@ -20,6 +20,9 @@ import javax.ws.rs.Consumes; import javax.ws.rs.HeaderParam; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; @@ -38,7 +41,13 @@ @RegisterProvider(value = ApiRepoExHandler.class) public interface MsgrReqApi extends IApi { + @POST Uni> sendMsg( MsgrMsgReqDto msgReq, @HeaderParam("X-FPI-System") String fpiSystem); + @POST + @Path("typing/{recipient}/{isTyping}") + Uni> toggleTyping( + @PathParam("recipient") String recipient, @PathParam("isTyping") Boolean isTypingParam); + }