mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
use withReply
This commit is contained in:
parent
8cd430ac07
commit
30b8e5b5ea
@ -463,7 +463,7 @@ import {poll} from "../../../mocks/poll.js";
|
|||||||
import {Clock as MockClock} from "../../../mocks/Clock.js";
|
import {Clock as MockClock} from "../../../mocks/Clock.js";
|
||||||
import {createMockStorage} from "../../../mocks/Storage";
|
import {createMockStorage} from "../../../mocks/Storage";
|
||||||
import {ListObserver} from "../../../mocks/ListObserver.js";
|
import {ListObserver} from "../../../mocks/ListObserver.js";
|
||||||
import {createEvent, withTextBody, withContent, withSender, withRedacts} from "../../../mocks/event.js";
|
import {createEvent, withTextBody, withContent, withSender, withRedacts, withReply} from "../../../mocks/event.js";
|
||||||
import {NullLogItem} from "../../../logging/NullLogger";
|
import {NullLogItem} from "../../../logging/NullLogger";
|
||||||
import {EventEntry} from "./entries/EventEntry.js";
|
import {EventEntry} from "./entries/EventEntry.js";
|
||||||
import {User} from "../../User.js";
|
import {User} from "../../User.js";
|
||||||
@ -740,16 +740,7 @@ export function tests() {
|
|||||||
const timeline = new Timeline({roomId, storage: await createMockStorage(), closeCallback: () => {},
|
const timeline = new Timeline({roomId, storage: await createMockStorage(), closeCallback: () => {},
|
||||||
fragmentIdComparer, pendingEvents: new ObservableArray(), clock: new MockClock()});
|
fragmentIdComparer, pendingEvents: new ObservableArray(), clock: new MockClock()});
|
||||||
const entryA = new EventEntry({ event: withTextBody("foo", createEvent("m.room.message", "event_id_1", alice)) });
|
const entryA = new EventEntry({ event: withTextBody("foo", createEvent("m.room.message", "event_id_1", alice)) });
|
||||||
let event = withContent({
|
const entryB = new EventEntry({ event: withReply("event_id_1", createEvent("m.room.message", "event_id_2", bob)), eventIndex: 2 });
|
||||||
body: "bar",
|
|
||||||
msgtype: "m.text",
|
|
||||||
"m.relates_to": {
|
|
||||||
"m.in_reply_to": {
|
|
||||||
"event_id": "event_id_1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, createEvent("m.room.message", "event_id_2", bob));
|
|
||||||
const entryB = new EventEntry({ event });
|
|
||||||
await timeline.load(new User(alice), "join", new NullLogItem());
|
await timeline.load(new User(alice), "join", new NullLogItem());
|
||||||
timeline.entries.subscribe({ onAdd: () => null, });
|
timeline.entries.subscribe({ onAdd: () => null, });
|
||||||
timeline.addEntries([entryA, entryB]);
|
timeline.addEntries([entryA, entryB]);
|
||||||
@ -763,16 +754,7 @@ export function tests() {
|
|||||||
await txn.complete();
|
await txn.complete();
|
||||||
const timeline = new Timeline({roomId, storage, closeCallback: () => {},
|
const timeline = new Timeline({roomId, storage, closeCallback: () => {},
|
||||||
fragmentIdComparer, pendingEvents: new ObservableArray(), clock: new MockClock()});
|
fragmentIdComparer, pendingEvents: new ObservableArray(), clock: new MockClock()});
|
||||||
let event = withContent({
|
const entryB = new EventEntry({ event: withReply("event_id_1", createEvent("m.room.message", "event_id_2", bob)), eventIndex: 2 });
|
||||||
body: "bar",
|
|
||||||
msgtype: "m.text",
|
|
||||||
"m.relates_to": {
|
|
||||||
"m.in_reply_to": {
|
|
||||||
"event_id": "event_id_1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, createEvent("m.room.message", "event_id_2", bob));
|
|
||||||
const entryB = new EventEntry({ event, eventIndex: 2 });
|
|
||||||
await timeline.load(new User(alice), "join", new NullLogItem());
|
await timeline.load(new User(alice), "join", new NullLogItem());
|
||||||
timeline.entries.subscribe({ onAdd: () => null, onUpdate: () => null });
|
timeline.entries.subscribe({ onAdd: () => null, onUpdate: () => null });
|
||||||
timeline.addEntries([entryB]);
|
timeline.addEntries([entryB]);
|
||||||
@ -783,16 +765,7 @@ export function tests() {
|
|||||||
"context entry is fetched from hs": async assert => {
|
"context entry is fetched from hs": async assert => {
|
||||||
const timeline = new Timeline({roomId, storage: await createMockStorage(), closeCallback: () => {},
|
const timeline = new Timeline({roomId, storage: await createMockStorage(), closeCallback: () => {},
|
||||||
fragmentIdComparer, pendingEvents: new ObservableArray(), clock: new MockClock(), hsApi});
|
fragmentIdComparer, pendingEvents: new ObservableArray(), clock: new MockClock(), hsApi});
|
||||||
let event = withContent({
|
const entryB = new EventEntry({ event: withReply("event_id_1", createEvent("m.room.message", "event_id_2", bob)), eventIndex: 2 });
|
||||||
body: "bar",
|
|
||||||
msgtype: "m.text",
|
|
||||||
"m.relates_to": {
|
|
||||||
"m.in_reply_to": {
|
|
||||||
"event_id": "event_id_1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, createEvent("m.room.message", "event_id_2", bob));
|
|
||||||
const entryB = new EventEntry({ event, eventIndex: 2 });
|
|
||||||
await timeline.load(new User(alice), "join", new NullLogItem());
|
await timeline.load(new User(alice), "join", new NullLogItem());
|
||||||
timeline.entries.subscribe({ onAdd: () => null, onUpdate: () => null });
|
timeline.entries.subscribe({ onAdd: () => null, onUpdate: () => null });
|
||||||
timeline.addEntries([entryB]);
|
timeline.addEntries([entryB]);
|
||||||
@ -804,17 +777,8 @@ export function tests() {
|
|||||||
const timeline = new Timeline({roomId, storage: await createMockStorage(), closeCallback: () => {},
|
const timeline = new Timeline({roomId, storage: await createMockStorage(), closeCallback: () => {},
|
||||||
fragmentIdComparer, pendingEvents: new ObservableArray(), clock: new MockClock()});
|
fragmentIdComparer, pendingEvents: new ObservableArray(), clock: new MockClock()});
|
||||||
const entryA = new EventEntry({ event: withTextBody("foo", createEvent("m.room.message", "event_id_1", alice)), eventIndex: 1 });
|
const entryA = new EventEntry({ event: withTextBody("foo", createEvent("m.room.message", "event_id_1", alice)), eventIndex: 1 });
|
||||||
const content = {
|
const entryB = new EventEntry({ event: withReply("event_id_1", createEvent("m.room.message", "event_id_2", bob)), eventIndex: 2 });
|
||||||
body: "bar",
|
const entryC = new EventEntry({ event: withReply("event_id_1", createEvent("m.room.message", "event_id_3", bob)), eventIndex: 3 });
|
||||||
msgtype: "m.text",
|
|
||||||
"m.relates_to": {
|
|
||||||
"m.in_reply_to": {
|
|
||||||
"event_id": "event_id_1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const entryB = new EventEntry({ event: withContent(content, createEvent("m.room.message", "event_id_2", bob)), eventIndex: 2 });
|
|
||||||
const entryC = new EventEntry({ event: withContent(content, createEvent("m.room.message", "event_id_3", bob)), eventIndex: 3 });
|
|
||||||
await timeline.load(new User(alice), "join", new NullLogItem());
|
await timeline.load(new User(alice), "join", new NullLogItem());
|
||||||
timeline.entries.subscribe({ onAdd: () => null, onUpdate: () => null });
|
timeline.entries.subscribe({ onAdd: () => null, onUpdate: () => null });
|
||||||
timeline.addEntries([entryA, entryB, entryC]);
|
timeline.addEntries([entryA, entryB, entryC]);
|
||||||
@ -825,16 +789,7 @@ export function tests() {
|
|||||||
"context entry in contextEntryNotInTimeline gets updated based on incoming redaction": async assert => {
|
"context entry in contextEntryNotInTimeline gets updated based on incoming redaction": async assert => {
|
||||||
const timeline = new Timeline({roomId, storage: await createMockStorage(), closeCallback: () => {},
|
const timeline = new Timeline({roomId, storage: await createMockStorage(), closeCallback: () => {},
|
||||||
fragmentIdComparer, pendingEvents: new ObservableArray(), clock: new MockClock(), hsApi});
|
fragmentIdComparer, pendingEvents: new ObservableArray(), clock: new MockClock(), hsApi});
|
||||||
let event = withContent({
|
const entryB = new EventEntry({ event: withReply("event_id_1", createEvent("m.room.message", "event_id_2", bob)), eventIndex: 2 });
|
||||||
body: "bar",
|
|
||||||
msgtype: "m.text",
|
|
||||||
"m.relates_to": {
|
|
||||||
"m.in_reply_to": {
|
|
||||||
"event_id": "event_id_1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, createEvent("m.room.message", "event_id_2", bob));
|
|
||||||
const entryB = new EventEntry({ event, eventIndex: 2 });
|
|
||||||
await timeline.load(new User(alice), "join", new NullLogItem());
|
await timeline.load(new User(alice), "join", new NullLogItem());
|
||||||
timeline.entries.subscribe({ onAdd: () => null, onUpdate: () => null });
|
timeline.entries.subscribe({ onAdd: () => null, onUpdate: () => null });
|
||||||
timeline.addEntries([entryB]);
|
timeline.addEntries([entryB]);
|
||||||
@ -847,17 +802,8 @@ export function tests() {
|
|||||||
"redaction of context entry triggers updates in other entries": async assert => {
|
"redaction of context entry triggers updates in other entries": async assert => {
|
||||||
const timeline = new Timeline({roomId, storage: await createMockStorage(), closeCallback: () => {},
|
const timeline = new Timeline({roomId, storage: await createMockStorage(), closeCallback: () => {},
|
||||||
fragmentIdComparer, pendingEvents: new ObservableArray(), clock: new MockClock(), hsApi});
|
fragmentIdComparer, pendingEvents: new ObservableArray(), clock: new MockClock(), hsApi});
|
||||||
const content = {
|
const entryB = new EventEntry({ event: withReply("event_id_1", createEvent("m.room.message", "event_id_2", bob)), eventIndex: 2 });
|
||||||
body: "bar",
|
const entryC = new EventEntry({ event: withReply("event_id_1", createEvent("m.room.message", "event_id_3", bob)), eventIndex: 3 });
|
||||||
msgtype: "m.text",
|
|
||||||
"m.relates_to": {
|
|
||||||
"m.in_reply_to": {
|
|
||||||
"event_id": "event_id_1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const entryB = new EventEntry({ event: withContent(content, createEvent("m.room.message", "event_id_2", bob)), eventIndex: 2 });
|
|
||||||
const entryC = new EventEntry({ event: withContent(content, createEvent("m.room.message", "event_id_3", bob)), eventIndex: 3 });
|
|
||||||
await timeline.load(new User(alice), "join", new NullLogItem());
|
await timeline.load(new User(alice), "join", new NullLogItem());
|
||||||
const bin = [];
|
const bin = [];
|
||||||
timeline.entries.subscribe({
|
timeline.entries.subscribe({
|
||||||
@ -879,16 +825,7 @@ export function tests() {
|
|||||||
const timeline = new Timeline({roomId, storage: await createMockStorage(), closeCallback: () => {},
|
const timeline = new Timeline({roomId, storage: await createMockStorage(), closeCallback: () => {},
|
||||||
fragmentIdComparer, pendingEvents: new ObservableArray(), clock: new MockClock(), hsApi});
|
fragmentIdComparer, pendingEvents: new ObservableArray(), clock: new MockClock(), hsApi});
|
||||||
const entryA = new EventEntry({ event: withTextBody("foo", createEvent("m.room.message", "event_id_1", alice)), eventIndex: 1 });
|
const entryA = new EventEntry({ event: withTextBody("foo", createEvent("m.room.message", "event_id_1", alice)), eventIndex: 1 });
|
||||||
let event = withContent({
|
const entryB = new EventEntry({ event: withReply("event_id_1", createEvent("m.room.message", "event_id_2", bob)), eventIndex: 2 });
|
||||||
body: "bar",
|
|
||||||
msgtype: "m.text",
|
|
||||||
"m.relates_to": {
|
|
||||||
"m.in_reply_to": {
|
|
||||||
"event_id": "event_id_1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, createEvent("m.room.message", "event_id_2", bob));
|
|
||||||
const entryB = new EventEntry({ event, eventIndex: 2 });
|
|
||||||
await timeline.load(new User(alice), "join", new NullLogItem());
|
await timeline.load(new User(alice), "join", new NullLogItem());
|
||||||
timeline.entries.subscribe({ onAdd: () => null, onUpdate: () => null });
|
timeline.entries.subscribe({ onAdd: () => null, onUpdate: () => null });
|
||||||
timeline.addEntries([entryB]);
|
timeline.addEntries([entryB]);
|
||||||
|
@ -37,3 +37,13 @@ export function withTxnId(txnId, event) {
|
|||||||
export function withRedacts(redacts, reason, event) {
|
export function withRedacts(redacts, reason, event) {
|
||||||
return Object.assign({redacts, content: {reason}}, event);
|
return Object.assign({redacts, content: {reason}}, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function withReply(replyToId, event) {
|
||||||
|
return withContent({
|
||||||
|
"m.relates_to": {
|
||||||
|
"m.in_reply_to": {
|
||||||
|
"event_id": replyToId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, event);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user