MessageFieldController constructor

MessageFieldController(
  1. ChatService? _chatService,
  2. UserService? _userService,
  3. AbstractSettingsRepository? _settingsRepository,
  4. AuthService? _authService,
  5. MyUserService? _myUserService,
  6. SessionService? _sessionService,
  7. NotificationService? _notificationService, {
  8. void onSubmit()?,
  9. void onChanged()?,
  10. void onCall(
    1. bool
    )?,
  11. String? text,
  12. List<ChatItemQuoteInput> quotes = const [],
  13. List<Attachment> attachments = const [],
  14. bool onKeyUp(
    1. LogicalKeyboardKey
    )?,
  15. bool canPin = true,
})

Implementation

MessageFieldController(
  this._chatService,
  this._userService,
  this._settingsRepository,
  this._authService,
  this._myUserService,
  this._sessionService,
  this._notificationService, {
  this.onSubmit,
  this.onChanged,
  this.onCall,
  String? text,
  List<ChatItemQuoteInput> quotes = const [],
  List<Attachment> attachments = const [],
  this.onKeyUp,
  this.canPin = true,
}) : quotes = RxList(quotes),
     attachments = RxList(
       attachments.map((e) => MapEntry(GlobalKey(), e)).toList(),
     ) {
  field = TextFieldState(
    text: text,
    onFocus: (s) => onChanged?.call(),
    submitted: false,
    onSubmitted: (s) {
      field.unsubmit();
      onSubmit?.call();
    },
    focus: FocusNode(onKeyEvent: (_, KeyEvent e) => handleNewLines(e, field)),
  );

  field.focus.addListener(_focusListener);

  _repliesWorker ??= ever(replied, (_) => onChanged?.call());
  _attachmentsWorker ??= ever(this.attachments, (_) => onChanged?.call());
  _editedWorker ??= ever(edited, (item) {
    if (item != null) {
      field.text = item.text?.val ?? '';
      this.attachments.value = item.attachments
          .map((e) => MapEntry(GlobalKey(), e))
          .toList();
      replied.value = item.repliesTo
          .map((e) => e.original)
          .nonNulls
          .map((e) => Rx(e))
          .toList();
    } else {
      field.text = '';
      this.attachments.clear();
      replied.clear();
    }

    onChanged?.call();
  });
}