-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(PeerChat): IsTyping endpoint (#250)
- Loading branch information
1 parent
636701c
commit 710f991
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
.../org/wise/portal/presentation/web/controllers/student/PeerChatTypingStatusController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.wise.portal.presentation.web.controllers.student; | ||
|
||
import javax.transaction.Transactional; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.messaging.handler.annotation.DestinationVariable; | ||
import org.springframework.messaging.handler.annotation.MessageMapping; | ||
import org.springframework.security.access.annotation.Secured; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.stereotype.Controller; | ||
import org.wise.portal.dao.ObjectNotFoundException; | ||
import org.wise.portal.domain.peergroup.PeerGroup; | ||
import org.wise.portal.service.peergroup.PeerGroupService; | ||
import org.wise.portal.spring.data.redis.MessagePublisher; | ||
|
||
@Secured({ "ROLE_TEACHER", "ROLE_STUDENT" }) | ||
@Controller | ||
public class PeerChatTypingStatusController extends AbstractPeerGroupWorkController { | ||
|
||
@Autowired | ||
private MessagePublisher redisPublisher; | ||
|
||
@Autowired | ||
private PeerGroupService peerGroupService; | ||
|
||
@Transactional() | ||
@MessageMapping("/api/peer-chat/{nodeId}/{componentId}/{peerGroupId}/{workgroupId}/is-typing") | ||
public void sendTypingStatusToPeerGroup(Authentication auth, | ||
@DestinationVariable Long peerGroupId, @DestinationVariable String nodeId, | ||
@DestinationVariable String componentId, @DestinationVariable int workgroupId) | ||
throws JSONException, ObjectNotFoundException { | ||
PeerGroup peerGroup = peerGroupService.getById(peerGroupId); | ||
if (isUserInPeerGroup(auth, peerGroup) || isUserTeacherOfPeerGroup(auth, peerGroup)) { | ||
JSONObject message = new JSONObject(); | ||
message.put("topic", String.format("/topic/peer-group/%s/is-typing", peerGroupId)); | ||
message.put("type", "isTyping"); | ||
JSONObject body = new JSONObject(); | ||
body.put("nodeId", nodeId); | ||
body.put("componentId", componentId); | ||
body.put("workgroupId", workgroupId); | ||
message.put("body", body); | ||
redisPublisher.publish(message.toString()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters