1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-12-26 04:48:51 +00:00

Use DisplayString for messages

This commit is contained in:
Pierre HUBERT 2020-04-16 15:10:47 +02:00
parent 32c491ae84
commit 0ec0f216e2
5 changed files with 22 additions and 15 deletions

View File

@ -8,6 +8,7 @@ import 'package:comunic/models/api_request.dart';
import 'package:comunic/models/api_response.dart';
import 'package:comunic/models/conversation.dart';
import 'package:comunic/models/conversation_message.dart';
import 'package:comunic/models/displayed_content.dart';
import 'package:comunic/models/new_conversation_message.dart';
import 'package:comunic/utils/account_utils.dart';
import 'package:meta/meta.dart';
@ -365,7 +366,7 @@ class ConversationsHelper {
conversationID: conversationID,
userID: map["ID_user"],
timeInsert: map["time_insert"],
message: map["message"],
message: DisplayedString(map["message"]),
imageURL: map["image_path"],
);
}

View File

@ -1,5 +1,6 @@
import 'package:comunic/helpers/database/database_contract.dart';
import 'package:comunic/models/cache_model.dart';
import 'package:comunic/models/displayed_content.dart';
import 'package:comunic/utils/account_utils.dart' as account;
import 'package:meta/meta.dart';
@ -12,7 +13,7 @@ class ConversationMessage extends CacheModel implements Comparable {
final int conversationID;
final int userID;
final int timeInsert;
final String message;
final DisplayedString message;
final String imageURL;
const ConversationMessage({
@ -30,7 +31,7 @@ class ConversationMessage extends CacheModel implements Comparable {
DateTime get date => DateTime.fromMillisecondsSinceEpoch(timeInsert * 1000);
bool get hasMessage => message != null && message.length > 0;
bool get hasMessage => !message.isNull && message.length > 0;
bool get hasImage => imageURL != null && imageURL != "null";
@ -48,17 +49,18 @@ class ConversationMessage extends CacheModel implements Comparable {
ConversationsMessagesTableContract.C_CONVERSATION_ID: conversationID,
ConversationsMessagesTableContract.C_USER_ID: userID,
ConversationsMessagesTableContract.C_TIME_INSERT: timeInsert,
ConversationsMessagesTableContract.C_MESSAGE: message,
ConversationsMessagesTableContract.C_MESSAGE: message.content,
ConversationsMessagesTableContract.C_IMAGE_URL: imageURL
};
}
ConversationMessage.fromMap(Map<String, dynamic> map)
: id = map[ConversationsMessagesTableContract.C_ID],
conversationID = map[ConversationsMessagesTableContract.C_CONVERSATION_ID],
conversationID =
map[ConversationsMessagesTableContract.C_CONVERSATION_ID],
userID = map[ConversationsMessagesTableContract.C_USER_ID],
timeInsert = map[ConversationsMessagesTableContract.C_TIME_INSERT],
message = map[ConversationsMessagesTableContract.C_MESSAGE],
message = DisplayedString(map[ConversationsMessagesTableContract.C_MESSAGE]),
imageURL = map[ConversationsMessagesTableContract.C_IMAGE_URL],
super.fromMap(map);
}

View File

@ -392,7 +392,7 @@ class _ConversationScreenState extends State<ConversationScreen> {
context: context,
title: tr("Update message"),
message: tr("Please enter new message content:"),
defaultValue: message.message,
defaultValue: message.message.content,
hint: tr("New message"));
if (newContent == null) return;

View File

@ -2,7 +2,7 @@ import 'package:comunic/models/conversation_message.dart';
import 'package:comunic/models/user.dart';
import 'package:comunic/ui/widgets/account_image_widget.dart';
import 'package:comunic/ui/widgets/network_image_widget.dart';
import 'package:comunic/ui/widgets/text_rich_content_widget.dart';
import 'package:comunic/ui/widgets/text_widget.dart';
import 'package:comunic/utils/date_utils.dart';
import 'package:comunic/utils/intl_utils.dart';
import 'package:comunic/utils/ui_utils.dart';
@ -124,8 +124,8 @@ class ConversationMessageTile extends StatelessWidget {
width: 200.0,
alignment: Alignment.centerRight,
child: Container(
child: TextRichContentWidget(
message.message,
child: TextWidget(
content: message.message,
textAlign: TextAlign.justify,
style: TextStyle(color: Colors.white),
),
@ -199,8 +199,8 @@ class ConversationMessageTile extends StatelessWidget {
width: 200.0,
alignment: Alignment.centerLeft,
child: Container(
child: TextRichContentWidget(
message.message,
child: TextWidget(
content: message.message,
textAlign: TextAlign.justify,
style: TextStyle(
color: darkTheme()

View File

@ -15,11 +15,13 @@ class TextWidget extends StatelessWidget {
final DisplayedString content;
final bool parseBBcode;
final TextStyle style;
final TextAlign textAlign;
const TextWidget({
Key key,
@required this.content,
this.parseBBcode = false,
this.textAlign = TextAlign.start,
this.style,
}) : assert(content != null),
assert(parseBBcode != null),
@ -40,6 +42,7 @@ class TextWidget extends StatelessWidget {
// Just parse link
return RichText(
textAlign: textAlign,
text: TextSpan(children: _parseLinks(context, content, style)),
);
}
@ -74,7 +77,7 @@ class TextWidget extends StatelessWidget {
child: InkWell(
child: Text(
word,
style: style.copyWith(color: Colors.blueAccent),
style: style.copyWith(color: Colors.indigo),
),
onTap: () => launch(word),
),
@ -93,7 +96,7 @@ class TextWidget extends StatelessWidget {
child: InkWell(
child: Text(
word,
style: style.copyWith(color: Colors.blueAccent),
style: style.copyWith(color: Colors.indigo),
),
onTap: () => openVirtualDirectory(context, word),
),
@ -110,7 +113,8 @@ class TextWidget extends StatelessWidget {
}
}
if (buff.isNotEmpty) changeWordType();
if (buff.isNotEmpty && (buff.length > 1 || buff.toString() != " "))
changeWordType();
return list;
}