mirror of
https://git.mills.io/saltyim/saltyim.git
synced 2024-06-30 02:31:08 +00:00
feat: send to outbox (#98)
closes: #67 Co-authored-by: Jon Lundy <jon@xuu.cc> Reviewed-on: https://git.mills.io/saltyim/saltyim/pulls/98 Co-authored-by: xuu <xuu@noreply@mills.io> Co-committed-by: xuu <xuu@noreply@mills.io>
This commit is contained in:
parent
b5f74b74f7
commit
d9eddfdad1
27
client.go
27
client.go
@ -3,10 +3,13 @@ package saltyim
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/sha256"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -224,10 +227,27 @@ func (cli *Client) Env(extraenvs string) []string {
|
|||||||
return env
|
return env
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cli *Client) Outbox() *url.URL {
|
||||||
|
ep := cli.me.Endpoint()
|
||||||
|
ep.Path = path.Join(
|
||||||
|
path.Dir(ep.Path),
|
||||||
|
fmt.Sprintf("%x", sha256.Sum256(cli.me.key.Private())),
|
||||||
|
)
|
||||||
|
return ep
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cli *Client) OutboxAddr() *Addr {
|
||||||
|
return &Addr{
|
||||||
|
endpoint: cli.Outbox(),
|
||||||
|
key: cli.me.key,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (cli *Client) String() string {
|
func (cli *Client) String() string {
|
||||||
b := &bytes.Buffer{}
|
b := &bytes.Buffer{}
|
||||||
fmt.Fprintln(b, "Me: ", cli.me)
|
fmt.Fprintln(b, "Me: ", cli.me)
|
||||||
fmt.Fprintln(b, "Endpoint: ", cli.me.Endpoint())
|
fmt.Fprintln(b, "Endpoint: ", cli.me.Endpoint())
|
||||||
|
fmt.Fprintln(b, "Outbox: ", cli.Outbox())
|
||||||
fmt.Fprintln(b, "Key: ", cli.key)
|
fmt.Fprintln(b, "Key: ", cli.key)
|
||||||
return b.String()
|
return b.String()
|
||||||
}
|
}
|
||||||
@ -333,7 +353,12 @@ func (cli *Client) Send(user, msg string) error {
|
|||||||
return fmt.Errorf("error looking up user %s: %w", user, err)
|
return fmt.Errorf("error looking up user %s: %w", user, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return cli.SendToAddr(addr, msg)
|
err = cli.SendToAddr(addr, msg)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return cli.SendToAddr(cli.OutboxAddr(), msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *Client) SendToAddr(addr *Addr, msg string) error {
|
func (cli *Client) SendToAddr(addr *Addr, msg string) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user