From fb61bdb09a8d6015fc3177422b43c5cb2f9d38ea Mon Sep 17 00:00:00 2001 From: Edouard Paris Date: Wed, 10 Apr 2019 15:02:09 +0200 Subject: [PATCH] fix models channel: use ChannelPoint --- ui/models/channels.go | 14 +++++++------- ui/models/models.go | 2 +- ui/views/channels.go | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ui/models/channels.go b/ui/models/channels.go index 15f47fe..04b77d5 100644 --- a/ui/models/channels.go +++ b/ui/models/channels.go @@ -7,7 +7,7 @@ import ( ) type Channels struct { - index map[uint64]*models.Channel + index map[string]*models.Channel list []*models.Channel mu sync.RWMutex } @@ -24,12 +24,12 @@ func (c *Channels) Get(index int) *models.Channel { return c.list[index] } -func (c *Channels) GetByID(id uint64) *models.Channel { - return c.index[id] +func (c *Channels) GetByChanPoint(chanPoint string) *models.Channel { + return c.index[chanPoint] } func (c *Channels) Contains(channel *models.Channel) bool { - _, ok := c.index[channel.ID] + _, ok := c.index[channel.ChannelPoint] return ok } @@ -39,7 +39,7 @@ func (c *Channels) Add(channel *models.Channel) { if c.Contains(channel) { return } - c.index[channel.ID] = channel + c.index[channel.ChannelPoint] = channel c.list = append(c.list, channel) } @@ -47,7 +47,7 @@ func (c *Channels) Update(newChannel *models.Channel) { c.mu.Lock() defer c.mu.Unlock() - oldChannel, ok := c.index[newChannel.ID] + oldChannel, ok := c.index[newChannel.ChannelPoint] if !ok { c.Add(newChannel) return @@ -82,7 +82,7 @@ func (c *Channels) Update(newChannel *models.Channel) { func NewChannels() *Channels { return &Channels{ list: []*models.Channel{}, - index: make(map[uint64]*models.Channel), + index: make(map[string]*models.Channel), } } diff --git a/ui/models/models.go b/ui/models/models.go index 0499195..81f4b06 100644 --- a/ui/models/models.go +++ b/ui/models/models.go @@ -50,7 +50,7 @@ func (m *Models) RefreshChannels(ctx context.Context) error { if !m.Channels.Contains(channels[i]) { m.Channels.Add(channels[i]) } - channel := m.Channels.GetByID(channels[i].ID) + channel := m.Channels.GetByChanPoint(channels[i].ChannelPoint) if channel != nil && (channel.UpdatesCount < channels[i].UpdatesCount || channel.LastUpdate == nil) { diff --git a/ui/views/channels.go b/ui/views/channels.go index 71e59b5..492b654 100644 --- a/ui/views/channels.go +++ b/ui/views/channels.go @@ -114,7 +114,7 @@ func (c *Channels) Set(g *gocui.Gui, x0, y0, x1, y1 int) error { func displayChannelsColumns(v *gocui.View) { 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", "ALIAS", "GAUGE", @@ -130,7 +130,7 @@ func (c *Channels) display() { p := message.NewPrinter(language.English) c.view.Clear() 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), alias(item), gauge(item),