Commit f8f2f3d8 authored by zauberstuhl's avatar zauberstuhl

Move saving posts to API

related to ganggo#6
parent 288aec38
......@@ -93,6 +93,9 @@ func (l ApiLike) Create() revel.Result {
User: user,
Message: entityLike,
}
// NOTE the user table should start with 1
// a null check would be better in respect of
// multiple database support
if user.Person.UserID > 0 {
var parentUser models.User
err = parentUser.FindByID(user.Person.UserID)
......
......@@ -18,7 +18,9 @@ package controllers
//
import (
"time"
"github.com/revel/revel"
"gopkg.in/ganggo/api.v0/app/helpers"
"gopkg.in/ganggo/ganggo.v0/app/models"
"gopkg.in/ganggo/ganggo.v0/app/jobs"
federation "gopkg.in/ganggo/federation.v0"
......@@ -45,8 +47,12 @@ func (p ApiPost) Index() revel.Result {
}
func (p ApiPost) Create() revel.Result {
var post string
p.Params.Bind(&post, "post")
var (
post models.Post
postText string
)
p.Params.Bind(&postText, "post")
user, err := models.GetCurrentUser(p.Session["TOKEN"])
if err != nil {
......@@ -54,11 +60,32 @@ func (p ApiPost) Create() revel.Result {
return p.RenderError(err)
}
// create post
guid, err := helpers.Uuid()
if err != nil {
revel.ERROR.Println(err)
return p.RenderError(err)
}
entity := federation.EntityStatusMessage{
RawMessage: postText,
DiasporaHandle: user.Person.DiasporaHandle,
Guid: guid,
CreatedAt: time.Now().UTC(),
ProviderName: "GangGo",
Public: true,
}
// save post locally
err = post.Create(&entity, nil)
if err != nil {
revel.ERROR.Println(err)
return p.RenderError(err)
}
dispatcher := jobs.Dispatcher{
User: user,
Message: federation.EntityStatusMessage{
RawMessage: post,
},
Message: &entity,
}
go dispatcher.Run()
......
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