Commit 934cf4dd authored by Lukas Matt's avatar Lukas Matt

wip

parent b3ac680a
package jobs
//
// GangGo Application Server
// Copyright (C) 2017 Lukas Matt <lukas@zauberstuhl.de>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
import (
federation "gopkg.in/ganggo/federation.v0"
run "github.com/revel/modules/jobs/app/jobs"
"github.com/revel/revel"
"gopkg.in/ganggo/ganggo.v0/app/models"
)
type Helo struct {}
// Run tries to start sharing with unknown servers
func (h Helo) Run() {
var pods models.Pods
err := pods.FindByHelo(false)
if err != nil {
revel.AppLog.Error(err.Error())
return
}
var user models.User
err = user.FindByUsername("hq")
if err != nil {
revel.AppLog.Error(err.Error())
return
}
for _, pod := range pods {
var person models.Person
err = person.FirstByPod(pod)
if err != nil {
revel.AppLog.Error(err.Error())
continue
}
//XXX x-social-relay
run.Now(Dispatcher{
User: user,
Message: federation.EntityContact{
Author: user.Person.Author,
Recipient: person.Author,
Sharing: true,
Following: true,
},
})
}
}
......@@ -78,3 +78,13 @@ func (person *Person) FindByAuthor(author string) (err error) {
return db.Where("author = ?", author).First(person).Error
}
func (person *Person) FirstByPod(pod Pod) error {
db, err := OpenDatabase()
if err != nil {
return err
}
defer db.Close()
return db.Where("pod_id = ?", pod.ID).First(person).Error
}
......@@ -74,3 +74,13 @@ func (pods *Pods) FindAll() (err error) { BACKEND_ONLY()
return db.Find(pods).Error
}
func (pods *Pods) FindByHelo(helo bool) error { BACKEND_ONLY()
db, err := OpenDatabase()
if err != nil {
return err
}
defer db.Close()
return db.Where("helo = ?", helo).Find(pods).Error
}
......@@ -20,6 +20,7 @@ package models
import (
"github.com/revel/revel"
"gopkg.in/ganggo/gorm.v2"
"gopkg.in/ganggo/ganggo.v0/app/helpers"
)
type SchemaMigration struct {
......@@ -73,6 +74,28 @@ func migrateSchema(db *gorm.DB) error {
//// Migrations End ////
// for reasons described in PR ganggo/ganggo#46 we need a
// default user account which can auto-follow unknown server
commit = "create_initial_user_account"
if _, ok := migrations[commit]; !ok {
password, err := helpers.Uuid()
if err != nil {
panic(err.Error())
}
db.Create(&User{
Password: password,
Username: "hq",
Person: Person {
Profile: Profile{
Searchable: true,
ImageUrl: "/public/img/avatar.png",
},
},
})
structMigrations = append(structMigrations, SchemaMigration{Commit: commit})
}
for _, m := range structMigrations {
err = db.Create(&m).Error
if err != nil {
......
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