Fix unencrypted calls
This commit is contained in:
parent
50d97ebeb2
commit
cbc66ea308
|
@ -633,10 +633,34 @@ class Room {
|
||||||
return uploadResp;
|
return uploadResp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<String> _sendContent(
|
||||||
|
String type,
|
||||||
|
Map<String, dynamic> content, {
|
||||||
|
String txid,
|
||||||
|
}) async {
|
||||||
|
txid ??= client.generateUniqueTransactionId();
|
||||||
|
final mustEncrypt = encrypted && client.encryptionEnabled;
|
||||||
|
final sendMessageContent = mustEncrypt
|
||||||
|
? await client.encryption
|
||||||
|
.encryptGroupMessagePayload(id, content, type: type)
|
||||||
|
: content;
|
||||||
|
return await client.sendMessage(
|
||||||
|
id,
|
||||||
|
mustEncrypt ? EventTypes.Encrypted : type,
|
||||||
|
txid,
|
||||||
|
sendMessageContent,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// Sends an event to this room with this json as a content. Returns the
|
/// Sends an event to this room with this json as a content. Returns the
|
||||||
/// event ID generated from the server.
|
/// event ID generated from the server.
|
||||||
Future<String> sendEvent(Map<String, dynamic> content,
|
Future<String> sendEvent(
|
||||||
{String type, String txid, Event inReplyTo, String editEventId}) async {
|
Map<String, dynamic> content, {
|
||||||
|
String type,
|
||||||
|
String txid,
|
||||||
|
Event inReplyTo,
|
||||||
|
String editEventId,
|
||||||
|
}) async {
|
||||||
type = type ?? EventTypes.Message;
|
type = type ?? EventTypes.Message;
|
||||||
final sendType =
|
final sendType =
|
||||||
(encrypted && client.encryptionEnabled) ? EventTypes.Encrypted : type;
|
(encrypted && client.encryptionEnabled) ? EventTypes.Encrypted : type;
|
||||||
|
@ -701,15 +725,10 @@ class Room {
|
||||||
|
|
||||||
// Send the text and on success, store and display a *sent* event.
|
// Send the text and on success, store and display a *sent* event.
|
||||||
try {
|
try {
|
||||||
final sendMessageContent = encrypted && client.encryptionEnabled
|
final res = await _sendContent(
|
||||||
? await client.encryption
|
|
||||||
.encryptGroupMessagePayload(id, content, type: type)
|
|
||||||
: content;
|
|
||||||
final res = await client.sendMessage(
|
|
||||||
id,
|
|
||||||
sendType,
|
sendType,
|
||||||
messageID,
|
content,
|
||||||
sendMessageContent,
|
txid: messageID,
|
||||||
);
|
);
|
||||||
syncUpdate.rooms.join.values.first.timeline.events.first
|
syncUpdate.rooms.join.values.first.timeline.events.first
|
||||||
.unsigned[MessageSendingStatusKey] = 1;
|
.unsigned[MessageSendingStatusKey] = 1;
|
||||||
|
@ -1355,16 +1374,10 @@ class Room {
|
||||||
'offer': {'sdp': sdp, 'type': type},
|
'offer': {'sdp': sdp, 'type': type},
|
||||||
'version': version,
|
'version': version,
|
||||||
};
|
};
|
||||||
|
return await _sendContent(
|
||||||
final sendMessageContent = encrypted && client.encryptionEnabled
|
|
||||||
? await client.encryption.encryptGroupMessagePayload(id, content,
|
|
||||||
type: EventTypes.CallInvite)
|
|
||||||
: content;
|
|
||||||
return await client.sendMessage(
|
|
||||||
id,
|
|
||||||
EventTypes.CallInvite,
|
EventTypes.CallInvite,
|
||||||
txid,
|
content,
|
||||||
sendMessageContent,
|
txid: txid,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1398,16 +1411,10 @@ class Room {
|
||||||
'candidates': candidates,
|
'candidates': candidates,
|
||||||
'version': version,
|
'version': version,
|
||||||
};
|
};
|
||||||
|
return await _sendContent(
|
||||||
final sendMessageContent = encrypted && client.encryptionEnabled
|
|
||||||
? await client.encryption.encryptGroupMessagePayload(id, content,
|
|
||||||
type: EventTypes.CallCandidates)
|
|
||||||
: content;
|
|
||||||
return await client.sendMessage(
|
|
||||||
id,
|
|
||||||
EventTypes.CallCandidates,
|
EventTypes.CallCandidates,
|
||||||
txid,
|
content,
|
||||||
sendMessageContent,
|
txid: txid,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1424,16 +1431,10 @@ class Room {
|
||||||
'answer': {'sdp': sdp, 'type': type},
|
'answer': {'sdp': sdp, 'type': type},
|
||||||
'version': version,
|
'version': version,
|
||||||
};
|
};
|
||||||
|
return await _sendContent(
|
||||||
final sendMessageContent = encrypted && client.encryptionEnabled
|
|
||||||
? await client.encryption.encryptGroupMessagePayload(id, content,
|
|
||||||
type: EventTypes.CallAnswer)
|
|
||||||
: content;
|
|
||||||
return await client.sendMessage(
|
|
||||||
id,
|
|
||||||
EventTypes.CallAnswer,
|
EventTypes.CallAnswer,
|
||||||
txid,
|
content,
|
||||||
sendMessageContent,
|
txid: txid,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1448,16 +1449,10 @@ class Room {
|
||||||
'call_id': callId,
|
'call_id': callId,
|
||||||
'version': version,
|
'version': version,
|
||||||
};
|
};
|
||||||
|
return await _sendContent(
|
||||||
final sendMessageContent = encrypted && client.encryptionEnabled
|
|
||||||
? await client.encryption.encryptGroupMessagePayload(id, content,
|
|
||||||
type: EventTypes.CallHangup)
|
|
||||||
: content;
|
|
||||||
return await client.sendMessage(
|
|
||||||
id,
|
|
||||||
EventTypes.CallHangup,
|
EventTypes.CallHangup,
|
||||||
txid,
|
content,
|
||||||
sendMessageContent,
|
txid: txid,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -183,10 +183,6 @@ void main() {
|
||||||
await room.sendReadReceipt('§1234:fakeServer.notExisting');
|
await room.sendReadReceipt('§1234:fakeServer.notExisting');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('enableEncryption', () async {
|
|
||||||
await room.enableEncryption();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('requestParticipants', () async {
|
test('requestParticipants', () async {
|
||||||
final participants = await room.requestParticipants();
|
final participants = await room.requestParticipants();
|
||||||
expect(participants.length, 1);
|
expect(participants.length, 1);
|
||||||
|
@ -455,6 +451,17 @@ void main() {
|
||||||
expect(room.pushRuleState, PushRuleState.dont_notify);
|
expect(room.pushRuleState, PushRuleState.dont_notify);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Test call methods', () async {
|
||||||
|
await room.inviteToCall('1234', 1234, 'sdp', txid: '1234');
|
||||||
|
await room.answerCall('1234', 'sdp', txid: '1234');
|
||||||
|
await room.hangupCall('1234', txid: '1234');
|
||||||
|
await room.sendCallCandidates('1234', [], txid: '1234');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('enableEncryption', () async {
|
||||||
|
await room.enableEncryption();
|
||||||
|
});
|
||||||
|
|
||||||
test('Enable encryption', () async {
|
test('Enable encryption', () async {
|
||||||
room.setState(
|
room.setState(
|
||||||
Event(
|
Event(
|
||||||
|
@ -482,13 +489,6 @@ void main() {
|
||||||
await room.setPushRuleState(PushRuleState.notify);
|
await room.setPushRuleState(PushRuleState.notify);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Test call methods', () async {
|
|
||||||
await room.inviteToCall('1234', 1234, 'sdp', txid: '1234');
|
|
||||||
await room.answerCall('1234', 'sdp', txid: '1234');
|
|
||||||
await room.hangupCall('1234', txid: '1234');
|
|
||||||
await room.sendCallCandidates('1234', [], txid: '1234');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Test tag methods', () async {
|
test('Test tag methods', () async {
|
||||||
await room.addTag(TagType.Favourite, order: 0.1);
|
await room.addTag(TagType.Favourite, order: 0.1);
|
||||||
await room.removeTag(TagType.Favourite);
|
await room.removeTag(TagType.Favourite);
|
||||||
|
|
Loading…
Reference in a new issue