Skip to content

Commit

Permalink
message: move Media function from context
Browse files Browse the repository at this point in the history
  • Loading branch information
demget committed Jan 22, 2022
1 parent 61dabe9 commit 10b7014
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
26 changes: 0 additions & 26 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ type Context interface {
// Message returns stored message if such presented.
Message() *Message

// Media returns message media if such presented.
Media() Media

// Callback returns stored callback if such presented.
Callback() *Callback

Expand Down Expand Up @@ -192,29 +189,6 @@ func (c *nativeContext) Message() *Message {
}
}

func (c *nativeContext) Media() Media {
m := c.Message()

switch {
case m.Photo != nil:
return m.Photo
case m.Voice != nil:
return m.Voice
case m.Audio != nil:
return m.Audio
case m.Animation != nil:
return m.Animation
case m.Document != nil:
return m.Document
case m.Video != nil:
return m.Video
case m.VideoNote != nil:
return m.VideoNote
default:
return nil
}
}

func (c *nativeContext) Callback() *Callback {
return c.u.Callback
}
Expand Down
23 changes: 23 additions & 0 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,26 @@ func (m *Message) EntityText(e MessageEntity) string {

return string(utf16.Decode(a[off:end]))
}

// Media returns the message's media if it contains either photo,
// voice, audio, animation, document, video or video note.
func (m *Message) Media() Media {
switch {
case m.Photo != nil:
return m.Photo
case m.Voice != nil:
return m.Voice
case m.Audio != nil:
return m.Audio
case m.Animation != nil:
return m.Animation
case m.Document != nil:
return m.Document
case m.Video != nil:
return m.Video
case m.VideoNote != nil:
return m.VideoNote
default:
return nil
}
}

0 comments on commit 10b7014

Please sign in to comment.