add getNotifications() api method

This commit is contained in:
ari melody 2024-07-02 12:55:51 +01:00
parent 5424772abb
commit bc6d02d974
Signed by: ari
GPG key ID: CF99829C92678188
2 changed files with 24 additions and 1 deletions

View file

@ -91,8 +91,27 @@ export async function verifyCredentials() {
return data;
}
export async function getNotifications(since_id, limit, types) {
if (!get(client).user) return false;
let url = `https://${get(client).instance.host}/api/v1/notifications`;
let params = new URLSearchParams();
if (since_id) params.append("max_id", last_post_id);
if (limit) params.append("limit", limit);
if (types) params.append("types", types.join(','));
const params_string = params.toString();
if (params_string) url += '?' + params_string;
const data = await fetch(url, {
method: 'GET',
headers: { "Authorization": "Bearer " + get(client).app.token }
}).then(res => res.json());
return data;
}
export async function getTimeline(last_post_id) {
if (!get(client).instance || !get(client).app) return false;
let url = `https://${get(client).instance.host}/api/v1/timelines/home`;
if (last_post_id) url += "?max_id=" + last_post_id;
const data = await fetch(url, {

View file

@ -93,6 +93,10 @@ export class Client {
return user;
}
async getNotifications(since_id, limit, types) {
return await api.getNotifications(since_id, limit, types);
}
async getTimeline(last_post_id) {
return await api.getTimeline(last_post_id);
}