2017-11-02 18:54:25 +00:00
|
|
|
/*
|
|
|
|
Copyright 2017 New Vector Ltd
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
import React from "react";
|
2021-06-18 15:13:55 +00:00
|
|
|
import { Room } from "matrix-js-sdk/src/models/room";
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
import AutocompleteProvider from "./AutocompleteProvider";
|
|
|
|
import { _t } from "../languageHandler";
|
|
|
|
import { MatrixClientPeg } from "../MatrixClientPeg";
|
|
|
|
import { PillCompletion } from "./Components";
|
2021-06-29 12:11:58 +00:00
|
|
|
import { ICompletion, ISelectionRange } from "./Autocompleter";
|
2022-12-12 11:24:14 +00:00
|
|
|
import RoomAvatar from "../components/views/avatars/RoomAvatar";
|
|
|
|
import { TimelineRenderingType } from "../contexts/RoomContext";
|
2017-11-02 18:54:25 +00:00
|
|
|
|
|
|
|
const AT_ROOM_REGEX = /@\S*/g;
|
|
|
|
|
|
|
|
export default class NotifProvider extends AutocompleteProvider {
|
2022-12-16 12:29:59 +00:00
|
|
|
public constructor(public room: Room, renderingType?: TimelineRenderingType) {
|
2021-11-18 12:47:11 +00:00
|
|
|
super({ commandRegex: AT_ROOM_REGEX, renderingType });
|
2017-11-02 18:54:25 +00:00
|
|
|
}
|
|
|
|
|
2022-12-16 12:29:59 +00:00
|
|
|
public async getCompletions(
|
|
|
|
query: string,
|
|
|
|
selection: ISelectionRange,
|
|
|
|
force = false,
|
|
|
|
limit = -1,
|
|
|
|
): Promise<ICompletion[]> {
|
2017-11-02 18:54:25 +00:00
|
|
|
const client = MatrixClientPeg.get();
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
if (!this.room.currentState.mayTriggerNotifOfType("room", client.credentials.userId)) return [];
|
2017-11-02 18:54:25 +00:00
|
|
|
|
2021-06-29 12:11:58 +00:00
|
|
|
const { command, range } = this.getCurrentCommand(query, selection, force);
|
2022-12-12 11:24:14 +00:00
|
|
|
if (
|
|
|
|
command?.[0].length > 1 &&
|
|
|
|
["@room", "@channel", "@everyone", "@here"].some((c) => c.startsWith(command[0]))
|
2022-02-09 09:03:28 +00:00
|
|
|
) {
|
2022-12-12 11:24:14 +00:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
completion: "@room",
|
|
|
|
completionId: "@room",
|
|
|
|
type: "at-room",
|
|
|
|
suffix: " ",
|
|
|
|
component: (
|
|
|
|
<PillCompletion title="@room" description={_t("Notify the whole room")}>
|
|
|
|
<RoomAvatar width={24} height={24} room={this.room} />
|
|
|
|
</PillCompletion>
|
|
|
|
),
|
|
|
|
range,
|
|
|
|
},
|
|
|
|
];
|
2017-11-02 18:54:25 +00:00
|
|
|
}
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
public getName(): string {
|
2022-12-12 11:24:14 +00:00
|
|
|
return "❗️ " + _t("Room Notification");
|
2017-11-02 18:54:25 +00:00
|
|
|
}
|
|
|
|
|
2022-12-16 12:29:59 +00:00
|
|
|
public renderCompletions(completions: React.ReactNode[]): React.ReactNode {
|
2019-09-30 13:04:39 +00:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className="mx_Autocomplete_Completion_container_pill mx_Autocomplete_Completion_container_truncate"
|
2021-02-18 10:55:24 +00:00
|
|
|
role="presentation"
|
2019-09-30 13:04:39 +00:00
|
|
|
aria-label={_t("Notification Autocomplete")}
|
|
|
|
>
|
2022-12-12 11:24:14 +00:00
|
|
|
{completions}
|
2019-09-30 13:04:39 +00:00
|
|
|
</div>
|
|
|
|
);
|
2017-11-02 18:54:25 +00:00
|
|
|
}
|
|
|
|
}
|