mirror of https://github.com/vector-im/riot-web
Merge pull request #5960 from matrix-org/travis/msc2876
Support UI for MSC2762: Widgets reading events from roomspull/21833/head
commit
3308368ac6
|
@ -600,6 +600,10 @@
|
|||
"See when the avatar changes in this room": "See when the avatar changes in this room",
|
||||
"Change the avatar of your active room": "Change the avatar of your active room",
|
||||
"See when the avatar changes in your active room": "See when the avatar changes in your active room",
|
||||
"Kick, ban, or invite people to this room, and make you leave": "Kick, ban, or invite people to this room, and make you leave",
|
||||
"See when people join, leave, or are invited to this room": "See when people join, leave, or are invited to this room",
|
||||
"Kick, ban, or invite people to your active room, and make you leave": "Kick, ban, or invite people to your active room, and make you leave",
|
||||
"See when people join, leave, or are invited to your active room": "See when people join, leave, or are invited to your active room",
|
||||
"Send stickers to this room as you": "Send stickers to this room as you",
|
||||
"See when a sticker is posted in this room": "See when a sticker is posted in this room",
|
||||
"Send stickers to your active room as you": "Send stickers to your active room as you",
|
||||
|
|
|
@ -44,6 +44,7 @@ import { CHAT_EFFECTS } from "../../effects";
|
|||
import { containsEmoji } from "../../effects/utils";
|
||||
import dis from "../../dispatcher/dispatcher";
|
||||
import {tryTransformPermalinkToLocalHref} from "../../utils/permalinks/Permalinks";
|
||||
import {MatrixEvent} from "matrix-js-sdk/src/models/event";
|
||||
|
||||
// TODO: Purge this from the universe
|
||||
|
||||
|
@ -144,6 +145,52 @@ export class StopGapWidgetDriver extends WidgetDriver {
|
|||
return {roomId, eventId: r.event_id};
|
||||
}
|
||||
|
||||
public async readRoomEvents(eventType: string, msgtype: string | undefined, limit: number): Promise<MatrixEvent[]> {
|
||||
limit = limit > 0 ? Math.min(limit, 25) : 25; // arbitrary choice
|
||||
|
||||
const client = MatrixClientPeg.get();
|
||||
const roomId = ActiveRoomObserver.activeRoomId;
|
||||
const room = client.getRoom(roomId);
|
||||
if (!client || !roomId || !room) throw new Error("Not in a room or not attached to a client");
|
||||
|
||||
const results: MatrixEvent[] = [];
|
||||
const events = room.getLiveTimeline().getEvents(); // timelines are most recent last
|
||||
for (let i = events.length - 1; i > 0; i--) {
|
||||
if (results.length >= limit) break;
|
||||
|
||||
const ev = events[i];
|
||||
if (ev.getType() !== eventType) continue;
|
||||
if (eventType === EventType.RoomMessage && msgtype && msgtype !== ev.getContent()['msgtype']) continue;
|
||||
results.push(ev);
|
||||
}
|
||||
|
||||
return results.map(e => e.event);
|
||||
}
|
||||
|
||||
public async readStateEvents(
|
||||
eventType: string, stateKey: string | undefined, limit: number,
|
||||
): Promise<MatrixEvent[]> {
|
||||
limit = limit > 0 ? Math.min(limit, 100) : 100; // arbitrary choice
|
||||
|
||||
const client = MatrixClientPeg.get();
|
||||
const roomId = ActiveRoomObserver.activeRoomId;
|
||||
const room = client.getRoom(roomId);
|
||||
if (!client || !roomId || !room) throw new Error("Not in a room or not attached to a client");
|
||||
|
||||
const results: MatrixEvent[] = [];
|
||||
const state = room.currentState.events.get(eventType);
|
||||
if (state) {
|
||||
if (stateKey === "" || !!stateKey) {
|
||||
const forKey = state.get(stateKey);
|
||||
if (forKey) results.push(forKey);
|
||||
} else {
|
||||
results.push(...Array.from(state.values()));
|
||||
}
|
||||
}
|
||||
|
||||
return results.slice(0, limit).map(e => e.event);
|
||||
}
|
||||
|
||||
public async askOpenID(observer: SimpleObservable<IOpenIDUpdate>) {
|
||||
const oidcState = WidgetPermissionStore.instance.getOIDCState(
|
||||
this.forWidget, this.forWidgetKind, this.inRoomId,
|
||||
|
|
|
@ -96,6 +96,16 @@ export class CapabilityText {
|
|||
[EventDirection.Receive]: _td("See when the avatar changes in your active room"),
|
||||
},
|
||||
},
|
||||
[EventType.RoomMember]: {
|
||||
[WidgetKind.Room]: {
|
||||
[EventDirection.Send]: _td("Kick, ban, or invite people to this room, and make you leave"),
|
||||
[EventDirection.Receive]: _td("See when people join, leave, or are invited to this room"),
|
||||
},
|
||||
[GENERIC_WIDGET_KIND]: {
|
||||
[EventDirection.Send]: _td("Kick, ban, or invite people to your active room, and make you leave"),
|
||||
[EventDirection.Receive]: _td("See when people join, leave, or are invited to your active room"),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
private static nonStateSendRecvCaps: ISendRecvStaticCapText = {
|
||||
|
|
Loading…
Reference in New Issue