fetchMediaBinary method

Future<void> fetchMediaBinary(
  1. String? msgType,
  2. String eventId,
  3. String msgId
)

Implementation

Future<void> fetchMediaBinary(
  String? msgType,
  String eventId,
  String msgId,
) async {
  switch (msgType) {
    case 'm.audio':
    case 'm.video':
      final messages = state.messages;

      final convo = await ref.read(chatProvider(roomId).future);
      if (convo == null) {
        throw RoomNotFound();
      }
      final data = await convo.mediaBinary(eventId, null);
      int index = messages.indexWhere((x) => x.id == msgId);
      if (index != -1) {
        final metadata = {...messages[index].metadata ?? {}};
        metadata['base64'] = base64Encode(data.asTypedList());
        final message = messages[index].copyWith(metadata: metadata);
        replaceMessageAt(index, message);
      }
      break;
  }
}