mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 12:14:11 +00:00 
			
		
		
		
	Show who is writing messages
This commit is contained in:
		@@ -17,6 +17,7 @@ import 'package:comunic/ui/tiles/server_conversation_message_tile.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/account_image_widget.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/safe_state.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/scroll_watcher.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/user_writing_in_conv_notifier.dart';
 | 
			
		||||
import 'package:comunic/utils/date_utils.dart';
 | 
			
		||||
import 'package:comunic/utils/files_utils.dart';
 | 
			
		||||
import 'package:comunic/utils/intl_utils.dart';
 | 
			
		||||
@@ -649,6 +650,7 @@ class _ConversationScreenState extends SafeState<ConversationScreen> {
 | 
			
		||||
              : null,
 | 
			
		||||
        ),
 | 
			
		||||
        _messages.length == 0 ? _buildNoMessagesNotice() : _buildMessagesList(),
 | 
			
		||||
        UserWritingInConvNotifier(convID: _conversation.id),
 | 
			
		||||
        _sendCancel != null ? _buildSendingWidget() : _buildSendMessageForm(),
 | 
			
		||||
        _showEmojiPicker ? _buildEmojiContainer() : Container(),
 | 
			
		||||
      ],
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										84
									
								
								lib/ui/widgets/user_writing_in_conv_notifier.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										84
									
								
								lib/ui/widgets/user_writing_in_conv_notifier.dart
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,84 @@
 | 
			
		||||
import 'package:comunic/helpers/events_helper.dart';
 | 
			
		||||
import 'package:comunic/helpers/server_config_helper.dart';
 | 
			
		||||
import 'package:comunic/helpers/users_helper.dart';
 | 
			
		||||
import 'package:comunic/lists/users_list.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/safe_state.dart';
 | 
			
		||||
import 'package:comunic/utils/intl_utils.dart';
 | 
			
		||||
import 'package:comunic/utils/log_utils.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
 | 
			
		||||
/// User writing a message in a conversation notifier
 | 
			
		||||
///
 | 
			
		||||
/// @author Pierre Hubert
 | 
			
		||||
 | 
			
		||||
class UserWritingInConvNotifier extends StatefulWidget {
 | 
			
		||||
  final int convID;
 | 
			
		||||
 | 
			
		||||
  const UserWritingInConvNotifier({Key key, @required this.convID})
 | 
			
		||||
      : assert(convID != null),
 | 
			
		||||
        super(key: key);
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  _UserWritingInConvNotifierState createState() =>
 | 
			
		||||
      _UserWritingInConvNotifierState();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class _UserWritingInConvNotifierState
 | 
			
		||||
    extends SafeState<UserWritingInConvNotifier> {
 | 
			
		||||
  final _usersInfo = UsersList();
 | 
			
		||||
 | 
			
		||||
  final _list = List();
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  void initState() {
 | 
			
		||||
    this.listen<WritingMessageInConversationEvent>((ev) async {
 | 
			
		||||
      try {
 | 
			
		||||
        if (ev.convID != widget.convID) return;
 | 
			
		||||
 | 
			
		||||
        if (!_usersInfo.hasUser(ev.userID))
 | 
			
		||||
          _usersInfo.add(await UsersHelper().getSingleWithThrow(ev.userID));
 | 
			
		||||
 | 
			
		||||
        _handleEvent(ev.userID);
 | 
			
		||||
      } catch (e, s) {
 | 
			
		||||
        logError(e, s);
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
    super.initState();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) => Padding(
 | 
			
		||||
        padding: EdgeInsets.only(left: 5, right: 5),
 | 
			
		||||
        child: Align(
 | 
			
		||||
          alignment: Alignment.centerLeft,
 | 
			
		||||
          child: Text(
 | 
			
		||||
            writingText,
 | 
			
		||||
            style: TextStyle(fontSize: 10),
 | 
			
		||||
            textAlign: TextAlign.justify,
 | 
			
		||||
          ),
 | 
			
		||||
        ),
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
  String get writingText {
 | 
			
		||||
    if (_list.isEmpty) return "";
 | 
			
		||||
 | 
			
		||||
    final users = _list.toSet().map((e) => _usersInfo.getUser(e)).toList();
 | 
			
		||||
 | 
			
		||||
    if (users.length == 1)
 | 
			
		||||
      return tr("%1% is writing...", args: {"1": users.first.fullName});
 | 
			
		||||
 | 
			
		||||
    return tr("%1% and %2% are writing...", args: {
 | 
			
		||||
      "1": users.first.fullName,
 | 
			
		||||
      "2": users.sublist(1).map((e) => e.fullName).join(", ")
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void _handleEvent(int userID) async {
 | 
			
		||||
    setState(() => this._list.add(userID));
 | 
			
		||||
 | 
			
		||||
    await Future.delayed(
 | 
			
		||||
        Duration(seconds: srvConfig.conversationsPolicy.writingEventLifetime));
 | 
			
		||||
 | 
			
		||||
    setState(() => this._list.removeAt(0));
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user