package de.tum.in.www1.artemis.service;

import org.springframework.messaging.simp.SimpMessageSendingOperations;
import org.springframework.stereotype.Service;

import de.tum.in.www1.artemis.domain.Participation;
import de.tum.in.www1.artemis.domain.Result;

/**
 * This service sends out websocket messages.
 */
@Service
public class WebsocketMessagingService {

    SimpMessageSendingOperations messagingTemplate;

    public WebsocketMessagingService(SimpMessageSendingOperations messagingTemplate) {
        this.messagingTemplate = messagingTemplate;
    }

    public void sendMessage(String topic, Object message) {
        messagingTemplate.convertAndSend(topic, message);
    }

    public void broadcastNewResult(Participation participation, Result result) {
        // remove some unnecessary properties to reduce the data sent to the client
        var resultParticipation = result.getParticipation();
        result.setParticipation(null);
        messagingTemplate.convertAndSend("/topic/participation/" + participation.getId() + "/newResults", result);
        // recover the participation because we might want to use it again after this method
        result.setParticipation(resultParticipation);
    }
}

@@ -564,128 +564,1072 @@
     
-public void sendMessage(String topic, Object message) %7B%0A        messagingTemplate.convertAndSend(topic, message);%0A    %7D%0A
+/**%0A     * Wrapper method to send a message over websocket to the given topic%0A     * @param topic the destination to which subscription the message should be sent%0A     * @param message any object that should be sent to the destination (topic), this will typically get transformed into json%0A     */%0A    public void sendMessage(String topic, Object message) %7B%0A        messagingTemplate.convertAndSend(topic, message);%0A    %7D%0A%0A    /**%0A     * Broadcast a new result to the client.%0A     *%0A     * @param participation the id is used in the destination (so that only clients who have subscribed the specific participation will receive the result)%0A     * @param result the new result that should be send to the client. It typically includes feedback, its participation will be cut off here to reduce the payload size.%0A     *               As the participation is already known to the client, we do not need to send it. This also cuts of the exercise (including the potentially huge%0A     *               problem statement and the course with all potential attributes%0A     */
 %0A   
@@ -1728,13 +1728,8 @@
 ove 
-some 
 unne
@@ -1784,16 +1784,93 @@
 e client
+ (we should not send the exercise and its potentially huge problem statement)
 %0A       
@@ -1962,16 +1962,17 @@
 (null);%0A
+%0A
         
@@ -2078,16 +2078,17 @@
 esult);%0A
+%0A
         

fix javadoc