/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import {
classMap,
html,
ifDefined,
styleMap,
when,
} from "chrome://global/content/vendor/lit.all.mjs";
import {
FxviewTabListBase,
FxviewTabRowBase,
} from "chrome://browser/content/firefoxview/fxview-tab-list.mjs";
/**
* A list of clickable chat history items
*/
export class ChatsTabList extends FxviewTabListBase {
static queries = {
...FxviewTabListBase.queries,
rowEls: {
all: "chats-tab-row",
},
};
itemTemplate = (tabItem, i) => {
let time;
if (tabItem.time || tabItem.closedAt) {
let stringTime = (tabItem.time || tabItem.closedAt).toString();
// Different APIs return time in different units, so we use
// the length to decide if it's milliseconds or nanoseconds.
if (stringTime.length === 16) {
time = (tabItem.time || tabItem.closedAt) / 1000;
} else {
time = tabItem.time || tabItem.closedAt;
}
}
return html``;
};
}
customElements.define("chats-tab-list", ChatsTabList);
/**
* A chat history item that displays favicon with optional overlay, title, url, and time
*
* @property {string} pageUrl - The last visited URL associated with this chat, if any
*/
export class ChatsTabRow extends FxviewTabRowBase {
static properties = {
...FxviewTabRowBase.properties,
pageUrl: { type: String },
convId: { type: String },
};
faviconTemplate() {
// Determine the icon and overlay based on whether chat has an associated page URL
let faviconUrl;
let overlayUrl = null;
// Treat about: URLs as internal/no external page
const hasExternalUrl = this.pageUrl && !this.pageUrl.startsWith("about:");
if (hasExternalUrl) {
// Chat has an associated page URL - show page favicon with chat overlay
faviconUrl = this.getImageUrl(this.favicon, this.pageUrl);
overlayUrl = "chrome://browser/content/firefoxview/empty-chat.svg";
} else {
// Chat has no page URL or internal about: page - show generic chat icon, no overlay
faviconUrl = "chrome://browser/content/firefoxview/view-chats.svg";
}
const backgroundImage = overlayUrl
? `url(${faviconUrl}), url(${overlayUrl})`
: `url(${faviconUrl})`;
return html``;
}
urlTemplate() {
const urlToDisplay =
this.pageUrl && !this.pageUrl.startsWith("about:") ? this.pageUrl : "";
return html`
${when(
this.searchQuery,
() => this.highlightSearchMatches(this.searchQuery, urlToDisplay),
() => urlToDisplay
)}
`;
}
render() {
return html`
${this.stylesheets()}
${this.faviconTemplate()} ${this.titleTemplate()}
${when(
!this.compact,
() =>
html`${this.urlTemplate()} ${this.dateTemplate()}
${this.timeTemplate()}`
)}
${this.secondaryButtonTemplate()} ${this.tertiaryButtonTemplate()}
`;
}
}
customElements.define("chats-tab-row", ChatsTabRow);