~chrisppy/beagles

11a8e069c460046882793b46d85c9bd7021b1978 — Chris Palmer 7 months ago 21fe9ae
Fix mark all (un)read bug
3 files changed, 38 insertions(+), 36 deletions(-)

M db/db.go
M ui/actions.go
M ui/ui.go
M db/db.go => db/db.go +1 -1
@@ 614,7 614,7 @@ func (s *Storage) MarkUnread(key string) (Items, error) {
				if !item.Read {
					continue
				}
				itemMap[key] = item
				itemMap[k] = item
			}
		}
	} else {

M ui/actions.go => ui/actions.go +36 -35
@@ 52,8 52,6 @@ func (i *UI) onCommandEnter(key tcell.Key) {
		case ":unhide":
			i.unhide()
		case ":update", ":up":
			i.commandLine.setText("updating feeds...")
			i.app.draw()
			go i.updateFeed(args)
		default:
			i.commandLine.setError("unrecognized command: " + input)


@@ 340,12 338,6 @@ func (i *UI) markUnread(event *tcell.EventKey) *tcell.EventKey {
	}

	i.app.update(func() {
		if it, ok := i.DB.Items[key]; ok {
			if !it.Read {
				return
			}
		}

		nitems, err := i.DB.MarkUnread(key)
		if err != nil {
			i.commandLine.setError(err.Error())


@@ 369,27 361,14 @@ func (i *UI) markRead(event *tcell.EventKey) *tcell.EventKey {
	}

	var key string
	var isList bool
	switch i.status {
	case listStatus, listContentStatus:
		i.app.update(func() {
			key = i.list.getKey()
			i.list.remove()
			i.sub.markReadByKey(key)
		})
		isList = true
		key = i.list.getKey()
	case subStatus, subContentStatus:
		i.app.update(func() {
			key = i.sub.getKey()

			if it, ok := i.DB.Items[key]; ok {
				if it.Read {
					return
				}
			}

			i.sub.markRead()
			i.list.removeByKey(i.DB.Items[key])

		})
		isList = false
		key = i.sub.getKey()
	default:
		return event
	}


@@ 400,9 379,20 @@ func (i *UI) markRead(event *tcell.EventKey) *tcell.EventKey {
			i.commandLine.setError(err.Error())
			return
		}

		for k := range itemMap {
			item := i.DB.Items[k]
			item.DeleteFile(i.DownloadDataHome, i.DB.Feeds)
			if !isList {
				i.list.removeByKey(item)
			}
		}

		if isList {
			i.list.remove()
			i.sub.markReadByKey(key)
		} else {
			i.sub.markRead()
		}
		i.setStatus(i.status)
	})


@@ 581,25 571,37 @@ func (i *UI) download(event *tcell.EventKey) *tcell.EventKey {
}

func (i *UI) updateFeed(args []string) {
	if i.isUpdating {
		return
	}

	i.isUpdating = true

	i.commandLine.setText("updating feeds...")
	i.app.draw()

	nitems, err := i.DB.Update()
	if err != nil {
		i.Logger.Errorln(err.Error())
		return
	}

	for _, item := range nitems.Sort() {
		i.app.update(func() {
	i.app.update(func() {
		for _, item := range nitems.Sort() {
			i.list.insert(item)
			i.sub.insert(item, i.hideRead)
		})
		if i.Config.Podcast.AutoDownload {
			if err := item.Download(i.DownloadDataHome, i.DB.Feeds); err != nil {
				i.Logger.Errorln(err.Error())
			if i.Config.Podcast.AutoDownload {
				if err := item.Download(i.DownloadDataHome, i.DB.Feeds); err != nil {
					i.Logger.Errorln(err.Error())
				}
			}
		}
	}

	i.setStatus(i.status)
		i.setStatus(i.status)
	})
	i.app.draw()

	i.isUpdating = false
}

func (i *UI) addFeed(args []string) {


@@ 739,7 741,6 @@ func (i *UI) searchItem(text string) {
func (i *UI) UpdateLoop(interval time.Duration) {
	for {
		<-time.After(interval)
		i.commandLine.setText("updating feeds...")
		i.updateFeed(nil)
	}
}

M ui/ui.go => ui/ui.go +1 -0
@@ 39,6 39,7 @@ type UI struct {
	DownloadDataHome string
	GeminiDataHome   string
	hideRead         bool
	isUpdating       bool
	DB               *db.Storage
	Config           *config.Config
	Logger           *wlog.WaterLog