correct type names for AP

This commit is contained in:
Iris Lightshard 2024-12-01 16:26:12 -07:00
parent 64d00083b7
commit cae8c8b597
Signed by: Iris Lightshard
GPG key ID: 688407174966CAF3

View file

@ -68,7 +68,7 @@ func (self *apOutbox) UnmarshalJSON(b []byte) error {
}
for _, raw := range self.RawOrderedItems {
var i apOutboxItem
var i apActivity
err := json.Unmarshal(raw, &i)
var x interface{}
@ -76,9 +76,9 @@ func (self *apOutbox) UnmarshalJSON(b []byte) error {
case "Create":
fallthrough
case "Update":
x = &apOutboxItemCreateUpdate{}
x = &apCreateUpdateActivity{}
case "Announce":
x = &apOutboxItemAnnounce{}
x = &apAnnounceActivity{}
}
err = json.Unmarshal(raw, &x)
if err != nil {
@ -89,7 +89,7 @@ func (self *apOutbox) UnmarshalJSON(b []byte) error {
return nil
}
type apOutboxItem struct {
type apActivity struct {
Actor string
Id string
Type string
@ -97,17 +97,17 @@ type apOutboxItem struct {
Published string
}
type apOutboxItemCreateUpdate struct {
Object apActivity
apOutboxItem
type apCreateUpdateActivity struct {
Object apObject
apActivity
}
type apOutboxItemAnnounce struct {
type apAnnounceActivity struct {
Object string
apOutboxItem
apActivity
}
type apActivity struct {
type apObject struct {
Id string
Content string
AttributedTo string
@ -154,32 +154,32 @@ func (self *anonAPAdapter) makeApRequest(method, url string, data io.Reader) (*h
return self.client.Do(req)
}
func (self *anonAPAdapter) toMsg(activity apActivity) *models.Message {
t, err := time.Parse(time.RFC3339, activity.Published)
func (self *anonAPAdapter) toMsg(object apObject) *models.Message {
t, err := time.Parse(time.RFC3339, object.Published)
if err != nil {
t = time.Now()
}
vis := strings.Split(activity.To, "#")
vis := strings.Split(object.To, "#")
if len(vis) > 1 {
activity.To = vis[1]
object.To = vis[1]
}
m := &models.Message{
Datagram: models.Datagram{
Id: activity.Id,
Uri: activity.Url,
Id: object.Id,
Uri: object.Url,
Type: "message",
Created: t.UnixMilli(),
Updated: nil,
Protocol: self.protocol,
Adapter: self.nickname,
},
Author: activity.AttributedTo,
Content: activity.Content,
ReplyTo: activity.InReplyTo,
Visibility: activity.To,
Author: object.AttributedTo,
Content: object.Content,
ReplyTo: object.InReplyTo,
Visibility: object.To,
}
for _, a := range activity.Attachment {
for _, a := range object.Attachment {
m.Attachments = append(m.Attachments, models.Attachment{
Src: a.Url,
Desc: a.Summary,
@ -276,21 +276,21 @@ func (self *anonAPAdapter) Fetch(etype string, ids []string) error {
ob.UnmarshalJSON(obData)
for _, i := range ob.OrderedItems {
switch a := i.(type) {
case *apOutboxItemCreateUpdate:
case *apCreateUpdateActivity:
msg := self.toMsg(a.Object)
if msg != nil {
self.send(msg)
}
case *apOutboxItemAnnounce:
case *apAnnounceActivity:
res, err = self.makeApRequest("GET", a.Object, nil)
if err != nil {
return err
}
fmt.Println(a.Object)
activityData := getBodyJson(res)
activity := apActivity{}
json.Unmarshal(activityData, &activity)
ogMsg := self.toMsg(activity)
objectData := getBodyJson(res)
object := apObject{}
json.Unmarshal(objectData, &object)
ogMsg := self.toMsg(object)
if ogMsg != nil {
self.send(ogMsg)
}
@ -326,10 +326,10 @@ func (self *anonAPAdapter) Fetch(etype string, ids []string) error {
if err != nil {
return err
}
activityData := getBodyJson(res)
activity := apActivity{}
json.Unmarshal(activityData, &activity)
message := self.toMsg(activity)
objectData := getBodyJson(res)
object := apObject{}
json.Unmarshal(objectData, &object)
message := self.toMsg(object)
if message != nil {
self.send(message)
}