Update static/js/07-team-channel-adapter.js
This commit is contained in:
parent
f08e24696c
commit
13b3564b84
@ -3,11 +3,14 @@
|
|||||||
|
|
||||||
window.Glow = window.Glow || {};
|
window.Glow = window.Glow || {};
|
||||||
|
|
||||||
|
// note:
|
||||||
|
// this file keeps team/channel helper methods available,
|
||||||
|
// but the old production monkey-patching adapter is disabled.
|
||||||
|
// rooms remain the stable fallback runtime path.
|
||||||
|
|
||||||
Glow.teamAdapter = Glow.teamAdapter || {
|
Glow.teamAdapter = Glow.teamAdapter || {
|
||||||
initialized: false,
|
initialized: false,
|
||||||
originalLoadRooms: null,
|
enabled: false
|
||||||
originalUpdateViewUI: null,
|
|
||||||
chatBarVisibilityInstalled: false
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Glow.loadTeamsForAdapter = async () => {
|
Glow.loadTeamsForAdapter = async () => {
|
||||||
@ -43,7 +46,7 @@ Glow.loadTeamsForAdapter = async () => {
|
|||||||
Glow.els.teamSelect.value = Glow.state.activeTeam.slug;
|
Glow.els.teamSelect.value = Glow.state.activeTeam.slug;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn("Team adapter could not load teams:", error);
|
console.warn("could not load teams:", error);
|
||||||
Glow.state.teams = [];
|
Glow.state.teams = [];
|
||||||
Glow.state.activeTeam = null;
|
Glow.state.activeTeam = null;
|
||||||
Glow.els.teamSelect.disabled = true;
|
Glow.els.teamSelect.disabled = true;
|
||||||
@ -69,7 +72,6 @@ Glow.loadChannelsForTeam = async (teamSlug, preferredChannelSlug = null) => {
|
|||||||
Glow.state.channels = channels;
|
Glow.state.channels = channels;
|
||||||
|
|
||||||
const matchingTeam = Glow.state.teams.find(team => team.slug === teamSlug);
|
const matchingTeam = Glow.state.teams.find(team => team.slug === teamSlug);
|
||||||
|
|
||||||
if (matchingTeam || data.team) {
|
if (matchingTeam || data.team) {
|
||||||
Glow.state.activeTeam = {
|
Glow.state.activeTeam = {
|
||||||
...(matchingTeam || {}),
|
...(matchingTeam || {}),
|
||||||
@ -89,24 +91,21 @@ Glow.loadChannelsForTeam = async (teamSlug, preferredChannelSlug = null) => {
|
|||||||
const selected =
|
const selected =
|
||||||
channels.find(channel => channel.slug === preferredChannelSlug) ||
|
channels.find(channel => channel.slug === preferredChannelSlug) ||
|
||||||
channels.find(channel => channel.slug === Glow.state.activeChannel?.slug) ||
|
channels.find(channel => channel.slug === Glow.state.activeChannel?.slug) ||
|
||||||
channels.find(channel => channel.slug === Glow.state.activeRoom?.slug) ||
|
|
||||||
channels.find(channel => channel.slug === "general") ||
|
channels.find(channel => channel.slug === "general") ||
|
||||||
channels[0] ||
|
channels[0] ||
|
||||||
null;
|
null;
|
||||||
|
|
||||||
Glow.state.activeChannel = selected;
|
Glow.state.activeChannel = selected;
|
||||||
Glow.state.activeRoom = selected;
|
|
||||||
|
|
||||||
Glow.els.roomSelect.disabled = !selected;
|
|
||||||
|
|
||||||
if (selected) {
|
if (selected) {
|
||||||
|
Glow.state.activeRoom = selected;
|
||||||
Glow.els.roomSelect.value = selected.slug;
|
Glow.els.roomSelect.value = selected.slug;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Glow.els.roomSelect.disabled = !selected;
|
||||||
};
|
};
|
||||||
|
|
||||||
Glow.decorateChannelSelector = () => {
|
Glow.decorateChannelSelector = () => {
|
||||||
if (!Glow.els.roomSelect) return;
|
if (!Glow.els.roomSelect) return;
|
||||||
|
|
||||||
Glow.els.roomSelect.classList.add("channel-select");
|
Glow.els.roomSelect.classList.add("channel-select");
|
||||||
Glow.els.roomSelect.setAttribute("aria-label", "Select channel");
|
Glow.els.roomSelect.setAttribute("aria-label", "Select channel");
|
||||||
};
|
};
|
||||||
@ -116,21 +115,25 @@ Glow.updateTeamChannelHeader = () => {
|
|||||||
const channel = Glow.state.activeChannel || Glow.state.activeRoom;
|
const channel = Glow.state.activeChannel || Glow.state.activeRoom;
|
||||||
const view = Glow.state.activeView;
|
const view = Glow.state.activeView;
|
||||||
|
|
||||||
if (view === "dm" || view === "dms" || view === "feed" || view === "pages" || view === "page" || view === "profile" || view === "settings" || view === "thread") {
|
if (
|
||||||
|
view === "dm" ||
|
||||||
|
view === "dms" ||
|
||||||
|
view === "feed" ||
|
||||||
|
view === "pages" ||
|
||||||
|
view === "page" ||
|
||||||
|
view === "profile" ||
|
||||||
|
view === "settings" ||
|
||||||
|
view === "thread"
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(view === "channel" || view === "room")) {
|
if (!(view === "channel" || view === "room")) return;
|
||||||
return;
|
if (!team || !channel || !Glow.els.headerTitle) return;
|
||||||
}
|
|
||||||
|
|
||||||
if (!team || !channel || !Glow.els.headerTitle) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Glow.els.headerTitle.textContent = `# ${channel.name}`;
|
Glow.els.headerTitle.textContent = `# ${channel.name}`;
|
||||||
Glow.els.headerSubtitle.textContent =
|
Glow.els.headerSubtitle.textContent =
|
||||||
`${team.name} · ${channel.description || "Channel conversation"}`;
|
`${team.name} · ${channel.description || "Channel conversation"}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
Glow.applyComposerVisibility = () => {
|
Glow.applyComposerVisibility = () => {
|
||||||
@ -345,7 +348,7 @@ Glow.manageTeamMembers = async team => {
|
|||||||
row.className = "member-row";
|
row.className = "member-row";
|
||||||
|
|
||||||
const name = document.createElement("span");
|
const name = document.createElement("span");
|
||||||
name.textContent = `${member.username} · ${member.membership_role}`;
|
name.textContent = `${member.username} · ${member.membership_role}`;
|
||||||
|
|
||||||
const actions = document.createElement("div");
|
const actions = document.createElement("div");
|
||||||
actions.className = "settings-actions";
|
actions.className = "settings-actions";
|
||||||
@ -528,152 +531,10 @@ Glow.refreshTeamAndChannelData = async (teamSlug = null, channelSlug = null) =>
|
|||||||
|
|
||||||
Glow.installTeamAdapter = () => {
|
Glow.installTeamAdapter = () => {
|
||||||
if (Glow.teamAdapter.initialized) return;
|
if (Glow.teamAdapter.initialized) return;
|
||||||
|
|
||||||
if (!Glow.els.teamSelect || !Glow.els.roomSelect) {
|
|
||||||
console.warn("Team adapter skipped: expected team/channel elements are missing.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Glow.teamAdapter.initialized = true;
|
Glow.teamAdapter.initialized = true;
|
||||||
|
|
||||||
Glow.state.teams ||= [];
|
|
||||||
Glow.state.channels ||= [];
|
|
||||||
Glow.state.activeTeam ||= null;
|
|
||||||
Glow.state.activeChannel ||= null;
|
|
||||||
|
|
||||||
Glow.decorateChannelSelector();
|
Glow.decorateChannelSelector();
|
||||||
|
console.info("team/channel helper mode enabled; runtime monkey-patching disabled.");
|
||||||
Glow.teamAdapter.originalLoadRooms = Glow.loadRooms;
|
|
||||||
|
|
||||||
Glow.loadRooms = async () => {
|
|
||||||
await Glow.teamAdapter.originalLoadRooms();
|
|
||||||
await Glow.loadTeamsForAdapter();
|
|
||||||
Glow.decorateChannelSelector();
|
|
||||||
|
|
||||||
if (Glow.state.activeTeam) {
|
|
||||||
try {
|
|
||||||
await Glow.loadChannelsForTeam(
|
|
||||||
Glow.state.activeTeam.slug,
|
|
||||||
Glow.state.activeRoom?.slug
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
console.warn("Team adapter could not load channels after rooms:", error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Glow.updateTeamChannelHeader();
|
|
||||||
};
|
|
||||||
|
|
||||||
Glow.teamAdapter.originalUpdateViewUI = Glow.updateViewUI;
|
|
||||||
|
|
||||||
Glow.updateViewUI = () => {
|
|
||||||
Glow.teamAdapter.originalUpdateViewUI?.();
|
|
||||||
Glow.updateTeamChannelHeader();
|
|
||||||
Glow.applyComposerVisibility();
|
|
||||||
};
|
|
||||||
|
|
||||||
const initializeAdapter = async () => {
|
|
||||||
await Glow.loadTeamsForAdapter();
|
|
||||||
Glow.decorateChannelSelector();
|
|
||||||
|
|
||||||
if (!Glow.state.activeTeam) {
|
|
||||||
Glow.applyComposerVisibility();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await Glow.loadChannelsForTeam(
|
|
||||||
Glow.state.activeTeam.slug,
|
|
||||||
Glow.state.activeRoom?.slug
|
|
||||||
);
|
|
||||||
|
|
||||||
Glow.updateTeamChannelHeader();
|
|
||||||
} catch (error) {
|
|
||||||
console.warn("Team adapter could not load initial channels:", error);
|
|
||||||
}
|
|
||||||
|
|
||||||
Glow.applyComposerVisibility();
|
|
||||||
};
|
|
||||||
|
|
||||||
initializeAdapter();
|
|
||||||
|
|
||||||
Glow.els.teamSelect.addEventListener("change", async () => {
|
|
||||||
const selected = Glow.state.teams.find(
|
|
||||||
team => team.slug === Glow.els.teamSelect.value
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!selected) return;
|
|
||||||
|
|
||||||
Glow.state.activeDm = null;
|
|
||||||
Glow.state.activeTeam = selected;
|
|
||||||
Glow.state.activeChannel = null;
|
|
||||||
Glow.state.activeRoom = null;
|
|
||||||
|
|
||||||
Glow.state.typingUsers = [];
|
|
||||||
Glow.state.dmTypingUsers = [];
|
|
||||||
Glow.renderTyping?.();
|
|
||||||
Glow.clearMessages?.();
|
|
||||||
|
|
||||||
try {
|
|
||||||
await Glow.loadChannelsForTeam(selected.slug);
|
|
||||||
|
|
||||||
Glow.state.activeView = "channel";
|
|
||||||
Glow.updateViewUI();
|
|
||||||
|
|
||||||
if (Glow.state.activeChannel) {
|
|
||||||
await Glow.loadChannelMessages?.();
|
|
||||||
Glow.pollTyping?.();
|
|
||||||
Glow.pingPresence?.();
|
|
||||||
Glow.refreshPresence?.();
|
|
||||||
} else {
|
|
||||||
Glow.renderEmptyState?.("No channels are available in this team.");
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
Glow.showToast(error.message || "Could not load channels for this team.", "error");
|
|
||||||
}
|
|
||||||
|
|
||||||
Glow.schedulePoll?.();
|
|
||||||
});
|
|
||||||
|
|
||||||
Glow.els.roomSelect.addEventListener("change", () => {
|
|
||||||
window.setTimeout(() => {
|
|
||||||
const selected = Glow.state.channels.find(
|
|
||||||
channel => channel.slug === Glow.els.roomSelect.value
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!selected) return;
|
|
||||||
|
|
||||||
Glow.state.activeDm = null;
|
|
||||||
Glow.state.activeChannel = selected;
|
|
||||||
Glow.state.activeRoom = selected;
|
|
||||||
|
|
||||||
if (
|
|
||||||
Glow.state.activeView === "room" ||
|
|
||||||
Glow.state.activeView === "channel"
|
|
||||||
) {
|
|
||||||
Glow.state.activeView = "channel";
|
|
||||||
}
|
|
||||||
|
|
||||||
Glow.updateViewUI();
|
|
||||||
Glow.pingPresence?.();
|
|
||||||
Glow.refreshPresence?.();
|
|
||||||
}, 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
console.info("Team/channel adapter enabled.");
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Glow.installTeamAdapter();
|
Glow.installTeamAdapter();
|
||||||
|
|
||||||
if (!Glow.teamAdapter.chatBarVisibilityInstalled) {
|
|
||||||
Glow.teamAdapter.chatBarVisibilityInstalled = true;
|
|
||||||
|
|
||||||
const previousUpdateViewUI = Glow.updateViewUI;
|
|
||||||
|
|
||||||
Glow.updateViewUI = () => {
|
|
||||||
previousUpdateViewUI?.();
|
|
||||||
Glow.applyComposerVisibility();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
Glow.applyComposerVisibility();
|
Glow.applyComposerVisibility();
|
||||||
Loading…
x
Reference in New Issue
Block a user