2020-06-06 07:44:36 +00:00
|
|
|
package message
|
|
|
|
|
|
|
|
import (
|
|
|
|
"html"
|
|
|
|
|
|
|
|
"github.com/diamondburned/cchat-gtk/internal/ui/messages/input"
|
|
|
|
)
|
|
|
|
|
|
|
|
type PresendContainer interface {
|
2020-06-13 07:29:32 +00:00
|
|
|
SetDone(id string)
|
|
|
|
SetLoading()
|
2020-06-06 07:44:36 +00:00
|
|
|
SetSentError(err error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// PresendGenericContainer is the generic container with extra methods
|
2020-06-13 07:29:32 +00:00
|
|
|
// implemented for stateful mutability of the generic message container.
|
2020-06-06 07:44:36 +00:00
|
|
|
type GenericPresendContainer struct {
|
|
|
|
*GenericContainer
|
2020-06-13 07:29:32 +00:00
|
|
|
sendString string // to be cleared on SetDone()
|
2020-06-06 07:44:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ PresendContainer = (*GenericPresendContainer)(nil)
|
|
|
|
|
|
|
|
func NewPresendContainer(msg input.PresendMessage) *GenericPresendContainer {
|
2020-06-07 04:27:28 +00:00
|
|
|
return WrapPresendContainer(NewEmptyContainer(), msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
func WrapPresendContainer(c *GenericContainer, msg input.PresendMessage) *GenericPresendContainer {
|
2020-06-06 07:44:36 +00:00
|
|
|
c.nonce = msg.Nonce()
|
|
|
|
c.authorID = msg.AuthorID()
|
2020-06-13 07:29:32 +00:00
|
|
|
c.UpdateTimestamp(msg.Time())
|
2020-06-06 07:44:36 +00:00
|
|
|
c.UpdateAuthorName(msg.Author())
|
|
|
|
|
|
|
|
p := &GenericPresendContainer{
|
|
|
|
GenericContainer: c,
|
2020-06-13 07:29:32 +00:00
|
|
|
sendString: msg.Content(),
|
2020-06-06 07:44:36 +00:00
|
|
|
}
|
2020-06-13 07:29:32 +00:00
|
|
|
p.SetLoading()
|
2020-06-06 07:44:36 +00:00
|
|
|
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *GenericPresendContainer) SetSensitive(sensitive bool) {
|
|
|
|
m.Content.SetSensitive(sensitive)
|
|
|
|
}
|
|
|
|
|
2020-06-13 07:29:32 +00:00
|
|
|
func (m *GenericPresendContainer) SetDone(id string) {
|
|
|
|
m.id = id
|
2020-06-06 07:44:36 +00:00
|
|
|
m.SetSensitive(true)
|
2020-06-13 07:29:32 +00:00
|
|
|
m.sendString = ""
|
2020-06-19 22:40:06 +00:00
|
|
|
m.Content.SetTooltipText("")
|
2020-06-06 07:44:36 +00:00
|
|
|
}
|
|
|
|
|
2020-06-13 07:29:32 +00:00
|
|
|
func (m *GenericPresendContainer) SetLoading() {
|
|
|
|
m.SetSensitive(false)
|
2020-06-19 22:40:06 +00:00
|
|
|
m.CBuffer.SetText(m.sendString)
|
2020-06-13 07:29:32 +00:00
|
|
|
m.Content.SetTooltipText("")
|
|
|
|
}
|
2020-06-07 04:27:28 +00:00
|
|
|
|
2020-06-13 07:29:32 +00:00
|
|
|
func (m *GenericPresendContainer) SetSentError(err error) {
|
|
|
|
m.SetSensitive(true) // allow events incl right clicks
|
2020-06-19 22:40:06 +00:00
|
|
|
m.CBuffer.SetText(`<span color="red">` + html.EscapeString(m.sendString) + `</span>`)
|
2020-06-06 07:44:36 +00:00
|
|
|
m.Content.SetTooltipText(err.Error())
|
|
|
|
}
|