Merge branch 'henri/make-sender-getter-async' into 'main'
refactor: make sender getter async Closes #296 See merge request famedly/company/frontend/famedlysdk!1042
This commit is contained in:
commit
311233f20a
|
|
@ -1,3 +1,9 @@
|
|||
## [0.9.8] - 2nd Jun 2022
|
||||
- feat: Add search for events in timeline (Krille Fear)
|
||||
- feat: Add waitForSync helper (Henri Carnot)
|
||||
- feat: Allow setting image size when generating a thumbnail (Henri Carnot)
|
||||
- refactr: Make event.sender async (Henri Carnot)
|
||||
|
||||
## [0.9.7] - 23rd May 2022
|
||||
- ci: use flutter images to install less (Nicolas Werner)
|
||||
- feat: implement session export (Lanna Michalke)
|
||||
|
|
|
|||
|
|
@ -37,7 +37,13 @@ abstract class RelationshipTypes {
|
|||
|
||||
/// All data exchanged over Matrix is expressed as an "event". Typically each client action (e.g. sending a message) correlates with exactly one event.
|
||||
class Event extends MatrixEvent {
|
||||
User get sender => room.getUserByMXIDSync(senderId);
|
||||
Future<User?> get eventSender async =>
|
||||
await room.requestUser(senderId, ignoreErrors: true);
|
||||
@Deprecated(
|
||||
'Use eventSender instead or senderFromMemoryOrFallback for a synchronous alternative')
|
||||
User get sender => senderFromMemoryOrFallback;
|
||||
User get senderFromMemoryOrFallback =>
|
||||
room.unsafeGetUserFromMemoryOrFallback(senderId);
|
||||
|
||||
/// The room this event belongs to. May be null.
|
||||
final Room room;
|
||||
|
|
@ -58,7 +64,9 @@ class Event extends MatrixEvent {
|
|||
|
||||
bool get redacted => redactedBecause != null;
|
||||
|
||||
User? get stateKeyUser => room.getUserByMXIDSync(stateKey!);
|
||||
User? get stateKeyUser => stateKey != null
|
||||
? room.unsafeGetUserFromMemoryOrFallback(stateKey!)
|
||||
: null;
|
||||
|
||||
Event({
|
||||
this.status = defaultStatus,
|
||||
|
|
@ -300,7 +308,8 @@ class Event extends MatrixEvent {
|
|||
if (receipt == null) return [];
|
||||
return receipt.content.entries
|
||||
.where((entry) => entry.value['event_id'] == eventId)
|
||||
.map((entry) => Receipt(room.getUserByMXIDSync(entry.key),
|
||||
.map((entry) => Receipt(
|
||||
room.unsafeGetUserFromMemoryOrFallback(entry.key),
|
||||
DateTime.fromMillisecondsSinceEpoch(entry.value['ts'])))
|
||||
.toList();
|
||||
}
|
||||
|
|
@ -623,15 +632,58 @@ class Event extends MatrixEvent {
|
|||
/// plaintextBody instead of the normal body.
|
||||
/// [removeMarkdown] allow to remove the markdown formating from the event body.
|
||||
/// Usefull form message preview or notifications text.
|
||||
Future<String> getLocalizedBodyAsync(MatrixLocalizations i18n,
|
||||
{bool withSenderNamePrefix = false,
|
||||
bool hideReply = false,
|
||||
bool hideEdit = false,
|
||||
bool plaintextBody = false,
|
||||
bool removeMarkdown = false}) async {
|
||||
if (redacted) {
|
||||
await redactedBecause?.eventSender;
|
||||
}
|
||||
|
||||
if (withSenderNamePrefix &&
|
||||
(type == EventTypes.Message || type.contains(EventTypes.Encrypted))) {
|
||||
// To be sure that if the event need to be localized, the user is in memory.
|
||||
// used by EventLocalizations._localizedBodyNormalMessage
|
||||
await eventSender;
|
||||
}
|
||||
|
||||
return _getLocalizedBody(i18n,
|
||||
withSenderNamePrefix: withSenderNamePrefix,
|
||||
hideReply: hideReply,
|
||||
hideEdit: hideEdit,
|
||||
plaintextBody: plaintextBody,
|
||||
removeMarkdown: removeMarkdown);
|
||||
}
|
||||
|
||||
@Deprecated("Use getLocalizedBodyAsync")
|
||||
String getLocalizedBody(MatrixLocalizations i18n,
|
||||
{bool withSenderNamePrefix = false,
|
||||
bool hideReply = false,
|
||||
bool hideEdit = false,
|
||||
bool plaintextBody = false,
|
||||
bool removeMarkdown = false}) {
|
||||
return _getLocalizedBody(i18n,
|
||||
withSenderNamePrefix: withSenderNamePrefix,
|
||||
hideReply: hideReply,
|
||||
hideEdit: hideEdit,
|
||||
plaintextBody: plaintextBody,
|
||||
removeMarkdown: removeMarkdown);
|
||||
}
|
||||
|
||||
String _getLocalizedBody(MatrixLocalizations i18n,
|
||||
{bool withSenderNamePrefix = false,
|
||||
bool hideReply = false,
|
||||
bool hideEdit = false,
|
||||
bool plaintextBody = false,
|
||||
bool removeMarkdown = false}) {
|
||||
if (redacted) {
|
||||
return i18n.removedBy(redactedBecause?.sender.calcDisplayname() ?? '');
|
||||
return i18n.removedBy(
|
||||
(redactedBecause?.senderFromMemoryOrFallback)?.calcDisplayname() ??
|
||||
senderId);
|
||||
}
|
||||
|
||||
var body = plaintextBody ? this.plaintextBody : this.body;
|
||||
|
||||
// we need to know if the message is an html message to be able to determine
|
||||
|
|
@ -684,7 +736,7 @@ class Event extends MatrixEvent {
|
|||
textOnlyMessageTypes.contains(messageType)) {
|
||||
final senderNameOrYou = senderId == room.client.userID
|
||||
? i18n.you
|
||||
: (sender.calcDisplayname());
|
||||
: senderFromMemoryOrFallback.calcDisplayname();
|
||||
localizedBody = '$senderNameOrYou: $localizedBody';
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -263,11 +263,13 @@ class Room {
|
|||
if (isDirectChat) {
|
||||
final user = directChatMatrixID;
|
||||
if (user != null) {
|
||||
return getUserByMXIDSync(user).avatarUrl;
|
||||
return unsafeGetUserFromMemoryOrFallback(user).avatarUrl;
|
||||
}
|
||||
}
|
||||
if (membership == Membership.invite) {
|
||||
return getState(EventTypes.RoomMember, client.userID!)?.sender.avatarUrl;
|
||||
return getState(EventTypes.RoomMember, client.userID!)
|
||||
?.senderFromMemoryOrFallback
|
||||
.avatarUrl;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
@ -356,7 +358,10 @@ class Room {
|
|||
List<User> get typingUsers {
|
||||
final typingMxid = ephemerals['m.typing']?.content['user_ids'];
|
||||
return (typingMxid is List)
|
||||
? typingMxid.cast<String>().map(getUserByMXIDSync).toList()
|
||||
? typingMxid
|
||||
.cast<String>()
|
||||
.map(unsafeGetUserFromMemoryOrFallback)
|
||||
.toList()
|
||||
: [];
|
||||
}
|
||||
|
||||
|
|
@ -401,18 +406,19 @@ class Room {
|
|||
if (heroes != null && heroes.isNotEmpty) {
|
||||
return heroes
|
||||
.where((hero) => hero.isNotEmpty)
|
||||
.map((hero) => getUserByMXIDSync(hero).calcDisplayname())
|
||||
.map((hero) =>
|
||||
unsafeGetUserFromMemoryOrFallback(hero).calcDisplayname())
|
||||
.join(', ');
|
||||
}
|
||||
if (isDirectChat) {
|
||||
final user = directChatMatrixID;
|
||||
if (user != null) {
|
||||
return getUserByMXIDSync(user).calcDisplayname();
|
||||
return unsafeGetUserFromMemoryOrFallback(user).calcDisplayname();
|
||||
}
|
||||
}
|
||||
if (membership == Membership.invite) {
|
||||
final sender = getState(EventTypes.RoomMember, client.userID!)
|
||||
?.sender
|
||||
?.senderFromMemoryOrFallback
|
||||
.calcDisplayname();
|
||||
if (sender != null) return sender;
|
||||
}
|
||||
|
|
@ -1009,7 +1015,7 @@ class Room {
|
|||
if (invitation != null &&
|
||||
invitation.content['is_direct'] is bool &&
|
||||
invitation.content['is_direct']) {
|
||||
await addToDirectChat(invitation.sender.id);
|
||||
await addToDirectChat(invitation.senderId);
|
||||
}
|
||||
} on MatrixException catch (exception) {
|
||||
if (leaveIfNotFound &&
|
||||
|
|
@ -1410,9 +1416,10 @@ class Room {
|
|||
(summary.mJoinedMemberCount ?? 0) + (summary.mInvitedMemberCount ?? 0);
|
||||
}
|
||||
|
||||
/// Returns the [User] object for the given [mxID] or requests it from
|
||||
/// the homeserver and returns a default [User] object while waiting.
|
||||
User getUserByMXIDSync(String mxID) {
|
||||
/// Returns the [User] object for the given [mxID] or return
|
||||
/// a fallback [User] and start a request to get the user
|
||||
/// from the homeserver.
|
||||
User unsafeGetUserFromMemoryOrFallback(String mxID) {
|
||||
final user = getState(EventTypes.RoomMember, mxID);
|
||||
if (user != null) {
|
||||
return user.asUser;
|
||||
|
|
|
|||
|
|
@ -20,13 +20,11 @@ import '../matrix.dart';
|
|||
|
||||
/// Represents a Matrix User which may be a participant in a Matrix Room.
|
||||
class User extends Event {
|
||||
factory User(
|
||||
String id, {
|
||||
String? membership,
|
||||
String? displayName,
|
||||
String? avatarUrl,
|
||||
required Room room,
|
||||
}) {
|
||||
factory User(String id,
|
||||
{String? membership,
|
||||
String? displayName,
|
||||
String? avatarUrl,
|
||||
required Room room}) {
|
||||
return User.fromState(
|
||||
stateKey: id,
|
||||
content: {
|
||||
|
|
|
|||
|
|
@ -31,17 +31,23 @@ abstract class EventLocalizations {
|
|||
Event event, MatrixLocalizations i18n, String body) {
|
||||
switch (event.messageType) {
|
||||
case MessageTypes.Image:
|
||||
return i18n.sentAPicture(event.sender.calcDisplayname());
|
||||
return i18n
|
||||
.sentAPicture(event.senderFromMemoryOrFallback.calcDisplayname());
|
||||
case MessageTypes.File:
|
||||
return i18n.sentAFile(event.sender.calcDisplayname());
|
||||
return i18n
|
||||
.sentAFile(event.senderFromMemoryOrFallback.calcDisplayname());
|
||||
case MessageTypes.Audio:
|
||||
return i18n.sentAnAudio(event.sender.calcDisplayname());
|
||||
return i18n
|
||||
.sentAnAudio(event.senderFromMemoryOrFallback.calcDisplayname());
|
||||
case MessageTypes.Video:
|
||||
return i18n.sentAVideo(event.sender.calcDisplayname());
|
||||
return i18n
|
||||
.sentAVideo(event.senderFromMemoryOrFallback.calcDisplayname());
|
||||
case MessageTypes.Location:
|
||||
return i18n.sharedTheLocation(event.sender.calcDisplayname());
|
||||
return i18n.sharedTheLocation(
|
||||
event.senderFromMemoryOrFallback.calcDisplayname());
|
||||
case MessageTypes.Sticker:
|
||||
return i18n.sentASticker(event.sender.calcDisplayname());
|
||||
return i18n
|
||||
.sentASticker(event.senderFromMemoryOrFallback.calcDisplayname());
|
||||
case MessageTypes.Emote:
|
||||
return '* $body';
|
||||
case MessageTypes.BadEncrypted:
|
||||
|
|
@ -78,30 +84,33 @@ abstract class EventLocalizations {
|
|||
String Function(Event event, MatrixLocalizations i18n, String body)?>
|
||||
localizationsMap = {
|
||||
EventTypes.Sticker: (event, i18n, body) =>
|
||||
i18n.sentASticker(event.sender.calcDisplayname()),
|
||||
EventTypes.Redaction: (event, i18n, body) =>
|
||||
i18n.redactedAnEvent(event.sender.calcDisplayname()),
|
||||
EventTypes.RoomAliases: (event, i18n, body) =>
|
||||
i18n.changedTheRoomAliases(event.sender.calcDisplayname()),
|
||||
i18n.sentASticker(event.senderFromMemoryOrFallback.calcDisplayname()),
|
||||
EventTypes.Redaction: (event, i18n, body) => i18n
|
||||
.redactedAnEvent(event.senderFromMemoryOrFallback.calcDisplayname()),
|
||||
EventTypes.RoomAliases: (event, i18n, body) => i18n.changedTheRoomAliases(
|
||||
event.senderFromMemoryOrFallback.calcDisplayname()),
|
||||
EventTypes.RoomCanonicalAlias: (event, i18n, body) =>
|
||||
i18n.changedTheRoomInvitationLink(event.sender.calcDisplayname()),
|
||||
i18n.changedTheRoomInvitationLink(
|
||||
event.senderFromMemoryOrFallback.calcDisplayname()),
|
||||
EventTypes.RoomCreate: (event, i18n, body) =>
|
||||
i18n.createdTheChat(event.sender.calcDisplayname()),
|
||||
i18n.createdTheChat(event.senderFromMemoryOrFallback.calcDisplayname()),
|
||||
EventTypes.RoomTombstone: (event, i18n, body) => i18n.roomHasBeenUpgraded,
|
||||
EventTypes.RoomJoinRules: (event, i18n, body) {
|
||||
final joinRules = JoinRules.values.firstWhereOrNull((r) =>
|
||||
r.toString().replaceAll('JoinRules.', '') ==
|
||||
event.content['join_rule']);
|
||||
if (joinRules == null) {
|
||||
return i18n.changedTheJoinRules(event.sender.calcDisplayname());
|
||||
return i18n.changedTheJoinRules(
|
||||
event.senderFromMemoryOrFallback.calcDisplayname());
|
||||
} else {
|
||||
return i18n.changedTheJoinRulesTo(
|
||||
event.sender.calcDisplayname(), joinRules.getLocalizedString(i18n));
|
||||
event.senderFromMemoryOrFallback.calcDisplayname(),
|
||||
joinRules.getLocalizedString(i18n));
|
||||
}
|
||||
},
|
||||
EventTypes.RoomMember: (event, i18n, body) {
|
||||
final targetName = event.stateKeyUser?.calcDisplayname() ?? '';
|
||||
final senderName = event.sender.calcDisplayname();
|
||||
final senderName = event.senderFromMemoryOrFallback.calcDisplayname();
|
||||
final userIsTarget = event.stateKey == event.room.client.userID;
|
||||
final userIsSender = event.senderId == event.room.client.userID;
|
||||
|
||||
|
|
@ -190,22 +199,27 @@ abstract class EventLocalizations {
|
|||
return text;
|
||||
},
|
||||
EventTypes.RoomPowerLevels: (event, i18n, body) =>
|
||||
i18n.changedTheChatPermissions(event.sender.calcDisplayname()),
|
||||
i18n.changedTheChatPermissions(
|
||||
event.senderFromMemoryOrFallback.calcDisplayname()),
|
||||
EventTypes.RoomName: (event, i18n, body) => i18n.changedTheChatNameTo(
|
||||
event.sender.calcDisplayname(), event.content['name']),
|
||||
event.senderFromMemoryOrFallback.calcDisplayname(),
|
||||
event.content['name']),
|
||||
EventTypes.RoomTopic: (event, i18n, body) =>
|
||||
i18n.changedTheChatDescriptionTo(
|
||||
event.sender.calcDisplayname(), event.content['topic']),
|
||||
EventTypes.RoomAvatar: (event, i18n, body) =>
|
||||
i18n.changedTheChatAvatar(event.sender.calcDisplayname()),
|
||||
event.senderFromMemoryOrFallback.calcDisplayname(),
|
||||
event.content['topic']),
|
||||
EventTypes.RoomAvatar: (event, i18n, body) => i18n.changedTheChatAvatar(
|
||||
event.senderFromMemoryOrFallback.calcDisplayname()),
|
||||
EventTypes.GuestAccess: (event, i18n, body) {
|
||||
final guestAccess = GuestAccess.values.firstWhereOrNull((r) =>
|
||||
r.toString().replaceAll('GuestAccess.', '') ==
|
||||
event.content['guest_access']);
|
||||
if (guestAccess == null) {
|
||||
return i18n.changedTheGuestAccessRules(event.sender.calcDisplayname());
|
||||
return i18n.changedTheGuestAccessRules(
|
||||
event.senderFromMemoryOrFallback.calcDisplayname());
|
||||
} else {
|
||||
return i18n.changedTheGuestAccessRulesTo(event.sender.calcDisplayname(),
|
||||
return i18n.changedTheGuestAccessRulesTo(
|
||||
event.senderFromMemoryOrFallback.calcDisplayname(),
|
||||
guestAccess.getLocalizedString(i18n));
|
||||
}
|
||||
},
|
||||
|
|
@ -214,35 +228,36 @@ abstract class EventLocalizations {
|
|||
r.toString().replaceAll('HistoryVisibility.', '') ==
|
||||
event.content['history_visibility']);
|
||||
if (historyVisibility == null) {
|
||||
return i18n.changedTheHistoryVisibility(event.sender.calcDisplayname());
|
||||
return i18n.changedTheHistoryVisibility(
|
||||
event.senderFromMemoryOrFallback.calcDisplayname());
|
||||
} else {
|
||||
return i18n.changedTheHistoryVisibilityTo(
|
||||
event.sender.calcDisplayname(),
|
||||
event.senderFromMemoryOrFallback.calcDisplayname(),
|
||||
historyVisibility.getLocalizedString(i18n));
|
||||
}
|
||||
},
|
||||
EventTypes.Encryption: (event, i18n, body) {
|
||||
var localizedBody =
|
||||
i18n.activatedEndToEndEncryption(event.sender.calcDisplayname());
|
||||
var localizedBody = i18n.activatedEndToEndEncryption(
|
||||
event.senderFromMemoryOrFallback.calcDisplayname());
|
||||
if (event.room.client.encryptionEnabled == false) {
|
||||
localizedBody += '. ' + i18n.needPantalaimonWarning;
|
||||
}
|
||||
return localizedBody;
|
||||
},
|
||||
EventTypes.CallAnswer: (event, i18n, body) =>
|
||||
i18n.answeredTheCall(event.sender.calcDisplayname()),
|
||||
EventTypes.CallAnswer: (event, i18n, body) => i18n
|
||||
.answeredTheCall(event.senderFromMemoryOrFallback.calcDisplayname()),
|
||||
EventTypes.CallHangup: (event, i18n, body) =>
|
||||
i18n.endedTheCall(event.sender.calcDisplayname()),
|
||||
i18n.endedTheCall(event.senderFromMemoryOrFallback.calcDisplayname()),
|
||||
EventTypes.CallInvite: (event, i18n, body) =>
|
||||
i18n.startedACall(event.sender.calcDisplayname()),
|
||||
EventTypes.CallCandidates: (event, i18n, body) =>
|
||||
i18n.sentCallInformations(event.sender.calcDisplayname()),
|
||||
i18n.startedACall(event.senderFromMemoryOrFallback.calcDisplayname()),
|
||||
EventTypes.CallCandidates: (event, i18n, body) => i18n.sentCallInformations(
|
||||
event.senderFromMemoryOrFallback.calcDisplayname()),
|
||||
EventTypes.Encrypted: (event, i18n, body) =>
|
||||
_localizedBodyNormalMessage(event, i18n, body),
|
||||
EventTypes.Message: (event, i18n, body) =>
|
||||
_localizedBodyNormalMessage(event, i18n, body),
|
||||
EventTypes.Reaction: (event, i18n, body) => i18n.sentReaction(
|
||||
event.sender.calcDisplayname(),
|
||||
event.senderFromMemoryOrFallback.calcDisplayname(),
|
||||
event.content
|
||||
.tryGetMap<String, dynamic>('m.relates_to')
|
||||
?.tryGet<String>('key') ??
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ class WrappedMediaStream {
|
|||
String? get displayName => getUser().displayName;
|
||||
|
||||
User getUser() {
|
||||
return room.getUserByMXIDSync(userId);
|
||||
return room.unsafeGetUserFromMemoryOrFallback(userId);
|
||||
}
|
||||
|
||||
bool isLocal() {
|
||||
|
|
@ -1240,7 +1240,8 @@ class VoIP {
|
|||
|
||||
final newCall = createNewCall(opts);
|
||||
newCall.remotePartyId = partyId;
|
||||
newCall.remoteUser = event.sender;
|
||||
newCall.remoteUser =
|
||||
(await event.eventSender) ?? User(event.senderId, room: event.room);
|
||||
final offer = RTCSessionDescription(
|
||||
event.content['offer']['sdp'],
|
||||
event.content['offer']['type'],
|
||||
|
|
@ -1284,7 +1285,8 @@ class VoIP {
|
|||
}
|
||||
|
||||
call.remotePartyId = partyId;
|
||||
call.remoteUser = event.sender;
|
||||
call.remoteUser =
|
||||
await event.eventSender ?? User(event.senderId, room: event.room);
|
||||
|
||||
final answer = RTCSessionDescription(
|
||||
event.content['answer']['sdp'], event.content['answer']['type']);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
name: matrix
|
||||
description: Matrix Dart SDK
|
||||
version: 0.9.7
|
||||
version: 0.9.8
|
||||
homepage: https://famedly.com
|
||||
repository: https://gitlab.com/famedly/company/frontend/famedlysdk.git
|
||||
|
||||
|
|
|
|||
|
|
@ -964,7 +964,7 @@ void main() {
|
|||
expect(event?.eventId, '123');
|
||||
expect(event?.body, 'Hello world');
|
||||
expect(event?.senderId, '@alicyy:example.com');
|
||||
expect(event?.sender.calcDisplayname(), 'AlicE');
|
||||
expect(event?.senderFromMemoryOrFallback.calcDisplayname(), 'AlicE');
|
||||
expect(event?.type, 'm.room.message');
|
||||
expect(event?.messageType, 'm.text');
|
||||
expect(event?.room.id, '!localpart2:server.abc');
|
||||
|
|
|
|||
|
|
@ -362,7 +362,7 @@ void main() {
|
|||
}
|
||||
}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'Removed by Example');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -429,7 +429,7 @@ void main() {
|
|||
'type': 'm.sticker',
|
||||
'unsigned': {'age': 1234}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'Example sent a sticker');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -443,7 +443,7 @@ void main() {
|
|||
'type': 'm.room.redaction',
|
||||
'unsigned': {'age': 1234}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'Example redacted an event');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -459,7 +459,7 @@ void main() {
|
|||
'type': 'm.room.aliases',
|
||||
'unsigned': {'age': 1234}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'Example changed the room aliases');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -475,7 +475,7 @@ void main() {
|
|||
'type': 'm.room.aliases',
|
||||
'unsigned': {'age': 1234}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'Example changed the room aliases');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -489,7 +489,7 @@ void main() {
|
|||
'type': 'm.room.canonical_alias',
|
||||
'unsigned': {'age': 1234}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'Example changed the room invitation link');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -511,7 +511,7 @@ void main() {
|
|||
'type': 'm.room.create',
|
||||
'unsigned': {'age': 1234}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'Example created the chat');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -528,7 +528,7 @@ void main() {
|
|||
'type': 'm.room.tombstone',
|
||||
'unsigned': {'age': 1234}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'Room has been upgraded');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -542,7 +542,7 @@ void main() {
|
|||
'type': 'm.room.join_rules',
|
||||
'unsigned': {'age': 1234}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'Example changed the join rules to Anyone can join');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -560,7 +560,7 @@ void main() {
|
|||
'type': 'm.room.member',
|
||||
'unsigned': {'age': 1234}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'Alice joined the chat');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -573,7 +573,7 @@ void main() {
|
|||
'state_key': '@alice:example.org',
|
||||
'type': 'm.room.member'
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'Example has invited Alice');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -589,7 +589,7 @@ void main() {
|
|||
'prev_content': {'membership': 'join'},
|
||||
}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'Example kicked Alice');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -605,7 +605,7 @@ void main() {
|
|||
'prev_content': {'membership': 'join'},
|
||||
}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'Example banned Alice');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -621,7 +621,7 @@ void main() {
|
|||
'prev_content': {'membership': 'invite'},
|
||||
}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'Alice accepted the invitation');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -637,7 +637,7 @@ void main() {
|
|||
'prev_content': {'membership': 'join'},
|
||||
}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'Example has invited Alice');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -653,7 +653,7 @@ void main() {
|
|||
'prev_content': {'membership': 'invite'},
|
||||
}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'Example has withdrawn the invitation for Alice');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -669,7 +669,7 @@ void main() {
|
|||
'prev_content': {'membership': 'invite'},
|
||||
}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'Alice rejected the invitation');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -694,7 +694,7 @@ void main() {
|
|||
'type': 'm.room.power_levels',
|
||||
'unsigned': {'age': 1234}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'Example changed the chat permissions');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -708,7 +708,7 @@ void main() {
|
|||
'type': 'm.room.name',
|
||||
'unsigned': {'age': 1234}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'Example changed the chat name to The room name');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -722,7 +722,7 @@ void main() {
|
|||
'type': 'm.room.topic',
|
||||
'unsigned': {'age': 1234}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'Example changed the chat description to A room topic');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -739,7 +739,7 @@ void main() {
|
|||
'type': 'm.room.avatar',
|
||||
'unsigned': {'age': 1234}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'Example changed the chat avatar');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -753,7 +753,7 @@ void main() {
|
|||
'type': 'm.room.history_visibility',
|
||||
'unsigned': {'age': 1234}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'Example changed the history visibility to Visible for all participants');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -771,7 +771,7 @@ void main() {
|
|||
'type': 'm.room.encryption',
|
||||
'unsigned': {'age': 1234}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'Example activated end to end encryption. Need pantalaimon');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -789,7 +789,7 @@ void main() {
|
|||
'type': 'm.room.message',
|
||||
'unsigned': {'age': 1234}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'This is an example text message');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -807,7 +807,7 @@ void main() {
|
|||
'type': 'm.room.message',
|
||||
'unsigned': {'age': 1234}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'* thinks this is an example emote');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -825,7 +825,7 @@ void main() {
|
|||
'type': 'm.room.message',
|
||||
'unsigned': {'age': 1234}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'This is an example notice');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -843,7 +843,7 @@ void main() {
|
|||
'type': 'm.room.message',
|
||||
'unsigned': {'age': 1234}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'Example sent a picture');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -862,7 +862,7 @@ void main() {
|
|||
'type': 'm.room.message',
|
||||
'unsigned': {'age': 1234}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'Example sent a file');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -884,7 +884,7 @@ void main() {
|
|||
'type': 'm.room.message',
|
||||
'unsigned': {'age': 1234}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'Example sent an audio');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -910,7 +910,7 @@ void main() {
|
|||
'type': 'm.room.message',
|
||||
'unsigned': {'age': 1234}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'Example shared the location');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -941,7 +941,7 @@ void main() {
|
|||
'type': 'm.room.message',
|
||||
'unsigned': {'age': 1234}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'Example sent a video');
|
||||
expect(event.isEventTypeKnown, true);
|
||||
|
||||
|
|
@ -954,12 +954,12 @@ void main() {
|
|||
'type': 'unknown.event.type',
|
||||
'unsigned': {'age': 1234}
|
||||
}, room);
|
||||
expect(event.getLocalizedBody(MatrixDefaultLocalizations()),
|
||||
expect(await event.getLocalizedBodyAsync(MatrixDefaultLocalizations()),
|
||||
'Unknown event unknown.event.type');
|
||||
expect(event.isEventTypeKnown, false);
|
||||
});
|
||||
|
||||
test('getLocalizedBody, parameters', () {
|
||||
test('getLocalizedBody, parameters', () async {
|
||||
final matrix = Client('testclient', httpClient: FakeMatrixApi());
|
||||
final room = Room(id: '!1234:example.com', client: matrix);
|
||||
var event = Event.fromJson({
|
||||
|
|
@ -977,7 +977,7 @@ void main() {
|
|||
'unsigned': {'age': 1234}
|
||||
}, room);
|
||||
expect(
|
||||
event.getLocalizedBody(MatrixDefaultLocalizations(),
|
||||
await event.getLocalizedBodyAsync(MatrixDefaultLocalizations(),
|
||||
plaintextBody: true),
|
||||
'**This is an example text message**');
|
||||
|
||||
|
|
@ -1006,10 +1006,11 @@ void main() {
|
|||
'unsigned': {'age': 1234}
|
||||
}, room);
|
||||
expect(
|
||||
event.getLocalizedBody(MatrixDefaultLocalizations(), hideEdit: true),
|
||||
await event.getLocalizedBodyAsync(MatrixDefaultLocalizations(),
|
||||
hideEdit: true),
|
||||
'This is an example text message');
|
||||
expect(
|
||||
event.getLocalizedBody(MatrixDefaultLocalizations(),
|
||||
await event.getLocalizedBodyAsync(MatrixDefaultLocalizations(),
|
||||
hideEdit: true, plaintextBody: true),
|
||||
'**This is an example text message**');
|
||||
|
||||
|
|
@ -1028,10 +1029,11 @@ void main() {
|
|||
'unsigned': {'age': 1234}
|
||||
}, room);
|
||||
expect(
|
||||
event.getLocalizedBody(MatrixDefaultLocalizations(), hideReply: true),
|
||||
await event.getLocalizedBodyAsync(MatrixDefaultLocalizations(),
|
||||
hideReply: true),
|
||||
'hmm, fox');
|
||||
expect(
|
||||
event.getLocalizedBody(MatrixDefaultLocalizations(),
|
||||
await event.getLocalizedBodyAsync(MatrixDefaultLocalizations(),
|
||||
hideReply: true, plaintextBody: true),
|
||||
'hmm, *fox*');
|
||||
|
||||
|
|
@ -1052,19 +1054,19 @@ void main() {
|
|||
'unsigned': {'age': 1234}
|
||||
}, room);
|
||||
expect(
|
||||
event.getLocalizedBody(MatrixDefaultLocalizations(),
|
||||
await event.getLocalizedBodyAsync(MatrixDefaultLocalizations(),
|
||||
removeMarkdown: true),
|
||||
'Title\nsome text and link\nokay and this is important');
|
||||
expect(
|
||||
event.getLocalizedBody(MatrixDefaultLocalizations(),
|
||||
await event.getLocalizedBodyAsync(MatrixDefaultLocalizations(),
|
||||
removeMarkdown: true, plaintextBody: true),
|
||||
'Title\nsome text and 🔗link\nokay and this is important');
|
||||
expect(
|
||||
event.getLocalizedBody(MatrixDefaultLocalizations(),
|
||||
await event.getLocalizedBodyAsync(MatrixDefaultLocalizations(),
|
||||
removeMarkdown: true, withSenderNamePrefix: true),
|
||||
'Example: Title\nsome text and link\nokay and this is important');
|
||||
expect(
|
||||
event.getLocalizedBody(MatrixDefaultLocalizations(),
|
||||
await event.getLocalizedBodyAsync(MatrixDefaultLocalizations(),
|
||||
removeMarkdown: true,
|
||||
plaintextBody: true,
|
||||
withSenderNamePrefix: true),
|
||||
|
|
|
|||
|
|
@ -103,7 +103,8 @@ void main() {
|
|||
expect(removeList, []);
|
||||
expect(timeline.events.length, 2);
|
||||
expect(timeline.events[0].eventId, '1');
|
||||
expect(timeline.events[0].sender.id, '@alice:example.com');
|
||||
expect(timeline.events[0].senderFromMemoryOrFallback.id,
|
||||
'@alice:example.com');
|
||||
expect(timeline.events[0].originServerTs.millisecondsSinceEpoch,
|
||||
testTimeStamp);
|
||||
expect(timeline.events[0].body, 'Testcase');
|
||||
|
|
|
|||
Loading…
Reference in New Issue