Fix friends for seasons 11+

This commit is contained in:
Eccentric 2024-02-04 16:01:24 +00:00
parent 615a53d1ba
commit 495e450a3c
4 changed files with 56 additions and 4 deletions

View File

@ -793,11 +793,11 @@ func clientGiftCatalogEntryAction(c *fiber.Ctx, person *p.Person, profile *p.Pro
socket, ok := socket.JabberSockets.Get(receiverPerson.ID)
if ok {
socket.Write(aid.JSONToBytes(aid.JSON{
socket.JabberSendMessageToPerson(aid.JSON{
"payload": aid.JSON{},
"type": "com.epicgames.gift.received",
"timestamp": time.Now().Format("2006-01-02T15:04:05.999Z"),
}))
})
}
}

View File

@ -62,7 +62,40 @@ func DeleteFriend(c *fiber.Ctx) error {
}
func GetFriendListSummary(c *fiber.Ctx) error {
return c.Status(200).JSON([]aid.JSON{})
person := c.Locals("person").(*p.Person)
summary := aid.JSON{
"friends": []aid.JSON{},
"blocklist": []aid.JSON{},
"incoming": []aid.JSON{},
"outgoing": []aid.JSON{},
"suggested": []aid.JSON{},
}
person.Relationships.Range(func(key string, value *p.Relationship) bool {
switch value.Direction {
case p.RelationshipInboundDirection:
res := value.GenerateFortniteSummaryEntry(p.GenerateTypeTowardsPerson)
if value.Status == "ACCEPTED" {
summary["friends"] = append(summary["friends"].([]aid.JSON), res)
break
}
summary["incoming"] = append(summary["incoming"].([]aid.JSON), res)
case p.RelationshipOutboundDirection:
res := value.GenerateFortniteSummaryEntry(p.GenerateTypeFromPerson)
if value.Status == "ACCEPTED" {
summary["friends"] = append(summary["friends"].([]aid.JSON), res)
break
}
summary["outgoing"] = append(summary["outgoing"].([]aid.JSON), res)
}
return true
})
return c.Status(200).JSON(summary)
}
func GetPersonSearch(c *fiber.Ctx) error {

View File

@ -120,7 +120,7 @@ func main() {
friends.Post("/public/friends/:accountId/:wanted", handlers.PostCreateFriend)
friends.Delete("/public/friends/:accountId/:wanted", handlers.DeleteFriend)
friends.Get("/:version/:accountId/summary", handlers.GetFriendListSummary)
friends.Get("/:version/:accountId/friends/:wanted", handlers.PostCreateFriend)
friends.Post("/:version/:accountId/friends/:wanted", handlers.PostCreateFriend)
game := fortnite.Group("/game/v2")
game.Get("/enabled_features", handlers.GetGameEnabledFeatures)

View File

@ -50,6 +50,25 @@ func (r *Relationship) GenerateFortniteFriendEntry(t RelationshipGenerateType) a
return result
}
func (r *Relationship) GenerateFortniteSummaryEntry(t RelationshipGenerateType) aid.JSON {
result := aid.JSON{
"created": time.Now().Add(-time.Hour * 24 * 3).Format(time.RFC3339),
"favorite": false,
"groups": []string{},
"mutual": 0,
"note": "",
}
switch t {
case GenerateTypeFromPerson:
result["accountId"] = r.Towards.ID
case GenerateTypeTowardsPerson:
result["accountId"] = r.From.ID
}
return result
}
func (r *Relationship) Save() (*Relationship, error) {
storage.Repo.Storage.SaveRelationship(r.ToDatabase())
r.From.Relationships.Set(r.Towards.ID, r)