Browse Source

Change Channel to use chat1.Channel

main
Sam 4 years ago
parent
commit
0cfaa93505
  1. 8
      chat.go
  2. 4
      keybase.go
  3. 73
      types.go

8
chat.go

@ -9,6 +9,8 @@ import ( @@ -9,6 +9,8 @@ import (
"os/exec"
"strings"
"time"
"samhofi.us/x/keybase/types/chat1"
)
// Returns a string representation of a message id suitable for use in a
@ -42,7 +44,7 @@ func getID(id uint) string { @@ -42,7 +44,7 @@ func getID(id uint) string {
}
// Creates a string of a json-encoded channel to pass to keybase chat api-listen --filter-channel
func createFilterString(channel Channel) string {
func createFilterString(channel chat1.ChatChannel) string {
if channel.Name == "" {
return ""
}
@ -51,7 +53,7 @@ func createFilterString(channel Channel) string { @@ -51,7 +53,7 @@ func createFilterString(channel Channel) string {
}
// Creates a string of json-encoded channels to pass to keybase chat api-listen --filter-channels
func createFiltersString(channels []Channel) string {
func createFiltersString(channels []chat1.ChatChannel) string {
if len(channels) == 0 {
return ""
}
@ -285,7 +287,7 @@ func (c Chat) Delete(messageID int) (ChatAPI, error) { @@ -285,7 +287,7 @@ func (c Chat) Delete(messageID int) (ChatAPI, error) {
// ChatList returns a list of all conversations.
// You can pass a Channel to use as a filter here, but you'll probably want to
// leave the TopicName empty.
func (k *Keybase) ChatList(opts ...Channel) (ChatAPI, error) {
func (k *Keybase) ChatList(opts ...chat1.ChatChannel) (ChatAPI, error) {
m := ChatAPI{
Params: &params{},
}

4
keybase.go

@ -5,6 +5,8 @@ import ( @@ -5,6 +5,8 @@ import (
"fmt"
"os/exec"
"strings"
"samhofi.us/x/keybase/types/chat1"
)
// Possible MemberTypes
@ -72,7 +74,7 @@ func (k *Keybase) Exec(command ...string) ([]byte, error) { @@ -72,7 +74,7 @@ func (k *Keybase) Exec(command ...string) ([]byte, error) {
}
// NewChat returns a new Chat instance
func (k *Keybase) NewChat(channel Channel) Chat {
func (k *Keybase) NewChat(channel chat1.ChatChannel) Chat {
return Chat{
keybase: k,
Channel: channel,

73
types.go

@ -5,18 +5,20 @@ import ( @@ -5,18 +5,20 @@ import (
"fmt"
"strings"
"time"
"samhofi.us/x/keybase/types/chat1"
)
// RunOptions holds a set of options to be passed to Run
type RunOptions struct {
Capacity int // Channel capacity for the buffered channel that holds messages. Defaults to 100 if not set
Heartbeat int64 // Send a heartbeat through the channel every X minutes (0 = off)
Local bool // Subscribe to local messages
HideExploding bool // Ignore exploding messages
Dev bool // Subscribe to dev channel messages
Wallet bool // Subscribe to wallet events
FilterChannel Channel // Only subscribe to messages from specified channel
FilterChannels []Channel // Only subscribe to messages from specified channels
Capacity int // Channel capacity for the buffered channel that holds messages. Defaults to 100 if not set
Heartbeat int64 // Send a heartbeat through the channel every X minutes (0 = off)
Local bool // Subscribe to local messages
HideExploding bool // Ignore exploding messages
Dev bool // Subscribe to dev channel messages
Wallet bool // Subscribe to wallet events
FilterChannel chat1.ChatChannel // Only subscribe to messages from specified channel
FilterChannels []chat1.ChatChannel // Only subscribe to messages from specified channels
}
// ChatAPI holds information about a message received by the `keybase chat api-listen` command
@ -229,19 +231,19 @@ type content struct { @@ -229,19 +231,19 @@ type content struct {
}
type msg struct {
ID int `json:"id"`
ConversationID string `json:"conversation_id"`
Channel Channel `json:"channel"`
Sender sender `json:"sender"`
SentAt int `json:"sent_at"`
SentAtMs int64 `json:"sent_at_ms"`
Content content `json:"content"`
Unread bool `json:"unread"`
AtMentionUsernames []string `json:"at_mention_usernames"`
IsEphemeral bool `json:"is_ephemeral"`
Etime int64 `json:"etime"`
HasPairwiseMacs bool `json:"has_pairwise_macs"`
ChannelMention string `json:"channel_mention"`
ID int `json:"id"`
ConversationID string `json:"conversation_id"`
Channel chat1.ChatChannel `json:"channel"`
Sender sender `json:"sender"`
SentAt int `json:"sent_at"`
SentAtMs int64 `json:"sent_at_ms"`
Content content `json:"content"`
Unread bool `json:"unread"`
AtMentionUsernames []string `json:"at_mention_usernames"`
IsEphemeral bool `json:"is_ephemeral"`
Etime int64 `json:"etime"`
HasPairwiseMacs bool `json:"has_pairwise_macs"`
ChannelMention string `json:"channel_mention"`
}
type summary struct {
@ -296,15 +298,6 @@ type notification struct { @@ -296,15 +298,6 @@ type notification struct {
Details details `json:"details"`
}
// Channel holds information about a conversation
type Channel struct {
Name string `json:"name,omitempty"`
Public bool `json:"public,omitempty"`
MembersType string `json:"members_type,omitempty"`
TopicType string `json:"topic_type,omitempty"`
TopicName string `json:"topic_name,omitempty"`
}
type BotCommand struct {
Name string `json:"name"`
Description string `json:"description"`
@ -342,7 +335,7 @@ func (d *duration) MarshalJSON() (b []byte, err error) { @@ -342,7 +335,7 @@ func (d *duration) MarshalJSON() (b []byte, err error) {
}
type options struct {
Channel *Channel `json:"channel,omitempty"`
Channel *chat1.ChatChannel `json:"channel,omitempty"`
MessageID int `json:"message_id,omitempty"`
Message *mesg `json:"message,omitempty"`
Pagination *pagination `json:"pagination,omitempty"`
@ -437,12 +430,12 @@ type rateLimits struct { @@ -437,12 +430,12 @@ type rateLimits struct {
}
type conversation struct {
ID string `json:"id"`
Channel Channel `json:"channel"`
Unread bool `json:"unread"`
ActiveAt int `json:"active_at"`
ActiveAtMs int64 `json:"active_at_ms"`
MemberStatus string `json:"member_status"`
ID string `json:"id"`
Channel chat1.ChatChannel `json:"channel"`
Unread bool `json:"unread"`
ActiveAt int `json:"active_at"`
ActiveAtMs int64 `json:"active_at_ms"`
MemberStatus string `json:"member_status"`
}
type SendPayment struct {
@ -831,7 +824,7 @@ type Keybase struct { @@ -831,7 +824,7 @@ type Keybase struct {
// Chat holds basic information about a specific conversation
type Chat struct {
keybase *Keybase
Channel Channel
Channel chat1.ChatChannel
}
type chat interface {
@ -900,10 +893,10 @@ type kvInterface interface { @@ -900,10 +893,10 @@ type kvInterface interface {
type keybase interface {
AdvertiseCommand(advertisement BotAdvertisement) (ChatAPI, error)
AdvertiseCommands(advertisements []BotAdvertisement) (ChatAPI, error)
ChatList(opts ...Channel) (ChatAPI, error)
ChatList(opts ...chat1.ChatChannel) (ChatAPI, error)
ClearCommands() (ChatAPI, error)
CreateTeam(name string) (TeamAPI, error)
NewChat(channel Channel) Chat
NewChat(channel chat1.ChatChannel) Chat
NewTeam(name string) Team
NewKV(team string) KV
NewWallet() Wallet

Loading…
Cancel
Save