Skip to content

Commit

Permalink
Don't use event.sender in CallMembership (#3793)
Browse files Browse the repository at this point in the history
* Don't use event.sender in CallMembership

I fell into another js-sdk trap: this is "only guaranteed to be set
for events that appear in a timeline" and not state events. It does
not say why. We only ever used it to get the sender user ID anyway,
so just use getSender().

* Fix test
  • Loading branch information
dbkr authored Oct 10, 2023
1 parent 2f79e6c commit c8f8fb5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
4 changes: 1 addition & 3 deletions spec/unit/matrixrtc/CallMembership.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ const membershipTemplate: CallMembershipData = {
function makeMockEvent(originTs = 0): MatrixEvent {
return {
getTs: jest.fn().mockReturnValue(originTs),
sender: {
userId: "@alice:example.org",
},
getSender: jest.fn().mockReturnValue("@alice:example.org"),
} as unknown as MatrixEvent;
}

Expand Down
8 changes: 4 additions & 4 deletions src/matrixrtc/CallMembership.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { MatrixEvent, RoomMember } from "../matrix";
import { MatrixEvent } from "../matrix";
import { deepCompare } from "../utils";
import { Focus } from "./focus";

Expand Down Expand Up @@ -42,11 +42,11 @@ export class CallMembership {
if (typeof data.device_id !== "string") throw new Error("Malformed membership event: device_id must be string");
if (typeof data.call_id !== "string") throw new Error("Malformed membership event: call_id must be string");
if (typeof data.scope !== "string") throw new Error("Malformed membership event: scope must be string");
if (!parentEvent.sender) throw new Error("Invalid parent event: sender is null");
if (!parentEvent.getSender()) throw new Error("Invalid parent event: sender is null");
}

public get member(): RoomMember {
return this.parentEvent.sender!;
public get sender(): string | undefined {
return this.parentEvent.getSender();
}

public get callId(): string {
Expand Down
2 changes: 1 addition & 1 deletion src/matrixrtc/MatrixRTCSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class MatrixRTCSession extends TypedEventEmitter<MatrixRTCSessionEvent, M
callMemberships.sort((a, b) => a.createdTs() - b.createdTs());
logger.debug(
"Call memberships, in order: ",
callMemberships.map((m) => [m.createdTs(), m.member.userId]),
callMemberships.map((m) => [m.createdTs(), m.sender]),
);

return callMemberships;
Expand Down

0 comments on commit c8f8fb5

Please sign in to comment.