Skip to content

Commit

Permalink
add: public responses timeline
Browse files Browse the repository at this point in the history
  • Loading branch information
trisuaso committed Dec 31, 2024
1 parent b5cb220 commit f15f7ab
Show file tree
Hide file tree
Showing 5 changed files with 383 additions and 42 deletions.
60 changes: 30 additions & 30 deletions crates/authbeam/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1687,7 +1687,7 @@ impl Database {
Ok(res)
}

/// Get all existing [`UserFollow`]s where `following` is the value of `user`, 50 at a time
/// Get all existing [`UserFollow`]s where `following` is the value of `user`, 12 at a time
///
/// # Arguments:
/// * `user`
Expand All @@ -1701,12 +1701,12 @@ impl Database {
let query: String = if (self.base.db.r#type == "sqlite") | (self.base.db.r#type == "mysql")
{
format!(
"SELECT * FROM \"xfollows\" WHERE \"following\" = ? LIMIT 50 OFFSET {}",
"SELECT * FROM \"xfollows\" WHERE \"following\" = ? LIMIT 12 OFFSET {}",
page * 50
)
} else {
format!(
"SELECT * FROM \"xfollows\" WHERE \"following\" = $1 LIMIT 50 OFFSET {}",
"SELECT * FROM \"xfollows\" WHERE \"following\" = $1 LIMIT 12 OFFSET {}",
page * 50
)
};
Expand Down Expand Up @@ -1847,7 +1847,7 @@ impl Database {
Ok(res)
}

/// Get all existing [`UserFollow`]s where `user` is the value of `user`, 50 at a time
/// Get all existing [`UserFollow`]s where `user` is the value of `user`, 12 at a time
///
/// # Arguments:
/// * `user`
Expand All @@ -1861,12 +1861,12 @@ impl Database {
let query: String = if (self.base.db.r#type == "sqlite") | (self.base.db.r#type == "mysql")
{
format!(
"SELECT * FROM \"xfollows\" WHERE \"user\" = ? LIMIT 50 OFFSET {}",
"SELECT * FROM \"xfollows\" WHERE \"user\" = ? LIMIT 12 OFFSET {}",
page * 50
)
} else {
format!(
"SELECT * FROM \"xfollows\" WHERE \"user\" = $1 LIMIT 50 OFFSET {}",
"SELECT * FROM \"xfollows\" WHERE \"user\" = $1 LIMIT 12 OFFSET {}",
page * 50
)
};
Expand Down Expand Up @@ -2255,7 +2255,7 @@ impl Database {
count
}

/// Get all notifications by their recipient, 50 at a time
/// Get all notifications by their recipient, 12 at a time
///
/// ## Arguments:
/// * `recipient`
Expand All @@ -2268,9 +2268,9 @@ impl Database {
// pull from database
let query: String = if (self.base.db.r#type == "sqlite") | (self.base.db.r#type == "mysql")
{
format!("SELECT * FROM \"xnotifications\" WHERE \"recipient\" = ? ORDER BY \"timestamp\" DESC LIMIT 50 OFFSET {}", page * 50)
format!("SELECT * FROM \"xnotifications\" WHERE \"recipient\" = ? ORDER BY \"timestamp\" DESC LIMIT 12 OFFSET {}", page * 12)
} else {
format!("SELECT * FROM \"xnotifications\" WHERE \"recipient\" = $1 ORDER BY \"timestamp\" DESC LIMIT 50 OFFSET {}", page * 50)
format!("SELECT * FROM \"xnotifications\" WHERE \"recipient\" = $1 ORDER BY \"timestamp\" DESC LIMIT 12 OFFSET {}", page * 12)
};

let c = &self.base.db.client;
Expand Down Expand Up @@ -3484,7 +3484,7 @@ impl Database {
}
}

/// Get all relationships where `user` is either `one` or `two` and the status is `status`, 50 at a time
/// Get all relationships where `user` is either `one` or `two` and the status is `status`, 12 at a time
///
/// # Arguments
/// * `user`
Expand All @@ -3499,9 +3499,9 @@ impl Database {
// pull from database
let query: String = if (self.base.db.r#type == "sqlite") | (self.base.db.r#type == "mysql")
{
format!("SELECT * FROM \"xrelationships\" WHERE (\"one\" = ? OR \"two\" = ?) AND \"status\" = ? ORDER BY \"timestamp\" DESC LIMIT 50 OFFSET {}", page * 50)
format!("SELECT * FROM \"xrelationships\" WHERE (\"one\" = ? OR \"two\" = ?) AND \"status\" = ? ORDER BY \"timestamp\" DESC LIMIT 12 OFFSET {}", page * 12)
} else {
format!("SELECT * FROM \"xrelationships\" WHERE (\"one\" = $1 OR \"two\" = $2) AND \"status\" = $3 ORDER BY \"timestamp\" DESC LIMIT 50 OFFSET {}", page * 50)
format!("SELECT * FROM \"xrelationships\" WHERE (\"one\" = $1 OR \"two\" = $2) AND \"status\" = $3 ORDER BY \"timestamp\" DESC LIMIT 12 OFFSET {}", page * 12)
};

let c = &self.base.db.client;
Expand Down Expand Up @@ -3891,7 +3891,7 @@ impl Database {
Ok(mail)
}

/// Get all mail by their recipient, 50 at a time
/// Get all mail by their recipient, 12 at a time
///
/// ## Arguments:
/// * `recipient`
Expand All @@ -3904,9 +3904,9 @@ impl Database {
// pull from database
let query: String = if (self.base.db.r#type == "sqlite") | (self.base.db.r#type == "mysql")
{
format!("SELECT * FROM \"xmail\" WHERE \"recipient\" LIKE ? OR \"recipient\" = ? ORDER BY \"timestamp\" DESC LIMIT 50 OFFSET {}", page * 50)
format!("SELECT * FROM \"xmail\" WHERE \"recipient\" LIKE ? OR \"recipient\" = ? ORDER BY \"timestamp\" DESC LIMIT 12 OFFSET {}", page * 12)
} else {
format!("SELECT * FROM \"xmail\" WHERE \"recipient\" LIKE $1 OR \"recipient\" = $2 ORDER BY \"timestamp\" DESC LIMIT 50 OFFSET {}", page * 50)
format!("SELECT * FROM \"xmail\" WHERE \"recipient\" LIKE $1 OR \"recipient\" = $2 ORDER BY \"timestamp\" DESC LIMIT 12 OFFSET {}", page * 12)
};

let c = &self.base.db.client;
Expand Down Expand Up @@ -3952,7 +3952,7 @@ impl Database {
Ok(res)
}

/// Get all mail by their recipient, 50 at a time
/// Get all mail by their recipient, 12 at a time
///
/// ## Arguments:
/// * `recipient`
Expand All @@ -3965,9 +3965,9 @@ impl Database {
// pull from database
let query: String = if (self.base.db.r#type == "sqlite") | (self.base.db.r#type == "mysql")
{
format!("SELECT * FROM \"xmail\" WHERE \"author\" LIKE ? OR \"author\" = ? ORDER BY \"timestamp\" DESC LIMIT 50 OFFSET {}", page * 50)
format!("SELECT * FROM \"xmail\" WHERE \"author\" LIKE ? OR \"author\" = ? ORDER BY \"timestamp\" DESC LIMIT 12 OFFSET {}", page * 12)
} else {
format!("SELECT * FROM \"xmail\" WHERE \"author\" LIKE $1 OR \"author\" = $2 ORDER BY \"timestamp\" DESC LIMIT 50 OFFSET {}", page * 50)
format!("SELECT * FROM \"xmail\" WHERE \"author\" LIKE $1 OR \"author\" = $2 ORDER BY \"timestamp\" DESC LIMIT 12 OFFSET {}", page * 12)
};

let c = &self.base.db.client;
Expand Down Expand Up @@ -4574,7 +4574,7 @@ impl Database {
Ok(transaction)
}

/// Get all transactions by the given user ID, 25 at a time
/// Get all transactions by the given user ID, 12 at a time
///
/// ## Arguments:
/// * `user`
Expand All @@ -4590,9 +4590,9 @@ impl Database {
// pull from database
let query: String = if (self.base.db.r#type == "sqlite") | (self.base.db.r#type == "mysql")
{
format!("SELECT * FROM \"xugc_transactions\" WHERE \"customer\" = ? OR \"merchant\" = ? ORDER BY \"timestamp\" DESC LIMIT 50 OFFSET {}", page * 50)
format!("SELECT * FROM \"xugc_transactions\" WHERE \"customer\" = ? OR \"merchant\" = ? ORDER BY \"timestamp\" DESC LIMIT 12 OFFSET {}", page * 12)
} else {
format!("SELECT * FROM \"xugc_transactions\" WHERE \"customer\" = $1 OR \"merchant\" = $2 ORDER BY \"timestamp\" DESC LIMIT 50 OFFSET {}", page * 50)
format!("SELECT * FROM \"xugc_transactions\" WHERE \"customer\" = $1 OR \"merchant\" = $2 ORDER BY \"timestamp\" DESC LIMIT 12 OFFSET {}", page * 12)
};

let c = &self.base.db.client;
Expand Down Expand Up @@ -4839,7 +4839,7 @@ impl Database {
Ok(item)
}

/// Get all items by their creator, 25 at a time
/// Get all items by their creator, 12 at a time
///
/// ## Arguments:
/// * `user`
Expand All @@ -4855,9 +4855,9 @@ impl Database {
// pull from database
let query: String = if (self.base.db.r#type == "sqlite") | (self.base.db.r#type == "mysql")
{
format!("SELECT * FROM \"xugc_items\" WHERE \"creator\" = ? ORDER BY \"timestamp\" DESC LIMIT 50 OFFSET {}", page * 50)
format!("SELECT * FROM \"xugc_items\" WHERE \"creator\" = ? ORDER BY \"timestamp\" DESC LIMIT 12 OFFSET {}", page * 12)
} else {
format!("SELECT * FROM \"xugc_items\" WHERE \"creator\" = $1 ORDER BY \"timestamp\" DESC LIMIT 50 OFFSET {}", page * 50)
format!("SELECT * FROM \"xugc_items\" WHERE \"creator\" = $1 ORDER BY \"timestamp\" DESC LIMIT 12 OFFSET {}", page * 12)
};

let c = &self.base.db.client;
Expand Down Expand Up @@ -4892,7 +4892,7 @@ impl Database {
Ok(res)
}

/// Get all items by their creator and type, 25 at a time
/// Get all items by their creator and type, 12 at a time
///
/// ## Arguments:
/// * `user`
Expand All @@ -4910,9 +4910,9 @@ impl Database {
// pull from database
let query: String = if (self.base.db.r#type == "sqlite") | (self.base.db.r#type == "mysql")
{
format!("SELECT * FROM \"xugc_items\" WHERE \"creator\" = ? AND \"type\" = ? ORDER BY \"timestamp\" DESC LIMIT 50 OFFSET {}", page * 50)
format!("SELECT * FROM \"xugc_items\" WHERE \"creator\" = ? AND \"type\" = ? ORDER BY \"timestamp\" DESC LIMIT 12 OFFSET {}", page * 12)
} else {
format!("SELECT * FROM \"xugc_items\" WHERE \"creator\" = $1 AND \"type\" = $2 ORDER BY \"timestamp\" DESC LIMIT 50 OFFSET {}", page * 50)
format!("SELECT * FROM \"xugc_items\" WHERE \"creator\" = $1 AND \"type\" = $2 ORDER BY \"timestamp\" DESC LIMIT 12 OFFSET {}", page * 12)
};

let c = &self.base.db.client;
Expand Down Expand Up @@ -4952,7 +4952,7 @@ impl Database {
Ok(res)
}

/// Get all items by their status, 25 at a time
/// Get all items by their status, 12 at a time
///
/// ## Arguments:
/// * `user`
Expand All @@ -4969,9 +4969,9 @@ impl Database {
// pull from database
let query: String = if (self.base.db.r#type == "sqlite") | (self.base.db.r#type == "mysql")
{
format!("SELECT * FROM \"xugc_items\" WHERE \"status\" = ? AND \"name\" LIKE ? AND \"cost\" != '-1' ORDER BY \"timestamp\" DESC LIMIT 50 OFFSET {}", page * 50)
format!("SELECT * FROM \"xugc_items\" WHERE \"status\" = ? AND \"name\" LIKE ? AND \"cost\" != '-1' ORDER BY \"timestamp\" DESC LIMIT 12 OFFSET {}", page * 12)
} else {
format!("SELECT * FROM \"xugc_items\" WHERE \"status\" = $1 AND \"name\" LIKE $2 AND \"cost\" != '-1' ORDER BY \"timestamp\" DESC LIMIT 50 OFFSET {}", page * 50)
format!("SELECT * FROM \"xugc_items\" WHERE \"status\" = $1 AND \"name\" LIKE $2 AND \"cost\" != '-1' ORDER BY \"timestamp\" DESC LIMIT 12 OFFSET {}", page * 12)
};

let c = &self.base.db.client;
Expand Down
41 changes: 38 additions & 3 deletions crates/rainbeam-core/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2098,6 +2098,41 @@ impl Database {
Ok(res)
}

/// Get all responses, 12 at a time
///
/// # Arguments
/// * `page`
pub async fn get_responses_paginated(&self, page: i32) -> Result<Vec<FullResponse>> {
// pull from database
let query: String = if (self.base.db.r#type == "sqlite") | (self.base.db.r#type == "mysql")
{
format!("SELECT * FROM \"xresponses\" WHERE \"context\" NOT LIKE '%\"unlisted\":true%' ORDER BY \"timestamp\" DESC LIMIT 12 OFFSET {}", page * 12)
} else {
format!("SELECT * FROM \"xresponses\" WHERE \"context\" NOT LIKE '%\"unlisted\":true%' ORDER BY \"timestamp\" DESC LIMIT 12 OFFSET {}", page * 12)
};

let c = &self.base.db.client;
let res = match sqlquery(&query).fetch_all(c).await {
Ok(p) => {
let mut out: Vec<FullResponse> = Vec::new();

for row in p {
let res = self.base.textify_row(row).0;
out.push(match self.gimme_response(res).await {
Ok(r) => r,
Err(e) => return Err(e),
});
}

out
}
Err(_) => return Err(DatabaseError::NotFound),
};

// return
Ok(res)
}

/// Get all responses by their author
///
/// # Arguments
Expand Down Expand Up @@ -6187,7 +6222,7 @@ impl Database {
Ok(res)
}

/// Get all messages by their chat, 50 at a time
/// Get all messages by their chat, 12 at a time
///
/// # Arguments
/// * `id`
Expand All @@ -6200,9 +6235,9 @@ impl Database {
// pull from database
let query: String = if (self.base.db.r#type == "sqlite") | (self.base.db.r#type == "mysql")
{
format!("SELECT * FROM \"xmessages\" WHERE \"chat\" = ? ORDER BY \"timestamp\" DESC LIMIT 50 OFFSET {}", page * 50)
format!("SELECT * FROM \"xmessages\" WHERE \"chat\" = ? ORDER BY \"timestamp\" DESC LIMIT 12 OFFSET {}", page * 12)
} else {
format!("SELECT * FROM \"xmessages\" WHERE \"chat\" = $1 ORDER BY \"timestamp\" DESC LIMIT 50 OFFSET {}", page * 50)
format!("SELECT * FROM \"xmessages\" WHERE \"chat\" = $1 ORDER BY \"timestamp\" DESC LIMIT 12 OFFSET {}", page * 12)
};

let c = &self.base.db.client;
Expand Down
109 changes: 109 additions & 0 deletions crates/rainbeam/templates/timelines/public_timeline.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{% extends "base.html" %} {% block title %}{{ config.name }}{% endblock %} {%
block head %}
<meta name="description" content="{{ config.description }}" />
{% endblock %} {% block nav_left %}
<a class="button active" href="/" title="Timeline">
{{ icon "house" }}
<span class="desktop">{{ text "general:link.timeline" }}</span>
<span class="mobile">{{ text "general:link.home" }}</span>
</a>

<a class="button" href="/inbox" title="My inbox">
{{ icon "inbox" }}
<span class="flex items-center gap-2">
<span>{{ text "general:link.inbox" }}</span>
{% if unread != 0 %}
<span class="notification tr">{{ unread }}</span>
{% endif %}
</span>
</a>
{% endblock %} {% block nav_right %}
<a class="button" href="/inbox/notifications" title="My notifications">
{{ icon "bell" }} {% if notifs != 0 %}
<span class="notification tr">{{ notifs }}</span>
{% endif %}
</a>
{% endblock %} {% block content %}
<article>
<main class="flex flex-col gap-2">
<div class="pillmenu convertible shadow">
<a href="/" class="active"
><span>{{ text "timelines:link.timeline" }}</span></a
>
<a href="/inbox/posts"
><span>{{ text "timelines:link.posts" }}</span></a
>
<a href="/inbox/global"
><span>{{ text "timelines:link.global" }}</span></a
>
</div>

<div class="pillmenu convertible shadow">
<a href="/public" class="active"
><span>{{ text "timelines:link.public" }}</span></a
>
<a href="/"><span>{{ text "timelines:link.following" }}</span></a>
</div>

<div class="flex justify-between items-center gap-2">
<h5>Feed</h5>
<div class="flex justify-between">
<div></div>
<a href="/search?driver=0" class="button secondary bold">
{{ icon "search" }} {{ text "general:link.search" }}
</a>
</div>
</div>

<!-- pagination buttons -->
{% if page != 0 %}
<div class="flex justify-center items-center gap-4 w-full">
<a class="button primary" href="?page=0">
{{ text "general:text.view_full_feed" }}
</a>
</div>
{% endif %}

<!-- feed -->
<div class="flex flex-col gap-4" id="feed">
<include-partial
src="/_app/timelines/public_timeline.html?page={{ page }}"
uses="app:clean_date_codes,app:link_filter,app:hook.alt,app:hook.partial_embeds,app:hook.check_reactions"
instant="true"
outerhtml="true"
></include-partial>
</div>
</main>
</article>

<script>
setTimeout(() => {
trigger("questions:carp");
}, 100);

use("app", (app) => {
app["hook.attach_to_partial"](
"/_app/timelines/public_timeline.html",
"/public",
document.getElementById("feed"),
document.body,
parseInt("{{ page }}"),
).then(() => {
console.log("partial end");
document.getElementById("feed").innerHTML +=
`<div class="w-full flex flex-col gap-2">
<hr />
<p class="w-full flex justify-center fade">
You've reached the end
</p>
</div>`;
});
});
</script>

{% if let Some(profile) = profile %} {% let other = profile.clone() %} {% if
profile.username == other.username %}
<div id="is_self"></div>
{% endif %} {% let raw_metadata =
crate::routing::pages::clean_metadata_raw(other.metadata) %} {% include
"components/theming.html" %} {% endif %} {% call super() %} {% endblock %}
Loading

0 comments on commit f15f7ab

Please sign in to comment.