dispatch_like.go 1.86 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
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 (
  "encoding/xml"
  "github.com/revel/revel"
23
  federation "gopkg.in/ganggo/federation.v0"
24 25
)

26 27
// XXX remove and replace with database sort
const LIKE_SIG_ORDER = "positive guid parent_guid target_type author"
zauberstuhl's avatar
zauberstuhl committed
28

29
func (d *Dispatcher) Like(like *federation.EntityLike) {
zauberstuhl's avatar
zauberstuhl committed
30 31
  authorSig, err := federation.AuthorSignature(
    *like, LIKE_SIG_ORDER, (*d).User.SerializedPrivateKey)
32 33 34 35
  if err != nil {
    revel.ERROR.Println(err)
    return
  }
zauberstuhl's avatar
zauberstuhl committed
36
  (*like).AuthorSignature = authorSig
37

zauberstuhl's avatar
zauberstuhl committed
38 39 40
  // if parent user is local generate a signature
  if d.ParentUser != nil {
    parentAuthorSig, err := federation.AuthorSignature(
zauberstuhl's avatar
zauberstuhl committed
41
      *like, LIKE_SIG_ORDER, d.ParentUser.SerializedPrivateKey)
zauberstuhl's avatar
zauberstuhl committed
42 43 44 45 46
    if err != nil {
      revel.ERROR.Println(err)
      return
    }
    (*like).ParentAuthorSignature = parentAuthorSig
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
  }

  entity := federation.Entity{
    Post: federation.EntityPost{
      Like: like,
    },
  }

  entityXml, err := xml.Marshal(entity)
  if err != nil {
    revel.ERROR.Println(err)
    return
  }

  payload, err := federation.MagicEnvelope(
    (*d).User.SerializedPrivateKey,
63
    like.Author, entityXml,
64 65 66
  )

  // send it to the network
zauberstuhl's avatar
zauberstuhl committed
67
  sendPublic(payload)
68
}