Unverified Commit 4de305d6 authored by Simon Esposito's avatar Simon Esposito Committed by GitHub
Browse files

Fix js runtime fields returned by listFriends (#633)

parent a3aabef0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
- Correctly set party ID in matchmaker matched callback input.
- Party close messages sent as expected.
- Fix TypeScript/JavaScript match dispatcher presence list validation.
- Fix JavaScript/Lua friendsList incorrect returned values.

## [3.3.0] - 2021-05-17
### Added
+3 −35
Original line number Diff line number Diff line
@@ -5554,45 +5554,13 @@ func (n *runtimeJavascriptNakamaModule) friendsList(r *goja.Runtime) func(goja.F

		userFriends := make([]interface{}, 0, len(friends.Friends))
		for _, f := range friends.Friends {
			fu := f.User

			fum := make(map[string]interface{}, 14)

			fum["id"] = fu.Id
			fum["username"] = fu.Username
			if fu.AppleId != "" {
				fum["apple_id"] = fu.AppleId
			}
			if fu.FacebookId != "" {
				fum["facebook_id"] = fu.FacebookId
			}
			if fu.FacebookInstantGameId != "" {
				fum["facebook_instant_game_id"] = fu.FacebookInstantGameId
			}
			if fu.GoogleId != "" {
				fum["google_id"] = fu.GoogleId
			}
			if fu.GamecenterId != "" {
				fum["gamecenter_id"] = fu.GamecenterId
			}
			if fu.SteamId != "" {
				fum["steam_id"] = fu.SteamId
			}
			fum["online"] = fu.Online
			fum["edge_count"] = fu.EdgeCount
			fum["create_time"] = fu.CreateTime.Seconds
			fum["update_time"] = fu.UpdateTime.Seconds

			metadataMap := make(map[string]interface{})
			err = json.Unmarshal([]byte(fu.Metadata), &metadataMap)
			fum, err := getJsUserData(f.User)
			if err != nil {
				panic(r.NewGoError(fmt.Errorf("failed to convert metadata to json: %s", err.Error())))
				panic(r.NewGoError(err))
			}
			pointerizeSlices(metadataMap)
			fum["metadata"] = metadataMap

			fm := make(map[string]interface{}, 3)
			fm["state"] = f.State
			fm["state"] = f.State.Value
			fm["update_time"] = f.UpdateTime.Seconds
			fm["user"] = fum

+2 −31
Original line number Diff line number Diff line
@@ -7358,40 +7358,11 @@ func (n *RuntimeLuaNakamaModule) friendsList(l *lua.LState) int {
	for i, f := range friends.Friends {
		u := f.User

		fut := l.CreateTable(0, 13)
		fut.RawSetString("id", lua.LString(u.Id))
		fut.RawSetString("username", lua.LString(u.Username))
		if u.AppleId != "" {
			fut.RawSetString("apple_id", lua.LString(u.AppleId))
		}
		if u.FacebookId != "" {
			fut.RawSetString("facebook_id", lua.LString(u.FacebookId))
		}
		if u.FacebookInstantGameId != "" {
			fut.RawSetString("facebook_instant_game_id", lua.LString(u.FacebookInstantGameId))
		}
		if u.GoogleId != "" {
			fut.RawSetString("google_id", lua.LString(u.GoogleId))
		}
		if u.GamecenterId != "" {
			fut.RawSetString("gamecenter_id", lua.LString(u.GamecenterId))
		}
		if u.SteamId != "" {
			fut.RawSetString("steam_id", lua.LString(u.SteamId))
		}
		fut.RawSetString("online", lua.LBool(u.Online))
		fut.RawSetString("edge_count", lua.LNumber(u.EdgeCount))
		fut.RawSetString("create_time", lua.LNumber(u.CreateTime.Seconds))
		fut.RawSetString("update_time", lua.LNumber(u.UpdateTime.Seconds))

		metadataMap := make(map[string]interface{})
		err = json.Unmarshal([]byte(u.Metadata), &metadataMap)
		fut, err := userToLuaTable(l, u)
		if err != nil {
			l.RaiseError(fmt.Sprintf("failed to convert metadata to json: %s", err.Error()))
			l.RaiseError(fmt.Sprintf("failed to convert user data to lua table: %s", err.Error()))
			return 0
		}
		metadataTable := RuntimeLuaConvertMap(l, metadataMap)
		fut.RawSetString("metadata", metadataTable)

		ft := l.CreateTable(0, 3)
		ft.RawSetString("state", lua.LNumber(f.State.Value))