Commit dd17c83b authored by zauberstuhl's avatar zauberstuhl

wip

parent 544d82ec
Pipeline #1286 failed with stages
......@@ -20,7 +20,7 @@ package controllers
import (
"net/http"
"github.com/revel/revel"
api "git.feneas.org/ganggo/api/app"
//api "git.feneas.org/ganggo/api/app"
"git.feneas.org/ganggo/ganggo/app/models"
federation "git.feneas.org/ganggo/federation"
helpers "git.feneas.org/ganggo/federation/helpers"
......@@ -109,8 +109,8 @@ func (c Webfinger) Webfinger() revel.Result {
federation.WebfingerDataLink {
Rel: "self",
Type: "application/activity+json",
Href: proto + address + "/api/" + api.API_VERSION +
"/ap/user/" + username + "/actor",
Href: proto + address + "/api/" + "v1" +
"/ap/person/" + username + "/actor",
},
federation.WebfingerDataLink {
Rel: "salmon",
......
......@@ -125,7 +125,7 @@ func init() {
federation.SetConfig(federation.Config{
Host: host, ApiVersion: apiVersion,
GuidURLFormat: host + "/posts/%s",
ApURLFormat: host + "/api/" + apiVersion + "/ap/%s",
ApURLFormat: host + "/api/v1/ap/%s",
})
// set custom logger options
......
......@@ -61,6 +61,26 @@ func (dispatcher *Dispatcher) Comment(comment models.Comment) {
endpoint = person.Pod.Inbox
}
post, err := federation.NewMessageComment(person.Pod.Protocol)
if err != nil {
revel.AppLog.Debug("Dispatcher Comment", err.Error(), err)
continue
}
post.SetAuthor(comment.Person.Author)
if !parentPost.Public {
post.SetRecipients(recipients)
}
post.SetText(comment.Text)
post.SetGuid(comment.Guid)
post.SetParent(parentPost.Guid)
post.SetCreatedAt(comment.CreatedAt)
err = post.SetSignature(priv)
if err != nil {
revel.AppLog.Error("Dispatcher Comment", err.Error(), err)
continue
}
var entity federation.MessageBase
if dispatcher.Retract {
retract, err := federation.NewMessageRetract(person.Pod.Protocol)
......@@ -71,27 +91,9 @@ func (dispatcher *Dispatcher) Comment(comment models.Comment) {
retract.SetAuthor(comment.Person.Author)
retract.SetParentType(federation.Comment)
retract.SetParentGuid(comment.Guid)
retract.SetParentMessage(post)
entity = retract
} else {
post, err := federation.NewMessageComment(person.Pod.Protocol)
if err != nil {
revel.AppLog.Debug("Dispatcher Comment", err.Error(), err)
continue
}
post.SetAuthor(comment.Person.Author)
if !parentPost.Public {
post.SetRecipients(recipients)
}
post.SetText(comment.Text)
post.SetGuid(comment.Guid)
post.SetParent(parentPost.Guid)
post.SetCreatedAt(comment.CreatedAt)
err = post.SetSignature(priv)
if err != nil {
revel.AppLog.Error("Dispatcher Comment", err.Error(), err)
continue
}
entity = post
}
......
......@@ -56,7 +56,7 @@ func (dispatcher *Dispatcher) Contact(contact models.AspectMembership) {
}
entity.SetAuthor(dispatcher.User.Person.Author)
entity.SetRecipient(person.Author)
entity.SetSharing(true)
entity.SetSharing(!dispatcher.Retract)
// send and retry if it fails the first time
run.Now(RetryOnFail{
......
......@@ -57,6 +57,21 @@ func (dispatcher *Dispatcher) Like(like models.Like) {
endpoint = person.Pod.Inbox
}
post, err := federation.NewMessageLike(person.Pod.Protocol)
if err != nil {
revel.AppLog.Error("Dispatcher Like", err.Error(), err)
return
}
post.SetAuthor(dispatcher.User.Person.Author)
post.SetGuid(like.Guid)
post.SetPositive(like.Positive)
post.SetParent(parentPost.Guid)
err = post.SetSignature(priv)
if err != nil {
revel.AppLog.Error("Dispatcher Like", err.Error(), err)
continue
}
var entity federation.MessageBase
if dispatcher.Retract {
retract, err := federation.NewMessageRetract(person.Pod.Protocol)
......@@ -67,22 +82,9 @@ func (dispatcher *Dispatcher) Like(like models.Like) {
retract.SetAuthor(dispatcher.User.Person.Author)
retract.SetParentType(federation.Like)
retract.SetParentGuid(like.Guid)
retract.SetParentMessage(post)
entity = retract
} else {
post, err := federation.NewMessageLike(person.Pod.Protocol)
if err != nil {
revel.AppLog.Error("Dispatcher Like", err.Error(), err)
return
}
post.SetAuthor(dispatcher.User.Person.Author)
post.SetGuid(like.Guid)
post.SetPositive(like.Positive)
post.SetParent(parentPost.Guid)
err = post.SetSignature(priv)
if err != nil {
revel.AppLog.Error("Dispatcher Like", err.Error(), err)
continue
}
entity = post
}
......
......@@ -61,17 +61,7 @@ func (dispatcher *Dispatcher) StatusMessage(post models.Post) {
}
var entity federation.MessageBase
if dispatcher.Retract {
msg, err := federation.NewMessageRetract(person.Pod.Protocol)
if err != nil {
revel.AppLog.Error("Dispatcher StatusMessage", err.Error(), err)
return
}
msg.SetAuthor(post.Person.Author)
msg.SetParentType(federation.StatusMessage)
msg.SetParentGuid(post.Guid)
entity = msg
} else if post.Type == models.StatusMessage {
if post.Type == models.StatusMessage {
msg, err := federation.NewMessagePost(person.Pod.Protocol)
if err != nil {
revel.AppLog.Error("Dispatcher StatusMessage", err.Error(), err)
......@@ -106,7 +96,21 @@ func (dispatcher *Dispatcher) StatusMessage(post models.Post) {
msg.SetCreatedAt(post.CreatedAt)
entity = msg
} else {
panic("Something went wrong!")
revel.AppLog.Error("Dispatcher StatusMessage unkown post type!!")
continue
}
if dispatcher.Retract {
msg, err := federation.NewMessageRetract(person.Pod.Protocol)
if err != nil {
revel.AppLog.Error("Dispatcher StatusMessage", err.Error(), err)
continue
}
msg.SetAuthor(post.Person.Author)
msg.SetParentType(federation.StatusMessage)
msg.SetParentGuid(post.Guid)
msg.SetParentMessage(entity)
entity = msg
}
// send and retry if it fails the first time
......
......@@ -18,15 +18,15 @@ package jobs
//
import (
"fmt"
"net/http"
// "fmt"
// "net/http"
"github.com/revel/revel"
"git.feneas.org/ganggo/ganggo/app/helpers"
"git.feneas.org/ganggo/ganggo/app/models"
federation "git.feneas.org/ganggo/federation"
fhelpers "git.feneas.org/ganggo/federation/helpers"
api "git.feneas.org/ganggo/api/app"
"bytes"
// fhelpers "git.feneas.org/ganggo/federation/helpers"
// api "git.feneas.org/ganggo/api/app"
// "bytes"
)
func (receiver *Receiver) Contact(entity federation.MessageContact) {
......@@ -70,59 +70,59 @@ func (receiver *Receiver) Contact(entity federation.MessageContact) {
// NOTE ActivityPub needs an accept response
// XXX how can we integrate this in the federation lib?
if entity.Type().Proto == federation.ActivityPubProtocol {
if follow, ok := entity.(*federation.ActivityPubFollow); ok {
var user models.User
var person models.Person
err = user.FindByID(contact.UserID)
if err != nil {
revel.AppLog.Error(err.Error())
return
}
//if entity.Type().Proto == federation.ActivityPubProtocol {
// if follow, ok := entity.(*federation.ActivityPubFollow); ok {
// var user models.User
// var person models.Person
// err = user.FindByID(contact.UserID)
// if err != nil {
// revel.AppLog.Error(err.Error())
// return
// }
err = person.FindByID(contact.PersonID)
if err != nil {
revel.AppLog.Error(err.Error())
return
}
// err = person.FindByID(contact.PersonID)
// if err != nil {
// revel.AppLog.Error(err.Error())
// return
// }
actor := fmt.Sprintf("%s%s/api/%s/ap/user/%s/actor",
api.PROTO, api.ADDRESS, api.API_VERSION, user.Username)
accept := &federation.ActivityPubAccept{
ActivityPubContext: federation.ActivityPubContext{
ActivityPubBase: federation.ActivityPubBase{
Id: actor, Type: federation.ActivityTypeAccept,
},
},
Actor: actor,
Object: *follow,
}
entityXml, err := accept.Marshal(nil, nil)
if err != nil {
revel.AppLog.Error(err.Error())
return
}
// actor := fmt.Sprintf("%s%s/api/%s/ap/user/%s/actor",
// api.PROTO, api.ADDRESS, api.API_VERSION, user.Username)
// accept := &federation.ActivityPubAccept{
// ActivityPubContext: federation.ActivityPubContext{
// ActivityPubBase: federation.ActivityPubBase{
// Id: actor, Type: federation.ActivityTypeAccept,
// },
// },
// Actor: actor,
// Object: *follow,
// }
// entityXml, err := accept.Marshal(nil, nil)
// if err != nil {
// revel.AppLog.Error(err.Error())
// return
// }
header := http.Header{
"Content-Type": []string{federation.CONTENT_TYPE_JSON},
}
// header := http.Header{
// "Content-Type": []string{federation.CONTENT_TYPE_JSON},
// }
privKey, err := fhelpers.ParseRSAPrivateKey(
[]byte(user.SerializedPrivateKey))
if err != nil {
revel.AppLog.Error(err.Error())
return
}
// privKey, err := fhelpers.ParseRSAPrivateKey(
// []byte(user.SerializedPrivateKey))
// if err != nil {
// revel.AppLog.Error(err.Error())
// return
// }
client := (&federation.HttpClient{}).New(actor, privKey)
err = client.Push(person.Inbox, header, bytes.NewBuffer(entityXml))
if err != nil {
revel.AppLog.Error(err.Error())
return
}
} else {
revel.AppLog.Error("Cannot cast to EntityFollow!")
return
}
}
// client := (&federation.HttpClient{}).New(actor, privKey)
// err = client.Push(person.Inbox, header, bytes.NewBuffer(entityXml))
// if err != nil {
// revel.AppLog.Error(err.Error())
// return
// }
// } else {
// revel.AppLog.Error("Cannot cast to EntityFollow!")
// return
// }
//}
}
......@@ -43,6 +43,36 @@ type Person struct {
Pod Pod `json:",omitempty"`
}
type People []Person
func (people *People) FindByLocalPost(post Post) error {
var visibility AspectVisibility
err := visibility.FindByPost(post)
if err != nil {
return err
}
var aspect Aspect
err = aspect.FindByID(visibility.AspectID)
if err != nil {
return err
}
for _, member := range aspect.Memberships {
var person Person
err = person.FindByID(member.PersonID)
if err != nil {
continue
}
// skip if not reachable
if !person.Pod.Alive {
continue
}
*people = append(*people, person)
}
return nil
}
// load relations on default
func (person *Person) AfterFind(db *gorm.DB) error {
if structLoaded(person.Profile.CreatedAt) {
......
......@@ -406,7 +406,7 @@ func (post *Post) FindByIDAndUser(id uint, user User) (err error) {
return query.Find(post).Error
}
func (post *Post) FindByGuid(guid string) (err error) { BACKEND_ONLY()
func (post *Post) FindByGuid(guid string) (err error) {
db, err := OpenDatabase()
if err != nil {
return err
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment