mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
bridgev2/provisioning: nest bridge state in whoami response
This commit is contained in:
parent
da4cbb554b
commit
23c5446324
3 changed files with 28 additions and 15 deletions
|
|
@ -18,6 +18,7 @@ import (
|
|||
|
||||
"github.com/tidwall/sjson"
|
||||
"go.mau.fi/util/jsontime"
|
||||
"go.mau.fi/util/ptr"
|
||||
"golang.org/x/exp/maps"
|
||||
|
||||
"maunium.net/go/mautrix"
|
||||
|
|
@ -89,10 +90,10 @@ type BridgeState struct {
|
|||
Error BridgeStateErrorCode `json:"error,omitempty"`
|
||||
Message string `json:"message,omitempty"`
|
||||
|
||||
UserID id.UserID `json:"user_id,omitempty"`
|
||||
RemoteID string `json:"remote_id,omitempty"`
|
||||
RemoteName string `json:"remote_name,omitempty"`
|
||||
RemoteProfile RemoteProfile `json:"remote_profile,omitempty"`
|
||||
UserID id.UserID `json:"user_id,omitempty"`
|
||||
RemoteID string `json:"remote_id,omitempty"`
|
||||
RemoteName string `json:"remote_name,omitempty"`
|
||||
RemoteProfile *RemoteProfile `json:"remote_profile,omitempty"`
|
||||
|
||||
Reason string `json:"reason,omitempty"`
|
||||
Info map[string]interface{} `json:"info,omitempty"`
|
||||
|
|
@ -186,7 +187,7 @@ func (pong *BridgeState) SendHTTP(ctx context.Context, url, token string) error
|
|||
func (pong *BridgeState) ShouldDeduplicate(newPong *BridgeState) bool {
|
||||
return pong != nil &&
|
||||
pong.StateEvent == newPong.StateEvent &&
|
||||
pong.RemoteProfile == newPong.RemoteProfile &&
|
||||
ptr.Val(pong.RemoteProfile) == ptr.Val(newPong.RemoteProfile) &&
|
||||
pong.Error == newPong.Error &&
|
||||
maps.EqualFunc(pong.Info, newPong.Info, reflect.DeepEqual) &&
|
||||
pong.Timestamp.Add(time.Duration(pong.TTL)*time.Second).After(time.Now())
|
||||
|
|
|
|||
|
|
@ -272,19 +272,25 @@ type RespWhoami struct {
|
|||
BridgeBot id.UserID `json:"bridge_bot"`
|
||||
CommandPrefix string `json:"command_prefix"`
|
||||
|
||||
ManagementRoom id.RoomID `json:"management_room"`
|
||||
ManagementRoom id.RoomID `json:"management_room,omitempty"`
|
||||
Logins []RespWhoamiLogin `json:"logins"`
|
||||
}
|
||||
|
||||
type RespWhoamiLogin struct {
|
||||
StateEvent status.BridgeStateEvent `json:"state_event"`
|
||||
StateTS jsontime.Unix `json:"state_ts"`
|
||||
StateReason string `json:"state_reason,omitempty"`
|
||||
StateInfo map[string]any `json:"state_info,omitempty"`
|
||||
ID networkid.UserLoginID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Profile status.RemoteProfile `json:"profile"`
|
||||
SpaceRoom id.RoomID `json:"space_room"`
|
||||
// Deprecated
|
||||
StateEvent status.BridgeStateEvent `json:"state_event"`
|
||||
// Deprecated
|
||||
StateTS jsontime.Unix `json:"state_ts"`
|
||||
// Deprecated
|
||||
StateReason string `json:"state_reason,omitempty"`
|
||||
// Deprecated
|
||||
StateInfo map[string]any `json:"state_info,omitempty"`
|
||||
|
||||
State status.BridgeState `json:"state"`
|
||||
ID networkid.UserLoginID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Profile status.RemoteProfile `json:"profile"`
|
||||
SpaceRoom id.RoomID `json:"space_room,omitempty"`
|
||||
}
|
||||
|
||||
func (prov *ProvisioningAPI) GetWhoami(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -301,11 +307,17 @@ func (prov *ProvisioningAPI) GetWhoami(w http.ResponseWriter, r *http.Request) {
|
|||
resp.Logins = make([]RespWhoamiLogin, len(logins))
|
||||
for i, login := range logins {
|
||||
prevState := login.BridgeState.GetPrevUnsent()
|
||||
// Clear redundant fields
|
||||
prevState.UserID = ""
|
||||
prevState.RemoteID = ""
|
||||
prevState.RemoteName = ""
|
||||
prevState.RemoteProfile = nil
|
||||
resp.Logins[i] = RespWhoamiLogin{
|
||||
StateEvent: prevState.StateEvent,
|
||||
StateTS: prevState.Timestamp,
|
||||
StateReason: prevState.Reason,
|
||||
StateInfo: prevState.Info,
|
||||
State: prevState,
|
||||
|
||||
ID: login.ID,
|
||||
Name: login.RemoteName,
|
||||
|
|
|
|||
|
|
@ -476,7 +476,7 @@ func (ul *UserLogin) FillBridgeState(state status.BridgeState) status.BridgeStat
|
|||
state.UserID = ul.UserMXID
|
||||
state.RemoteID = string(ul.ID)
|
||||
state.RemoteName = ul.RemoteName
|
||||
state.RemoteProfile = ul.RemoteProfile
|
||||
state.RemoteProfile = &ul.RemoteProfile
|
||||
filler, ok := ul.Client.(status.StandaloneCustomBridgeStateFiller)
|
||||
if ok {
|
||||
return filler.FillBridgeState(state)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue