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.
|
|
|
|
*/
|
|
|
|
|
2020-04-21 09:01:05 +00:00
|
|
|
import React from 'react';
|
2020-04-20 18:00:54 +00:00
|
|
|
import Room from "matrix-js-sdk/src/models/room";
|
2017-11-02 18:54:25 +00:00
|
|
|
import AutocompleteProvider from './AutocompleteProvider';
|
|
|
|
import { _t } from '../languageHandler';
|
2019-12-20 21:13:46 +00:00
|
|
|
import {MatrixClientPeg} from '../MatrixClientPeg';
|
2017-11-02 18:54:25 +00:00
|
|
|
import {PillCompletion} from './Components';
|
2019-12-20 01:19:56 +00:00
|
|
|
import * as sdk from '../index';
|
2020-04-20 18:00:54 +00:00
|
|
|
import {ICompletion, ISelectionRange} from "./Autocompleter";
|
2017-11-02 18:54:25 +00:00
|
|
|
|
|
|
|
const AT_ROOM_REGEX = /@\S*/g;
|
|
|
|
|
|
|
|
export default class NotifProvider extends AutocompleteProvider {
|
2020-04-20 18:00:54 +00:00
|
|
|
room: Room;
|
|
|
|
|
2017-11-02 18:54:25 +00:00
|
|
|
constructor(room) {
|
|
|
|
super(AT_ROOM_REGEX);
|
|
|
|
this.room = room;
|
|
|
|
}
|
|
|
|
|
2020-04-20 18:00:54 +00:00
|
|
|
async getCompletions(query: string, selection: ISelectionRange, force= false): Promise<ICompletion[]> {
|
2017-11-02 18:54:25 +00:00
|
|
|
const RoomAvatar = sdk.getComponent('views.avatars.RoomAvatar');
|
|
|
|
|
|
|
|
const client = MatrixClientPeg.get();
|
|
|
|
|
|
|
|
if (!this.room.currentState.mayTriggerNotifOfType('room', client.credentials.userId)) return [];
|
|
|
|
|
|
|
|
const {command, range} = this.getCurrentCommand(query, selection, force);
|
|
|
|
if (command && command[0] && '@room'.startsWith(command[0]) && command[0].length > 1) {
|
|
|
|
return [{
|
|
|
|
completion: '@room',
|
2018-05-12 19:04:58 +00:00
|
|
|
completionId: '@room',
|
2019-09-23 12:39:19 +00:00
|
|
|
type: "at-room",
|
2017-11-02 18:54:25 +00:00
|
|
|
suffix: ' ',
|
|
|
|
component: (
|
2020-05-30 12:30:59 +00:00
|
|
|
<PillCompletion title="@room" description={_t("Notify the whole room")}>
|
|
|
|
<RoomAvatar width={24} height={24} room={this.room} />
|
|
|
|
</PillCompletion>
|
2017-11-02 18:54:25 +00:00
|
|
|
),
|
|
|
|
range,
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
getName() {
|
|
|
|
return '❗️ ' + _t('Room Notification');
|
|
|
|
}
|
|
|
|
|
2020-04-20 18:00:54 +00:00
|
|
|
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"
|
|
|
|
role="listbox"
|
|
|
|
aria-label={_t("Notification Autocomplete")}
|
|
|
|
>
|
|
|
|
{ completions }
|
|
|
|
</div>
|
|
|
|
);
|
2017-11-02 18:54:25 +00:00
|
|
|
}
|
|
|
|
}
|