feat: default accounts appear on homepage if not following an account
This commit is contained in:
@@ -27,6 +27,7 @@ enableDebug = false # enable request logs and debug endpoints (/.sessions)
|
|||||||
logLevel = "info" # log level (debug, info, warn, error, fatal)
|
logLevel = "info" # log level (debug, info, warn, error, fatal)
|
||||||
proxy = "" # http/https url, SOCKS proxies are not supported
|
proxy = "" # http/https url, SOCKS proxies are not supported
|
||||||
proxyAuth = ""
|
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
|
# Change default preferences here, see src/prefs_impl.nim for a complete list
|
||||||
[Preferences]
|
[Preferences]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
import parsecfg except Config
|
import parsecfg except Config
|
||||||
import types, strutils
|
import types, strutils, sequtils
|
||||||
|
|
||||||
proc get*[T](config: parseCfg.Config; section, key: string; default: T): T =
|
proc get*[T](config: parseCfg.Config; section, key: string; default: T): T =
|
||||||
let val = config.getSectionValue(section, key)
|
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)
|
when T is int: parseInt(val)
|
||||||
elif T is bool: parseBool(val)
|
elif T is bool: parseBool(val)
|
||||||
elif T is string: val
|
elif T is string: val
|
||||||
|
elif T is seq[string]: val.split(',').mapIt(it.strip())
|
||||||
|
|
||||||
proc getConfig*(path: string): (Config, parseCfg.Config) =
|
proc getConfig*(path: string): (Config, parseCfg.Config) =
|
||||||
var cfg = loadConfig(path)
|
var cfg = loadConfig(path)
|
||||||
@@ -41,7 +42,8 @@ proc getConfig*(path: string): (Config, parseCfg.Config) =
|
|||||||
enableDebug: cfg.get("Config", "enableDebug", false),
|
enableDebug: cfg.get("Config", "enableDebug", false),
|
||||||
logLevel: cfg.get("Config", "logLevel", ""),
|
logLevel: cfg.get("Config", "logLevel", ""),
|
||||||
proxy: cfg.get("Config", "proxy", ""),
|
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)
|
return (conf, cfg)
|
||||||
|
|||||||
@@ -101,22 +101,28 @@ routes:
|
|||||||
get "/":
|
get "/":
|
||||||
let prefs = cookiePrefs()
|
let prefs = cookiePrefs()
|
||||||
|
|
||||||
if prefs.following.len > 0:
|
if prefs.following.len > 0 or cfg.defaultFollowedAccounts.len > 0:
|
||||||
let
|
let
|
||||||
cursor = getCursor()
|
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))
|
var homepageQuery = initQuery(params(request))
|
||||||
if @"f".len == 0:
|
if @"f".len == 0:
|
||||||
homepageQuery.kind = tweets
|
homepageQuery.kind = tweets
|
||||||
|
|
||||||
homepageQuery.fromUser = prefs.following
|
homepageQuery.fromUser = accounts
|
||||||
|
|
||||||
let
|
let
|
||||||
timeline = await getGraphTweetSearch(homepageQuery, cursor)
|
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]
|
var users: seq[User]
|
||||||
for username in prefs.following:
|
for username in accounts:
|
||||||
try:
|
try:
|
||||||
let user = await getCachedUser(username)
|
let user = await getCachedUser(username)
|
||||||
users.add(user)
|
users.add(user)
|
||||||
@@ -127,7 +133,6 @@ routes:
|
|||||||
tdiv(class="following-column"):
|
tdiv(class="following-column"):
|
||||||
tdiv(class="profile-cards"):
|
tdiv(class="profile-cards"):
|
||||||
for user in users:
|
for user in users:
|
||||||
let currentPath = if @"f".len > 0: "/?f=" & @"f" else: "/"
|
|
||||||
renderUserCard(user, prefs, currentPath)
|
renderUserCard(user, prefs, currentPath)
|
||||||
|
|
||||||
tdiv(class="timeline"):
|
tdiv(class="timeline"):
|
||||||
|
|||||||
@@ -26,6 +26,25 @@
|
|||||||
button {
|
button {
|
||||||
float: unset;
|
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 {
|
.timeline-banner img {
|
||||||
|
|||||||
@@ -290,6 +290,7 @@ type
|
|||||||
logLevel*: string
|
logLevel*: string
|
||||||
proxy*: string
|
proxy*: string
|
||||||
proxyAuth*: string
|
proxyAuth*: string
|
||||||
|
defaultFollowedAccounts*: seq[string]
|
||||||
|
|
||||||
rssCacheTime*: int
|
rssCacheTime*: int
|
||||||
listCacheTime*: int
|
listCacheTime*: int
|
||||||
|
|||||||
@@ -65,6 +65,19 @@ proc renderHomepageTimeline*(results: Timeline; prefs: Prefs; path: string): VNo
|
|||||||
|
|
||||||
renderTimelineTweets(results, prefs, path)
|
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 =
|
proc renderUserSearch*(results: Result[User]; prefs: Prefs; path: string): VNode =
|
||||||
buildHtml(tdiv(class="timeline-container")):
|
buildHtml(tdiv(class="timeline-container")):
|
||||||
renderSearchTabs(results.query)
|
renderSearchTabs(results.query)
|
||||||
|
|||||||
Reference in New Issue
Block a user