feat: default accounts appear on homepage if not following an account

This commit is contained in:
2025-11-22 15:19:12 -03:00
parent 704db60297
commit dba8410146
6 changed files with 48 additions and 7 deletions

View File

@@ -27,6 +27,7 @@ enableDebug = false # enable request logs and debug endpoints (/.sessions)
logLevel = "info" # log level (debug, info, warn, error, fatal)
proxy = "" # http/https url, SOCKS proxies are not supported
proxyAuth = ""
defaultFollowedAccounts = "eff,fsf" # default accounts to show when user follows none
# Change default preferences here, see src/prefs_impl.nim for a complete list
[Preferences]

View File

@@ -1,6 +1,6 @@
# SPDX-License-Identifier: AGPL-3.0-only
import parsecfg except Config
import types, strutils
import types, strutils, sequtils
proc get*[T](config: parseCfg.Config; section, key: string; default: T): T =
let val = config.getSectionValue(section, key)
@@ -9,6 +9,7 @@ proc get*[T](config: parseCfg.Config; section, key: string; default: T): T =
when T is int: parseInt(val)
elif T is bool: parseBool(val)
elif T is string: val
elif T is seq[string]: val.split(',').mapIt(it.strip())
proc getConfig*(path: string): (Config, parseCfg.Config) =
var cfg = loadConfig(path)
@@ -41,7 +42,8 @@ proc getConfig*(path: string): (Config, parseCfg.Config) =
enableDebug: cfg.get("Config", "enableDebug", false),
logLevel: cfg.get("Config", "logLevel", ""),
proxy: cfg.get("Config", "proxy", ""),
proxyAuth: cfg.get("Config", "proxyAuth", "")
proxyAuth: cfg.get("Config", "proxyAuth", ""),
defaultFollowedAccounts: cfg.get("Config", "defaultFollowedAccounts", @["eff", "fsf"])
)
return (conf, cfg)

View File

@@ -101,22 +101,28 @@ routes:
get "/":
let prefs = cookiePrefs()
if prefs.following.len > 0:
if prefs.following.len > 0 or cfg.defaultFollowedAccounts.len > 0:
let
cursor = getCursor()
accounts = if prefs.following.len > 0: prefs.following else: cfg.defaultFollowedAccounts
isDefault = prefs.following.len == 0
currentPath = if @"f".len > 0: "/?f=" & @"f" else: "/"
var homepageQuery = initQuery(params(request))
if @"f".len == 0:
homepageQuery.kind = tweets
homepageQuery.fromUser = prefs.following
homepageQuery.fromUser = accounts
let
timeline = await getGraphTweetSearch(homepageQuery, cursor)
html = renderHomepageTimeline(timeline, prefs, getPath())
html = if isDefault:
renderDefaultTimeline(timeline, prefs, getPath())
else:
renderHomepageTimeline(timeline, prefs, getPath())
var users: seq[User]
for username in prefs.following:
for username in accounts:
try:
let user = await getCachedUser(username)
users.add(user)
@@ -127,7 +133,6 @@ routes:
tdiv(class="following-column"):
tdiv(class="profile-cards"):
for user in users:
let currentPath = if @"f".len > 0: "/?f=" & @"f" else: "/"
renderUserCard(user, prefs, currentPath)
tdiv(class="timeline"):

View File

@@ -26,6 +26,25 @@
button {
float: unset;
}
&.timeline-default {
background-color: var(--bg_panel);
border-bottom: 1px solid var(--bg_elements);
margin-bottom: 5px;
.timeline-default-message {
color: var(--fg_color);
font-size: 16px;
font-weight: normal;
margin: 0;
padding: 5px;
strong {
font-weight: bold;
color: var(--accent);
}
}
}
}
.timeline-banner img {

View File

@@ -290,6 +290,7 @@ type
logLevel*: string
proxy*: string
proxyAuth*: string
defaultFollowedAccounts*: seq[string]
rssCacheTime*: int
listCacheTime*: int

View File

@@ -65,6 +65,19 @@ proc renderHomepageTimeline*(results: Timeline; prefs: Prefs; path: string): VNo
renderTimelineTweets(results, prefs, path)
proc renderDefaultTimeline*(results: Timeline; prefs: Prefs; path: string): VNode =
let query = results.query
buildHtml(tdiv(class="timeline-container")):
tdiv(class="timeline-header timeline-default"):
h2(class="timeline-default-message"):
text "Follow people to populate your "
strong: text "own"
text " feed"
renderHomepageTabs(query)
renderTimelineTweets(results, prefs, path)
proc renderUserSearch*(results: Result[User]; prefs: Prefs; path: string): VNode =
buildHtml(tdiv(class="timeline-container")):
renderSearchTabs(results.query)