mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-12-24 14:34:12 +01:00
Update data sent in bridge status updates
This commit is contained in:
parent
d851285787
commit
b865205198
1 changed files with 17 additions and 10 deletions
|
@ -24,17 +24,19 @@ import (
|
|||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/Rhymen/go-whatsapp"
|
||||
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
type BridgeErrorCode string
|
||||
|
||||
const (
|
||||
WANotLoggedIn BridgeErrorCode = "wa-not-logged-in"
|
||||
WANotLoggedIn BridgeErrorCode = "logged-out"
|
||||
WANotConnected BridgeErrorCode = "wa-not-connected"
|
||||
WAConnecting BridgeErrorCode = "wa-connecting"
|
||||
WATimeout BridgeErrorCode = "wa-timeout"
|
||||
|
@ -52,17 +54,24 @@ var bridgeHumanErrors = map[BridgeErrorCode]string{
|
|||
}
|
||||
|
||||
type BridgeState struct {
|
||||
OK bool `json:"ok"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
TTL int `json:"ttl"`
|
||||
OK bool `json:"ok"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
TTL int `json:"ttl"`
|
||||
|
||||
ErrorSource string `json:"error_source,omitempty"`
|
||||
Error BridgeErrorCode `json:"error,omitempty"`
|
||||
Message string `json:"message,omitempty"`
|
||||
|
||||
UserID id.UserID `json:"user_id"`
|
||||
UserID id.UserID `json:"user_id"`
|
||||
RemoteID string `json:"remote_id"`
|
||||
RemoteName string `json:"remote_name"`
|
||||
}
|
||||
|
||||
func (pong *BridgeState) fill() {
|
||||
func (pong *BridgeState) fill(user *User) {
|
||||
pong.UserID = user.MXID
|
||||
pong.RemoteID = strings.TrimSuffix(user.JID, whatsapp.NewUserSuffix)
|
||||
pong.RemoteName = fmt.Sprintf("+%s", pong.RemoteID)
|
||||
|
||||
pong.Timestamp = time.Now().Unix()
|
||||
if !pong.OK {
|
||||
pong.TTL = 60
|
||||
|
@ -121,8 +130,7 @@ func (user *User) sendBridgeState(state BridgeState) {
|
|||
return
|
||||
}
|
||||
|
||||
state.UserID = user.MXID
|
||||
state.fill()
|
||||
state.fill(user)
|
||||
if user.prevBridgeStatus != nil && user.prevBridgeStatus.shouldDeduplicate(&state) {
|
||||
return
|
||||
}
|
||||
|
@ -195,8 +203,7 @@ func (prov *ProvisioningAPI) BridgeStatePing(w http.ResponseWriter, r *http.Requ
|
|||
resp.Error = WANotConnected
|
||||
}
|
||||
}
|
||||
resp.UserID = user.MXID
|
||||
resp.fill()
|
||||
resp.fill(user)
|
||||
user.log.Debugfln("Responding bridge state in bridge status endpoint: %+v", resp)
|
||||
jsonResponse(w, http.StatusOK, &resp)
|
||||
user.prevBridgeStatus = &resp
|
||||
|
|
Loading…
Reference in a new issue