Add struct for ping response
This commit is contained in:
@@ -171,37 +171,34 @@ func (p *ProvisioningAPI) disconnect(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type respPing struct {
|
||||||
|
Discord struct {
|
||||||
|
ID string `json:"id,omitempty"`
|
||||||
|
LoggedIn bool `json:"logged_in"`
|
||||||
|
Connected bool `json:"connected"`
|
||||||
|
Conn struct {
|
||||||
|
LastHeartbeatAck int64 `json:"last_heartbeat_ack,omitempty"`
|
||||||
|
LastHeartbeatSent int64 `json:"last_heartbeat_sent,omitempty"`
|
||||||
|
} `json:"conn"`
|
||||||
|
}
|
||||||
|
MXID id.UserID `json:"mxid"`
|
||||||
|
ManagementRoom id.RoomID `json:"management_room"`
|
||||||
|
}
|
||||||
|
|
||||||
func (p *ProvisioningAPI) ping(w http.ResponseWriter, r *http.Request) {
|
func (p *ProvisioningAPI) ping(w http.ResponseWriter, r *http.Request) {
|
||||||
user := r.Context().Value("user").(*User)
|
user := r.Context().Value("user").(*User)
|
||||||
|
|
||||||
discord := map[string]interface{}{
|
resp := respPing{
|
||||||
"logged_in": user.IsLoggedIn(),
|
MXID: user.MXID,
|
||||||
"connected": user.Connected(),
|
ManagementRoom: user.ManagementRoom,
|
||||||
"conn": nil,
|
|
||||||
}
|
}
|
||||||
|
resp.Discord.LoggedIn = user.IsLoggedIn()
|
||||||
user.Lock()
|
resp.Discord.Connected = user.Connected()
|
||||||
if user.DiscordID != "" {
|
resp.Discord.ID = user.DiscordID
|
||||||
discord["id"] = user.DiscordID
|
|
||||||
}
|
|
||||||
|
|
||||||
if user.Session != nil {
|
if user.Session != nil {
|
||||||
user.Session.Lock()
|
resp.Discord.Conn.LastHeartbeatAck = user.Session.LastHeartbeatAck.UnixMilli()
|
||||||
discord["conn"] = map[string]interface{}{
|
resp.Discord.Conn.LastHeartbeatSent = user.Session.LastHeartbeatSent.UnixMilli()
|
||||||
"last_heartbeat_ack": user.Session.LastHeartbeatAck,
|
|
||||||
"last_heartbeat_sent": user.Session.LastHeartbeatSent,
|
|
||||||
}
|
|
||||||
user.Session.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := map[string]interface{}{
|
|
||||||
"discord": discord,
|
|
||||||
"management_room": user.ManagementRoom,
|
|
||||||
"mxid": user.MXID,
|
|
||||||
}
|
|
||||||
|
|
||||||
user.Unlock()
|
|
||||||
|
|
||||||
jsonResponse(w, http.StatusOK, resp)
|
jsonResponse(w, http.StatusOK, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user