Move types to types.go
This commit is contained in:
40
chat.go
40
chat.go
@ -11,44 +11,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"samhofi.us/x/keybase/types/chat1"
|
"samhofi.us/x/keybase/types/chat1"
|
||||||
"samhofi.us/x/keybase/types/stellar1"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type SubscriptionType struct {
|
|
||||||
Type string `json:"type"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type SubscriptionMessage struct {
|
|
||||||
Message chat1.MsgSummary
|
|
||||||
Conversation chat1.ConvSummary
|
|
||||||
}
|
|
||||||
|
|
||||||
type SubscriptionConversation struct {
|
|
||||||
Conversation chat1.ConvSummary
|
|
||||||
}
|
|
||||||
|
|
||||||
type SubscriptionWalletEvent struct {
|
|
||||||
Payment stellar1.PaymentDetailsLocal
|
|
||||||
}
|
|
||||||
|
|
||||||
type PaymentHolder struct {
|
|
||||||
Payment stellar1.PaymentDetailsLocal `json:"notification"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Handlers struct {
|
|
||||||
ChatHandler *func(SubscriptionMessage)
|
|
||||||
ConversationHandler *func(SubscriptionConversation)
|
|
||||||
WalletHandler *func(SubscriptionWalletEvent)
|
|
||||||
ErrorHandler *func(error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type SubscriptionChannels struct {
|
|
||||||
chat chan SubscriptionMessage
|
|
||||||
conversation chan SubscriptionConversation
|
|
||||||
wallet chan SubscriptionWalletEvent
|
|
||||||
error chan error
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns a string representation of a message id suitable for use in a
|
// Returns a string representation of a message id suitable for use in a
|
||||||
// pagination struct
|
// pagination struct
|
||||||
func getID(id uint) string {
|
func getID(id uint) string {
|
||||||
@ -111,7 +75,7 @@ func getNewMessages(k *Keybase, subs *SubscriptionChannels, execOptions []string
|
|||||||
go func(scanner *bufio.Scanner, subs *SubscriptionChannels) {
|
go func(scanner *bufio.Scanner, subs *SubscriptionChannels) {
|
||||||
for {
|
for {
|
||||||
scanner.Scan()
|
scanner.Scan()
|
||||||
var subType SubscriptionType
|
var subType subscriptionType
|
||||||
t := scanner.Text()
|
t := scanner.Text()
|
||||||
json.Unmarshal([]byte(t), &subType)
|
json.Unmarshal([]byte(t), &subType)
|
||||||
switch subType.Type {
|
switch subType.Type {
|
||||||
@ -144,7 +108,7 @@ func getNewMessages(k *Keybase, subs *SubscriptionChannels, execOptions []string
|
|||||||
subs.conversation <- subscriptionConv
|
subs.conversation <- subscriptionConv
|
||||||
}
|
}
|
||||||
case "wallet":
|
case "wallet":
|
||||||
var holder PaymentHolder
|
var holder paymentHolder
|
||||||
if err := json.Unmarshal([]byte(t), &holder); err != nil {
|
if err := json.Unmarshal([]byte(t), &holder); err != nil {
|
||||||
subs.error <- err
|
subs.error <- err
|
||||||
break
|
break
|
||||||
|
|||||||
36
types.go
36
types.go
@ -7,6 +7,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"samhofi.us/x/keybase/types/chat1"
|
"samhofi.us/x/keybase/types/chat1"
|
||||||
|
"samhofi.us/x/keybase/types/stellar1"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RunOptions holds a set of options to be passed to Run
|
// RunOptions holds a set of options to be passed to Run
|
||||||
@ -21,6 +22,41 @@ type RunOptions struct {
|
|||||||
FilterChannels []chat1.ChatChannel // Only subscribe to messages from specified channels
|
FilterChannels []chat1.ChatChannel // Only subscribe to messages from specified channels
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type subscriptionType struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SubscriptionMessage struct {
|
||||||
|
Message chat1.MsgSummary
|
||||||
|
Conversation chat1.ConvSummary
|
||||||
|
}
|
||||||
|
|
||||||
|
type SubscriptionConversation struct {
|
||||||
|
Conversation chat1.ConvSummary
|
||||||
|
}
|
||||||
|
|
||||||
|
type SubscriptionWalletEvent struct {
|
||||||
|
Payment stellar1.PaymentDetailsLocal
|
||||||
|
}
|
||||||
|
|
||||||
|
type paymentHolder struct {
|
||||||
|
Payment stellar1.PaymentDetailsLocal `json:"notification"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Handlers struct {
|
||||||
|
ChatHandler *func(SubscriptionMessage)
|
||||||
|
ConversationHandler *func(SubscriptionConversation)
|
||||||
|
WalletHandler *func(SubscriptionWalletEvent)
|
||||||
|
ErrorHandler *func(error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type SubscriptionChannels struct {
|
||||||
|
chat chan SubscriptionMessage
|
||||||
|
conversation chan SubscriptionConversation
|
||||||
|
wallet chan SubscriptionWalletEvent
|
||||||
|
error chan error
|
||||||
|
}
|
||||||
|
|
||||||
// Error holds an error message returned by the API
|
// Error holds an error message returned by the API
|
||||||
type Error struct {
|
type Error struct {
|
||||||
Code int `json:"code"`
|
Code int `json:"code"`
|
||||||
|
|||||||
Reference in New Issue
Block a user