sendTextEvent method

Future<String?> sendTextEvent(
  1. String message, {
  2. String? txid,
  3. Event? inReplyTo,
  4. String? editEventId,
  5. bool parseMarkdown = true,
  6. bool parseCommands = true,
  7. String msgtype = MessageTypes.Text,
  8. String? threadRootEventId,
  9. String? threadLastEventId,
  10. StringBuffer? commandStdout,
})

Sends a normal text message to this room. Returns the event ID generated by the server for this message.

Implementation

Future<String?> sendTextEvent(
  String message, {
  String? txid,
  Event? inReplyTo,
  String? editEventId,
  bool parseMarkdown = true,
  bool parseCommands = true,
  String msgtype = MessageTypes.Text,
  String? threadRootEventId,
  String? threadLastEventId,
  StringBuffer? commandStdout,
}) {
  if (parseCommands) {
    return client.parseAndRunCommand(
      this,
      message,
      inReplyTo: inReplyTo,
      editEventId: editEventId,
      txid: txid,
      threadRootEventId: threadRootEventId,
      threadLastEventId: threadLastEventId,
      stdout: commandStdout,
    );
  }
  final event = <String, dynamic>{
    'msgtype': msgtype,
    'body': message,
  };
  if (parseMarkdown) {
    final html = markdown(
      event['body'],
      getEmotePacks: () => getImagePacksFlat(ImagePackUsage.emoticon),
      getMention: getMention,
      convertLinebreaks: client.convertLinebreaksInFormatting,
    );
    // if the decoded html is the same as the body, there is no need in sending a formatted message
    if (HtmlUnescape().convert(html.replaceAll(RegExp(r'<br />\n?'), '\n')) !=
        event['body']) {
      event['format'] = 'org.matrix.custom.html';
      event['formatted_body'] = html;
    }
  }
  return sendEvent(
    event,
    txid: txid,
    inReplyTo: inReplyTo,
    editEventId: editEventId,
    threadRootEventId: threadRootEventId,
    threadLastEventId: threadLastEventId,
  );
}