change emote packs slightly

This commit is contained in:
Sorunome 2020-05-15 21:05:28 +02:00
parent 98d2f8d6bb
commit d6e9131b12
No known key found for this signature in database
GPG key ID: B19471D07FC9BE9C

View file

@ -497,25 +497,14 @@ class Room {
return resp['event_id']; return resp['event_id'];
} }
/// Sends a normal text message to this room. Returns the event ID generated /// return all current emote packs for this room
/// by the server for this message. Map<String, Map<String, String>> get emotePacks {
Future<String> sendTextEvent(String message, {String txid, Event inReplyTo, bool parseMarkdown = true}) { final packs = <String, Map<String, String>>{};
final event = <String, dynamic>{
'msgtype': 'm.text',
'body': message,
};
if (message.startsWith('/me ')) {
event['msgtype'] = 'm.emote';
event['body'] = message.substring(4);
}
if (parseMarkdown) {
// load the emote packs
final emotePacks = <String, Map<String, String>>{};
final addEmotePack = (String packName, Map<String, dynamic> content) { final addEmotePack = (String packName, Map<String, dynamic> content) {
emotePacks[packName] = <String, String>{}; packs[packName] = <String, String>{};
content.forEach((key, value) { content.forEach((key, value) {
if (key is String && value is String && value.startsWith('mxc://')) { if (key is String && value is String && value.startsWith('mxc://')) {
emotePacks[packName][key] = value; packs[packName][key] = value;
} }
}); });
}; };
@ -527,7 +516,22 @@ class Room {
if (userEmotes != null && userEmotes.content['short'] is Map) { if (userEmotes != null && userEmotes.content['short'] is Map) {
addEmotePack('user', userEmotes.content['short']); addEmotePack('user', userEmotes.content['short']);
} }
final html = markdown(event['body'], emotePacks); return packs;
}
/// Sends a normal text message to this room. Returns the event ID generated
/// by the server for this message.
Future<String> sendTextEvent(String message, {String txid, Event inReplyTo, bool parseMarkdown = true, Map<String, Map<String, String>> emotePacks}) {
final event = <String, dynamic>{
'msgtype': 'm.text',
'body': message,
};
if (message.startsWith('/me ')) {
event['msgtype'] = 'm.emote';
event['body'] = message.substring(4);
}
if (parseMarkdown) {
final html = markdown(event['body'], emotePacks ?? this.emotePacks);
// if the decoded html is the same as the body, there is no need in sending a formatted message // if the decoded html is the same as the body, there is no need in sending a formatted message
if (HtmlUnescape().convert(html) != event['body']) { if (HtmlUnescape().convert(html) != event['body']) {
event['format'] = 'org.matrix.custom.html'; event['format'] = 'org.matrix.custom.html';