package syncapi import ( "fmt" "github.com/dariuszjaniak/warp/server/internal/matrix/id" ) // The component's errors are plain wrapped sentinels rather than HTTP // errors, the same as the roomserver's: this package is called from the // Client-Server handlers and, later, from the application service API, and // a component that returned HTTP statuses would be deciding something that // is not its to decide. The handler maps them; see clientapi.syncError. // errForbiddenf is a refusal the caller is told the reason for. // // The reason is passed through to the client on purpose, as it is in the // roomserver: "M_FORBIDDEN" on its own sends a user to their operator and // the operator to the logs, and nothing in these messages is anything the // caller could not work out from the room's state. func errForbiddenf(format string, args ...any) error { return fmt.Errorf("%w: %s", ErrForbidden, fmt.Sprintf(format, args...)) } // errInvalidParamf is a request parameter this server will not accept. func errInvalidParamf(format string, args ...any) error { return fmt.Errorf("%w: %s", ErrInvalidParam, fmt.Sprintf(format, args...)) } // errInvalidTokenf is a ?since= or ?from= that could not be read. func errInvalidTokenf(format string, args ...any) error { return fmt.Errorf("%w: %s", ErrInvalidToken, fmt.Sprintf(format, args...)) } // localpartOf returns the localpart of a user ID of this server. func (s *API) localpartOf(userID string) (string, bool) { localpart, serverName, err := id.SplitUserID(userID) if err != nil || serverName != s.serverName { return "", false } return localpart, true } // isLocal reports whether a user ID belongs to this server. func (s *API) isLocal(userID string) bool { _, ok := s.localpartOf(userID) return ok }