Invitations into hosted rooms: the dialog's details, and joining as a public room
CI / build (push) Successful in 34s
CI / build (push) Successful in 34s
The invitation carries the room as the dialog shows it (name, owner, image, occupancy, description) and the inviter's picture, age and gender from IMVU's public profile. Accepting names the room (room_instance_id), so the client joins it as a public room with the invite rather than opening a private chat, and getParticipants before joining asks the hub, so the client sees its inviter there. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
210bc064e9
commit
2df46da3ad
3 files changed
+116
-9
No files matched your search
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -318,6 +319,11 @@ func TestBadgesAndRoomInfo(t *testing.T) {
|
||||
|
||||
func TestPhase2(t *testing.T) {
|
||||
r, h, _ := setup()
|
||||
imvu := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
fmt.Fprintf(w, `{"denormalized": {"https://api.imvu.com/user/user-88": {"data": {"username": "Erin", "age": 30, "gender": "f", "thumbnail_url": "https://x/p.png"}}}}`)
|
||||
}))
|
||||
defer imvu.Close()
|
||||
r.HTTPClient = &http.Client{Transport: rewrite{imvu.URL}}
|
||||
var userMsgs []string
|
||||
r.UserDeliver = func(mount string, b []byte) error { userMsgs = append(userMsgs, mount+" "+string(b)); return nil }
|
||||
call := func(method string, args xmlrpc.Struct) xmlrpc.Value {
|
||||
@@ -350,15 +356,25 @@ func TestPhase2(t *testing.T) {
|
||||
for i := 0; i < 100 && len(userMsgs) == 0; i++ {
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
if len(userMsgs) != 1 || !strings.HasPrefix(userMsgs[0], "web_msg chatInvite ") || !strings.Contains(userMsgs[0], `"location":"88-2100000003"`) || !strings.Contains(userMsgs[0], `"name":"Erin"`) {
|
||||
if len(userMsgs) != 1 || !strings.HasPrefix(userMsgs[0], "web_msg chatInvite ") || !strings.Contains(userMsgs[0], `"room_instance_id":"88-2100000003"`) || !strings.Contains(userMsgs[0], `"maxOccupancy":10`) || !strings.Contains(userMsgs[0], `"gender":"f"`) || !strings.Contains(userMsgs[0], `"name":"Erin"`) {
|
||||
t.Fatalf("invitation %v", userMsgs)
|
||||
}
|
||||
var inv map[string]any
|
||||
json.Unmarshal([]byte(strings.TrimPrefix(userMsgs[0], "web_msg chatInvite ")), &inv)
|
||||
// Before accepting (not in the room), getParticipants says who's in it, so the client sees its inviter there.
|
||||
r.leave(3)
|
||||
if ps := call("chat.getParticipants", xmlrpc.Struct{{Name: "chatId", Value: int64(2100000003)}}); !strings.Contains(fmt.Sprint(ps), "88") {
|
||||
t.Fatalf("participants before joining %v", ps)
|
||||
}
|
||||
accepted := call("chat.acceptInvite", xmlrpc.Struct{{Name: "inviteId", Value: int64(inv["inviteId"].(float64))}, {Name: "chatId", Value: int64(2100000003)}})
|
||||
if get(accepted, "chatId") != int64(2100000003) || h.sentOf("room.invite_reply")[0]["accept"] != true || h.sentOf("room.join")[len(h.sentOf("room.join"))-1]["invite"] != "xyz" {
|
||||
if get(accepted, "room_instance_id") != "88-2100000003" || h.sentOf("room.invite_reply")[0]["accept"] != true {
|
||||
t.Fatalf("accepting: %v, sent %v", accepted, h.sent)
|
||||
}
|
||||
// The client then joins the room, with the invite.
|
||||
xmlrpcCall(t, r, "chat.imvu.com", "chat.getOrMakeChat", xmlrpc.Struct{{Name: "activity", Value: "publicroom-88-2100000003"}})
|
||||
if joins := h.sentOf("room.join"); joins[len(joins)-1]["invite"] != "xyz" {
|
||||
t.Fatalf("join after accepting %v", joins)
|
||||
}
|
||||
|
||||
// Booting: the *boot line also tells the hub; bootOutOfChat is answered here.
|
||||
r.Send("/chat/2100000003", "messages", []byte(`{"message": "*boot 7 88", "userId": 7}`), nil, false)
|
||||
@@ -415,3 +431,13 @@ func TestAppendRoomToEmptyList(t *testing.T) {
|
||||
t.Fatalf("list %s %s %s", list["is_ap"], list["is_vip"], list["name"])
|
||||
}
|
||||
}
|
||||
|
||||
// rewrite sends every request to a test server.
|
||||
type rewrite struct{ to string }
|
||||
|
||||
func (t rewrite) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
u, _ := url.Parse(t.to + req.URL.Path)
|
||||
req = req.Clone(req.Context())
|
||||
req.URL, req.Host = u, u.Host
|
||||
return http.DefaultTransport.RoundTrip(req)
|
||||
}
|
||||
Reference in new issue
Block a user