1
0
Fork 0
mirror of https://github.com/diamondburned/cchat-gtk.git synced 2024-11-01 12:04:15 +00:00
cchat-gtk/internal/ui/messages/message/sending.go

67 lines
1.6 KiB
Go
Raw Normal View History

2020-06-06 07:44:36 +00:00
package message
import (
"html"
"github.com/diamondburned/cchat-gtk/internal/ui/messages/input"
)
type PresendContainer interface {
SetDone(id string)
SetLoading()
2020-06-06 07:44:36 +00:00
SetSentError(err error)
}
// PresendGenericContainer is the generic container with extra methods
// implemented for stateful mutability of the generic message container.
2020-06-06 07:44:36 +00:00
type GenericPresendContainer struct {
*GenericContainer
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()
c.UpdateTimestamp(msg.Time())
2020-06-06 07:44:36 +00:00
c.UpdateAuthorName(msg.Author())
p := &GenericPresendContainer{
GenericContainer: c,
sendString: msg.Content(),
2020-06-06 07:44:36 +00:00
}
p.SetLoading()
2020-06-06 07:44:36 +00:00
return p
}
func (m *GenericPresendContainer) SetSensitive(sensitive bool) {
m.Content.SetSensitive(sensitive)
}
func (m *GenericPresendContainer) SetDone(id string) {
m.id = id
2020-06-06 07:44:36 +00:00
m.SetSensitive(true)
m.sendString = ""
m.Content.SetTooltipText("")
2020-06-06 07:44:36 +00:00
}
func (m *GenericPresendContainer) SetLoading() {
m.SetSensitive(false)
m.Content.SetText(m.sendString)
m.Content.SetTooltipText("")
// m.CBuffer.SetText(m.sendString)
}
2020-06-07 04:27:28 +00:00
func (m *GenericPresendContainer) SetSentError(err error) {
m.SetSensitive(true) // allow events incl right clicks
m.Content.SetMarkup(`<span color="red">` + html.EscapeString(m.sendString) + `</span>`)
2020-06-06 07:44:36 +00:00
m.Content.SetTooltipText(err.Error())
}