dmitri.shuralyov.com/app/changes

Add repo parameter to ThreadType.

It's needed because in some meta-services that unify multiple
underlying services, the ThreadType changes depending on the RepoSpec.

Improve local variable name.

Similar to https://github.com/shurcooL/issuesapp/commit/60bf33177c6943f244f14f81f145bc8b6c63f6cc.
Follows https://dmitri.shuralyov.com/service/change/...$commit/891fba5eb78bd1e1c421e6c7c422ccda350d246d.
dmitshur committed 6 years ago commit 04f366dcc540bf583cb10b1108c90fbd43700f58
Showing partial commit. Full Commit
Collapse all
main.go
@@ -249,23 +249,22 @@ func stateFilter(query url.Values) (change.StateFilter, error) {
	default:
		return "", fmt.Errorf("unsupported state filter value: %q", selectedTabName)
	}
}

func (s state) augmentUnread(ctx context.Context, es []component.ChangeEntry, is change.Service, notificationsService notifications.Service) []component.ChangeEntry {
func (s state) augmentUnread(ctx context.Context, es []component.ChangeEntry, service change.Service, notificationsService notifications.Service) []component.ChangeEntry {
	if notificationsService == nil {
		return es
	}

	tt, ok := is.(interface {
		ThreadType() string
	tt, ok := service.(interface {
		ThreadType(repo string) string
	})
	if !ok {
		log.Println("augmentUnread: changes service doesn't implement ThreadType")
		log.Println("augmentUnread: change service doesn't implement ThreadType")
		return es
	}
	threadType := tt.ThreadType()

	if s.CurrentUser.ID == 0 {
		// Unauthenticated user cannot have any unread changes.
		return es
	}
@@ -279,11 +278,13 @@ func (s state) augmentUnread(ctx context.Context, es []component.ChangeEntry, is
		return es
	}

	unreadThreads := make(map[uint64]struct{}) // Set of unread thread IDs.
	for _, n := range ns {
		if n.ThreadType != threadType { // Assumes RepoSpec matches because we filtered via notifications.ListOptions.
		// n.RepoSpec == s.RepoSpec is guaranteed because we filtered in notifications.ListOptions,
		// so we only need to check that n.ThreadType matches.
		if n.ThreadType != tt.ThreadType(s.RepoSpec) {
			continue
		}
		unreadThreads[n.ThreadID] = struct{}{}
	}