snow/handlers/friends.go

70 lines
1.9 KiB
Go
Raw Normal View History

2024-01-03 23:25:17 +00:00
package handlers
import (
2024-01-29 23:46:22 +00:00
"fmt"
"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 {
aid.Print(fmt.Sprintf("Error creating relationship: %s", err.Error()))
return c.Status(400).JSON(aid.ErrorBadRequest(err.Error()))
}
2024-01-30 16:34:17 +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
})
from.JabberNotifyFriends()
2024-01-29 23:46:22 +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
})
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 {
return c.SendStatus(204)
}
func GetFriendListSummary(c *fiber.Ctx) error {
return c.Status(200).JSON([]aid.JSON{})
2024-01-03 23:25:17 +00:00
}
func GetPersonSearch(c *fiber.Ctx) error {
return c.Status(200).JSON([]aid.JSON{})
2024-01-03 23:25:17 +00:00
}