Add deleting friends

This commit is contained in:
Eccentric 2024-02-10 02:27:42 +00:00
parent 0951a63bfe
commit 6fc1694930
3 changed files with 47 additions and 0 deletions

View File

@ -56,6 +56,36 @@ func PostCreateFriend(c *fiber.Ctx) error {
}
func DeleteFriend(c *fiber.Ctx) error {
person := c.Locals("person").(*p.Person)
relationship, found := person.Relationships.Get(c.Params("wanted"))
if !found {
return c.Status(404).JSON(aid.ErrorNotFound)
}
from, found := socket.JabberSockets.Get(relationship.From.ID)
if found {
from.JabberSendMessageToPerson(aid.JSON{
"type": "com.epicgames.friends.core.apiobjects.FriendRemoval",
"timestamp": time.Now().Format(time.RFC3339),
"payload": relationship.GenerateFortniteFriendRemovalEntry(p.GenerateTypeFromPerson),
})
from.JabberNotifyFriends()
}
towards, found := socket.JabberSockets.Get(relationship.Towards.ID)
if found {
towards.JabberSendMessageToPerson(aid.JSON{
"type": "com.epicgames.friends.core.apiobjects.FriendRemoval",
"timestamp": time.Now().Format(time.RFC3339),
"payload": relationship.GenerateFortniteFriendRemovalEntry(p.GenerateTypeTowardsPerson),
})
towards.JabberNotifyFriends()
}
relationship.Delete()
person.Relationships.Delete(c.Params("friend"))
return c.SendStatus(204)
}

View File

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

View File

@ -50,6 +50,22 @@ func (r *Relationship) GenerateFortniteFriendEntry(t RelationshipGenerateType) a
return result
}
func (r *Relationship) GenerateFortniteFriendRemovalEntry(t RelationshipGenerateType) aid.JSON {
result := aid.JSON{
"reason": "DELETED",
}
switch t {
case GenerateTypeFromPerson:
result["accountId"] = r.Towards.ID
case GenerateTypeTowardsPerson:
result["accountId"] = r.From.ID
}
return result
}
func (r *Relationship) GenerateFortniteSummaryEntry(t RelationshipGenerateType) aid.JSON {
result := aid.JSON{
"created": time.Now().Add(-time.Hour * 24 * 3).Format(time.RFC3339),