fix: return saved group nickname profile
This commit is contained in:
+14
-6
@@ -4688,7 +4688,7 @@ func serveIMGroupMemberSettings(wrt http.ResponseWriter, req *http.Request, topi
|
|||||||
}
|
}
|
||||||
|
|
||||||
func serveIMGroupMyProfile(wrt http.ResponseWriter, req *http.Request, topic string) {
|
func serveIMGroupMyProfile(wrt http.ResponseWriter, req *http.Request, topic string) {
|
||||||
if req.Method != http.MethodPut {
|
if req.Method != http.MethodPut && req.Method != http.MethodGet {
|
||||||
writeIMError(wrt, req, http.StatusMethodNotAllowed, 30002, imReasonMethodNotAllowed, "method not allowed", nil)
|
writeIMError(wrt, req, http.StatusMethodNotAllowed, 30002, imReasonMethodNotAllowed, "method not allowed", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -4696,6 +4696,19 @@ func serveIMGroupMyProfile(wrt http.ResponseWriter, req *http.Request, topic str
|
|||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
private := groupPrivateMap(selfSub.Private)
|
||||||
|
currentVersion := intFromAny(private["profile_version"])
|
||||||
|
if currentVersion <= 0 {
|
||||||
|
currentVersion = 1
|
||||||
|
}
|
||||||
|
if req.Method == http.MethodGet {
|
||||||
|
writeIMSuccess(wrt, req, map[string]any{
|
||||||
|
"nickname": stringFromAny(private["nickname"]),
|
||||||
|
"version": currentVersion,
|
||||||
|
"updated_at": stringFromAny(private["profile_updated_at"]),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
var body imGroupMemberProfileUpdateRequest
|
var body imGroupMemberProfileUpdateRequest
|
||||||
if !decodeIMJSONBody(wrt, req, &body) {
|
if !decodeIMJSONBody(wrt, req, &body) {
|
||||||
return
|
return
|
||||||
@@ -4705,11 +4718,6 @@ func serveIMGroupMyProfile(wrt http.ResponseWriter, req *http.Request, topic str
|
|||||||
writeIMError(wrt, req, http.StatusBadRequest, 30000, imReasonMalformedRequest, "malformed request", map[string]any{"field": "nickname"})
|
writeIMError(wrt, req, http.StatusBadRequest, 30000, imReasonMalformedRequest, "malformed request", map[string]any{"field": "nickname"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
private := groupPrivateMap(selfSub.Private)
|
|
||||||
currentVersion := intFromAny(private["profile_version"])
|
|
||||||
if currentVersion <= 0 {
|
|
||||||
currentVersion = 1
|
|
||||||
}
|
|
||||||
if body.Version > 0 && body.Version != currentVersion {
|
if body.Version > 0 && body.Version != currentVersion {
|
||||||
writeIMError(wrt, req, http.StatusConflict, 30006, "VERSION_CONFLICT", "version conflict", map[string]any{"current_version": currentVersion})
|
writeIMError(wrt, req, http.StatusConflict, 30006, "VERSION_CONFLICT", "version conflict", map[string]any{"current_version": currentVersion})
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -3835,6 +3835,44 @@ func TestServeIMGroupMyProfileKeepsSubscriptionNicknameWhenBusinessMemberMissing
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestServeIMGroupMyProfileGetReturnsSubscriptionNickname(t *testing.T) {
|
||||||
|
ctrl := gomock.NewController(t)
|
||||||
|
defer ctrl.Finish()
|
||||||
|
expectIMBearer(t, ctrl, "token-1", 7, 42)
|
||||||
|
oldSubs := store.Subs
|
||||||
|
subs := mock_store.NewMockSubsPersistenceInterface(ctrl)
|
||||||
|
store.Subs = subs
|
||||||
|
defer func() {
|
||||||
|
store.Subs = oldSubs
|
||||||
|
}()
|
||||||
|
|
||||||
|
subs.EXPECT().Get(types.TenantID(7), "grpAlpha", types.Uid(42), false).Return(&types.Subscription{
|
||||||
|
TenantID: 7,
|
||||||
|
User: types.Uid(42).String(),
|
||||||
|
Topic: "grpAlpha",
|
||||||
|
ModeWant: types.ModeCFull,
|
||||||
|
ModeGiven: types.ModeCFull,
|
||||||
|
Private: map[string]any{
|
||||||
|
"nickname": "Coffee 备注",
|
||||||
|
"profile_version": 3,
|
||||||
|
"profile_updated_at": "2026-09-03T01:00:00Z",
|
||||||
|
},
|
||||||
|
}, nil)
|
||||||
|
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/v1/im/groups/grpAlpha/members/me/profile", nil)
|
||||||
|
req.Header.Set("Authorization", "Bearer token-1")
|
||||||
|
rec := httptest.NewRecorder()
|
||||||
|
serveIMGroupResource(rec, req)
|
||||||
|
|
||||||
|
if rec.Code != http.StatusOK {
|
||||||
|
t.Fatalf("profile get status: got %d body=%s", rec.Code, rec.Body.String())
|
||||||
|
}
|
||||||
|
data := decodeIMHTTPResponse(t, rec).Data.(map[string]any)
|
||||||
|
if data["nickname"] != "Coffee 备注" || data["version"].(float64) != 3 || data["updated_at"] != "2026-09-03T01:00:00Z" {
|
||||||
|
t.Fatalf("unexpected profile get response: %#v", data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestServeIMGroupLeave(t *testing.T) {
|
func TestServeIMGroupLeave(t *testing.T) {
|
||||||
ctrl := gomock.NewController(t)
|
ctrl := gomock.NewController(t)
|
||||||
defer ctrl.Finish()
|
defer ctrl.Finish()
|
||||||
|
|||||||
Reference in New Issue
Block a user