From 9d750e73f6cdd6e3e7eb0ebd2c582637a79b7418 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Tue, 21 Aug 2018 13:37:49 +0300 Subject: [PATCH] update features, remove events --- README.md | 20 ++++++-------- v1/client.go | 40 ++++++++++++--------------- v1/client_test.go | 70 ++++++++++++++++++++--------------------------- v1/types.go | 31 ++++++++++----------- 4 files changed, 72 insertions(+), 89 deletions(-) diff --git a/README.md b/README.md index 344a804..5690f3e 100644 --- a/README.md +++ b/README.md @@ -27,19 +27,17 @@ func main() { var client = v1.New("https://token.url", "cb8ccf05e38a47543ad8477d49bcba99be73bff503ea6") ch := Channel{ Type: "telegram", - Events: []string{ - "message_sent", - "message_read", - }, Settings: ChannelSettings{ - ReceiveMessageMode: MsgModeAlways, SpamAllowed: false, - Features: ChannelFeatures{ - StatusDelivered: ChannelFeatureNone, - MessageDeleting: ChannelFeatureSend, - MessageEditing: ChannelFeatureBoth, - MessageQuoting: ChannelFeatureBoth, - ImageMessage: ChannelFeatureReceive, + Status: Status{ + Delivered: ChannelFeatureNone, + Read: ChannelFeatureReceive, + }, + Text: ChannelSettingsText{ + Creating: ChannelFeatureBoth, + Editing: ChannelFeatureSend, + Quoting: ChannelFeatureReceive, + Deleting: ChannelFeatureBoth, }, }, } diff --git a/v1/client.go b/v1/client.go index d6c85c3..8894ff0 100644 --- a/v1/client.go +++ b/v1/client.go @@ -26,19 +26,17 @@ func New(url string, token string) *MgClient { // // request := ActivateRequest{ // Type: "telegram", -// Events: []string{ -// "message_sent", -// "message_read", -// }, // Settings: ChannelSettings{ -// ReceiveMessageMode: MsgModeAlways, // SpamAllowed: false, -// Features: ChannelFeatures{ -// StatusDelivered: ChannelFeatureNone, -// MessageDeleting: ChannelFeatureSend, -// MessageEditing: ChannelFeatureBoth, -// MessageQuoting: ChannelFeatureBoth, -// ImageMessage: ChannelFeatureReceive, +// Status: Status{ +// Delivered: ChannelFeatureNone, +// Read: ChannelFeatureReceive, +// }, +// Text: ChannelSettingsText{ +// Creating: ChannelFeatureBoth, +// Editing: ChannelFeatureBoth, +// Quoting: ChannelFeatureReceive, +// Deleting: ChannelFeatureSend, // }, // }, // } @@ -79,19 +77,17 @@ func (c *MgClient) ActivateTransportChannel(request Channel) (ActivateResponse, // request := ActivateRequest{ // ID: 3053450384, // Type: "telegram", -// Events: []string{ -// "message_sent", -// "message_read", -// }, // Settings: ChannelSettings{ -// ReceiveMessageMode: MsgModeNever, // SpamAllowed: false, -// Features: ChannelFeatures{ -// StatusDelivered: ChannelFeatureNone, -// MessageDeleting: ChannelFeatureSend, -// MessageEditing: ChannelFeatureBoth, -// MessageQuoting: ChannelFeatureBoth, -// ImageMessage: ChannelFeatureReceive, +// Status: Status{ +// Delivered: ChannelFeatureNone, +// Read: ChannelFeatureReceive, +// }, +// Text: ChannelSettingsText{ +// Creating: ChannelFeatureBoth, +// Editing: ChannelFeatureSend, +// Quoting: ChannelFeatureReceive, +// Deleting: ChannelFeatureBoth, // }, // }, // } diff --git a/v1/client_test.go b/v1/client_test.go index e0d700e..e6b8668 100644 --- a/v1/client_test.go +++ b/v1/client_test.go @@ -24,19 +24,17 @@ func TestMgClient_ActivateTransportChannel(t *testing.T) { ch := Channel{ ID: channelId, Type: "telegram", - Events: []string{ - "message_sent", - "message_read", - }, Settings: ChannelSettings{ - ReceiveMessageMode: MsgModeAlways, - SpamAllowed: false, - Features: ChannelFeatures{ - StatusDelivered: ChannelFeatureNone, - MessageDeleting: ChannelFeatureSend, - MessageEditing: ChannelFeatureBoth, - MessageQuoting: ChannelFeatureBoth, - ImageMessage: ChannelFeatureReceive, + SpamAllowed: false, + Status: Status{ + Delivered: ChannelFeatureNone, + Read: ChannelFeatureReceive, + }, + Text: ChannelSettingsText{ + Creating: ChannelFeatureBoth, + Editing: ChannelFeatureSend, + Quoting: ChannelFeatureReceive, + Deleting: ChannelFeatureBoth, }, }, } @@ -54,21 +52,17 @@ func TestMgClient_ActivateNewTransportChannel(t *testing.T) { c := client() ch := Channel{ Type: "telegram", - Events: []string{ - "message_sent", - "message_updated", - "message_deleted", - "message_read", - }, Settings: ChannelSettings{ - ReceiveMessageMode: MsgModeNever, - SpamAllowed: false, - Features: ChannelFeatures{ - StatusDelivered: ChannelFeatureNone, - MessageDeleting: ChannelFeatureSend, - MessageEditing: ChannelFeatureBoth, - MessageQuoting: ChannelFeatureBoth, - ImageMessage: ChannelFeatureReceive, + SpamAllowed: false, + Status: Status{ + Delivered: ChannelFeatureNone, + Read: ChannelFeatureBoth, + }, + Text: ChannelSettingsText{ + Creating: ChannelFeatureBoth, + Editing: ChannelFeatureSend, + Quoting: ChannelFeatureBoth, + Deleting: ChannelFeatureSend, }, }, } @@ -98,21 +92,17 @@ func TestMgClient_UpdateTransportChannel(t *testing.T) { c := client() ch := Channel{ ID: channelId, - Events: []string{ - "message_sent", - "message_updated", - "message_deleted", - "message_read", - }, Settings: ChannelSettings{ - ReceiveMessageMode: "always", - SpamAllowed: false, - Features: ChannelFeatures{ - StatusDelivered: ChannelFeatureNone, - MessageDeleting: ChannelFeatureSend, - MessageEditing: ChannelFeatureBoth, - MessageQuoting: ChannelFeatureBoth, - ImageMessage: ChannelFeatureReceive, + SpamAllowed: false, + Status: Status{ + Delivered: ChannelFeatureNone, + Read: ChannelFeatureBoth, + }, + Text: ChannelSettingsText{ + Creating: ChannelFeatureBoth, + Editing: ChannelFeatureBoth, + Quoting: ChannelFeatureBoth, + Deleting: ChannelFeatureBoth, }, }, } diff --git a/v1/types.go b/v1/types.go index 8ad2b5d..eeb24fd 100644 --- a/v1/types.go +++ b/v1/types.go @@ -10,9 +10,6 @@ const ( ChannelFeatureReceive string = "receive" ChannelFeatureSend string = "send" ChannelFeatureBoth string = "both" - - MsgModeNever string = "never" - MsgModeAlways string = "always" ) // MgClient type @@ -27,26 +24,28 @@ type MgClient struct { type Channel struct { ID uint64 `json:"id,omitempty"` Type string `json:"type,omitempty"` - Events []string `json:"events,omitempty,brackets"` Settings ChannelSettings `json:"settings,omitempty,brackets"` } // ChannelSettings struct type ChannelSettings struct { - Features ChannelFeatures `json:"features"` - ReceiveMessageMode string `json:"receive_message_mode"` - SpamAllowed bool `json:"spam_allowed"` + SpamAllowed bool `json:"spam_allowed"` + Status Status `json:"status"` + Text ChannelSettingsText `json:"text"` } -// ChannelFeatures struct -type ChannelFeatures struct { - StatusDelivered string `json:"status_delivered"` - StatusRead string `json:"status_read"` - MessageDeleting string `json:"message_deleting"` - MessageEditing string `json:"message_editing"` - MessageQuoting string `json:"message_quoting"` - ImageMessage string `json:"image_message"` - FileMessage string `json:"file_message"` +// Status struct +type Status struct { + Delivered string `json:"delivered"` + Read string `json:"read"` +} + +// ChannelSettingsText struct +type ChannelSettingsText struct { + Creating string `json:"creating"` + Editing string `json:"editing"` + Quoting string `json:"quoting"` + Deleting string `json:"deleting"` } // ActivateResponse channel activation response