48 Commits

Author SHA1 Message Date
acc3e3ddec Fix ListConvsOnName 2020-05-12 14:45:50 -04:00
22396f8276 Add ListConvsOnName 2020-05-12 01:39:29 -04:00
c9a2bd80bc Add New() for creating new keybase objects.
This function accepts functional options, and allows you to set an alternate home dir for keybase
2020-05-11 22:48:30 -04:00
Sam
111d41b901 Update ListMembers to output correct type 2020-04-22 13:30:01 -04:00
Sam
300e330b8d Update AVDL compiled types 2020-04-22 13:29:22 -04:00
Sam
d69b73c5c1 use v2 types 2020-04-09 09:15:14 -04:00
Sam
b51c00a910 Update AVDL compiled types 2020-04-08 22:55:36 -04:00
Sam
0fd676670f Version 2 2020-04-06 12:43:35 -04:00
Sam
74992fe2c3 Remove ReadMessage -- it will eventually be replaced by the API's get method 2020-03-30 14:06:59 -04:00
Sam
74fb4a152b Add ListMembers methods 2020-03-14 21:27:40 -04:00
Sam
07f5168a6a subscriptionChannels should not be exported 2020-03-12 11:35:36 -04:00
0631dc60a7 updated phrasing to match go standards 2020-03-12 15:23:08 +00:00
71d1800637 added comments to exported types 2020-03-12 15:21:46 +00:00
Sam
c852393504 Fix download methods 2020-03-12 09:01:41 -04:00
Sam
ef7a20a94b Add download methods 2020-03-12 00:48:26 -04:00
Sam
21b141b7a1 Add UploadToChannel and UploadToConversation 2020-03-12 00:31:59 -04:00
Sam
8cef252023 Remove chat.Read() chat.Next() and chat.Previous() as they have been replaced 2020-03-12 00:24:48 -04:00
Sam
dd6726911e Remove old advertisement types as they are no longer used 2020-03-12 00:15:07 -04:00
Sam
0316bc6db1 Add AdvertiseCommands and ClearCommands 2020-03-12 00:07:38 -04:00
Sam
a22970a284 Add Next and Previous read methods 2020-03-11 17:16:46 -04:00
Sam
ad3edadc79 Add read methods 2020-03-11 15:21:48 -04:00
Sam
5a7a6d7538 Simplify funcs that wrap SendMessage 2020-03-08 11:47:34 -04:00
Sam
4e55ebaf05 Remove more custom types 2020-03-08 10:33:20 -04:00
Sam
6c11327289 Convert keystore funcs to use avdl compiled types 2020-03-06 14:17:23 -05:00
Sam
f6d26e1905 Add license 2020-03-03 08:15:49 -05:00
Sam
0feb664405 Remove wallet and convs from options, and instead automatically enable them if the correct handlers are present 2020-03-02 22:02:21 -05:00
Sam
ca2a1fdf25 Remove custom types 2020-02-29 10:12:15 -05:00
Sam
c031c36a00 Move types to types.go 2020-02-29 00:49:50 -05:00
Sam
5f211c7a90 Add support for new-conversation events 2020-02-29 00:39:22 -05:00
Sam
3bcca84908 Allow different types of notifications to come through separate channels 2020-02-29 00:24:40 -05:00
Sam
93daa56db1 Add GetConversations() 2020-02-16 23:49:58 -05:00
Sam
c272c05092 Add GetConversations 2020-02-16 23:21:20 -05:00
Sam
67ffd89a00 Add delete message funcs 2020-02-16 22:14:44 -05:00
Sam
97adac7fa4 Remove chat.React() 2020-02-16 22:08:15 -05:00
Sam
e24450a0af Add ReactByChannel and ReactByConvID 2020-02-16 22:00:04 -05:00
Sam
5bcd11703a Change the word To to By since it seems to make more sense 2020-02-16 21:53:59 -05:00
Sam
c4f06fa79b Remove chat.Edit 2020-02-16 16:11:56 -05:00
Sam
b50d3bcfa2 Clean up some of the comments 2020-02-16 16:09:08 -05:00
Sam
b55e4b8315 Add Edit funcs 2020-02-16 15:59:37 -05:00
Sam
450f2c1558 Add method arg to SendMessage 2020-02-16 15:58:44 -05:00
Sam
219ef492f5 Remove chat.Reply 2020-02-16 15:52:30 -05:00
Sam
26e487659c Ephemeral duration should be optional 2020-02-16 15:38:25 -05:00
Sam
3faadfd076 Add ReplyToChannel and ReplyToConvID, and attempt to fix ephemeral sends 2020-02-16 15:22:47 -05:00
Sam
d791203856 Add SendEphemeralToChannel and SendEphemeralToConvID 2020-02-16 14:48:13 -05:00
Sam
285567309a Add SendMessageToConvID 2020-02-16 14:07:26 -05:00
Sam
4e2656445c Add SendMessage and SendMessageToChannel, and the necessary types to go with them 2020-02-16 14:01:39 -05:00
Sam
0cfaa93505 Change Channel to use chat1.Channel 2020-01-29 17:07:42 -05:00
Sam
6d85c97e05 Add avdl compiled types 2020-01-29 16:19:18 -05:00
6 changed files with 5 additions and 210 deletions

View File

@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"os/exec"
"time"
"samhofi.us/x/keybase/v2/types/chat1"
@ -44,7 +45,7 @@ func getNewMessages(k *Keybase, subs *subscriptionChannels, execOptions []string
cmd = append(cmd, execString...)
execCmd := execCommand(k.ExePath, cmd...)
execCmd := exec.Command(k.ExePath, cmd...)
stdOut, _ := execCmd.StdoutPipe()
execCmd.Start()
scanner := bufio.NewScanner(stdOut)
@ -768,6 +769,7 @@ func (k *Keybase) ListConvsOnName(channel chat1.ChatChannel) (*[]chat1.ConvSumma
arg := newListConvsOnNameArg(channel)
jsonBytes, _ := json.Marshal(arg)
fmt.Printf("%#v\n", arg)
cmdOut, err := k.Exec("chat", "api", "-m", string(jsonBytes))
if err != nil {

View File

@ -1,135 +0,0 @@
package keybase
import (
"os/exec"
"testing"
"samhofi.us/x/keybase/v2/types/chat1"
)
func TestListConvsOnName(t *testing.T) {
execCommand = createFakeExecCommand("listconvsonname")
defer func() { execCommand = exec.Command }()
channel := chat1.ChatChannel{
Name: "mkbot",
MembersType: TEAM,
}
k := New()
res, err := k.ListConvsOnName(channel)
if err != nil {
t.Errorf("Expected nil error, got %#v", err)
}
channelcount := 10
if len(*res) != channelcount {
t.Errorf("Expected %d channels, got %d channels", channelcount, len(*res))
}
}
func TestSendMessageByChannel(t *testing.T) {
execCommand = createFakeExecCommand("send")
defer func() { execCommand = exec.Command }()
channel := chat1.ChatChannel{
Name: "user1,user2",
MembersType: USER,
}
k := New()
res, err := k.SendMessageByChannel(channel, "Hello!")
if err != nil {
t.Errorf("Expected nil error, got %#v", err)
}
if expected := "message sent"; res.Message != expected {
t.Errorf(`res.Message: expected "%s", got "%v"`, expected, res.Message)
}
if expected := uint(894); uint(*res.MessageID) != expected {
t.Errorf(`res.MessageID: expected %d, got %d`, expected, uint(*res.MessageID))
}
}
func TestSendMessageByConvID(t *testing.T) {
execCommand = createFakeExecCommand("send")
defer func() { execCommand = exec.Command }()
k := New()
res, err := k.SendMessageByConvID(chat1.ConvIDStr("000049d2395435dff0c865c18832d9645eb69fd74a2814ef55310b294092ba6d"), "Hello!")
if err != nil {
t.Errorf("Expected nil error, got %#v", err)
}
if expected := "message sent"; res.Message != expected {
t.Errorf(`res.Message: expected "%s", got "%v"`, expected, res.Message)
}
if expected := uint(894); uint(*res.MessageID) != expected {
t.Errorf(`res.MessageID: expected %d, got %d`, expected, uint(*res.MessageID))
}
}
func TestCreateFilterString(t *testing.T) {
tables := []struct {
channel chat1.ChatChannel
expected string
}{
{
chat1.ChatChannel{},
``,
},
{
chat1.ChatChannel{Name: "faketeam", MembersType: TEAM},
`{"name":"faketeam","members_type":"team"}`,
},
{
chat1.ChatChannel{Name: "user1,user2", MembersType: USER},
`{"name":"user1,user2","members_type":"impteamnative"}`,
},
}
for _, table := range tables {
if result := createFilterString(table.channel); result != table.expected {
t.Errorf(`Expected "%s", got "%s"`, table.expected, result)
}
}
}
func TestCreateFiltersString(t *testing.T) {
tables := []struct {
channel []chat1.ChatChannel
expected string
}{
{
[]chat1.ChatChannel{},
``,
},
{
[]chat1.ChatChannel{
chat1.ChatChannel{Name: "faketeam1", MembersType: TEAM},
chat1.ChatChannel{Name: "faketeam2", MembersType: TEAM},
},
`[{"name":"faketeam1","members_type":"team"},{"name":"faketeam2","members_type":"team"}]`,
},
{
[]chat1.ChatChannel{
chat1.ChatChannel{Name: "user1,user2", MembersType: USER},
chat1.ChatChannel{Name: "user3,user4", MembersType: USER},
},
`[{"name":"user1,user2","members_type":"impteamnative"},{"name":"user3,user4","members_type":"impteamnative"}]`,
},
{
[]chat1.ChatChannel{
chat1.ChatChannel{Name: "user1,user2", MembersType: USER},
chat1.ChatChannel{Name: "faketeam1", MembersType: TEAM},
},
`[{"name":"user1,user2","members_type":"impteamnative"},{"name":"faketeam1","members_type":"team"}]`,
},
}
for _, table := range tables {
if result := createFiltersString(table.channel); result != table.expected {
t.Errorf(`Expected "%s", got "%s"`, table.expected, result)
}
}
}

2
go.mod
View File

@ -1,3 +1,3 @@
module samhofi.us/x/keybase
module samhofi.us/x/keybase/v2
go 1.13

View File

@ -9,9 +9,6 @@ import (
"samhofi.us/x/keybase/v2/types/chat1"
)
// Used for testing
var execCommand = exec.Command
// Possible MemberTypes
const (
TEAM string = "team"
@ -73,7 +70,7 @@ func (k *Keybase) Exec(command ...string) ([]byte, error) {
cmd = append(cmd, command...)
out, err := execCommand(k.ExePath, cmd...).Output()
out, err := exec.Command(k.ExePath, cmd...).Output()
if err != nil {
return []byte{}, err
}

View File

@ -1,68 +0,0 @@
package keybase
import (
"fmt"
"os"
"os/exec"
"testing"
)
func createFakeExecCommand(caller string) func(command string, args ...string) *exec.Cmd {
return func(command string, args ...string) *exec.Cmd {
cs := []string{"-test.run=ExecHelper", "--"}
cs = append(cs, args...)
cmd := exec.Command(os.Args[0], cs...)
cmd.Env = []string{"GO_WANT_HELPER_PROCESS=1", "GO_WANT_HELPER_CALLER=" + caller}
return cmd
}
}
func TestNew(t *testing.T) {
execCommand = createFakeExecCommand("new")
defer func() { execCommand = exec.Command }()
k := New()
if expected := "keybase"; k.ExePath != expected {
t.Errorf(`k.ExePath: expected "%s", got "%s"`, expected, k.ExePath)
}
if expected := ""; k.HomePath != expected {
t.Errorf(`k.HomePath: expected "%s", got "%s"`, expected, k.HomePath)
}
k = New(
SetExePath("/path/to/exepath"),
SetHomePath("/path/to/homepath"),
)
if expected := "/path/to/exepath"; k.ExePath != expected {
t.Errorf(`k.ExePath: expected "%s", got "%s"`, expected, k.ExePath)
}
if expected := "/path/to/homepath"; k.HomePath != expected {
t.Errorf(`k.HomePath: expected "%s", got "%s"`, expected, k.HomePath)
}
}
func TestExecHelper(t *testing.T) {
if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" {
return
}
var (
listconvsonname = `{"result":{"conversations":[{"id":"0000b9d9be8586029d4876af2192b94d6705603cf6859fc27c746de94befd45c","channel":{"name":"mkbot","members_type":"team","topic_type":"chat"},"is_default_conv":false,"unread":true,"active_at":1589468132,"active_at_ms":1589468132734,"member_status":"active","creator_info":{"ctime":1551848940888,"username":"dxb"}},{"id":"0000d2c4d915aa04c093a25b9496cd885ff510f4eeeacac5a7249f65d82ed0ad","channel":{"name":"mkbot","members_type":"team","topic_type":"chat"},"is_default_conv":false,"unread":false,"active_at":1589633805,"active_at_ms":1589633805970,"member_status":"active","creator_info":{"ctime":1551848919282,"username":"dxb"}},{"id":"0000e967261971be5aae47d1cfd7d77e695d4a2f90e2ee35236ef3472b2884d4","channel":{"name":"mkbot","members_type":"team","topic_type":"chat","topic_name":"gameroom"},"is_default_conv":false,"unread":true,"active_at":1589468113,"active_at_ms":1589468113173,"member_status":"active","creator_info":{"ctime":1566244683161,"username":"dxb"}},{"id":"0000d5ae3da566307f6c9906881e5bd08dc9a0bf8c341b5769240026e367c478","channel":{"name":"mkbot","members_type":"team","topic_type":"chat","topic_name":"general"},"is_default_conv":true,"unread":false,"active_at":1589348381,"active_at_ms":1589348381358,"member_status":"active","creator_info":{"ctime":1551840458201,"username":"dxb"}},{"id":"0000d7cf1e6f51d75f9a354c2cb7c3bd30415f184bbb9eba0c57aa50827b7663","channel":{"name":"mkbot","members_type":"team","topic_type":"chat","topic_name":"test1"},"is_default_conv":false,"unread":true,"active_at":1589468203,"active_at_ms":1589468203686,"member_status":"active","creator_info":{"ctime":1551849049656,"username":"dxb"}},{"id":"0000d0cf70804671490e7f8f21c207a1ac6a8bc2ee05db804fb4531ab6c06f05","channel":{"name":"mkbot","members_type":"team","topic_type":"chat","topic_name":"test2"},"is_default_conv":false,"unread":true,"active_at":1589468118,"active_at_ms":1589468118254,"member_status":"active","creator_info":{"ctime":1551849050007,"username":"dxb"}},{"id":"000044e620fef1e84b623350faff06ebef7a0cd7e403ba81a1b35d311976b9f6","channel":{"name":"mkbot","members_type":"team","topic_type":"chat","topic_name":"test3"},"is_default_conv":false,"unread":true,"active_at":1589468117,"active_at_ms":1589468117094,"member_status":"active","creator_info":{"ctime":1551849050351,"username":"dxb"}},{"id":"0000a8dd5969f6bb414562278a5abf8f3bd80b39d7cdcf0d3df5045f05fbac77","channel":{"name":"mkbot","members_type":"team","topic_type":"chat","topic_name":"test4"},"is_default_conv":false,"unread":true,"active_at":1589468197,"active_at_ms":1589468197735,"member_status":"active","creator_info":{"ctime":1551849050729,"username":"dxb"}},{"id":"00004380e20bf4d56cf5e80a7435d594e07ebe043da93468c93c9bf0080f9ef5","channel":{"name":"mkbot","members_type":"team","topic_type":"chat","topic_name":"test5"},"is_default_conv":false,"unread":true,"active_at":1589468203,"active_at_ms":1589468203980,"member_status":"active","creator_info":{"ctime":1551849051084,"username":"dxb"}},{"id":"00003bd0aa429c33eee546f20efb76c9e0a9854b0ca18278300bcf6fc4c4fb93","channel":{"name":"mkbot","members_type":"team","topic_type":"chat","topic_name":"trivia"},"is_default_conv":false,"unread":false,"active_at":1589468113,"active_at_ms":1589468113074,"member_status":"active","creator_info":{"ctime":1580428008401,"username":"dxb"}}],"offline":false}}`
send = `{"result":{"message":"message sent","id":894,"ratelimits":[{"tank":"chat","capacity":9000,"reset":155,"gas":8991}]}}`
)
var jsonOut string
switch os.Getenv("GO_WANT_HELPER_CALLER") {
case "listconvsonname":
jsonOut = listconvsonname
case "send":
jsonOut = send
default:
jsonOut = ""
}
fmt.Fprintf(os.Stdout, jsonOut)
os.Exit(0)
}

View File

@ -114,7 +114,6 @@ type SendMessageOptions struct {
ReplyTo *chat1.MessageID `json:"reply_to,omitempty"`
ExplodingLifetime *ExplodingLifetime `json:"exploding_lifetime,omitempty"`
UnreadOnly bool `json:"unread_only,omitempty"`
NonBlock bool `json:"nonblock,omitempty"`
}
type sendMessageParams struct {