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