A self hosted chat application with end-to-end encrypted messaging.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
package org.ros.chatto.controller;
import java.security.Principal; import java.time.Instant; import java.util.Date; import java.util.List;
import javax.validation.Valid;
import org.ros.chatto.dto.ChatMessageDTO; import org.ros.chatto.dto.ReencryptionDTO; import org.ros.chatto.service.ChatService; import org.ros.chatto.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;
@RestController @RequestMapping("/api/admin") public class AdminRESTController { @Autowired private ChatService chatService;
@Autowired private UserService userService;
@PostMapping(value = "/post/re-encrypt", consumes = { "application/json" }) public ResponseEntity<ReencryptionDTO> reencryptMessages( @RequestBody @Valid List<ReencryptionDTO> reencryptionDTOs, Principal principal) { if (reencryptionDTOs.size() > 0) { chatService.reencryptMessages(reencryptionDTOs); } return new ResponseEntity<ReencryptionDTO>(HttpStatus.OK); }
@GetMapping(value = "/get/messages/{userName}") public List<ReencryptionDTO> sendAllMessages(@PathVariable String userName, Principal principal) { List<ReencryptionDTO> reencryptionDTOs = chatService .getAllMessagesForReencryption(principal.getName(), userName); return reencryptionDTOs; }
@GetMapping(value = "/get/messages/{userName}/{lastMessageTime}") public List<ChatMessageDTO> sendNewMessages(@PathVariable String userName, @PathVariable Instant lastMessageTime, Principal principal) { List<ChatMessageDTO> chatMessageDTOs = chatService.getNewMessages( principal.getName(), userName, Date.from(lastMessageTime)); return chatMessageDTOs; }
@GetMapping("/get/users") public List<String> getAllOtherUsers(Principal principal) { return userService.findAllOtherUsers(principal.getName()); } }
|