clean up the one or many arrays a little

This commit is contained in:
Ted Unangst 2023-07-30 13:08:53 -04:00
parent a7adc79f20
commit bed7d662bb
1 changed files with 18 additions and 25 deletions

View File

@ -468,19 +468,12 @@ func newphone(a []string, obj junk.Junk) []string {
}
func extractattrto(obj junk.Junk) string {
who, _ := obj.GetString("attributedTo")
if who != "" {
return who
}
o, ok := obj.GetMap("attributedTo")
if ok {
id, ok := o.GetString("id")
if ok {
return id
}
}
arr, _ := obj.GetArray("attributedTo")
arr := oneforall(obj, "attributedTo")
for _, a := range arr {
s, ok := a.(string)
if ok {
return s
}
o, ok := a.(junk.Junk)
if ok {
t, _ := o.GetString("type")
@ -489,14 +482,21 @@ func extractattrto(obj junk.Junk) string {
return id
}
}
s, ok := a.(string)
if ok {
return s
}
}
return ""
}
func oneforall(obj junk.Junk, key string) []interface{} {
if val, ok := obj.GetMap(key); ok {
return []interface{}{val}
}
if str, ok := obj.GetString(key); ok {
return []interface{}{str}
}
arr, _ := obj.GetArray(key)
return arr
}
func firstofmany(obj junk.Junk, key string) string {
if val, _ := obj.GetString(key); val != "" {
return val
@ -958,7 +958,7 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
}
}
if !preferorig {
atts, _ := obj.GetArray("attachment")
atts := oneforall(obj, "attachment")
for _, atti := range atts {
att, ok := atti.(junk.Junk)
if !ok {
@ -967,9 +967,6 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
}
procatt(att)
}
if att, ok := obj.GetMap("attachment"); ok {
procatt(att)
}
}
proctag := func(tag junk.Junk) {
tt, _ := tag.GetString("type")
@ -1016,7 +1013,7 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
mentions = append(mentions, m)
}
}
tags, _ := obj.GetArray("tag")
tags := oneforall(obj, "tag")
for _, tagi := range tags {
tag, ok := tagi.(junk.Junk)
if !ok {
@ -1024,10 +1021,6 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
}
proctag(tag)
}
tag, ok := obj.GetMap("tag")
if ok {
proctag(tag)
}
if starttime, ok := obj.GetString("startTime"); ok {
if start, err := time.Parse(time.RFC3339, starttime); err == nil {
t := new(Time)