<commit_before>package server

import (
	"net/http"
	"net/url"
	"strings"

	"github.com/spf13/viper"

	"github.com/khlieng/dispatch/storage"
)

type connectDefaults struct {
	Name        string
	Host        string
	Port        int
	Channels    []string
	Password    bool
	SSL         bool
	ReadOnly    bool
	ShowDetails bool
}

type indexData struct {
	Defaults connectDefaults
	Servers  []Server
	Channels []*storage.Channel
	HexIP    bool

	Settings *storage.ClientSettings

	// Users in the selected channel
	Users *Userlist

	// Last messages in the selected channel
	Messages *Messages
}

func getIndexData(r *http.Request, state *State) *indexData {
	data := indexData{
		HexIP: viper.GetBool("hexIP"),
	}

	data.Defaults = connectDefaults{
		Name:        viper.GetString("defaults.name"),
		Host:        viper.GetString("defaults.host"),
		Port:        viper.GetInt("defaults.port"),
		Channels:    viper.GetStringSlice("defaults.channels"),
		Password:    viper.GetString("defaults.password") != "",
		SSL:         viper.GetBool("defaults.ssl"),
		ReadOnly:    viper.GetBool("defaults.readonly"),
		ShowDetails: viper.GetBool("defaults.show_details"),
	}

	if state == nil {
		return &data
	}

	data.Settings = state.user.GetClientSettings()

	servers, err := state.user.GetServers()
	if err != nil {
		return nil
	}
	connections := state.getConnectionStates()
	for _, server := range servers {
		server.Password = ""
		server.Username = ""
		server.Realname = ""

		data.Servers = append(data.Servers, Server{
			Server: server,
			Status: newConnectionUpdate(server.Host, connections[server.Host]),
		})
	}

	channels, err := state.user.GetChannels()
	if err != nil {<commit_msg>Send default settings when there is no user yet<commit_after>package server

import (
	"net/http"
	"net/url"
	"strings"

	"github.com/spf13/viper"

	"github.com/khlieng/dispatch/storage"
)

type connectDefaults struct {
	Name        string
	Host        string
	Port        int
	Channels    []string
	Password    bool
	SSL         bool
	ReadOnly    bool
	ShowDetails bool
}

type indexData struct {
	Defaults connectDefaults
	Servers  []Server
	Channels []*storage.Channel
	HexIP    bool

	Settings *storage.ClientSettings

	// Users in the selected channel
	Users *Userlist

	// Last messages in the selected channel
	Messages *Messages
}

func getIndexData(r *http.Request, state *State) *indexData {
	data := indexData{
		HexIP: viper.GetBool("hexIP"),
	}

	data.Defaults = connectDefaults{
		Name:        viper.GetString("defaults.name"),
		Host:        viper.GetString("defaults.host"),
		Port:        viper.GetInt("defaults.port"),
		Channels:    viper.GetStringSlice("defaults.channels"),
		Password:    viper.GetString("defaults.password") != "",
		SSL:         viper.GetBool("defaults.ssl"),
		ReadOnly:    viper.GetBool("defaults.readonly"),
		ShowDetails: viper.GetBool("defaults.show_details"),
	}

	if state == nil {
		data.Settings = storage.DefaultClientSettings()
		return &data
	}

	data.Settings = state.user.GetClientSettings()

	servers, err := state.user.GetServers()
	if err != nil {
		return nil
	}
	connections := state.getConnectionStates()
	for _, server := range servers {
		server.Password = ""
		server.Username = ""
		server.Realname = ""

		data.Servers = append(data.Servers, Server{
			Server: server,
			Status: newConnectionUpdate(server.Host, connections[server.Host]),
		})
	}

	channels, err := state.user.GetChannels()
	if err != nil {
{'fraction_non_alphanumeric': 0.12160600808781051, 'fraction_numerical': 0.0011554015020219526, 'mean_word_length': 3.4857512953367875, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5750081', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1096, 'n_words': 252}