Skip to content

Commit

Permalink
Add Reset and GetFileID methods to Filer interface
Browse files Browse the repository at this point in the history
  • Loading branch information
m0sth8 committed Jul 23, 2016
1 parent 2cc6390 commit 96d87da
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
10 changes: 10 additions & 0 deletions configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,16 @@ func (cfg WebhookCfg) Exist() bool {
return cfg.Certificate == nil
}

// Reset method sets new Certificate
func (cfg *WebhookCfg) Reset(i InputFile) {
cfg.Certificate = i
}

// GetFileID for webhook is always empty
func (cfg *WebhookCfg) GetFileID() string {
return ""
}

// AnswerCallbackCfg contains information on making a anserCallbackQuery response.
type AnswerCallbackCfg struct {
CallbackQueryID string `json:"callback_query_id"`
Expand Down
20 changes: 20 additions & 0 deletions configs_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ import (
"strconv"
)

// Assert interfaces
var _ Filer = (*PhotoCfg)(nil)
var _ Filer = (*AudioCfg)(nil)
var _ Filer = (*VideoCfg)(nil)
var _ Filer = (*VoiceCfg)(nil)
var _ Filer = (*DocumentCfg)(nil)
var _ Filer = (*StickerCfg)(nil)
var _ Filer = (*WebhookCfg)(nil)

// BaseMessage is a base type for all message config types.
// Implements Messenger interface.
type BaseMessage struct {
Expand Down Expand Up @@ -278,6 +287,11 @@ type BaseFile struct {
InputFile InputFile
}

// GetFileID returns fileID if it's exist
func (b BaseFile) GetFileID() string {
return b.FileID
}

// Exist returns true if file exists on telegram servers
func (b BaseFile) Exist() bool {
return b.FileID != ""
Expand All @@ -300,6 +314,12 @@ func (b BaseFile) Values() (url.Values, error) {
return v, nil
}

// Reset method removes FileID and sets new InputFile
func (b *BaseFile) Reset(i InputFile) {
b.FileID = ""
b.InputFile = i
}

// PhotoCfg contains information about a SendPhoto request.
// Use it to send information about a venue
// Implements Filer and Messenger interfaces.
Expand Down
5 changes: 5 additions & 0 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ func CloneMessage(msg *Message, baseMessage *BaseMessage) Messenger {
BaseMessage: base,
FileID: msg.Photo[len(msg.Photo)-1].FileID,
},
Caption: msg.Caption,
}
}
if msg.Location != nil {
Expand All @@ -315,6 +316,9 @@ func CloneMessage(msg *Message, baseMessage *BaseMessage) Messenger {
BaseMessage: base,
FileID: msg.Audio.FileID,
},
Duration: msg.Audio.Duration,
Performer: msg.Audio.Performer,
Title: msg.Audio.Title,
}
}
if msg.Voice != nil {
Expand All @@ -323,6 +327,7 @@ func CloneMessage(msg *Message, baseMessage *BaseMessage) Messenger {
BaseMessage: base,
FileID: msg.Voice.FileID,
},
Duration: msg.Voice.Duration,
}
}
if msg.Document != nil {
Expand Down
4 changes: 4 additions & 0 deletions interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ type Filer interface {
File() InputFile
// Exist returns true if file exists on telegram servers
Exist() bool
// Reset removes FileID and sets new InputFile
Reset(InputFile)
// GetFileID returns fileID if it's exist
GetFileID() string
}

// ReplyMarkup describes interface for reply_markup keyboards.
Expand Down

0 comments on commit 96d87da

Please sign in to comment.