2024-01-03 23:25:17 +00:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
2024-01-29 23:46:22 +00:00
|
|
|
"time"
|
|
|
|
|
2024-01-03 23:25:17 +00:00
|
|
|
"github.com/ectrc/snow/aid"
|
2024-01-29 23:46:22 +00:00
|
|
|
p "github.com/ectrc/snow/person"
|
|
|
|
"github.com/ectrc/snow/socket"
|
2024-01-03 23:25:17 +00:00
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func GetFriendList(c *fiber.Ctx) error {
|
2024-01-29 23:46:22 +00:00
|
|
|
person := c.Locals("person").(*p.Person)
|
|
|
|
result := []aid.JSON{}
|
|
|
|
|
2024-01-30 16:34:17 +00:00
|
|
|
person.Relationships.Range(func(key string, value *p.Relationship) bool {
|
|
|
|
switch value.Direction {
|
|
|
|
case p.RelationshipInboundDirection:
|
|
|
|
result = append(result, value.GenerateFortniteFriendEntry(p.GenerateTypeTowardsPerson))
|
|
|
|
case p.RelationshipOutboundDirection:
|
|
|
|
result = append(result, value.GenerateFortniteFriendEntry(p.GenerateTypeFromPerson))
|
|
|
|
}
|
2024-01-29 23:46:22 +00:00
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
|
|
|
return c.Status(200).JSON(result)
|
2024-01-03 23:25:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func PostCreateFriend(c *fiber.Ctx) error {
|
2024-01-30 16:34:17 +00:00
|
|
|
relationship, err := c.Locals("person").(*p.Person).CreateRelationship(c.Params("wanted"))
|
2024-01-29 23:46:22 +00:00
|
|
|
if err != nil {
|
|
|
|
return c.Status(400).JSON(aid.ErrorBadRequest(err.Error()))
|
|
|
|
}
|
2024-01-30 16:34:17 +00:00
|
|
|
|
2024-01-31 00:16:57 +00:00
|
|
|
from, found := socket.JabberSockets.Get(relationship.From.ID)
|
2024-01-29 23:46:22 +00:00
|
|
|
if found {
|
2024-01-30 16:34:17 +00:00
|
|
|
from.JabberSendMessageToPerson(aid.JSON{
|
2024-01-29 23:46:22 +00:00
|
|
|
"type": "com.epicgames.friends.core.apiobjects.Friend",
|
|
|
|
"timestamp": time.Now().Format(time.RFC3339),
|
2024-01-30 16:34:17 +00:00
|
|
|
"payload": relationship.GenerateFortniteFriendEntry(p.GenerateTypeFromPerson),
|
2024-01-29 23:46:22 +00:00
|
|
|
})
|
2024-01-31 00:16:57 +00:00
|
|
|
from.JabberNotifyFriends()
|
2024-01-29 23:46:22 +00:00
|
|
|
}
|
|
|
|
|
2024-01-31 00:16:57 +00:00
|
|
|
towards, found := socket.JabberSockets.Get(relationship.Towards.ID)
|
2024-01-29 23:46:22 +00:00
|
|
|
if found {
|
2024-01-30 16:34:17 +00:00
|
|
|
towards.JabberSendMessageToPerson(aid.JSON{
|
2024-01-29 23:46:22 +00:00
|
|
|
"type": "com.epicgames.friends.core.apiobjects.Friend",
|
|
|
|
"timestamp": time.Now().Format(time.RFC3339),
|
2024-01-30 16:34:17 +00:00
|
|
|
"payload": relationship.GenerateFortniteFriendEntry(p.GenerateTypeTowardsPerson),
|
2024-01-29 23:46:22 +00:00
|
|
|
})
|
2024-01-31 00:16:57 +00:00
|
|
|
towards.JabberNotifyFriends()
|
2024-01-29 23:46:22 +00:00
|
|
|
}
|
|
|
|
|
2024-01-03 23:25:17 +00:00
|
|
|
return c.SendStatus(204)
|
|
|
|
}
|
|
|
|
|
|
|
|
func DeleteFriend(c *fiber.Ctx) error {
|
2024-02-10 02:27:42 +00:00
|
|
|
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"))
|
|
|
|
|
2024-01-03 23:25:17 +00:00
|
|
|
return c.SendStatus(204)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetFriendListSummary(c *fiber.Ctx) error {
|
2024-02-04 16:01:24 +00:00
|
|
|
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)
|
2024-01-03 23:25:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetPersonSearch(c *fiber.Ctx) error {
|
2024-01-28 19:40:45 +00:00
|
|
|
return c.Status(200).JSON([]aid.JSON{})
|
2024-01-03 23:25:17 +00:00
|
|
|
}
|