Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using FedBOX as storage backend through C2S ActivityPub #25

Merged
merged 93 commits into from
Nov 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
7874b46
First step into removing API package
mariusor Aug 25, 2019
e8d7d04
Update some activitypub and activitystreams functionality
mariusor Aug 25, 2019
7fb2c4f
For a while tests will be broken
mariusor Aug 25, 2019
d12e5e8
Moved to using go-ap/errors package
mariusor Aug 25, 2019
81f9d1a
Use full uuid coming from fedbox
mariusor Aug 29, 2019
5f6a4aa
Use latest activitypub package
mariusor Aug 29, 2019
d0b5ff5
Removed the need for local Osin OAuth2 server
mariusor Aug 29, 2019
337714c
Moved away from custom implementations of Collections and Activity ob…
mariusor Aug 29, 2019
b782486
Removed OAuth server functionality from the frontend
mariusor Aug 29, 2019
3832b6f
Refactored local activitypub
mariusor Aug 29, 2019
8b2fb39
Better error message
mariusor Aug 31, 2019
bf0d422
Bootstrap with multiple callback uris
mariusor Aug 25, 2019
8d20f36
Reset db before running docker
mariusor Aug 25, 2019
ada15f2
Adding wrapped error messages to bootstrap errors output
mariusor Sep 1, 2019
6dfc54e
Updated to go 1.13 and removed use of package x/errors
mariusor Sep 4, 2019
8140dff
Use fedbox Oauth2 login
mariusor Sep 6, 2019
55a57f5
Better separation between API Url and Base Url
mariusor Sep 6, 2019
9ac1dee
Mock email addresses if empty for all domains
mariusor Sep 6, 2019
45e8fce
Replace the data we save to session with full account
mariusor Sep 6, 2019
9e51bd1
Change how we load votes from fedbox
mariusor Sep 6, 2019
2b7fff1
Convert scores to int type
mariusor Sep 7, 2019
4cd5abf
Fix loading actor from session, and not overwriting the value by load…
mariusor Sep 7, 2019
f3af274
Add vote loading for logged actor and items
mariusor Sep 7, 2019
b65f303
Fix loading an item's votes in LoadItem method
mariusor Sep 8, 2019
89aeba5
Removed older hardcoded OAuth bearer
mariusor Sep 8, 2019
5878e57
Load collection IRIs for all actors not just federated ones
mariusor Sep 8, 2019
9e70916
Use current actor's outbox IRI for Activity end-point
mariusor Sep 8, 2019
5472688
Added hardcoded public and fedbox.git To audiences for submitted items
mariusor Sep 9, 2019
4671247
Fix loading the item after a successful create/update/delete activity
mariusor Sep 9, 2019
cceea79
Fix loading an item's replies
mariusor Sep 9, 2019
72f737a
Improvements to loading items
mariusor Sep 10, 2019
cc5b550
Removed visited property on comments
mariusor Sep 10, 2019
18661d0
Added prefer dark/light colorscheme css
mariusor Sep 14, 2019
5697d09
Updated go-ap packages
mariusor Sep 14, 2019
47b3760
Updated go-ap packages
mariusor Sep 24, 2019
ad4837c
Update activity works now
mariusor Sep 27, 2019
085dbb9
Removing some local filter elements from qstring encoding
mariusor Sep 27, 2019
fdca8de
Making voteing work, more or less
mariusor Sep 27, 2019
86652f6
Updated go-ap packages
mariusor Oct 4, 2019
6d72061
Adding properties where to load the shares/likes collection IRIs
mariusor Oct 4, 2019
74b37f9
Improvements to saving votes using C2S AP
mariusor Oct 4, 2019
94c5c67
Fix flash error for failed login
mariusor Oct 6, 2019
b833fc1
Fix vote counting based on number of Likes/Dislikes in a collection
mariusor Oct 6, 2019
7574c54
Improved error handling from errors coming from fedbox
mariusor Oct 6, 2019
c116c52
Fix posting to proper outboxes when saving items and votes
mariusor Oct 6, 2019
15dde26
Updated packages
mariusor Oct 7, 2019
51d856b
Updating package URL variables
mariusor Oct 7, 2019
678f0d5
Removed tests
mariusor Oct 7, 2019
d9d275e
Removed all code that wasn't useful in the context of the fedbox migr…
mariusor Oct 7, 2019
458da51
Send activities to the underlying's service inbox too
mariusor Oct 13, 2019
185206e
Fixed loading votes for items
mariusor Oct 13, 2019
fc6e327
Updated go-ap packages
mariusor Oct 13, 2019
a23970a
Making voting work
mariusor Oct 13, 2019
1504d13
Don't load from session if current account is already set
mariusor Oct 13, 2019
cee6614
Removed other unnecessary code
mariusor Oct 14, 2019
f536884
Adding two requests Yay/Nay action
mariusor Oct 14, 2019
2781daa
Implemented basic 'followed' functionality
mariusor Oct 14, 2019
de9ebad
Make loading by domain work with fedbox
mariusor Oct 14, 2019
ec985b1
Solve nil dereference when loading an unknown activity
mariusor Oct 14, 2019
49d24ed
Err when finding multiple accounts with same name
mariusor Oct 14, 2019
8d44e31
Clarified func name
mariusor Oct 15, 2019
42a4666
Updated packages
mariusor Oct 15, 2019
dfb73c9
A slightly better threading
mariusor Oct 18, 2019
bb583fa
Showing fractional values for date units other than day, hour, minute
mariusor Oct 19, 2019
5474b60
Adding an UpdatedBy field to items
mariusor Oct 19, 2019
e59bd7b
Showing if an item has been updated
mariusor Oct 19, 2019
5100691
Use UUID as item/votes hashes
mariusor Oct 19, 2019
f996ef7
Correctly load an item after an update
mariusor Oct 19, 2019
f408d02
Starting to move away from separate OP property in favour of a list o…
mariusor Oct 20, 2019
0563cb4
Improvements to the wrong way we're threading items
mariusor Nov 16, 2019
64757a1
Revert "Improvements to the wrong way we're threading items"
mariusor Nov 16, 2019
bb47438
Revert "Starting to move away from separate OP property in favour of …
mariusor Nov 16, 2019
9797aa6
Single digit precision for human readable relative time format
mariusor Nov 16, 2019
d9619df
Add deleted function to accounts too
mariusor Nov 16, 2019
babf764
Remove hardcoded hash for anonymous user
mariusor Nov 16, 2019
a05542f
For first level replies makes OP be the same as Parent
mariusor Nov 16, 2019
c39c6c2
Improve loading of replies based on context query parameter
mariusor Nov 16, 2019
386cfb5
Loading current item OP from its parent if it has one
mariusor Nov 16, 2019
ff22dd2
Slight improvement to how we handle flash errors
mariusor Nov 16, 2019
8e2be8e
Make registration work with new fedbox
mariusor Nov 16, 2019
099044b
Adding webfinger and nodeinfo to littr instances
mariusor Nov 17, 2019
313567e
Go fmt
mariusor Nov 17, 2019
15fa911
Add submitted votes of an account
mariusor Nov 17, 2019
1737ced
Send anonymous requests to shared inbox when saving items too
mariusor Nov 17, 2019
ec2ca32
Adding register link to the header
mariusor Nov 17, 2019
36fddfd
Moved .well-known urls out of the frontend routes
mariusor Nov 17, 2019
0af9518
Make sure we load the current account from session every request
mariusor Nov 17, 2019
c714184
Don't set the current account on the handler, as it is common for all…
mariusor Nov 17, 2019
fc0cb90
Load SubmittedBy property as AnonymousAccount if missing or equivalen…
mariusor Nov 17, 2019
5335fe1
Removed obsolete db package
mariusor Nov 17, 2019
a8b692d
Added issues tracker
mariusor Nov 17, 2019
4a0db66
Moved activitypub package outside the app one
mariusor Nov 17, 2019
b47c8ed
Removed conflicts
mariusor Nov 17, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ tasks:
set +x
cd littr.go
make all
- tests: |
set +x
set -a
source ~/.env.test
cd littr.go
make test
# - tests: |
# set +x
# set -a
# source ~/.env.test
# cd littr.go
# make test
30 changes: 3 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,47 +22,23 @@ endif
BUILD := $(GO) build $(BUILDFLAGS)
TEST := $(GO) test $(BUILDFLAGS)

.PHONY: all cli run clean images test
.PHONY: all run clean images test

all: app cli
all: app

app: bin/app
bin/app: go.mod main.go $(APPSOURCES)
$(BUILD) -tags $(ENV) -o $@ ./main.go

bootstrap: bin/bootstrap
bin/bootstrap: go.mod cli/bootstrap/main.go $(APPSOURCES)
$(BUILD) -tags $(ENV) -o $@ cli/bootstrap/main.go

votes: bin/votes
bin/votes: go.mod cli/votes/main.go $(APPSOURCES)
$(BUILD) -tags $(ENV) -o $@ cli/votes/main.go

keys: bin/keys
bin/keys: go.mod cli/keys/main.go $(APPSOURCES)
$(BUILD) -tags $(ENV) -o $@ cli/keys/main.go

poach: bin/poach
bin/poach: go.mod cli/poach/main.go $(APPSOURCES)
$(BUILD) -tags $(ENV) -o $@ cli/poach/main.go

fetcher: bin/fetcher
bin/fetcher: go.mod cli/fetcher/main.go $(APPSOURCES)
$(BUILD) -tags $(ENV) -o $@ cli/fetcher/main.go

cli: bootstrap votes keys

run: app
@./bin/app

clean:
-$(RM) bin/*
$(MAKE) -C docker $@
$(MAKE) -C tests $@

images:
$(MAKE) -C docker $@

test: app
$(TEST) ./{app,cli,internal}/...
$(MAKE) -C tests $@
$(TEST) ./{app,internal}/...
180 changes: 180 additions & 0 deletions activitypub/activitypub.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
package activitypub

import (
"github.com/buger/jsonparser"
ap "github.com/go-ap/activitypub"
as "github.com/go-ap/activitystreams"
"github.com/go-ap/auth"
"github.com/go-ap/errors"
)

// Actor it should be identical to:
// github.com/go-ap/activitypub/actors.go#actor
// We need it here in order to be able to add to it our Score property
type Actor struct {
auth.Person
// Score is our own custom property for which we needed to extend the existing AP one
Score int `jsonld:"score"`
}

// Object it should be identical to:
// github.com/go-ap/activitypub/objects.go#Object
// We need it here in order to be able to add to it our Score property
type Object struct {
ap.Object
Score int `jsonld:"score"`
}

// GetID returns the ObjectID pointer of current Actor instance
func (a Actor) GetID() *as.ObjectID {
id := a.ID
return &id
}
func (a Actor) GetType() as.ActivityVocabularyType {
return a.Type
}
func (a Actor) GetLink() as.IRI {
return as.IRI(a.ID)
}
func (a Actor) IsLink() bool {
return false
}

func (a Actor) IsObject() bool {
return true
}

// GetID returns the ObjectID pointer of current Object instance
func (a Object) GetID() *as.ObjectID {
id := as.ObjectID(a.ID)
return &id
}

// GetLink returns the IRI of the Object object
func (a Object) GetLink() as.IRI {
return as.IRI(a.ID)
}

// GetType returns the current Object object's type
func (a Object) GetType() as.ActivityVocabularyType {
return a.Type
}

// IsLink returns false for an Object object
func (a Object) IsLink() bool {
return false
}

// IsObject returns true for an Object object
func (a Object) IsObject() bool {
return true
}

// UnmarshalJSON tries to load json data to Object object
func (a *Object) UnmarshalJSON(data []byte) error {
ob := ap.Object{}
err := ob.UnmarshalJSON(data)
if err != nil {
return err
}

a.Object = ob
if score, err := jsonparser.GetInt(data, "score"); err == nil {
a.Score = int(score)
}

return nil
}

// UnmarshalJSON tries to load json data to Actor object
func (a *Actor) UnmarshalJSON(data []byte) error {
p := auth.Person{}
if err := p.UnmarshalJSON(data); err != nil {
return err
}

a.Person = p
if score, err := jsonparser.GetInt(data, "score"); err == nil {
a.Score = int(score)
}

return nil
}

// JSONGetItemByType
func JSONGetItemByType(typ as.ActivityVocabularyType) (as.Item, error) {
if as.ActorTypes.Contains(typ) {
act := &Actor{}
act.Type = typ
return act, nil
} else if as.ObjectTypes.Contains(typ) {
ob := &Object{}
ob.Type = typ
return ob, nil
}
return as.JSONGetItemByType(typ)
}

// ToObject
func ToObject(it as.Item) (*Object, error) {
switch i := it.(type) {
case *Object:
return i, nil
case Object:
return &i, nil
default:
ob, err := as.ToObject(it)
if err != nil {
return nil, err
}
return &Object{
Object: ap.Object{
Parent: *ob,
},
}, nil
}
return nil, errors.Newf("unable to convert object")
}

type withObjectFn func(*Object) error

// OnObject
func OnObject(it as.Item, fn withObjectFn) error {
ob, err := ToObject(it)
if err != nil {
return err
}
return fn(ob)
}

// ToActor
func ToActor(it as.Item) (*Actor, error) {
switch i := it.(type) {
case *Actor:
return i, nil
case Actor:
return &i, nil
default:
pers, err := ap.ToPerson(it)
if err != nil {
return nil, err
}
return &Actor{
Person: auth.Person{
Person: *pers,
},
}, nil
}
return nil, errors.Newf("unable to convert object")
}

type withPersonFn func(*Actor) error

// OnActor
func OnActor(it as.Item, fn withPersonFn) error {
ob, err := ToActor(it)
if err != nil {
return err
}
return fn(ob)
}
23 changes: 15 additions & 8 deletions app/accounts.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package app

import (
"bytes"
"fmt"
"github.com/pborman/uuid"
"time"

"github.com/mariusor/littr.go/internal/errors"
"github.com/go-ap/errors"
)

type SSHKey struct {
Expand Down Expand Up @@ -51,7 +53,7 @@ type AccountCollection []Account
type Account struct {
Email string `json:"email,omitempty"`
Hash Hash `json:"hash,omitempty"`
Score int64 `json:"score,omitempty"`
Score int `json:"score,omitempty"`
Handle string `json:"handle,omitempty"`
CreatedAt time.Time `json:"-"`
UpdatedAt time.Time `json:"-"`
Expand All @@ -61,7 +63,7 @@ type Account struct {
}

// Hash is a local type for string, it should hold a [32]byte array actually
type Hash string
type Hash uuid.UUID

// String returns the hash as a string
func (h Hash) String() string {
Expand All @@ -70,9 +72,9 @@ func (h Hash) String() string {

// Short returns a minimal valuable string value
func (h Hash) Short() string {
if len(h) > 10 {
return string(h[0:10])
}
//if len(h) > 10 {
// return string(h[0:10])
//}
return string(h)
}

Expand Down Expand Up @@ -127,7 +129,7 @@ func (a Account) VotedOn(i Item) *Vote {
if v.Item == nil {
continue
}
if v.Item.Hash == i.Hash {
if bytes.Equal(v.Item.Hash, i.Hash) {
return &v
}
}
Expand All @@ -143,14 +145,19 @@ func (a Account) GetLink() string {

// IsLogged should show if current user was loaded from a session
func (a Account) IsLogged() bool {
return !a.CreatedAt.IsZero() || a.Hash != AnonymousHash
return !a.CreatedAt.IsZero() || !bytes.Equal(a.Hash, AnonymousHash)
}

// HasIcon
func (a Account) HasIcon() bool {
return a.HasMetadata() && len(a.Metadata.Icon.URI) > 0
}

// Deleted
func (a Account) Deleted() bool {
return (a.Flags & FlagsDeleted) == FlagsDeleted
}

// First
func (a AccountCollection) First() (*Account, error) {
for _, act := range a {
Expand Down
Loading