7260525eec
This command finalizes support for dynamic message loading. The behavior is as follows: When a user selects a channel for the first time, an "initial load" of messages will happen. When the user is scrolled all the way to the bottom of the message view, the store will continuously remove old messages to save memory. Scrolling all the way to the top loads more messages.
42 lines
947 B
JavaScript
42 lines
947 B
JavaScript
import { getAuthToken } from "./storage";
|
|
|
|
export default async function(method, endpoint, auth=true, body=null) {
|
|
const options = {
|
|
method,
|
|
};
|
|
|
|
if (body) {
|
|
options.body = JSON.stringify(body);
|
|
options.headers = {
|
|
...options.headers || {},
|
|
"Content-Type": "application/json"
|
|
};
|
|
}
|
|
|
|
if (auth) {
|
|
const token = getAuthToken();
|
|
if (token) {
|
|
options.headers = {
|
|
...options.headers || {},
|
|
"Authorization": `Bearer ${token}`
|
|
};
|
|
}
|
|
}
|
|
|
|
try {
|
|
const res = await fetch(endpoint, options);
|
|
return {
|
|
success: true,
|
|
json: await res.json(),
|
|
ok: res.ok,
|
|
status: res.status
|
|
}
|
|
} catch (e) {
|
|
return {
|
|
success: false,
|
|
json: null,
|
|
ok: false,
|
|
status: null
|
|
}
|
|
}
|
|
}
|