Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Commit

Permalink
Merge pull request #683 from textileio/sander/more-mobile-invites
Browse files Browse the repository at this point in the history
mobile: add missing invite methods
  • Loading branch information
sanderpick committed Apr 15, 2019
2 parents 1a80cf3 + 5e5a595 commit 60baa75
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 17 deletions.
11 changes: 5 additions & 6 deletions README.md
Expand Up @@ -75,11 +75,11 @@ Check out the [docs site](https://docs.textile.io/) for more detailed usage inst

## Building

There are various things to build… first off run setup:
There are various things to build… first off, run setup:

make setup

If you plan on building the bindings fro iOS or Android, install and init the `gomobile` tools:
If you plan on building the bindings for iOS or Android, install and init the `gomobile` tools:

go get golang.org/x/mobile/cmd/gomobile
gomobile init
Expand All @@ -100,11 +100,11 @@ If you plan on building the bindings fro iOS or Android, install and init the `g

make docs

#### Tray app
#### Desktop

The build is made by a vendored version of `go-astilectron-bundler`. Due to Go's painful package management, you'll want to delete any `go-astilectron`-related binaries and source code you have installed from `github.com/asticode` in your `$GOPATH`. Then you can install the vendored `go-astilectron-bundler`:
Install `go-astilectron-bundler`:

go install ./vendor/github.com/asticode/go-astilectron-bundler/astilectron-bundler
go get github.com/asticode/go-astilectron-bundler/...

Change into the `tray` folder and build the app:

Expand All @@ -113,7 +113,6 @@ Change into the `tray` folder and build the app:

Double-click the built app in `tray/output/{darwin,linux,windows}-amd64`, or run it directly:


go run *.go

You can also build the architecture-specific versions with:
Expand Down
8 changes: 6 additions & 2 deletions core/api_blocks.go
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net/http"
"strconv"
"strings"

"github.com/gin-gonic/gin"
"github.com/textileio/go-textile/ipfs"
Expand Down Expand Up @@ -177,12 +178,15 @@ func (a *api) toDots(blocks *pb.BlockList) (string, error) {
dot := toDot(b)

for _, p := range b.Parents {
if strings.TrimSpace(p) == "" {
continue
}
pp, err := a.node.Block(p)
if err != nil {
log.Errorf("error getting block %s: %s", p, err)
log.Warningf("block %s: %s", p, err)
dots += "\n " + dot + " -> MISSING_" + pre(p) + ";"
continue
}

dots += "\n " + dot + " -> " + toDot(pp) + ";"
}
}
Expand Down
16 changes: 8 additions & 8 deletions core/invites.go
Expand Up @@ -99,8 +99,8 @@ func (t *Textile) Invites() *pb.InviteViewList {
}

// AcceptInvite adds a new thread, and notifies the inviter of the join
func (t *Textile) AcceptInvite(inviteId string) (mh.Multihash, error) {
invite := t.datastore.Invites().Get(inviteId)
func (t *Textile) AcceptInvite(id string) (mh.Multihash, error) {
invite := t.datastore.Invites().Get(id)
if invite == nil {
return nil, ErrThreadInviteNotFound
}
Expand All @@ -110,7 +110,7 @@ func (t *Textile) AcceptInvite(inviteId string) (mh.Multihash, error) {
return nil, err
}

if err := t.IgnoreInvite(inviteId); err != nil {
if err := t.IgnoreInvite(id); err != nil {
return nil, err
}

Expand All @@ -119,8 +119,8 @@ func (t *Textile) AcceptInvite(inviteId string) (mh.Multihash, error) {

// AcceptExternalInvite attemps to download an encrypted thread key from an external invite,
// adds a new thread, and notifies the inviter of the join
func (t *Textile) AcceptExternalInvite(inviteId string, key []byte) (mh.Multihash, error) {
ciphertext, err := ipfs.DataAtPath(t.node, fmt.Sprintf("%s", inviteId))
func (t *Textile) AcceptExternalInvite(id string, key []byte) (mh.Multihash, error) {
ciphertext, err := ipfs.DataAtPath(t.node, fmt.Sprintf("%s", id))
if err != nil {
return nil, err
}
Expand All @@ -134,11 +134,11 @@ func (t *Textile) AcceptExternalInvite(inviteId string, key []byte) (mh.Multihas
}

// IgnoreInvite deletes the invite and removes the associated notification.
func (t *Textile) IgnoreInvite(inviteId string) error {
if err := t.datastore.Invites().Delete(inviteId); err != nil {
func (t *Textile) IgnoreInvite(id string) error {
if err := t.datastore.Invites().Delete(id); err != nil {
return err
}
return t.datastore.Notifications().DeleteByBlock(inviteId)
return t.datastore.Notifications().DeleteByBlock(id)
}

// handleThreadAdd uses an add block to join a thread
Expand Down
30 changes: 29 additions & 1 deletion mobile/invites.go
Expand Up @@ -29,7 +29,26 @@ func (m *Mobile) AddExternalInvite(threadId string) ([]byte, error) {
return proto.Marshal(invite)
}

// AcceptExternalInvite notifies the thread of a join
// Invites calls core Invites
func (m *Mobile) Invites() ([]byte, error) {
return proto.Marshal(m.node.Invites())
}

// AcceptInvite calls core AcceptInvite
func (m *Mobile) AcceptInvite(id string) (string, error) {
if !m.node.Online() {
return "", core.ErrOffline
}

hash, err := m.node.AcceptInvite(id)
if err != nil {
return "", err
}

return hash.B58String(), nil
}

// AcceptExternalInvite calls core AcceptExternalInvite
func (m *Mobile) AcceptExternalInvite(id string, key string) (string, error) {
if !m.node.Online() {
return "", core.ErrOffline
Expand All @@ -47,3 +66,12 @@ func (m *Mobile) AcceptExternalInvite(id string, key string) (string, error) {

return hash.B58String(), nil
}

// IgnoreInvite calls core IgnoreInvite
func (m *Mobile) IgnoreInvite(id string) error {
if !m.node.Online() {
return core.ErrOffline
}

return m.node.IgnoreInvite(id)
}

0 comments on commit 60baa75

Please sign in to comment.