~chrisppy/beagles

3fa66672f988d73fa5a794e287df6788b568f4db — Chris Palmer 1 year, 4 months ago 73792cd
Fix rm in subscription panel
5 files changed, 56 insertions(+), 57 deletions(-)

M db/db.go
M db/feed.go
M ui/actions.go
M ui/status.go
M ui/tree.go
M db/db.go => db/db.go +14 -14
@@ 276,54 276,54 @@ func (s *Storage) CreateFeed(url string) (Items, error) {
}

// DeleteFeed will delete the Feed, Items, and relevant items it the queue.
func (s *Storage) DeleteFeed(url string) (Items, error) {
func (s *Storage) DeleteFeed(url string) (*Feed, Items, error) {
	db, err := openDB(s.Path)
	if err != nil {
		return nil, err
		return nil, nil, err
	}

	items, err := s.Feeds.Delete(db, url)
	feed, err := s.Feeds.Delete(db, url)
	if err != nil {
		if err := db.Close(); err != nil {
			return nil, err
			return nil, nil, err
		}

		return nil, err
		return nil, nil, err
	}

	nitems := make(Items)
	for key := range items {
	for key := range feed.Items {
		it, err := s.Items.Delete(db, key)
		if err != nil {
			if err := db.Close(); err != nil {
				return nil, err
				return nil, nil, err
			}

			return nil, err
			return nil, nil, err
		}
		if err := s.Queue.Delete(db, key); err != nil {
			if err := db.Close(); err != nil {
				return nil, err
				return nil, nil, err
			}

			return nil, err
			return nil, nil, err
		}
		if err := s.Favorites.Delete(db, key); err != nil {
			if err := db.Close(); err != nil {
				return nil, err
				return nil, nil, err
			}

			return nil, err
			return nil, nil, err
		}

		nitems[key] = it
	}

	if err := db.Close(); err != nil {
		return nil, err
		return nil, nil, err
	}

	return nitems, nil
	return feed, nitems, nil
}

// Update will check for rss updates

M db/feed.go => db/feed.go +2 -2
@@ 178,7 178,7 @@ func (f Feeds) Insert(db *bolt.DB, url string, gmniPath string) ([]*gofeed.Item,
}

// Delete will remove a feed from the database
func (f Feeds) Delete(db *bolt.DB, url string) (map[string]bool, error) {
func (f Feeds) Delete(db *bolt.DB, url string) (*Feed, error) {
	if url == "" {
		return nil, fmt.Errorf("url was empty, unable to delete")
	}


@@ 196,7 196,7 @@ func (f Feeds) Delete(db *bolt.DB, url string) (map[string]bool, error) {

	delete(f, url)

	return feed.Items, nil
	return feed, nil
}

// AddItems will update the feeds map of items and unread count

M ui/actions.go => ui/actions.go +23 -12
@@ 396,6 396,7 @@ func (i *UI) markUnread(event *tcell.EventKey) *tcell.EventKey {
		}

		i.sub.markUnread()
		i.setStatus(i.status)
	})
	i.app.draw()
	return nil


@@ 442,6 443,7 @@ func (i *UI) markRead(event *tcell.EventKey) *tcell.EventKey {
			item := i.DB.Items[k]
			item.DeleteFile(i.DownloadDataHome, i.DB.Feeds)
		}
		i.setStatus(i.status)
	})
	i.app.draw()



@@ 467,11 469,11 @@ func (i *UI) markFavorite(event *tcell.EventKey) *tcell.EventKey {
		item, err := i.DB.Favorite(key)
		if err != nil {
			i.commandLine.setError(err.Error())
			i.setStatus(i.status)
			return
		}

		i.fav.insert(item)
		i.setStatus(i.status)
	})
	i.app.draw()



@@ 495,9 497,9 @@ func (i *UI) unmarkFavorite(event *tcell.EventKey) *tcell.EventKey {
	i.app.update(func() {
		if err := i.DB.Unfavorite(key); err != nil {
			i.commandLine.setError(err.Error())
			i.setStatus(i.status)
			return
		}
		i.setStatus(i.status)
	})

	i.app.draw()


@@ 531,10 533,10 @@ func (i *UI) openLink(event *tcell.EventKey) *tcell.EventKey {
		go func() {
			if err := util.OpenBrowser(key, i.Config.Browser); err != nil {
				i.commandLine.setError(err.Error())
				i.setStatus(i.status)
				i.app.draw()
			}
		}()
		i.setStatus(i.status)
	})

	i.app.draw()


@@ 571,10 573,10 @@ func (i *UI) play(event *tcell.EventKey) *tcell.EventKey {

		if err := item.ExtPlay(ep.Bin, ep.Args, i.DownloadDataHome, i.DB.Feeds); err != nil {
			i.commandLine.setError(err.Error())
			i.setStatus(i.status)
			i.app.draw()
			return
		}
		i.setStatus(i.status)
	})
	i.app.draw()
	return nil


@@ 612,6 614,7 @@ func (i *UI) download(event *tcell.EventKey) *tcell.EventKey {
		}

		i.commandLine.setText("")
		i.setStatus(i.status)
	})
	i.app.draw()
	return nil


@@ 638,6 641,7 @@ func (i *UI) updateFeed(args []string) {
		}

		i.commandLine.setText("")
		i.setStatus(i.status)
	})
	i.app.draw()
}


@@ 661,16 665,16 @@ func (i *UI) addFeed(args []string) {
		for _, v := range nitems.Sort() {
			i.list.insert(v)

			if node := i.sub.find(v.FeedURL, i.sub.Node.GetChildren()); node == nil {
			if node, _ := i.sub.find(v.FeedURL, i.sub.Node.GetChildren()); node == nil {
				f := i.DB.Feeds[v.FeedURL]
				i.sub.add(f, i.DB.Items, i.hideRead)
			}
		}

		i.commandLine.setText("")
		i.setStatus(i.status)
	})
	i.app.draw()
	i.setStatus(i.status)
}
func (i *UI) deleteFeed(args []string) {
	i.commandLine.setText("removing feed...")


@@ 681,19 685,16 @@ func (i *UI) deleteFeed(args []string) {
		s := len(args)
		if s > 2 {
			i.commandLine.setError("remove must contain at most one url")
			i.setStatus(i.status)
			return
		} else if s == 1 {
			if i.status != subStatus && i.status != subContentStatus {
				i.commandLine.setError("remove can contain no urls if on a feed in the subscription page")
				i.setStatus(i.status)
				return
			}

			key := i.sub.getKey()
			if _, ok := i.DB.Feeds[key]; !ok {
				i.commandLine.setError("remove can contain no urls if on a feed")
				i.setStatus(i.status)
				return
			}
			arg = key


@@ 701,20 702,24 @@ func (i *UI) deleteFeed(args []string) {
			arg = args[1]
		}

		nitems, err := i.DB.DeleteFeed(arg)
		feed, nitems, err := i.DB.DeleteFeed(arg)
		if err != nil {
			i.commandLine.setError(err.Error())
			i.setStatus(i.status)
			return
		}

		if nitems == nil || len(nitems) == 0 {
			return
		}

		for _, v := range nitems {
			i.list.removeByKey(v)
			i.fav.removeByKey(v)
			i.sub.removeByKey(v)
		}
		i.sub.removeFeedByKey(feed)

		i.commandLine.setText("")
		i.setStatus(i.status)
	})

	i.app.draw()


@@ 733,6 738,7 @@ func (i *UI) hide() {

		i.commandLine.setError("hide is not yet implemented!")
		// TODO: remove each hidden element
		i.setStatus(i.status)
	})
	i.app.draw()
}


@@ 750,6 756,7 @@ func (i *UI) unhide() {

		i.commandLine.setError("unhide is not yet implemented!")
		// TODO: add each element
		i.setStatus(i.status)
	})
	i.app.draw()
}


@@ 757,6 764,8 @@ func (i *UI) unhide() {
func (i *UI) searchFeed(text string) {
	i.app.update(func() {
		i.commandLine.setError("search feed is not yet implemented!")
		// TODO: hide elements not in pattern
		i.setStatus(i.status)
	})
	i.app.draw()
}


@@ 764,6 773,8 @@ func (i *UI) searchFeed(text string) {
func (i *UI) searchItem(text string) {
	i.app.update(func() {
		i.commandLine.setError("search item is not yet implemented!")
		// TODO: hide elements not in pattern
		i.setStatus(i.status)
	})
	i.app.draw()
}

M ui/status.go => ui/status.go +4 -4
@@ 65,15 65,15 @@ func (i *UI) setStatus(s statusType) {
		panel = "favorite"
		sltext = "-- CONTENT --"
		widget = i.favContent.Widget
	case helpStatus:
		panel = "help"
		sltext = "-- HELP --"
		widget = i.helpContent.Widget
	case commandStatus:
		i.Mode = cmd
		sltext = "-- COMMAND --"
		widget = i.commandLine.Widget
		cltext = ":"
	case helpStatus:
		panel = "help"
		sltext = "-- HELP --"
		widget = i.helpContent.Widget
	case searchFeedStatus:
		i.Mode = search
		sltext = "-- SEARCH --"

M ui/tree.go => ui/tree.go +13 -25
@@ 236,7 236,7 @@ func (w *tree) pageDown() string {
}

func (w *tree) markReadByKey(key string) {
	node := w.find(key, w.Node.GetChildren())
	node, _ := w.find(key, w.Node.GetChildren())
	if node == nil {
		return
	}


@@ 306,7 306,7 @@ func (w *tree) toggle() {
}

func (w *tree) insert(item *db.Item, hide bool) {
	node := w.find(item.FeedURL, w.Node.GetChildren())
	node, _ := w.find(item.FeedURL, w.Node.GetChildren())
	if node == nil {
		return
	}


@@ 322,38 322,26 @@ func (w *tree) insert(item *db.Item, hide bool) {
	node.AddChild(n)
}

func (w *tree) find(ref string, nodes []*tui.TreeNode) *tui.TreeNode {
	for _, node := range nodes {
func (w *tree) find(ref string, nodes []*tui.TreeNode) (*tui.TreeNode, int) {
	for i, node := range nodes {
		if ref == fmt.Sprintf("%v", node.GetReference()) {
			return node
		} else if n := w.find(ref, node.GetChildren()); n != nil {
			return n
			return node, i
		} else if n, j := w.find(ref, node.GetChildren()); n != nil {
			return n, j
		}
	}
	return nil
	return nil, 0
}

func (w *tree) removeByKey(item *db.Item) {
	node := w.find(item.FeedURL, w.Node.GetChildren())
func (w *tree) removeFeedByKey(feed *db.Feed) {
	node, i := w.find(feed.Link, w.Node.GetChildren())
	if node == nil {
		return
	}

	delete(w.ChildParent, item.Link)

	var in int
	var found bool
	for i, ch := range node.GetChildren() {
		if item.Link == fmt.Sprintf("%v", ch.GetReference()) {
			in = i
			found = true
			break
		}
	}

	if !found {
		return
	for k := range feed.Items {
		delete(w.ChildParent, k)
	}

	node.SetChildren(append(node.GetChildren()[:in], node.GetChildren()[in+1:]...))
	w.Node.SetChildren(append(w.Node.GetChildren()[:i], w.Node.GetChildren()[i+1:]...))
}