This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/plugins/chat/assets/javascripts/discourse/widgets/chat-invitation-notification-item.js
Roman Rizzi 5c699e4384
DEV: Pass messageId as a dynamic segment instead of a query param (#20013)
* DEV: Rnemae channel path to just c

Also swap the channel id and channel slug params to be consistent with core.

* linting

* channel_path

* Drop slugify helper and channel route without slug

* Request slug and route models through the channel model if possible

* DEV: Pass messageId as a dynamic segment instead of a query param

* Ensure change is backwards-compatible

* drop query param from oneboxes

* Correctly extract channelId from routes

* Better route organization using siblings for regular and near-message

* Ensures sessions are unique even when using parallelism

* prevents didReceiveAttrs to clear input mid test

* we disable animations in capybara so sometimes the message was barely showing

* adds wait

* ensures finished loading

* is it causing more harm than good?

* this check is slowing things for no reason

* actually target the button

* more resilient select chat message

* apply similar fix to bookmark

* fix

---------

Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
2023-02-01 12:39:23 -03:00

46 lines
1.5 KiB
JavaScript

import I18n from "I18n";
import RawHtml from "discourse/widgets/raw-html";
import { createWidgetFrom } from "discourse/widgets/widget";
import { DefaultNotificationItem } from "discourse/widgets/default-notification-item";
import { h } from "virtual-dom";
import { formatUsername } from "discourse/lib/utilities";
import { iconNode } from "discourse-common/lib/icon-library";
import slugifyChannel from "discourse/plugins/chat/discourse/lib/slugify-channel";
createWidgetFrom(DefaultNotificationItem, "chat-invitation-notification-item", {
services: ["chat", "router"],
text(data) {
const username = formatUsername(data.invited_by_username);
return I18n.t("notifications.chat_invitation_html", { username });
},
html(attrs) {
const notificationType = attrs.notification_type;
const lookup = this.site.get("notificationLookup");
const notificationName = lookup[notificationType];
const { data } = attrs;
const text = this.text(data);
const title = this.notificationTitle(notificationName, data);
const html = new RawHtml({ html: `<div>${text}</div>` });
const contents = [iconNode("link"), html];
const href = this.url(data);
return h(
"a",
{ attributes: { title, href, "data-auto-route": true } },
contents
);
},
url(data) {
const slug = slugifyChannel({
title: data.chat_channel_title,
slug: data.chat_channel_slug,
});
return `/chat/c/${slug || "-"}/${data.chat_channel_id}/${
data.chat_message_id
}`;
},
});