Skip to content

Commit

Permalink
feat(typing): expose API for typing indicators (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincejv authored Nov 3, 2022
1 parent c281af3 commit dc2059b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -51,6 +53,21 @@ public Uni<RespDto<MsgrReqReply>> sendMsg(
});
}

@POST
@Path("typing/{recipient}/{isTyping}")
public Uni<RespDto<MsgrReqReply>> 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<MsgrReqReply>();
resp.setResp(svcResp);
resp.setTimestamp(DateUtil.nowAsStr());
resp.setStatus("%s typing indicator for %s".formatted(isTyping ? "Activated" : "Deactivated", recipient));
return resp;
});
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,10 @@ public Uni<MsgrReqReply> postMsg(MsgrMsgReqDto msgReq, String appSource) {
});
}

public Uni<MsgrReqReply> toggleTyping(String recipient, boolean isTyping) {
return metaMsgrApiSvc.sendTypingIndicator(recipient, isTyping)
.onFailure().recoverWithUni(ex-> Uni.createFrom().failure(
new FPISvcEx("Failed to update typing status", ex)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -38,7 +41,13 @@
@RegisterProvider(value = ApiRepoExHandler.class)
public interface MsgrReqApi extends IApi {

@POST
Uni<RespDto<MsgrReqReply>> sendMsg(
MsgrMsgReqDto msgReq, @HeaderParam("X-FPI-System") String fpiSystem);

@POST
@Path("typing/{recipient}/{isTyping}")
Uni<RespDto<MsgrReqReply>> toggleTyping(
@PathParam("recipient") String recipient, @PathParam("isTyping") Boolean isTypingParam);

}

0 comments on commit dc2059b

Please sign in to comment.