Fix tests
This commit is contained in:
parent
54feb4b6a9
commit
06bcf90d6e
|
@ -21,13 +21,13 @@
|
||||||
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import 'package:famedlysdk/src/responses/ErrorResponse.dart';
|
||||||
import 'package:famedlysdk/src/Client.dart';
|
import 'package:famedlysdk/src/Client.dart';
|
||||||
import 'package:famedlysdk/src/utils/MxContent.dart';
|
import 'package:famedlysdk/src/utils/MxContent.dart';
|
||||||
import 'package:famedlysdk/src/Room.dart';
|
import 'package:famedlysdk/src/Room.dart';
|
||||||
|
|
||||||
/// Represents a Matrix User which may be a participant in a Matrix Room.
|
/// Represents a Matrix User which may be a participant in a Matrix Room.
|
||||||
class User {
|
class User {
|
||||||
|
|
||||||
/// The full qualified Matrix ID in the format @username:server.abc.
|
/// The full qualified Matrix ID in the format @username:server.abc.
|
||||||
final String id;
|
final String id;
|
||||||
|
|
||||||
|
@ -62,7 +62,8 @@ class User {
|
||||||
@Deprecated("Use avatarUrl instead!")
|
@Deprecated("Use avatarUrl instead!")
|
||||||
MxContent get avatar_url => avatarUrl;
|
MxContent get avatar_url => avatarUrl;
|
||||||
|
|
||||||
User(this.id, {
|
User(
|
||||||
|
this.id, {
|
||||||
this.membership,
|
this.membership,
|
||||||
this.displayName,
|
this.displayName,
|
||||||
this.avatarUrl,
|
this.avatarUrl,
|
||||||
|
@ -72,8 +73,7 @@ class User {
|
||||||
|
|
||||||
/// Returns the displayname or the local part of the Matrix ID if the user
|
/// Returns the displayname or the local part of the Matrix ID if the user
|
||||||
/// has no displayname.
|
/// has no displayname.
|
||||||
String calcDisplayname() =>
|
String calcDisplayname() => displayName.isEmpty
|
||||||
displayName.isEmpty
|
|
||||||
? mxid.replaceFirst("@", "").split(":")[0]
|
? mxid.replaceFirst("@", "").split(":")[0]
|
||||||
: displayName;
|
: displayName;
|
||||||
|
|
||||||
|
@ -90,13 +90,15 @@ class User {
|
||||||
/// Checks if the client's user has the permission to kick this user.
|
/// Checks if the client's user has the permission to kick this user.
|
||||||
Future<bool> get canKick async {
|
Future<bool> get canKick async {
|
||||||
final int ownPowerLevel = await room.client.store.getPowerLevel(room.id);
|
final int ownPowerLevel = await room.client.store.getPowerLevel(room.id);
|
||||||
return ownPowerLevel > powerLevel && ownPowerLevel >= room.powerLevels["power_kick"];
|
return ownPowerLevel > powerLevel &&
|
||||||
|
ownPowerLevel >= room.powerLevels["power_kick"];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks if the client's user has the permission to ban or unban this user.
|
/// Checks if the client's user has the permission to ban or unban this user.
|
||||||
Future<bool> get canBan async {
|
Future<bool> get canBan async {
|
||||||
final int ownPowerLevel = await room.client.store.getPowerLevel(room.id);
|
final int ownPowerLevel = await room.client.store.getPowerLevel(room.id);
|
||||||
return ownPowerLevel > powerLevel && ownPowerLevel >= room.powerLevels["power_ban"];
|
return ownPowerLevel > powerLevel &&
|
||||||
|
ownPowerLevel >= room.powerLevels["power_ban"];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Call the Matrix API to kick this user from this room.
|
/// Call the Matrix API to kick this user from this room.
|
||||||
|
@ -130,7 +132,8 @@ class User {
|
||||||
if (roomID != null) return roomID;
|
if (roomID != null) return roomID;
|
||||||
|
|
||||||
// Start a new direct chat
|
// Start a new direct chat
|
||||||
Map<String,dynamic> resp = await room.client.connection.jsonRequest(type: "POST", action: "/client/r0/createRoom", data: {
|
Map<String, dynamic> resp = await room.client.connection
|
||||||
|
.jsonRequest(type: "POST", action: "/client/r0/createRoom", data: {
|
||||||
"invite": [id],
|
"invite": [id],
|
||||||
"is_direct": true,
|
"is_direct": true,
|
||||||
"preset": "trusted_private_chat"
|
"preset": "trusted_private_chat"
|
||||||
|
@ -145,5 +148,4 @@ class User {
|
||||||
|
|
||||||
return resp["room_id"];
|
return resp["room_id"];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ void main() {
|
||||||
expect(event.status, status);
|
expect(event.status, status);
|
||||||
expect(event.text, body);
|
expect(event.text, body);
|
||||||
expect(event.formattedText, formatted_body);
|
expect(event.formattedText, formatted_body);
|
||||||
expect(event.getBody(), formatted_body);
|
expect(event.getBody(), body);
|
||||||
expect(event.type, EventTypes.Text);
|
expect(event.type, EventTypes.Text);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -107,7 +107,7 @@ void main() {
|
||||||
expect(room.guestAccess, guestAccess);
|
expect(room.guestAccess, guestAccess);
|
||||||
expect(room.historyVisibility, historyVisibility);
|
expect(room.historyVisibility, historyVisibility);
|
||||||
expect(room.joinRules, joinRules);
|
expect(room.joinRules, joinRules);
|
||||||
expect(room.lastMessage, "<b>Hello</b> World");
|
expect(room.lastMessage, body);
|
||||||
expect(room.timeCreated.toTimeStamp() >= now, true);
|
expect(room.timeCreated.toTimeStamp() >= now, true);
|
||||||
room.powerLevels.forEach((String key, int value) {
|
room.powerLevels.forEach((String key, int value) {
|
||||||
expect(value, 0);
|
expect(value, 0);
|
||||||
|
|
Loading…
Reference in a new issue