fix models channel: use ChannelPoint

pull/1/head
Edouard Paris 5 years ago
parent 92f33b2a48
commit fb61bdb09a

@ -7,7 +7,7 @@ import (
) )
type Channels struct { type Channels struct {
index map[uint64]*models.Channel index map[string]*models.Channel
list []*models.Channel list []*models.Channel
mu sync.RWMutex mu sync.RWMutex
} }
@ -24,12 +24,12 @@ func (c *Channels) Get(index int) *models.Channel {
return c.list[index] return c.list[index]
} }
func (c *Channels) GetByID(id uint64) *models.Channel { func (c *Channels) GetByChanPoint(chanPoint string) *models.Channel {
return c.index[id] return c.index[chanPoint]
} }
func (c *Channels) Contains(channel *models.Channel) bool { func (c *Channels) Contains(channel *models.Channel) bool {
_, ok := c.index[channel.ID] _, ok := c.index[channel.ChannelPoint]
return ok return ok
} }
@ -39,7 +39,7 @@ func (c *Channels) Add(channel *models.Channel) {
if c.Contains(channel) { if c.Contains(channel) {
return return
} }
c.index[channel.ID] = channel c.index[channel.ChannelPoint] = channel
c.list = append(c.list, channel) c.list = append(c.list, channel)
} }
@ -47,7 +47,7 @@ func (c *Channels) Update(newChannel *models.Channel) {
c.mu.Lock() c.mu.Lock()
defer c.mu.Unlock() defer c.mu.Unlock()
oldChannel, ok := c.index[newChannel.ID] oldChannel, ok := c.index[newChannel.ChannelPoint]
if !ok { if !ok {
c.Add(newChannel) c.Add(newChannel)
return return
@ -82,7 +82,7 @@ func (c *Channels) Update(newChannel *models.Channel) {
func NewChannels() *Channels { func NewChannels() *Channels {
return &Channels{ return &Channels{
list: []*models.Channel{}, list: []*models.Channel{},
index: make(map[uint64]*models.Channel), index: make(map[string]*models.Channel),
} }
} }

@ -50,7 +50,7 @@ func (m *Models) RefreshChannels(ctx context.Context) error {
if !m.Channels.Contains(channels[i]) { if !m.Channels.Contains(channels[i]) {
m.Channels.Add(channels[i]) m.Channels.Add(channels[i])
} }
channel := m.Channels.GetByID(channels[i].ID) channel := m.Channels.GetByChanPoint(channels[i].ChannelPoint)
if channel != nil && if channel != nil &&
(channel.UpdatesCount < channels[i].UpdatesCount || (channel.UpdatesCount < channels[i].UpdatesCount ||
channel.LastUpdate == nil) { channel.LastUpdate == nil) {

@ -114,7 +114,7 @@ func (c *Channels) Set(g *gocui.Gui, x0, y0, x1, y1 int) error {
func displayChannelsColumns(v *gocui.View) { func displayChannelsColumns(v *gocui.View) {
v.Clear() v.Clear()
fmt.Fprintln(v, fmt.Sprintf("%-13s %-20s %-21s %12s %12s %5s %-15s %s", fmt.Fprintln(v, fmt.Sprintf("%-13s %-25s %-21s %12s %12s %5s %-15s %s",
"STATUS", "STATUS",
"ALIAS", "ALIAS",
"GAUGE", "GAUGE",
@ -130,7 +130,7 @@ func (c *Channels) display() {
p := message.NewPrinter(language.English) p := message.NewPrinter(language.English)
c.view.Clear() c.view.Clear()
for _, item := range c.channels.List() { for _, item := range c.channels.List() {
line := fmt.Sprintf("%s %-20s %s %s %s %5d %15s %d %500s", line := fmt.Sprintf("%s %-25s %s %s %s %5d %15s %d %500s",
status(item), status(item),
alias(item), alias(item),
gauge(item), gauge(item),

Loading…
Cancel
Save