forked from andyburke/autonomous.contact
fix: get channel creation and chat to sort of work
This commit is contained in:
parent
afeb6f75e8
commit
de77f0fbe9
3 changed files with 37 additions and 37 deletions
|
|
@ -67,7 +67,7 @@ const APP = {
|
|||
*/
|
||||
|
||||
if (!document.body.dataset.channel || document.body.dataset.channel !== channel_id) {
|
||||
const previous = document.body.dataset.channel;
|
||||
const previous = typeof document.body.dataset.channel === 'string' ? document.body.dataset.channel : undefined;
|
||||
|
||||
/*
|
||||
console.dir({
|
||||
|
|
@ -80,24 +80,38 @@ const APP = {
|
|||
});
|
||||
*/
|
||||
|
||||
if ( channel_id ) {
|
||||
document.body.dataset.channel = channel_id;
|
||||
}
|
||||
else {
|
||||
delete document.body.dataset.channel;
|
||||
}
|
||||
|
||||
const target_channel_id = channel_id ?? this.CHANNELS.CHANNEL_LIST[0]?.id;
|
||||
|
||||
// TODO: allow a different default than chat
|
||||
const hash_target = '/chat' + ( target_channel_id ? `/channel/${ target_channel_id }` : '' );
|
||||
|
||||
if ( window.location.hash?.slice( 1 ) !== hash_target ) {
|
||||
if ( previous !== target_channel_id ) {
|
||||
this._emit( 'channel_changed', {
|
||||
previous,
|
||||
channel_id
|
||||
channel_id: target_channel_id
|
||||
});
|
||||
|
||||
if (!channel_id) {
|
||||
const first_channel_id = this.CHANNELS.CHANNEL_LIST[0]?.id;
|
||||
if (first_channel_id) {
|
||||
window.location.hash = `/chat/channel/${first_channel_id}`; // TODO: allow a different default than chat
|
||||
}
|
||||
|
||||
window.location.hash = hash_target;
|
||||
}
|
||||
}
|
||||
|
||||
if (!document.body.dataset.view || document.body.dataset.view !== view) {
|
||||
const previous = document.body.dataset.view;
|
||||
const previous = typeof document.body.dataset.view === 'string' ? document.body.dataset.view : undefined;
|
||||
if ( view ) {
|
||||
document.body.dataset.view = view;
|
||||
}
|
||||
else {
|
||||
delete document.body.dataset.view;
|
||||
}
|
||||
|
||||
/*
|
||||
console.dir({
|
||||
|
|
@ -236,10 +250,11 @@ const APP = {
|
|||
_update_channels_timeout: undefined,
|
||||
CHANNEL_LIST: [],
|
||||
|
||||
update: async () => {
|
||||
update: async ( force = false ) => {
|
||||
const now = new Date();
|
||||
const time_since_last_update = now - (APP.CHANNELS._last_channel_update ?? 0);
|
||||
if (time_since_last_update < UPDATE_CHANNELS_FREQUENCY / 2) {
|
||||
const sufficient_time_has_passed_since_last_update = time_since_last_update > UPDATE_CHANNELS_FREQUENCY / 2;
|
||||
if ( !force && !sufficient_time_has_passed_since_last_update ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -165,6 +165,12 @@
|
|||
overflow: hidden;
|
||||
transition: all 0.5s;
|
||||
"
|
||||
on_reply="(new_channel) => {
|
||||
APP.CHANNELS.update(true);
|
||||
document.getElementById('new-channel-name-input').value = '';
|
||||
document.getElementById('channel-create').style['height'] = '0';
|
||||
window.location.hash = `/chat/channel/${new_channel.id}`;
|
||||
}"
|
||||
>
|
||||
<input
|
||||
id="new-channel-name-input"
|
||||
|
|
@ -175,27 +181,6 @@
|
|||
/>
|
||||
|
||||
<input type="submit" hidden />
|
||||
<script>
|
||||
{
|
||||
const form = document.currentScript.closest("form");
|
||||
const channel_create_form = document.getElementById("channel-create");
|
||||
const new_channel_name_input =
|
||||
document.getElementById("new-channel-name-input");
|
||||
|
||||
form.on_reply = (new_channel) => {
|
||||
const channel_list = document.getElementById("channel-list");
|
||||
channel_list.querySelectorAll( 'li' ).forEach( (li) => li.classList.remove( 'active' ) );
|
||||
channel_list.insertAdjacentHTML(
|
||||
"beforeend",
|
||||
`<li id="channel-selector-${new_channel.id}" class="channel active"><a href="#/chat/channel/${new_channel.id}">${new_channel.name}</a></li>`,
|
||||
);
|
||||
|
||||
new_channel_name_input.value = "";
|
||||
window.location.hash = `/chat/channel/${new_channel.id}`;
|
||||
channel_create_form.style["height"] = "0";
|
||||
};
|
||||
}
|
||||
</script>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@
|
|||
<div
|
||||
id="chat-content"
|
||||
data-feed
|
||||
data-precheck="!!document.body.dataset.user && document.body.dataset.user.indexOf( 'events.read.chat' ) !== -1"
|
||||
data-source="/api/events?type=chat,reaction&channel=${ document.body.dataset.channel }&limit=100&sort=newest&wait=true&after_id=${ feed.__newest_id ?? 'able-able-able-able-able-able-able-able-able-able' }"
|
||||
data-precheck="!!document.body.dataset.user && document.body.dataset.user.indexOf( 'events.read.chat' ) !== -1 && document.body.dataset.channel"
|
||||
data-source="/api/channels/${ document.body.dataset.channel }/events?type=chat,reaction&limit=100&sort=newest&wait=true&after_id=${ feed.__newest_id ?? 'able-able-able-able-able-able-able-able-able-able' }"
|
||||
data-longpolling="true"
|
||||
data-reverse="true"
|
||||
data-insert="append"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue