aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server/xmpp/XMPPStatusPage.java
blob: 90c8fe596fed346397d6229696f86307a4660493 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.juick.server.xmpp;

import com.juick.server.XMPPServer;
import com.juick.server.xmpp.helpers.XMPPStatus;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import rocks.xmpp.addr.Jid;

import javax.inject.Inject;
import java.util.stream.Collectors;

@RestController
@ConditionalOnProperty("xmppbot_jid")
public class XMPPStatusPage {
    @Inject
    private XMPPServer xmpp;
    @RequestMapping(method = RequestMethod.GET, value = "/api/xmpp-status", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public XMPPStatus xmppStatus() {
        XMPPStatus status = new XMPPStatus();
        if (xmpp != null) {
            status.setInbound(xmpp.getInConnections().stream().map(c -> c.from).flatMap(j -> j.stream().map(Jid::getDomain)).collect(Collectors.toList()));
            status.setOutbound(xmpp.getOutConnections().keySet().stream()
                    .map(c -> c.to).map(Jid::getDomain).collect(Collectors.toList()));
        }
        return status;
    }
}