Compare commits
59 Commits
v13.0.0
...
v14.0.0-rc.2
| Author | SHA1 | Date | |
|---|---|---|---|
| f5fcc20840 | |||
| 17e20c17b3 | |||
| 39fd350ffe | |||
| b4d100baff | |||
| 15cd675354 | |||
| e8137d3f88 | |||
| a7a08fd760 | |||
| df51f95fbd | |||
| a14cf1a339 | |||
| 30758600f0 | |||
| 823242a93c | |||
| 1dbd7158ad | |||
| 46b3f0babd | |||
| b4bc554d7a | |||
| 1485969493 | |||
| 92f7ddcf3e | |||
| 90d480b4cf | |||
| 2515d07c8f | |||
| 7acb9416c2 | |||
| 0c4212ca90 | |||
| 9a06a05a75 | |||
| f05a0615f7 | |||
| 6b93687ff0 | |||
| 8d910d5e26 | |||
| 9264050f41 | |||
| eab0c54663 | |||
| 82a254b7bd | |||
| 0f6a59ed98 | |||
| afb4682987 | |||
| a18326519b | |||
| b033540f95 | |||
| ff529d733d | |||
| 5951958c05 | |||
| 886f2fb95d | |||
| f6ce0c581e | |||
| 5ce68b6c12 | |||
| c748aebfc5 | |||
| f8ec445ff0 | |||
| 5d4f347eaa | |||
| 1359c0574e | |||
| b1d239b292 | |||
| 70031415e8 | |||
| 5a73a9758a | |||
| 6848e96244 | |||
| b53566e074 | |||
| 012b914a97 | |||
| 3c6eed0135 | |||
| b83977e72f | |||
| 5c6a643436 | |||
| 1ca1a69eb8 | |||
| 76ea1ba192 | |||
| 8cd8ec134e | |||
| 9f42647a75 | |||
| a4cacbc73a | |||
| f24840d09c | |||
| acb7991cc5 | |||
| 6addc7dd3d | |||
| 4606422e57 | |||
| 35ee58dfe1 |
@@ -1,3 +1,24 @@
|
||||
Changes in [14.0.0-rc.2](https://github.com/vector-im/element-desktop/releases/tag/v14.0.0-rc.2) (2021-10-07)
|
||||
=============================================================================================================
|
||||
|
||||
Changes in [14.0.0-rc.1](https://github.com/vector-im/element-desktop/releases/tag/v14.0.0-rc.1) (2021-10-04)
|
||||
=============================================================================================================
|
||||
|
||||
## 🚨 BREAKING CHANGES
|
||||
* Support for call upgrades. `setLocalVideoMuted()` and `setMicrophoneMuted()` are now `async` and return the new mute state ([\#1827](https://github.com/matrix-org/matrix-js-sdk/pull/1827)). Contributed by [SimonBrandner](https://github.com/SimonBrandner).
|
||||
|
||||
## ✨ Features
|
||||
* Implement file versioning for tree spaces ([\#1952](https://github.com/matrix-org/matrix-js-sdk/pull/1952)).
|
||||
* Allow answering calls without audio/video ([\#1950](https://github.com/matrix-org/matrix-js-sdk/pull/1950)). Contributed by [SimonBrandner](https://github.com/SimonBrandner).
|
||||
* Add `bound` to `IThreepid` ([\#1941](https://github.com/matrix-org/matrix-js-sdk/pull/1941)). Contributed by [SimonBrandner](https://github.com/SimonBrandner).
|
||||
* Add `trusted_locally` to `TrustInfo` ([\#1942](https://github.com/matrix-org/matrix-js-sdk/pull/1942)). Contributed by [SimonBrandner](https://github.com/SimonBrandner).
|
||||
|
||||
## 🐛 Bug Fixes
|
||||
* Fix incorrect return value type in getJoinedRooms() ([\#1959](https://github.com/matrix-org/matrix-js-sdk/pull/1959)). Contributed by [psrpinto](https://github.com/psrpinto).
|
||||
* Make sure to set `callLengthInterval` only once ([\#1958](https://github.com/matrix-org/matrix-js-sdk/pull/1958)). Fixes vector-im/element-web#19221 and vector-im/element-web#19221. Contributed by [SimonBrandner](https://github.com/SimonBrandner).
|
||||
* Fix event partitioning from non threading ready clients ([\#1948](https://github.com/matrix-org/matrix-js-sdk/pull/1948)).
|
||||
* Ensure unencrypted fields get exposed by getEffectiveEvent() ([\#1938](https://github.com/matrix-org/matrix-js-sdk/pull/1938)). Fixes vector-im/element-web#19062 and vector-im/element-web#19062.
|
||||
|
||||
Changes in [13.0.0](https://github.com/vector-im/element-desktop/releases/tag/v13.0.0) (2021-09-27)
|
||||
===================================================================================================
|
||||
|
||||
|
||||
@@ -98,6 +98,21 @@ We use continuous integration, and all pull requests get automatically tested:
|
||||
if your change breaks the build, then the PR will show that there are failed
|
||||
checks, so please check back after a few minutes.
|
||||
|
||||
Tests
|
||||
-----
|
||||
If your PR is a feature (ie. if it's being labelled with the 'T-Enhancement'
|
||||
label) then we require that the PR also includes tests. These need to test that
|
||||
your feature works as expected and ideally test edge cases too. For the js-sdk
|
||||
itself, your tests should generally be unit tests. matrix-react-sdk also uses
|
||||
these guidelines, so for that your tests can be unit tests using
|
||||
react-test-utils, snapshot tests or screenshot tests.
|
||||
|
||||
We don't require tests for bug fixes (T-Defect) but strongly encourage regression
|
||||
tests for the bug itself wherever possible.
|
||||
|
||||
In the future we may formalise this more with a minimum test coverage
|
||||
percentage for the diff.
|
||||
|
||||
Code style
|
||||
----------
|
||||
The js-sdk aims to target TypeScript/ES6. All new files should be written in
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "matrix-js-sdk",
|
||||
"version": "13.0.0",
|
||||
"version": "14.0.0-rc.2",
|
||||
"description": "Matrix Client-Server SDK for Javascript",
|
||||
"scripts": {
|
||||
"prepublishOnly": "yarn build",
|
||||
|
||||
@@ -14,21 +14,25 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { MatrixClient } from "../../../src";
|
||||
import { IContent, MatrixClient, MatrixEvent } from "../../../src";
|
||||
import { Room } from "../../../src/models/room";
|
||||
import { UNSTABLE_MSC3089_BRANCH } from "../../../src/@types/event";
|
||||
import { IEncryptedFile, RelationType, UNSTABLE_MSC3089_BRANCH } from "../../../src/@types/event";
|
||||
import { EventTimelineSet } from "../../../src/models/event-timeline-set";
|
||||
import { EventTimeline } from "../../../src/models/event-timeline";
|
||||
import { MSC3089Branch } from "../../../src/models/MSC3089Branch";
|
||||
import { MSC3089TreeSpace } from "../../../src/models/MSC3089TreeSpace";
|
||||
|
||||
describe("MSC3089Branch", () => {
|
||||
let client: MatrixClient;
|
||||
// @ts-ignore - TS doesn't know that this is a type
|
||||
let indexEvent: any;
|
||||
let directory: MSC3089TreeSpace;
|
||||
let branch: MSC3089Branch;
|
||||
let branch2: MSC3089Branch;
|
||||
|
||||
const branchRoomId = "!room:example.org";
|
||||
const fileEventId = "$file";
|
||||
const fileEventId2 = "$second_file";
|
||||
|
||||
const staticTimelineSets = {} as EventTimelineSet;
|
||||
const staticRoom = {
|
||||
@@ -50,7 +54,12 @@ describe("MSC3089Branch", () => {
|
||||
getRoomId: () => branchRoomId,
|
||||
getStateKey: () => fileEventId,
|
||||
});
|
||||
branch = new MSC3089Branch(client, indexEvent);
|
||||
directory = new MSC3089TreeSpace(client, branchRoomId);
|
||||
branch = new MSC3089Branch(client, indexEvent, directory);
|
||||
branch2 = new MSC3089Branch(client, {
|
||||
getRoomId: () => branchRoomId,
|
||||
getStateKey: () => fileEventId2,
|
||||
} as MatrixEvent, directory);
|
||||
});
|
||||
|
||||
it('should know the file event ID', () => {
|
||||
@@ -69,13 +78,15 @@ describe("MSC3089Branch", () => {
|
||||
});
|
||||
|
||||
it('should be able to delete the file', async () => {
|
||||
const eventIdOrder = [fileEventId, fileEventId2];
|
||||
|
||||
const stateFn = jest.fn()
|
||||
.mockImplementation((roomId: string, eventType: string, content: any, stateKey: string) => {
|
||||
expect(roomId).toEqual(branchRoomId);
|
||||
expect(eventType).toEqual(UNSTABLE_MSC3089_BRANCH.unstable); // test that we're definitely using the unstable value
|
||||
expect(content).toMatchObject({});
|
||||
expect(content['active']).toBeUndefined();
|
||||
expect(stateKey).toEqual(fileEventId);
|
||||
expect(stateKey).toEqual(eventIdOrder[stateFn.mock.calls.length - 1]);
|
||||
|
||||
return Promise.resolve(); // return value not used
|
||||
});
|
||||
@@ -83,16 +94,19 @@ describe("MSC3089Branch", () => {
|
||||
|
||||
const redactFn = jest.fn().mockImplementation((roomId: string, eventId: string) => {
|
||||
expect(roomId).toEqual(branchRoomId);
|
||||
expect(eventId).toEqual(fileEventId);
|
||||
expect(eventId).toEqual(eventIdOrder[stateFn.mock.calls.length - 1]);
|
||||
|
||||
return Promise.resolve(); // return value not used
|
||||
});
|
||||
client.redactEvent = redactFn;
|
||||
|
||||
branch.getVersionHistory = () => Promise.resolve([branch, branch2]);
|
||||
branch2.getVersionHistory = () => Promise.resolve([branch2]);
|
||||
|
||||
await branch.delete();
|
||||
|
||||
expect(stateFn).toHaveBeenCalledTimes(1);
|
||||
expect(redactFn).toHaveBeenCalledTimes(1);
|
||||
expect(stateFn).toHaveBeenCalledTimes(2);
|
||||
expect(redactFn).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('should know its name', async () => {
|
||||
@@ -127,6 +141,22 @@ describe("MSC3089Branch", () => {
|
||||
expect(stateFn).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should be v1 by default', () => {
|
||||
indexEvent.getContent = () => ({ active: true });
|
||||
|
||||
const res = branch.version;
|
||||
|
||||
expect(res).toEqual(1);
|
||||
});
|
||||
|
||||
it('should be vN when set', () => {
|
||||
indexEvent.getContent = () => ({ active: true, version: 3 });
|
||||
|
||||
const res = branch.version;
|
||||
|
||||
expect(res).toEqual(3);
|
||||
});
|
||||
|
||||
it('should be unlocked by default', async () => {
|
||||
indexEvent.getContent = () => ({ active: true });
|
||||
|
||||
@@ -169,13 +199,13 @@ describe("MSC3089Branch", () => {
|
||||
it('should be able to return event information', async () => {
|
||||
const mxcLatter = "example.org/file";
|
||||
const fileContent = { isFile: "not quite", url: "mxc://" + mxcLatter };
|
||||
const eventsArr = [
|
||||
{ getId: () => "$not-file", getContent: () => ({}) },
|
||||
{ getId: () => fileEventId, getContent: () => ({ file: fileContent }) },
|
||||
];
|
||||
client.getEventTimeline = () => Promise.resolve({
|
||||
getEvents: () => eventsArr,
|
||||
}) as any as Promise<EventTimeline>; // partial
|
||||
const fileEvent = { getId: () => fileEventId, getOriginalContent: () => ({ file: fileContent }) };
|
||||
staticRoom.getUnfilteredTimelineSet = () => ({
|
||||
findEventById: (eventId) => {
|
||||
expect(eventId).toEqual(fileEventId);
|
||||
return fileEvent;
|
||||
},
|
||||
}) as EventTimelineSet;
|
||||
client.mxcUrlToHttp = (mxc: string) => {
|
||||
expect(mxc).toEqual("mxc://" + mxcLatter);
|
||||
return `https://example.org/_matrix/media/v1/download/${mxcLatter}`;
|
||||
@@ -194,17 +224,109 @@ describe("MSC3089Branch", () => {
|
||||
it('should be able to return the event object', async () => {
|
||||
const mxcLatter = "example.org/file";
|
||||
const fileContent = { isFile: "not quite", url: "mxc://" + mxcLatter };
|
||||
const eventsArr = [
|
||||
{ getId: () => "$not-file", getContent: () => ({}) },
|
||||
{ getId: () => fileEventId, getContent: () => ({ file: fileContent }) },
|
||||
];
|
||||
client.getEventTimeline = () => Promise.resolve({
|
||||
getEvents: () => eventsArr,
|
||||
}) as any as Promise<EventTimeline>; // partial
|
||||
const fileEvent = { getId: () => fileEventId, getOriginalContent: () => ({ file: fileContent }) };
|
||||
staticRoom.getUnfilteredTimelineSet = () => ({
|
||||
findEventById: (eventId) => {
|
||||
expect(eventId).toEqual(fileEventId);
|
||||
return fileEvent;
|
||||
},
|
||||
}) as EventTimelineSet;
|
||||
client.mxcUrlToHttp = (mxc: string) => {
|
||||
expect(mxc).toEqual("mxc://" + mxcLatter);
|
||||
return `https://example.org/_matrix/media/v1/download/${mxcLatter}`;
|
||||
};
|
||||
client.decryptEventIfNeeded = () => Promise.resolve();
|
||||
|
||||
const res = await branch.getFileEvent();
|
||||
expect(res).toBeDefined();
|
||||
expect(res).toBe(eventsArr[1]);
|
||||
expect(res).toBe(fileEvent);
|
||||
});
|
||||
|
||||
it('should create new versions of itself', async () => {
|
||||
const canaryName = "canary";
|
||||
const fileContents = "contents go here";
|
||||
const canaryContents = Uint8Array.from(Array.from(fileContents).map((_, i) => fileContents.charCodeAt(i)));
|
||||
const canaryFile = {} as IEncryptedFile;
|
||||
const canaryAddl = { canary: true };
|
||||
indexEvent.getContent = () => ({ active: true, retained: true });
|
||||
const stateKeyOrder = [fileEventId2, fileEventId];
|
||||
const stateFn = jest.fn()
|
||||
.mockImplementation((roomId: string, eventType: string, content: any, stateKey: string) => {
|
||||
expect(roomId).toEqual(branchRoomId);
|
||||
expect(eventType).toEqual(UNSTABLE_MSC3089_BRANCH.unstable); // test that we're definitely using the unstable value
|
||||
expect(stateKey).toEqual(stateKeyOrder[stateFn.mock.calls.length - 1]);
|
||||
if (stateKey === fileEventId) {
|
||||
expect(content).toMatchObject({
|
||||
retained: true, // canary for copying state
|
||||
active: false,
|
||||
});
|
||||
} else if (stateKey === fileEventId2) {
|
||||
expect(content).toMatchObject({
|
||||
active: true,
|
||||
version: 2,
|
||||
name: canaryName,
|
||||
});
|
||||
} else {
|
||||
throw new Error("Unexpected state key: " + stateKey);
|
||||
}
|
||||
|
||||
return Promise.resolve(); // return value not used
|
||||
});
|
||||
client.sendStateEvent = stateFn;
|
||||
|
||||
const createFn = jest.fn().mockImplementation((
|
||||
name: string,
|
||||
contents: ArrayBuffer,
|
||||
info: Partial<IEncryptedFile>,
|
||||
addl: IContent,
|
||||
) => {
|
||||
expect(name).toEqual(canaryName);
|
||||
expect(contents).toBe(canaryContents);
|
||||
expect(info).toBe(canaryFile);
|
||||
expect(addl).toMatchObject({
|
||||
...canaryAddl,
|
||||
"m.new_content": true,
|
||||
"m.relates_to": {
|
||||
"rel_type": RelationType.Replace,
|
||||
"event_id": fileEventId,
|
||||
},
|
||||
});
|
||||
|
||||
return Promise.resolve({ event_id: fileEventId2 });
|
||||
});
|
||||
directory.createFile = createFn;
|
||||
|
||||
await branch.createNewVersion(canaryName, canaryContents, canaryFile, canaryAddl);
|
||||
|
||||
expect(stateFn).toHaveBeenCalledTimes(2);
|
||||
expect(createFn).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should fetch file history', async () => {
|
||||
branch2.getFileEvent = () => Promise.resolve({
|
||||
replacingEventId: () => undefined,
|
||||
getId: () => fileEventId2,
|
||||
} as MatrixEvent);
|
||||
branch.getFileEvent = () => Promise.resolve({
|
||||
replacingEventId: () => fileEventId2,
|
||||
getId: () => fileEventId,
|
||||
} as MatrixEvent);
|
||||
|
||||
const events = [await branch.getFileEvent(), await branch2.getFileEvent(), {
|
||||
replacingEventId: () => null,
|
||||
getId: () => "$unknown",
|
||||
}];
|
||||
staticRoom.getLiveTimeline = () => ({ getEvents: () => events }) as EventTimeline;
|
||||
|
||||
directory.getFile = (evId: string) => {
|
||||
expect(evId).toEqual(fileEventId);
|
||||
return branch;
|
||||
};
|
||||
|
||||
const results = await branch2.getVersionHistory();
|
||||
expect(results).toMatchObject([
|
||||
branch2,
|
||||
branch,
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -908,6 +908,7 @@ describe("MSC3089TreeSpace", () => {
|
||||
body: fileName,
|
||||
url: mxc,
|
||||
file: fileInfo,
|
||||
metadata: true, // additional content from test
|
||||
[UNSTABLE_MSC3089_LEAF.unstable]: {}, // test to ensure we're definitely using unstable
|
||||
});
|
||||
|
||||
@@ -925,14 +926,82 @@ describe("MSC3089TreeSpace", () => {
|
||||
name: fileName,
|
||||
});
|
||||
|
||||
return Promise.resolve(); // return value not used.
|
||||
return Promise.resolve({ event_id: "wrong" }); // return value shouldn't be used
|
||||
});
|
||||
client.sendStateEvent = sendStateFn;
|
||||
|
||||
const buf = Uint8Array.from(Array.from(fileContents).map((_, i) => fileContents.charCodeAt(i)));
|
||||
|
||||
// We clone the file info just to make sure it doesn't get mutated for the test.
|
||||
await tree.createFile(fileName, buf, Object.assign({}, fileInfo));
|
||||
const result = await tree.createFile(fileName, buf, Object.assign({}, fileInfo), { metadata: true });
|
||||
expect(result).toMatchObject({ event_id: fileEventId });
|
||||
|
||||
expect(uploadFn).toHaveBeenCalledTimes(1);
|
||||
expect(sendMsgFn).toHaveBeenCalledTimes(1);
|
||||
expect(sendStateFn).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should upload file versions', async () => {
|
||||
const mxc = "mxc://example.org/file";
|
||||
const fileInfo = {
|
||||
mimetype: "text/plain",
|
||||
// other fields as required by encryption, but ignored here
|
||||
};
|
||||
const fileEventId = "$file";
|
||||
const fileName = "My File.txt";
|
||||
const fileContents = "This is a test file";
|
||||
|
||||
// Mock out Blob for the test environment
|
||||
(<any>global).Blob = MockBlob;
|
||||
|
||||
const uploadFn = jest.fn().mockImplementation((contents: Blob, opts: any) => {
|
||||
expect(contents).toBeInstanceOf(Blob);
|
||||
expect(contents.size).toEqual(fileContents.length);
|
||||
expect(opts).toMatchObject({
|
||||
includeFilename: false,
|
||||
onlyContentUri: true, // because the tests rely on this - we shouldn't really be testing for this.
|
||||
});
|
||||
return Promise.resolve(mxc);
|
||||
});
|
||||
client.uploadContent = uploadFn;
|
||||
|
||||
const sendMsgFn = jest.fn().mockImplementation((roomId: string, contents: any) => {
|
||||
expect(roomId).toEqual(tree.roomId);
|
||||
const content = {
|
||||
msgtype: MsgType.File,
|
||||
body: fileName,
|
||||
url: mxc,
|
||||
file: fileInfo,
|
||||
};
|
||||
expect(contents).toMatchObject({
|
||||
...content,
|
||||
"m.new_content": content,
|
||||
[UNSTABLE_MSC3089_LEAF.unstable]: {}, // test to ensure we're definitely using unstable
|
||||
});
|
||||
|
||||
return Promise.resolve({ event_id: fileEventId }); // eslint-disable-line camelcase
|
||||
});
|
||||
client.sendMessage = sendMsgFn;
|
||||
|
||||
const sendStateFn = jest.fn()
|
||||
.mockImplementation((roomId: string, eventType: string, content: any, stateKey: string) => {
|
||||
expect(roomId).toEqual(tree.roomId);
|
||||
expect(eventType).toEqual(UNSTABLE_MSC3089_BRANCH.unstable); // test to ensure we're definitely using unstable
|
||||
expect(stateKey).toEqual(fileEventId);
|
||||
expect(content).toMatchObject({
|
||||
active: true,
|
||||
name: fileName,
|
||||
});
|
||||
|
||||
return Promise.resolve({ event_id: "wrong" }); // return value shouldn't be used
|
||||
});
|
||||
client.sendStateEvent = sendStateFn;
|
||||
|
||||
const buf = Uint8Array.from(Array.from(fileContents).map((_, i) => fileContents.charCodeAt(i)));
|
||||
|
||||
// We clone the file info just to make sure it doesn't get mutated for the test.
|
||||
const result = await tree.createFile(fileName, buf, Object.assign({}, fileInfo), { "m.new_content": true });
|
||||
expect(result).toMatchObject({ event_id: fileEventId });
|
||||
|
||||
expect(uploadFn).toHaveBeenCalledTimes(1);
|
||||
expect(sendMsgFn).toHaveBeenCalledTimes(1);
|
||||
@@ -985,4 +1054,22 @@ describe("MSC3089TreeSpace", () => {
|
||||
expect(files.length).toEqual(1);
|
||||
expect(files[0].indexEvent).toBe(firstFile);
|
||||
});
|
||||
|
||||
it('should list all files', () => {
|
||||
const firstFile = { getContent: () => ({ active: true }) };
|
||||
const secondFile = { getContent: () => ({ active: false }) }; // deliberately inactive
|
||||
room.currentState = {
|
||||
getStateEvents: (eventType: string, stateKey?: string) => {
|
||||
expect(eventType).toEqual(UNSTABLE_MSC3089_BRANCH.unstable); // test to ensure we're definitely using unstable
|
||||
expect(stateKey).toBeUndefined();
|
||||
return [firstFile, secondFile];
|
||||
},
|
||||
};
|
||||
|
||||
const files = tree.listAllFiles();
|
||||
expect(files).toBeDefined();
|
||||
expect(files.length).toEqual(2);
|
||||
expect(files[0].indexEvent).toBe(firstFile);
|
||||
expect(files[1].indexEvent).toBe(secondFile);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as utils from "../test-utils";
|
||||
import { EventStatus, MatrixEvent } from "../../src";
|
||||
import { DuplicateStrategy, EventStatus, MatrixEvent } from "../../src";
|
||||
import { EventTimeline } from "../../src/models/event-timeline";
|
||||
import { RoomState } from "../../src";
|
||||
import { Room } from "../../src";
|
||||
@@ -113,7 +113,7 @@ describe("Room", function() {
|
||||
dupe.event.event_id = events[0].getId();
|
||||
room.addLiveEvents(events);
|
||||
expect(room.timeline[0]).toEqual(events[0]);
|
||||
room.addLiveEvents([dupe], "replace");
|
||||
room.addLiveEvents([dupe], DuplicateStrategy.Replace);
|
||||
expect(room.timeline[0]).toEqual(dupe);
|
||||
});
|
||||
|
||||
|
||||
@@ -83,6 +83,17 @@ class MockRTCPeerConnection {
|
||||
getStats() { return []; }
|
||||
}
|
||||
|
||||
class MockMediaStream {
|
||||
constructor(
|
||||
public id,
|
||||
) {}
|
||||
|
||||
getTracks() { return []; }
|
||||
getAudioTracks() { return [{ enabled: true }]; }
|
||||
getVideoTracks() { return [{ enabled: true }]; }
|
||||
addEventListener() {}
|
||||
}
|
||||
|
||||
describe('Call', function() {
|
||||
let client;
|
||||
let call;
|
||||
@@ -98,13 +109,7 @@ describe('Call', function() {
|
||||
global.navigator = {
|
||||
mediaDevices: {
|
||||
// @ts-ignore Mock
|
||||
getUserMedia: () => {
|
||||
return {
|
||||
getTracks: () => [],
|
||||
getAudioTracks: () => [],
|
||||
getVideoTracks: () => [],
|
||||
};
|
||||
},
|
||||
getUserMedia: () => new MockMediaStream("local_stream"),
|
||||
},
|
||||
};
|
||||
|
||||
@@ -115,7 +120,7 @@ describe('Call', function() {
|
||||
RTCSessionDescription: {},
|
||||
// @ts-ignore Mock
|
||||
RTCIceCandidate: {},
|
||||
getUserMedia: {},
|
||||
getUserMedia: () => new MockMediaStream("local_stream"),
|
||||
};
|
||||
// @ts-ignore Mock
|
||||
global.document = {};
|
||||
@@ -319,7 +324,7 @@ describe('Call', function() {
|
||||
sdp: DUMMY_SDP,
|
||||
},
|
||||
[SDPStreamMetadataKey]: {
|
||||
"stream_id": {
|
||||
"remote_stream": {
|
||||
purpose: SDPStreamMetadataPurpose.Usermedia,
|
||||
audio_muted: true,
|
||||
video_muted: false,
|
||||
@@ -329,8 +334,8 @@ describe('Call', function() {
|
||||
},
|
||||
});
|
||||
|
||||
call.pushRemoteFeed({ id: "stream_id", getAudioTracks: () => ["track1"], getVideoTracks: () => ["track1"] });
|
||||
const feed = call.getFeeds().find((feed) => feed.stream.id === "stream_id");
|
||||
call.pushRemoteFeed(new MockMediaStream("remote_stream"));
|
||||
const feed = call.getFeeds().find((feed) => feed.stream.id === "remote_stream");
|
||||
expect(feed?.purpose).toBe(SDPStreamMetadataPurpose.Usermedia);
|
||||
expect(feed?.isAudioMuted()).toBeTruthy();
|
||||
expect(feed?.isVideoMuted()).not.toBeTruthy();
|
||||
|
||||
@@ -25,4 +25,5 @@ export interface IThreepid {
|
||||
address: string;
|
||||
validated_at: number; // eslint-disable-line camelcase
|
||||
added_at: number; // eslint-disable-line camelcase
|
||||
bound?: boolean;
|
||||
}
|
||||
|
||||
+18
-5
@@ -531,7 +531,7 @@ export interface IRequestTokenResponse {
|
||||
submit_url?: string;
|
||||
}
|
||||
|
||||
interface IRequestMsisdnTokenResponse extends IRequestTokenResponse {
|
||||
export interface IRequestMsisdnTokenResponse extends IRequestTokenResponse {
|
||||
msisdn: string;
|
||||
success: boolean;
|
||||
intl_fmt: string;
|
||||
@@ -568,6 +568,10 @@ interface IRoomInitialSyncResponse {
|
||||
presence: Partial<IEvent>; // legacy and undocumented, api is deprecated so this won't get attention
|
||||
}
|
||||
|
||||
interface IJoinedRoomsResponse {
|
||||
joined_rooms: string[];
|
||||
}
|
||||
|
||||
interface IJoinedMembersResponse {
|
||||
joined: {
|
||||
[userId: string]: {
|
||||
@@ -4288,7 +4292,16 @@ export class MatrixClient extends EventEmitter {
|
||||
* @return {module:http-api.MatrixError} Rejects: with an error response.
|
||||
*/
|
||||
public kick(roomId: string, userId: string, reason?: string, callback?: Callback): Promise<{}> {
|
||||
return this.setMembershipState(roomId, userId, "leave", reason, callback);
|
||||
const path = utils.encodeUri("/rooms/$roomId/kick", {
|
||||
$roomId: roomId,
|
||||
});
|
||||
const data = {
|
||||
user_id: userId,
|
||||
reason: reason,
|
||||
};
|
||||
return this.http.authedRequest(
|
||||
callback, "POST", path, undefined, data,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -5022,7 +5035,7 @@ export class MatrixClient extends EventEmitter {
|
||||
email: string,
|
||||
clientSecret: string,
|
||||
sendAttempt: number,
|
||||
nextLink: string,
|
||||
nextLink?: string,
|
||||
): Promise<IRequestTokenResponse> {
|
||||
return this.requestTokenFromEndpoint(
|
||||
"/account/3pid/email/requestToken",
|
||||
@@ -5054,7 +5067,7 @@ export class MatrixClient extends EventEmitter {
|
||||
phoneNumber: string,
|
||||
clientSecret: string,
|
||||
sendAttempt: number,
|
||||
nextLink: string,
|
||||
nextLink?: string,
|
||||
): Promise<IRequestMsisdnTokenResponse> {
|
||||
return this.requestTokenFromEndpoint(
|
||||
"/account/3pid/msisdn/requestToken",
|
||||
@@ -6665,7 +6678,7 @@ export class MatrixClient extends EventEmitter {
|
||||
* @return {Promise} Resolves: A list of the user's current rooms
|
||||
* @return {module:http-api.MatrixError} Rejects: with an error response.
|
||||
*/
|
||||
public getJoinedRooms(): Promise<string[]> {
|
||||
public getJoinedRooms(): Promise<IJoinedRoomsResponse> {
|
||||
const path = utils.encodeUri("/joined_rooms", {});
|
||||
return this.http.authedRequest(undefined, "GET", path);
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ type SigInfo = {
|
||||
export type TrustInfo = {
|
||||
usable: boolean; // is the backup trusted, true iff there is a sig that is valid & from a trusted device
|
||||
sigs: SigInfo[];
|
||||
// eslint-disable-next-line camelcase
|
||||
trusted_locally?: boolean;
|
||||
};
|
||||
|
||||
export interface IKeyBackupCheck {
|
||||
|
||||
+98
-12
@@ -15,8 +15,9 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
import { MatrixClient } from "../client";
|
||||
import { IEncryptedFile, UNSTABLE_MSC3089_BRANCH } from "../@types/event";
|
||||
import { MatrixEvent } from "./event";
|
||||
import { IEncryptedFile, RelationType, UNSTABLE_MSC3089_BRANCH } from "../@types/event";
|
||||
import { IContent, MatrixEvent } from "./event";
|
||||
import { MSC3089TreeSpace } from "./MSC3089TreeSpace";
|
||||
|
||||
/**
|
||||
* Represents a [MSC3089](https://github.com/matrix-org/matrix-doc/pull/3089) branch - a reference
|
||||
@@ -24,7 +25,11 @@ import { MatrixEvent } from "./event";
|
||||
* without notice.
|
||||
*/
|
||||
export class MSC3089Branch {
|
||||
public constructor(private client: MatrixClient, public readonly indexEvent: MatrixEvent) {
|
||||
public constructor(
|
||||
private client: MatrixClient,
|
||||
public readonly indexEvent: MatrixEvent,
|
||||
public readonly directory: MSC3089TreeSpace,
|
||||
) {
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
@@ -42,19 +47,27 @@ export class MSC3089Branch {
|
||||
return this.indexEvent.getContent()["active"] === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Version for the file, one-indexed.
|
||||
*/
|
||||
public get version(): number {
|
||||
return this.indexEvent.getContent()["version"] ?? 1;
|
||||
}
|
||||
|
||||
private get roomId(): string {
|
||||
return this.indexEvent.getRoomId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the file from the tree.
|
||||
* Deletes the file from the tree, including all prior edits/versions.
|
||||
* @returns {Promise<void>} Resolves when complete.
|
||||
*/
|
||||
public async delete(): Promise<void> {
|
||||
await this.client.sendStateEvent(this.roomId, UNSTABLE_MSC3089_BRANCH.name, {}, this.id);
|
||||
await this.client.redactEvent(this.roomId, this.id);
|
||||
|
||||
// TODO: Delete edit history as well
|
||||
const nextVersion = (await this.getVersionHistory())[1]; // [0] will be us
|
||||
if (nextVersion) await nextVersion.delete(); // implicit recursion
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,7 +117,7 @@ export class MSC3089Branch {
|
||||
public async getFileInfo(): Promise<{ info: IEncryptedFile, httpUrl: string }> {
|
||||
const event = await this.getFileEvent();
|
||||
|
||||
const file = event.getContent()['file'];
|
||||
const file = event.getOriginalContent()['file'];
|
||||
const httpUrl = this.client.mxcUrlToHttp(file['url']);
|
||||
|
||||
return { info: file, httpUrl: httpUrl };
|
||||
@@ -118,15 +131,88 @@ export class MSC3089Branch {
|
||||
const room = this.client.getRoom(this.roomId);
|
||||
if (!room) throw new Error("Unknown room");
|
||||
|
||||
const timeline = await this.client.getEventTimeline(room.getUnfilteredTimelineSet(), this.id);
|
||||
if (!timeline) throw new Error("Failed to get timeline for room event");
|
||||
|
||||
const event = timeline.getEvents().find(e => e.getId() === this.id);
|
||||
const event = room.getUnfilteredTimelineSet().findEventById(this.id);
|
||||
if (!event) throw new Error("Failed to find event");
|
||||
|
||||
// Sometimes the event context doesn't decrypt for us, so do that.
|
||||
await this.client.decryptEventIfNeeded(event, { emit: false, isRetry: false });
|
||||
// Sometimes the event isn't decrypted for us, so do that. We specifically set `emit: true`
|
||||
// to ensure that the relations system in the sdk will function.
|
||||
await this.client.decryptEventIfNeeded(event, { emit: true, isRetry: true });
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new version of this file.
|
||||
* @param {string} name The name of the file.
|
||||
* @param {ArrayBuffer} encryptedContents The encrypted contents.
|
||||
* @param {Partial<IEncryptedFile>} info The encrypted file information.
|
||||
* @param {IContent} additionalContent Optional event content fields to include in the message.
|
||||
* @returns {Promise<void>} Resolves when uploaded.
|
||||
*/
|
||||
public async createNewVersion(
|
||||
name: string,
|
||||
encryptedContents: ArrayBuffer,
|
||||
info: Partial<IEncryptedFile>,
|
||||
additionalContent?: IContent,
|
||||
): Promise<void> {
|
||||
const fileEventResponse = await this.directory.createFile(name, encryptedContents, info, {
|
||||
...(additionalContent ?? {}),
|
||||
"m.new_content": true,
|
||||
"m.relates_to": {
|
||||
"rel_type": RelationType.Replace,
|
||||
"event_id": this.id,
|
||||
},
|
||||
});
|
||||
|
||||
// Update the version of the new event
|
||||
await this.client.sendStateEvent(this.roomId, UNSTABLE_MSC3089_BRANCH.name, {
|
||||
active: true,
|
||||
name: name,
|
||||
version: this.version + 1,
|
||||
}, fileEventResponse['event_id']);
|
||||
|
||||
// Deprecate ourselves
|
||||
await this.client.sendStateEvent(this.roomId, UNSTABLE_MSC3089_BRANCH.name, {
|
||||
...(this.indexEvent.getContent()),
|
||||
active: false,
|
||||
}, this.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the file's version history, starting at this file.
|
||||
* @returns {Promise<MSC3089Branch[]>} Resolves to the file's version history, with the
|
||||
* first element being the current version and the last element being the first version.
|
||||
*/
|
||||
public async getVersionHistory(): Promise<MSC3089Branch[]> {
|
||||
const fileHistory: MSC3089Branch[] = [];
|
||||
fileHistory.push(this); // start with ourselves
|
||||
|
||||
const room = this.client.getRoom(this.roomId);
|
||||
if (!room) throw new Error("Invalid or unknown room");
|
||||
|
||||
// Clone the timeline to reverse it, getting most-recent-first ordering, hopefully
|
||||
// shortening the awful loop below. Without the clone, we can unintentionally mutate
|
||||
// the timeline.
|
||||
const timelineEvents = [...room.getLiveTimeline().getEvents()].reverse();
|
||||
|
||||
// XXX: This is a very inefficient search, but it's the best we can do with the
|
||||
// relations structure we have in the SDK. As of writing, it is not worth the
|
||||
// investment in improving the structure.
|
||||
let childEvent: MatrixEvent;
|
||||
let parentEvent = await this.getFileEvent();
|
||||
do {
|
||||
childEvent = timelineEvents.find(e => e.replacingEventId() === parentEvent.getId());
|
||||
if (childEvent) {
|
||||
const branch = this.directory.getFile(childEvent.getId());
|
||||
if (branch) {
|
||||
fileHistory.push(branch);
|
||||
parentEvent = childEvent;
|
||||
} else {
|
||||
break; // prevent infinite loop
|
||||
}
|
||||
}
|
||||
} while (childEvent);
|
||||
|
||||
return fileHistory;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import {
|
||||
import { MSC3089Branch } from "./MSC3089Branch";
|
||||
import promiseRetry from "p-retry";
|
||||
import { isRoomSharedHistory } from "../crypto/algorithms/megolm";
|
||||
import { ISendEventResponse } from "../@types/requests";
|
||||
|
||||
/**
|
||||
* The recommended defaults for a tree space's power levels. Note that this
|
||||
@@ -452,26 +453,38 @@ export class MSC3089TreeSpace {
|
||||
* @param {ArrayBuffer} encryptedContents The encrypted contents.
|
||||
* @param {Partial<IEncryptedFile>} info The encrypted file information.
|
||||
* @param {IContent} additionalContent Optional event content fields to include in the message.
|
||||
* @returns {Promise<void>} Resolves when uploaded.
|
||||
* @returns {Promise<ISendEventResponse>} Resolves to the file event's sent response.
|
||||
*/
|
||||
public async createFile(
|
||||
name: string,
|
||||
encryptedContents: ArrayBuffer,
|
||||
info: Partial<IEncryptedFile>,
|
||||
additionalContent?: IContent,
|
||||
): Promise<void> {
|
||||
): Promise<ISendEventResponse> {
|
||||
const mxc = await this.client.uploadContent(new Blob([encryptedContents]), {
|
||||
includeFilename: false,
|
||||
onlyContentUri: true,
|
||||
});
|
||||
info.url = mxc;
|
||||
|
||||
const res = await this.client.sendMessage(this.roomId, {
|
||||
...(additionalContent ?? {}),
|
||||
const fileContent = {
|
||||
msgtype: MsgType.File,
|
||||
body: name,
|
||||
url: mxc,
|
||||
file: info,
|
||||
};
|
||||
|
||||
additionalContent = additionalContent ?? {};
|
||||
if (additionalContent["m.new_content"]) {
|
||||
// We do the right thing according to the spec, but due to how relations are
|
||||
// handled we also end up duplicating this information to the regular `content`
|
||||
// as well.
|
||||
additionalContent["m.new_content"] = fileContent;
|
||||
}
|
||||
|
||||
const res = await this.client.sendMessage(this.roomId, {
|
||||
...additionalContent,
|
||||
...fileContent,
|
||||
[UNSTABLE_MSC3089_LEAF.name]: {},
|
||||
});
|
||||
|
||||
@@ -479,6 +492,8 @@ export class MSC3089TreeSpace {
|
||||
active: true,
|
||||
name: name,
|
||||
}, res['event_id']);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -488,7 +503,7 @@ export class MSC3089TreeSpace {
|
||||
*/
|
||||
public getFile(fileEventId: string): MSC3089Branch {
|
||||
const branch = this.room.currentState.getStateEvents(UNSTABLE_MSC3089_BRANCH.name, fileEventId);
|
||||
return branch ? new MSC3089Branch(this.client, branch) : null;
|
||||
return branch ? new MSC3089Branch(this.client, branch, this) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -496,7 +511,15 @@ export class MSC3089TreeSpace {
|
||||
* @returns {MSC3089Branch[]} The known files. May be empty, but not null.
|
||||
*/
|
||||
public listFiles(): MSC3089Branch[] {
|
||||
return this.listAllFiles().filter(b => b.isActive);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an array of all known files for the tree, including inactive/invalid ones.
|
||||
* @returns {MSC3089Branch[]} The known files. May be empty, but not null.
|
||||
*/
|
||||
public listAllFiles(): MSC3089Branch[] {
|
||||
const branches = this.room.currentState.getStateEvents(UNSTABLE_MSC3089_BRANCH.name) ?? [];
|
||||
return branches.map(e => new MSC3089Branch(this.client, e)).filter(b => b.isActive);
|
||||
return branches.map(e => new MSC3089Branch(this.client, e, this));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import { Relations } from './relations';
|
||||
import { Room } from "./room";
|
||||
import { Filter } from "../filter";
|
||||
import { EventType, RelationType } from "../@types/event";
|
||||
import { RoomState } from "./room-state";
|
||||
|
||||
// var DEBUG = false;
|
||||
const DEBUG = true;
|
||||
@@ -45,6 +46,11 @@ interface IOpts {
|
||||
unstableClientRelationAggregation?: boolean;
|
||||
}
|
||||
|
||||
export enum DuplicateStrategy {
|
||||
Ignore = "ignore",
|
||||
Replace = "replace",
|
||||
}
|
||||
|
||||
export class EventTimelineSet extends EventEmitter {
|
||||
private readonly timelineSupport: boolean;
|
||||
private unstableClientRelationAggregation: boolean;
|
||||
@@ -509,8 +515,14 @@ export class EventTimelineSet extends EventEmitter {
|
||||
* @param {MatrixEvent} event Event to be added
|
||||
* @param {string?} duplicateStrategy 'ignore' or 'replace'
|
||||
* @param {boolean} fromCache whether the sync response came from cache
|
||||
* @param roomState the state events to reconcile metadata from
|
||||
*/
|
||||
public addLiveEvent(event: MatrixEvent, duplicateStrategy?: "ignore" | "replace", fromCache = false): void {
|
||||
public addLiveEvent(
|
||||
event: MatrixEvent,
|
||||
duplicateStrategy: DuplicateStrategy = DuplicateStrategy.Ignore,
|
||||
fromCache = false,
|
||||
roomState?: RoomState,
|
||||
): void {
|
||||
if (this.filter) {
|
||||
const events = this.filter.filterRoomTimeline([event]);
|
||||
if (!events.length) {
|
||||
@@ -520,16 +532,19 @@ export class EventTimelineSet extends EventEmitter {
|
||||
|
||||
const timeline = this._eventIdToTimeline[event.getId()];
|
||||
if (timeline) {
|
||||
if (duplicateStrategy === "replace") {
|
||||
if (duplicateStrategy === DuplicateStrategy.Replace) {
|
||||
debuglog("EventTimelineSet.addLiveEvent: replacing duplicate event " +
|
||||
event.getId());
|
||||
const tlEvents = timeline.getEvents();
|
||||
for (let j = 0; j < tlEvents.length; j++) {
|
||||
if (tlEvents[j].getId() === event.getId()) {
|
||||
// still need to set the right metadata on this event
|
||||
if (!roomState) {
|
||||
roomState = timeline.getState(EventTimeline.FORWARDS);
|
||||
}
|
||||
EventTimeline.setEventMetadata(
|
||||
event,
|
||||
timeline.getState(EventTimeline.FORWARDS),
|
||||
roomState,
|
||||
false,
|
||||
);
|
||||
tlEvents[j] = event;
|
||||
@@ -545,7 +560,7 @@ export class EventTimelineSet extends EventEmitter {
|
||||
return;
|
||||
}
|
||||
|
||||
this.addEventToTimeline(event, this.liveTimeline, false, fromCache);
|
||||
this.addEventToTimeline(event, this.liveTimeline, false, fromCache, roomState);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -566,9 +581,10 @@ export class EventTimelineSet extends EventEmitter {
|
||||
timeline: EventTimeline,
|
||||
toStartOfTimeline: boolean,
|
||||
fromCache = false,
|
||||
roomState?: RoomState,
|
||||
) {
|
||||
const eventId = event.getId();
|
||||
timeline.addEvent(event, toStartOfTimeline);
|
||||
timeline.addEvent(event, toStartOfTimeline, roomState);
|
||||
this._eventIdToTimeline[eventId] = timeline;
|
||||
|
||||
this.setRelationsTarget(event);
|
||||
|
||||
@@ -347,8 +347,11 @@ export class EventTimeline {
|
||||
* @param {MatrixEvent} event new event
|
||||
* @param {boolean} atStart true to insert new event at the start
|
||||
*/
|
||||
public addEvent(event: MatrixEvent, atStart: boolean): void {
|
||||
const stateContext = atStart ? this.startState : this.endState;
|
||||
public addEvent(event: MatrixEvent, atStart: boolean, stateContext?: RoomState): void {
|
||||
if (!stateContext) {
|
||||
stateContext = atStart ? this.startState : this.endState;
|
||||
}
|
||||
|
||||
const timelineSet = this.getTimelineSet();
|
||||
|
||||
if (timelineSet.room) {
|
||||
|
||||
+35
-7
@@ -285,8 +285,28 @@ export class MatrixEvent extends EventEmitter {
|
||||
* @returns {IEvent} The event in wire format.
|
||||
*/
|
||||
public getEffectiveEvent(): IEvent {
|
||||
// clearEvent doesn't have all the fields, so we'll copy what we can from this.event
|
||||
return Object.assign({}, this.event, this.clearEvent) as IEvent;
|
||||
const content = Object.assign({}, this.getContent()); // clone for mutation
|
||||
|
||||
if (this.getWireType() === EventType.RoomMessageEncrypted) {
|
||||
// Encrypted events sometimes aren't symmetrical on the `content` so we'll copy
|
||||
// that over too, but only for missing properties. We don't copy over mismatches
|
||||
// between the plain and decrypted copies of `content` because we assume that the
|
||||
// app is relying on the decrypted version, so we want to expose that as a source
|
||||
// of truth here too.
|
||||
for (const [key, value] of Object.entries(this.getWireContent())) {
|
||||
// Skip fields from the encrypted event schema though - we don't want to leak
|
||||
// these.
|
||||
if (["algorithm", "ciphertext", "device_id", "sender_key", "session_id"].includes(key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (content[key] === undefined) content[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
// clearEvent doesn't have all the fields, so we'll copy what we can from this.event.
|
||||
// We also copy over our "fixed" content key.
|
||||
return Object.assign({}, this.event, this.clearEvent, { content }) as IEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -412,11 +432,19 @@ export class MatrixEvent extends EventEmitter {
|
||||
* or in the main room timeline
|
||||
*/
|
||||
public get replyInThread(): boolean {
|
||||
const replyTo = this.getWireContent()
|
||||
?.["m.relates_to"]
|
||||
?.["m.in_reply_to"];
|
||||
return (this.replyEventId
|
||||
&& replyTo[UNSTABLE_ELEMENT_REPLY_IN_THREAD.name])
|
||||
/**
|
||||
* UNSTABLE_ELEMENT_REPLY_IN_THREAD can live either
|
||||
* at the m.relates_to and m.in_reply_to level
|
||||
* This will likely change once we settle on a
|
||||
* way to achieve threads
|
||||
* TODO: Clean this up once we have a clear way forward
|
||||
*/
|
||||
|
||||
const relatesTo = this.getWireContent()?.["m.relates_to"];
|
||||
const replyTo = relatesTo?.["m.in_reply_to"];
|
||||
|
||||
return relatesTo?.[UNSTABLE_ELEMENT_REPLY_IN_THREAD.name]
|
||||
|| (this.replyEventId && replyTo[UNSTABLE_ELEMENT_REPLY_IN_THREAD.name])
|
||||
|| this.thread instanceof Thread;
|
||||
}
|
||||
|
||||
|
||||
@@ -578,7 +578,7 @@ export class RoomState extends EventEmitter {
|
||||
* @param {number} powerLevel The power level of the member
|
||||
* @return {boolean} true if the given power level is sufficient
|
||||
*/
|
||||
private hasSufficientPowerLevelFor(action: string, powerLevel: number): boolean {
|
||||
public hasSufficientPowerLevelFor(action: string, powerLevel: number): boolean {
|
||||
const powerLevelsEvent = this.getStateEvents(EventType.RoomPowerLevels, "");
|
||||
|
||||
let powerLevels = {};
|
||||
|
||||
+4
-11
@@ -20,7 +20,7 @@ limitations under the License.
|
||||
|
||||
import { EventEmitter } from "events";
|
||||
|
||||
import { EventTimelineSet } from "./event-timeline-set";
|
||||
import { EventTimelineSet, DuplicateStrategy } from "./event-timeline-set";
|
||||
import { EventTimeline } from "./event-timeline";
|
||||
import { getHttpUriForMxc } from "../content-repo";
|
||||
import * as utils from "../utils";
|
||||
@@ -1298,13 +1298,6 @@ export class Room extends EventEmitter {
|
||||
* @experimental
|
||||
*/
|
||||
public addThreadedEvent(event: MatrixEvent): void {
|
||||
if (event.getUnsigned().transaction_id) {
|
||||
const existingEvent = this.txnToEvent[event.getUnsigned().transaction_id];
|
||||
if (existingEvent) {
|
||||
// remote echo of an event we sent earlier
|
||||
this.handleRemoteEcho(event, existingEvent);
|
||||
}
|
||||
}
|
||||
let thread = this.findEventById(event.parentEventId)?.getThread();
|
||||
if (thread) {
|
||||
thread.addEvent(event);
|
||||
@@ -1327,12 +1320,12 @@ export class Room extends EventEmitter {
|
||||
* @fires module:client~MatrixClient#event:"Room.timeline"
|
||||
* @private
|
||||
*/
|
||||
private addLiveEvent(event: MatrixEvent, duplicateStrategy?: "ignore" | "replace", fromCache = false): void {
|
||||
private addLiveEvent(event: MatrixEvent, duplicateStrategy?: DuplicateStrategy, fromCache = false): void {
|
||||
if (event.isRedaction()) {
|
||||
const redactId = event.event.redacts;
|
||||
|
||||
// if we know about this event, redact its contents now.
|
||||
const redactedEvent = this.getUnfilteredTimelineSet().findEventById(redactId);
|
||||
const redactedEvent = this.findEventById(redactId);
|
||||
if (redactedEvent) {
|
||||
redactedEvent.makeRedacted(event);
|
||||
|
||||
@@ -1713,7 +1706,7 @@ export class Room extends EventEmitter {
|
||||
* @param {boolean} fromCache whether the sync response came from cache
|
||||
* @throws If <code>duplicateStrategy</code> is not falsey, 'replace' or 'ignore'.
|
||||
*/
|
||||
public addLiveEvents(events: MatrixEvent[], duplicateStrategy?: "replace" | "ignore", fromCache = false): void {
|
||||
public addLiveEvents(events: MatrixEvent[], duplicateStrategy?: DuplicateStrategy, fromCache = false): void {
|
||||
let i;
|
||||
if (duplicateStrategy && ["replace", "ignore"].indexOf(duplicateStrategy) === -1) {
|
||||
throw new Error("duplicateStrategy MUST be either 'replace' or 'ignore'");
|
||||
|
||||
+28
-3
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
import { EventEmitter } from "events";
|
||||
import { MatrixClient } from "../matrix";
|
||||
import { MatrixEvent } from "./event";
|
||||
import { EventTimeline } from "./event-timeline";
|
||||
import { EventTimelineSet } from './event-timeline-set';
|
||||
import { Room } from './room';
|
||||
|
||||
@@ -25,6 +26,11 @@ export enum ThreadEvent {
|
||||
Update = "Thread.update"
|
||||
}
|
||||
|
||||
interface ISerialisedThread {
|
||||
id: string;
|
||||
tails: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* @experimental
|
||||
*/
|
||||
@@ -58,7 +64,7 @@ export class Thread extends EventEmitter {
|
||||
* Will fire "Thread.update"
|
||||
* @param event The event to add
|
||||
*/
|
||||
public async addEvent(event: MatrixEvent): Promise<void> {
|
||||
public async addEvent(event: MatrixEvent, toStartOfTimeline = false): Promise<void> {
|
||||
if (this.timelineSet.findEventById(event.getId()) || event.status !== null) {
|
||||
return;
|
||||
}
|
||||
@@ -72,8 +78,20 @@ export class Thread extends EventEmitter {
|
||||
this.root = event.getId();
|
||||
}
|
||||
|
||||
// all the relevant membership info to hydrate events with a sender
|
||||
// is held in the main room timeline
|
||||
// We want to fetch the room state from there and pass it down to this thread
|
||||
// timeline set to let it reconcile an event with its relevant RoomMember
|
||||
const roomState = this.room.getLiveTimeline().getState(EventTimeline.FORWARDS);
|
||||
|
||||
event.setThread(this);
|
||||
this.timelineSet.addLiveEvent(event);
|
||||
this.timelineSet.addEventToTimeline(
|
||||
event,
|
||||
this.timelineSet.getLiveTimeline(),
|
||||
toStartOfTimeline,
|
||||
false,
|
||||
roomState,
|
||||
);
|
||||
|
||||
if (this.ready) {
|
||||
this.client.decryptEventIfNeeded(event, {});
|
||||
@@ -96,7 +114,7 @@ export class Thread extends EventEmitter {
|
||||
);
|
||||
}
|
||||
|
||||
this.addEvent(mxEvent);
|
||||
this.addEvent(mxEvent, true);
|
||||
if (mxEvent.replyEventId) {
|
||||
await this.fetchReplyChain();
|
||||
} else {
|
||||
@@ -199,6 +217,13 @@ export class Thread extends EventEmitter {
|
||||
return this.timelineSet.findEventById(eventId) instanceof MatrixEvent;
|
||||
}
|
||||
|
||||
public toJson(): ISerialisedThread {
|
||||
return {
|
||||
id: this.id,
|
||||
tails: Array.from(this.tail),
|
||||
};
|
||||
}
|
||||
|
||||
public on(event: ThreadEvent, listener: (...args: any[]) => void): this {
|
||||
super.on(event, listener);
|
||||
return this;
|
||||
|
||||
@@ -47,7 +47,7 @@ export class RoomHierarchy {
|
||||
* @constructor
|
||||
*/
|
||||
constructor(
|
||||
private readonly root: Room,
|
||||
public readonly root: Room,
|
||||
private readonly pageSize?: number,
|
||||
private readonly maxDepth?: number,
|
||||
private readonly suggestedOnly = false,
|
||||
@@ -61,6 +61,10 @@ export class RoomHierarchy {
|
||||
return !!this.serverSupportError || !!this.nextBatch || !this._rooms;
|
||||
}
|
||||
|
||||
public get loading(): boolean {
|
||||
return !!this.loadRequest;
|
||||
}
|
||||
|
||||
public get rooms(): IHierarchyRoom[] {
|
||||
return this._rooms;
|
||||
}
|
||||
|
||||
+1
-1
@@ -321,7 +321,7 @@ export class SyncApi {
|
||||
// - It's related to a reply in thread event
|
||||
let shouldLiveInThreadTimeline = event.replyInThread;
|
||||
if (!shouldLiveInThreadTimeline) {
|
||||
const parentEventId = event.getWireContent()["m.relates_to"]?.event_id;
|
||||
const parentEventId = event.parentEventId;
|
||||
const parentEvent = room?.findEventById(parentEventId) || events.find((mxEv: MatrixEvent) => {
|
||||
return mxEv.getId() === parentEventId;
|
||||
});
|
||||
|
||||
+105
-12
@@ -391,6 +391,19 @@ export class MatrixCall extends EventEmitter {
|
||||
});
|
||||
}
|
||||
|
||||
public get hasLocalUserMediaAudioTrack(): boolean {
|
||||
return this.localUsermediaStream?.getAudioTracks().length > 0;
|
||||
}
|
||||
|
||||
public get hasRemoteUserMediaAudioTrack(): boolean {
|
||||
return this.getRemoteFeeds().some((feed) => {
|
||||
return (
|
||||
feed.purpose === SDPStreamMetadataPurpose.Usermedia &&
|
||||
feed.stream.getAudioTracks().length > 0
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
public get localUsermediaFeed(): CallFeed {
|
||||
return this.getLocalFeeds().find((feed) => feed.purpose === SDPStreamMetadataPurpose.Usermedia);
|
||||
}
|
||||
@@ -683,13 +696,34 @@ export class MatrixCall extends EventEmitter {
|
||||
this.setState(CallState.Ended);
|
||||
}
|
||||
|
||||
private shouldAnswerWithMediaType(
|
||||
wantedValue: boolean | undefined, valueOfTheOtherSide: boolean | undefined, type: "audio" | "video",
|
||||
): boolean {
|
||||
if (wantedValue && !valueOfTheOtherSide) {
|
||||
// TODO: Figure out how to do this
|
||||
logger.warn(`Unable to answer with ${type} because the other side isn't sending it either.`);
|
||||
return false;
|
||||
} else if (
|
||||
!utils.isNullOrUndefined(wantedValue) &&
|
||||
wantedValue !== valueOfTheOtherSide &&
|
||||
!this.opponentSupportsSDPStreamMetadata()
|
||||
) {
|
||||
logger.warn(
|
||||
`Unable to answer with ${type}=${wantedValue} because the other side doesn't support it. ` +
|
||||
`Answering with ${type}=${valueOfTheOtherSide}.`,
|
||||
);
|
||||
return valueOfTheOtherSide;
|
||||
}
|
||||
return wantedValue ?? valueOfTheOtherSide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Answer a call.
|
||||
*/
|
||||
public async answer(): Promise<void> {
|
||||
if (this.inviteOrAnswerSent) {
|
||||
return;
|
||||
}
|
||||
public async answer(audio?: boolean, video?: boolean): Promise<void> {
|
||||
if (this.inviteOrAnswerSent) return;
|
||||
// TODO: Figure out how to do this
|
||||
if (audio === false && video === false) throw new Error("You CANNOT answer a call without media");
|
||||
|
||||
logger.debug(`Answering call ${this.callId}`);
|
||||
|
||||
@@ -699,8 +733,8 @@ export class MatrixCall extends EventEmitter {
|
||||
|
||||
try {
|
||||
const mediaStream = await this.client.getMediaHandler().getUserMediaStream(
|
||||
true,
|
||||
this.hasRemoteUserMediaVideoTrack,
|
||||
this.shouldAnswerWithMediaType(audio, this.hasRemoteUserMediaAudioTrack, "audio"),
|
||||
this.shouldAnswerWithMediaType(video, this.hasRemoteUserMediaVideoTrack, "video"),
|
||||
);
|
||||
this.waitForLocalAVStream = false;
|
||||
this.gotUserMediaForAnswer(mediaStream);
|
||||
@@ -774,6 +808,50 @@ export class MatrixCall extends EventEmitter {
|
||||
this.sendVoipEvent(EventType.CallReject, {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an audio and/or video track - upgrades the call
|
||||
* @param {boolean} audio should add an audio track
|
||||
* @param {boolean} video should add an video track
|
||||
*/
|
||||
private async upgradeCall(
|
||||
audio: boolean, video: boolean,
|
||||
): Promise<void> {
|
||||
// We don't do call downgrades
|
||||
if (!audio && !video) return;
|
||||
if (!this.opponentSupportsSDPStreamMetadata()) return;
|
||||
|
||||
try {
|
||||
const upgradeAudio = audio && !this.hasLocalUserMediaAudioTrack;
|
||||
const upgradeVideo = video && !this.hasLocalUserMediaVideoTrack;
|
||||
logger.debug(`Upgrading call: audio?=${upgradeAudio} video?=${upgradeVideo}`);
|
||||
|
||||
const stream = await this.client.getMediaHandler().getUserMediaStream(upgradeAudio, upgradeVideo);
|
||||
if (upgradeAudio && upgradeVideo) {
|
||||
if (this.hasLocalUserMediaAudioTrack) return;
|
||||
if (this.hasLocalUserMediaVideoTrack) return;
|
||||
|
||||
this.pushLocalFeed(stream, SDPStreamMetadataPurpose.Usermedia);
|
||||
} else if (upgradeAudio) {
|
||||
if (this.hasLocalUserMediaAudioTrack) return;
|
||||
|
||||
const audioTrack = stream.getAudioTracks()[0];
|
||||
this.localUsermediaStream.addTrack(audioTrack);
|
||||
this.peerConn.addTrack(audioTrack, this.localUsermediaStream);
|
||||
} else if (upgradeVideo) {
|
||||
if (this.hasLocalUserMediaVideoTrack) return;
|
||||
|
||||
const videoTrack = stream.getVideoTracks()[0];
|
||||
this.localUsermediaStream.addTrack(videoTrack);
|
||||
this.peerConn.addTrack(videoTrack, this.localUsermediaStream);
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error("Failed to upgrade the call", error);
|
||||
this.emit(CallEvent.Error,
|
||||
new CallError(CallErrorCode.NoUserMedia, "Failed to get camera access: ", error),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this.remoteSDPStreamMetadata is defined, otherwise returns false
|
||||
* @returns {boolean} can screenshare
|
||||
@@ -888,10 +966,16 @@ export class MatrixCall extends EventEmitter {
|
||||
/**
|
||||
* Set whether our outbound video should be muted or not.
|
||||
* @param {boolean} muted True to mute the outbound video.
|
||||
* @returns the new mute state
|
||||
*/
|
||||
public setLocalVideoMuted(muted: boolean): void {
|
||||
public async setLocalVideoMuted(muted: boolean): Promise<boolean> {
|
||||
if (!this.hasLocalUserMediaVideoTrack && !muted) {
|
||||
await this.upgradeCall(false, true);
|
||||
return this.isLocalVideoMuted();
|
||||
}
|
||||
this.localUsermediaFeed?.setVideoMuted(muted);
|
||||
this.updateMuteStatus();
|
||||
return this.isLocalVideoMuted();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -910,10 +994,16 @@ export class MatrixCall extends EventEmitter {
|
||||
/**
|
||||
* Set whether the microphone should be muted or not.
|
||||
* @param {boolean} muted True to mute the mic.
|
||||
* @returns the new mute state
|
||||
*/
|
||||
public setMicrophoneMuted(muted: boolean): void {
|
||||
public async setMicrophoneMuted(muted: boolean): Promise<boolean> {
|
||||
if (!this.hasLocalUserMediaAudioTrack && !muted) {
|
||||
await this.upgradeCall(true, false);
|
||||
return this.isMicrophoneMuted();
|
||||
}
|
||||
this.localUsermediaFeed?.setAudioMuted(muted);
|
||||
this.updateMuteStatus();
|
||||
return this.isMicrophoneMuted();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1482,10 +1572,13 @@ export class MatrixCall extends EventEmitter {
|
||||
// chrome doesn't implement any of the 'onstarted' events yet
|
||||
if (this.peerConn.iceConnectionState == 'connected') {
|
||||
this.setState(CallState.Connected);
|
||||
this.callLengthInterval = setInterval(() => {
|
||||
this.callLength++;
|
||||
this.emit(CallEvent.LengthChanged, this.callLength);
|
||||
}, 1000);
|
||||
|
||||
if (!this.callLengthInterval) {
|
||||
this.callLengthInterval = setInterval(() => {
|
||||
this.callLength++;
|
||||
this.emit(CallEvent.LengthChanged, this.callLength);
|
||||
}, 1000);
|
||||
}
|
||||
} else if (this.peerConn.iceConnectionState == 'failed') {
|
||||
this.hangup(CallErrorCode.IceFailed, false);
|
||||
}
|
||||
|
||||
+25
-8
@@ -48,6 +48,7 @@ export class CallFeed extends EventEmitter {
|
||||
private videoMuted: boolean,
|
||||
) {
|
||||
super();
|
||||
this.updateStream(null, stream);
|
||||
|
||||
if (this.hasAudioTrack) {
|
||||
this.initVolumeMeasuring();
|
||||
@@ -58,6 +59,25 @@ export class CallFeed extends EventEmitter {
|
||||
return this.stream.getAudioTracks().length > 0;
|
||||
}
|
||||
|
||||
private updateStream(oldStream: MediaStream, newStream: MediaStream): void {
|
||||
if (oldStream) {
|
||||
oldStream.removeEventListener("addtrack", this.onAddTrack);
|
||||
this.measureVolumeActivity(false);
|
||||
}
|
||||
if (newStream) {
|
||||
this.stream = newStream;
|
||||
newStream.addEventListener("addtrack", this.onAddTrack);
|
||||
|
||||
if (this.hasAudioTrack) {
|
||||
this.initVolumeMeasuring();
|
||||
} else {
|
||||
this.measureVolumeActivity(false);
|
||||
}
|
||||
}
|
||||
|
||||
this.emit(CallFeedEvent.NewStream, this.stream);
|
||||
}
|
||||
|
||||
private initVolumeMeasuring(): void {
|
||||
const AudioContext = window.AudioContext || window.webkitAudioContext;
|
||||
if (!this.hasAudioTrack || !AudioContext) return;
|
||||
@@ -74,6 +94,10 @@ export class CallFeed extends EventEmitter {
|
||||
this.frequencyBinCount = new Float32Array(this.analyser.frequencyBinCount);
|
||||
}
|
||||
|
||||
private onAddTrack = (): void => {
|
||||
this.emit(CallFeedEvent.NewStream, this.stream);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns callRoom member
|
||||
* @returns member of the callRoom
|
||||
@@ -116,14 +140,7 @@ export class CallFeed extends EventEmitter {
|
||||
* @param newStream new stream with which to replace the current one
|
||||
*/
|
||||
public setNewStream(newStream: MediaStream): void {
|
||||
this.stream = newStream;
|
||||
this.emit(CallFeedEvent.NewStream, this.stream);
|
||||
|
||||
if (this.hasAudioTrack) {
|
||||
this.initVolumeMeasuring();
|
||||
} else {
|
||||
this.measureVolumeActivity(false);
|
||||
}
|
||||
this.updateStream(this.stream, newStream);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user