Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5290157999 |
@@ -20,17 +20,16 @@ type SessionResp struct {
|
|||||||
|
|
||||||
// ProfileResp is an account's own profile.
|
// ProfileResp is an account's own profile.
|
||||||
type ProfileResp struct {
|
type ProfileResp struct {
|
||||||
UserID string `json:"user_id"`
|
UserID string `json:"user_id"`
|
||||||
DisplayName string `json:"display_name"`
|
DisplayName string `json:"display_name"`
|
||||||
PreferredLanguage string `json:"preferred_language"`
|
PreferredLanguage string `json:"preferred_language"`
|
||||||
TimeZone string `json:"time_zone"`
|
TimeZone string `json:"time_zone"`
|
||||||
AwayStart string `json:"away_start"`
|
AwayStart string `json:"away_start"`
|
||||||
AwayEnd string `json:"away_end"`
|
AwayEnd string `json:"away_end"`
|
||||||
HintBalance int `json:"hint_balance"`
|
HintBalance int `json:"hint_balance"`
|
||||||
BlockChat bool `json:"block_chat"`
|
BlockChat bool `json:"block_chat"`
|
||||||
BlockFriendRequests bool `json:"block_friend_requests"`
|
BlockFriendRequests bool `json:"block_friend_requests"`
|
||||||
IsGuest bool `json:"is_guest"`
|
IsGuest bool `json:"is_guest"`
|
||||||
NotificationsInAppOnly bool `json:"notifications_in_app_only"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TileJSON is one placed tile, used in both play requests and move responses.
|
// TileJSON is one placed tile, used in both play requests and move responses.
|
||||||
|
|||||||
@@ -215,14 +215,13 @@ func (c *Client) ListInvitations(ctx context.Context, userID string) (Invitation
|
|||||||
func (c *Client) UpdateProfile(ctx context.Context, userID string, p ProfileResp) (ProfileResp, error) {
|
func (c *Client) UpdateProfile(ctx context.Context, userID string, p ProfileResp) (ProfileResp, error) {
|
||||||
var out ProfileResp
|
var out ProfileResp
|
||||||
body := map[string]any{
|
body := map[string]any{
|
||||||
"display_name": p.DisplayName,
|
"display_name": p.DisplayName,
|
||||||
"preferred_language": p.PreferredLanguage,
|
"preferred_language": p.PreferredLanguage,
|
||||||
"time_zone": p.TimeZone,
|
"time_zone": p.TimeZone,
|
||||||
"away_start": p.AwayStart,
|
"away_start": p.AwayStart,
|
||||||
"away_end": p.AwayEnd,
|
"away_end": p.AwayEnd,
|
||||||
"block_chat": p.BlockChat,
|
"block_chat": p.BlockChat,
|
||||||
"block_friend_requests": p.BlockFriendRequests,
|
"block_friend_requests": p.BlockFriendRequests,
|
||||||
"notifications_in_app_only": p.NotificationsInAppOnly,
|
|
||||||
}
|
}
|
||||||
err := c.do(ctx, http.MethodPut, "/api/v1/user/profile", userID, "", body, &out)
|
err := c.do(ctx, http.MethodPut, "/api/v1/user/profile", userID, "", body, &out)
|
||||||
return out, err
|
return out, err
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ func encodeProfile(p backendclient.ProfileResp) []byte {
|
|||||||
fb.ProfileAddIsGuest(b, p.IsGuest)
|
fb.ProfileAddIsGuest(b, p.IsGuest)
|
||||||
fb.ProfileAddAwayStart(b, awayStart)
|
fb.ProfileAddAwayStart(b, awayStart)
|
||||||
fb.ProfileAddAwayEnd(b, awayEnd)
|
fb.ProfileAddAwayEnd(b, awayEnd)
|
||||||
fb.ProfileAddNotificationsInAppOnly(b, p.NotificationsInAppOnly)
|
|
||||||
b.Finish(fb.ProfileEnd(b))
|
b.Finish(fb.ProfileEnd(b))
|
||||||
return b.FinishedBytes()
|
return b.FinishedBytes()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -233,14 +233,13 @@ func profileUpdateHandler(backend *backendclient.Client) Handler {
|
|||||||
return func(ctx context.Context, req Request) ([]byte, error) {
|
return func(ctx context.Context, req Request) ([]byte, error) {
|
||||||
in := fb.GetRootAsUpdateProfileRequest(req.Payload, 0)
|
in := fb.GetRootAsUpdateProfileRequest(req.Payload, 0)
|
||||||
p := backendclient.ProfileResp{
|
p := backendclient.ProfileResp{
|
||||||
DisplayName: string(in.DisplayName()),
|
DisplayName: string(in.DisplayName()),
|
||||||
PreferredLanguage: string(in.PreferredLanguage()),
|
PreferredLanguage: string(in.PreferredLanguage()),
|
||||||
TimeZone: string(in.TimeZone()),
|
TimeZone: string(in.TimeZone()),
|
||||||
AwayStart: string(in.AwayStart()),
|
AwayStart: string(in.AwayStart()),
|
||||||
AwayEnd: string(in.AwayEnd()),
|
AwayEnd: string(in.AwayEnd()),
|
||||||
BlockChat: in.BlockChat(),
|
BlockChat: in.BlockChat(),
|
||||||
BlockFriendRequests: in.BlockFriendRequests(),
|
BlockFriendRequests: in.BlockFriendRequests(),
|
||||||
NotificationsInAppOnly: in.NotificationsInAppOnly(),
|
|
||||||
}
|
}
|
||||||
out, err := backend.UpdateProfile(ctx, req.UserID, p)
|
out, err := backend.UpdateProfile(ctx, req.UserID, p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package transcode_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -203,15 +202,11 @@ func TestGcgRoundTrip(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestProfileUpdateRoundTripAway(t *testing.T) {
|
func TestProfileUpdateRoundTripAway(t *testing.T) {
|
||||||
var gotBody map[string]any
|
|
||||||
backend, cleanup := fakeBackend(t, func(w http.ResponseWriter, r *http.Request) {
|
backend, cleanup := fakeBackend(t, func(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method != http.MethodPut || r.URL.Path != "/api/v1/user/profile" {
|
if r.Method != http.MethodPut || r.URL.Path != "/api/v1/user/profile" {
|
||||||
t.Errorf("unexpected %s %q", r.Method, r.URL.Path)
|
t.Errorf("unexpected %s %q", r.Method, r.URL.Path)
|
||||||
}
|
}
|
||||||
_ = json.NewDecoder(r.Body).Decode(&gotBody)
|
_, _ = w.Write([]byte(`{"user_id":"u-1","display_name":"Kaya","preferred_language":"ru","time_zone":"Europe/Moscow","away_start":"00:00","away_end":"07:30"}`))
|
||||||
// Respond with notifications_in_app_only=false to exercise the encode path
|
|
||||||
// carrying a non-default value back to the client.
|
|
||||||
_, _ = w.Write([]byte(`{"user_id":"u-1","display_name":"Kaya","preferred_language":"ru","time_zone":"Europe/Moscow","away_start":"00:00","away_end":"07:30","notifications_in_app_only":false}`))
|
|
||||||
})
|
})
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
@@ -230,7 +225,6 @@ func TestProfileUpdateRoundTripAway(t *testing.T) {
|
|||||||
fb.UpdateProfileRequestAddTimeZone(b, tz)
|
fb.UpdateProfileRequestAddTimeZone(b, tz)
|
||||||
fb.UpdateProfileRequestAddAwayStart(b, as)
|
fb.UpdateProfileRequestAddAwayStart(b, as)
|
||||||
fb.UpdateProfileRequestAddAwayEnd(b, ae)
|
fb.UpdateProfileRequestAddAwayEnd(b, ae)
|
||||||
fb.UpdateProfileRequestAddNotificationsInAppOnly(b, true)
|
|
||||||
b.Finish(fb.UpdateProfileRequestEnd(b))
|
b.Finish(fb.UpdateProfileRequestEnd(b))
|
||||||
|
|
||||||
payload, err := op.Handler(context.Background(), transcode.Request{UserID: "u-1", Payload: b.FinishedBytes()})
|
payload, err := op.Handler(context.Background(), transcode.Request{UserID: "u-1", Payload: b.FinishedBytes()})
|
||||||
@@ -241,12 +235,4 @@ func TestProfileUpdateRoundTripAway(t *testing.T) {
|
|||||||
if string(p.AwayStart()) != "00:00" || string(p.AwayEnd()) != "07:30" || string(p.PreferredLanguage()) != "ru" {
|
if string(p.AwayStart()) != "00:00" || string(p.AwayEnd()) != "07:30" || string(p.PreferredLanguage()) != "ru" {
|
||||||
t.Fatalf("profile away round-trip wrong: start=%q end=%q lang=%q", p.AwayStart(), p.AwayEnd(), p.PreferredLanguage())
|
t.Fatalf("profile away round-trip wrong: start=%q end=%q lang=%q", p.AwayStart(), p.AwayEnd(), p.PreferredLanguage())
|
||||||
}
|
}
|
||||||
// The request's in-app-only flag (true) must reach the backend, and the backend's
|
|
||||||
// value (false) must come back in the encoded Profile.
|
|
||||||
if v, ok := gotBody["notifications_in_app_only"].(bool); !ok || v != true {
|
|
||||||
t.Errorf("forwarded notifications_in_app_only = %v (ok=%v), want true", gotBody["notifications_in_app_only"], ok)
|
|
||||||
}
|
|
||||||
if p.NotificationsInAppOnly() {
|
|
||||||
t.Error("response notifications_in_app_only = true, want false")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user