Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'FIGBERT/follows' (zedeus/nitter#363)
- Loading branch information
Showing
9 changed files
with
157 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import jester, asyncdispatch, strutils, sequtils | ||
import router_utils | ||
import ../types | ||
|
||
export follow | ||
|
||
proc addUserToFollowing*(following, toAdd: string): string = | ||
var updated = following.split(",") | ||
if updated == @[""]: | ||
return toAdd | ||
elif toAdd in updated: | ||
return following | ||
else: | ||
updated = concat(updated, @[toAdd]) | ||
result = updated.join(",") | ||
|
||
proc removeUserFromFollowing*(following, remove: string): string = | ||
var updated = following.split(",") | ||
if updated == @[""]: | ||
return "" | ||
else: | ||
updated = filter(updated, proc(x: string): bool = x != remove) | ||
result = updated.join(",") | ||
|
||
proc createFollowRouter*(cfg: Config) = | ||
router follow: | ||
post "/follow/@name": | ||
let | ||
following = cookiePrefs().following | ||
toAdd = @"name" | ||
updated = addUserToFollowing(following, toAdd) | ||
setCookie("following", updated, daysForward(360), | ||
httpOnly=true, secure=cfg.useHttps, path="/") | ||
redirect(refPath()) | ||
post "/unfollow/@name": | ||
let | ||
following = cookiePrefs().following | ||
remove = @"name" | ||
updated = removeUserFromFollowing(following, remove) | ||
setCookie("following", updated, daysForward(360), | ||
httpOnly=true, secure=cfg.useHttps, path="/") | ||
redirect(refPath()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import jester | ||
import asyncdispatch, strutils, options, router_utils, timeline | ||
import ".."/[prefs, types, utils, redis_cache] | ||
import ../views/[general, home, search] | ||
|
||
export home | ||
|
||
proc showHome*(request: Request; query: Query; cfg: Config; prefs: Prefs; | ||
after: string): Future[string] {.async.} = | ||
let | ||
timeline = await getSearch[Tweet](query, after) | ||
html = renderHome(timeline, prefs, getPath()) | ||
return renderMain(html, request, cfg, prefs) | ||
|
||
proc createHomeRouter*(cfg: Config) = | ||
router home: | ||
get "/": | ||
let | ||
prefs = cookiePrefs() | ||
after = getCursor() | ||
names = getNames(prefs.following) | ||
|
||
var query = request.getQuery("", prefs.following) | ||
query.fromUser = names | ||
|
||
if @"scroll".len > 0: | ||
var timeline = await getSearch[Tweet](query, after) | ||
if timeline.content.len == 0: resp Http404 | ||
timeline.beginning = true | ||
resp $renderHome(timeline, prefs, getPath()) | ||
|
||
if names.len == 0: | ||
resp renderMain(renderSearch(), request, cfg, themePrefs()) | ||
resp (await showHome(request, query, cfg, prefs, after)) | ||
get "/following": | ||
let | ||
prefs = cookiePrefs() | ||
names = getNames(prefs.following) | ||
var | ||
profs: seq[Profile] | ||
query = request.getQuery("", prefs.following) | ||
query.fromUser = names | ||
query.kind = userList | ||
|
||
for name in names: | ||
let prof = await getCachedProfile(name) | ||
profs &= @[prof] | ||
|
||
resp renderMain(renderFollowing(query, profs, prefs), request, cfg, prefs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import karax/[karaxdsl, vdom] | ||
import search, timeline, renderutils | ||
import ../types | ||
|
||
proc renderFollowingUsers*(results: seq[Profile]; prefs: Prefs): VNode = | ||
buildHtml(tdiv(class="timeline")): | ||
for user in results: | ||
renderUser(user, prefs) | ||
|
||
proc renderHomeTabs*(query: Query): VNode = | ||
buildHtml(ul(class="tab")): | ||
li(class=query.getTabClass(posts)): | ||
a(href="/"): text "Tweets" | ||
li(class=query.getTabClass(userList)): | ||
a(href=("/following")): text "Following" | ||
|
||
proc renderHome*(results: Result[Tweet]; prefs: Prefs; path: string): VNode = | ||
let query = results.query | ||
buildHtml(tdiv(class="timeline-container")): | ||
if query.fromUser.len > 0: | ||
renderHomeTabs(query) | ||
|
||
if query.fromUser.len == 0 or query.kind == tweets: | ||
tdiv(class="timeline-header"): | ||
renderSearchPanel(query) | ||
|
||
renderTimelineTweets(results, prefs, path) | ||
|
||
proc renderFollowing*(query: Query; following: seq[Profile]; prefs: Prefs): VNode = | ||
buildHtml(tdiv(class="timeline-container")): | ||
renderHomeTabs(query) | ||
renderFollowingUsers(following, prefs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters