diff --git a/handlers/client.go b/handlers/client.go index f666153..e58c347 100644 --- a/handlers/client.go +++ b/handlers/client.go @@ -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"), - })) + }) } } diff --git a/handlers/friends.go b/handlers/friends.go index e439f1d..06c41c6 100644 --- a/handlers/friends.go +++ b/handlers/friends.go @@ -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 { diff --git a/main.go b/main.go index b5df41d..00791ff 100644 --- a/main.go +++ b/main.go @@ -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) diff --git a/person/relationships.go b/person/relationships.go index 4811c7c..6920006 100644 --- a/person/relationships.go +++ b/person/relationships.go @@ -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)