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

Websocket #40

Merged
merged 4 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import lombok.RequiredArgsConstructor;

import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;


@Controller
@RequiredArgsConstructor
// @RequestMapping("/api/v1")
public class ChatController {

private final ChatMessageService chatMessageService;
Expand All @@ -20,8 +18,7 @@ public ChatMessage processMessage(@RequestBody ChatMessageDTO chatMessage) {
return chatMessageService.saveusermessage(chatMessage);
}
@MessageMapping("/sendgroupmessage")
// @SendTo("/user/public")
public GroupMessage processGroupMessage(@Payload GroupMessageDTO groupMessage) {
public GroupMessage processGroupMessage(@RequestBody GroupMessageDTO groupMessage) {
return chatMessageService.savegroupmessage(groupMessage);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import java.util.Date;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ChatMessageDTO2 {
private Long senderId;
private String content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
@AllArgsConstructor
public class ChatMessageService {
private final ChatMessageRepository chatMessageRepository;
private final ConversationRepository conversationRepository;
private final UserRepository userRepository;
private final GroupMessageRepository groupMessageRepository;
private final Functions functions;
Expand All @@ -45,13 +44,11 @@ public ChatMessage saveusermessage(ChatMessageDTO chatMessage) {

messagingTemplate.convertAndSendToUser(
chatId, "/queue/messages",
new ChatNotification(
chatId,
new ChatMessageDTO2(
chatMessage1.getSender().getId(),
chatMessage1.getContent(),
new Date(System.currentTimeMillis()),
false
)
new java.util.Date(System.currentTimeMillis()),
chatMessage1.getSender().getUsername())
);
return chatMessage1;

Expand All @@ -67,12 +64,12 @@ public GroupMessage savegroupmessage(GroupMessageDTO groupMessageDTO) {

messagingTemplate.convertAndSendToUser(
Long.toString(groupMessageDTO.getGroupId()), "/queue/messages",
new GroupNotification(
groupMessage.getGroupId(),
new GroupMessageDTO(
groupMessage.getSender().getId(),
groupMessage.getContent(),
new Date(System.currentTimeMillis()),
true
groupMessage.getGroupId(),
groupMessage.getSender().getUsername(),
new Date(System.currentTimeMillis())
)
);
return groupMessage;
Expand Down Expand Up @@ -123,6 +120,7 @@ public List<GroupMessageDTO> findGroupMessages(Long groupId) {
groupMessageDTO.setTimestamp(groupMessage.getTimestamp());
groupMessageDTO.setSenderId(groupMessage.getSender().getId());
groupMessageDTO.setSenderName(groupMessage.getSender().getUsername());
groupMessageDTO.setGroupId(groupMessage.getGroupId());
groupMessages2.add(groupMessageDTO);
}
User connectedUser = functions.getConnectedUser();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

import java.util.Date;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class GroupMessageDTO {
private Long senderId;
private String content;
Expand Down

This file was deleted.

Loading