mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 04:49:21 +00:00
Cache parsed emojies
This commit is contained in:
parent
6e96a554ff
commit
824be11013
@ -1,5 +1,6 @@
|
||||
import 'package:comunic/models/api_request.dart';
|
||||
import 'package:comunic/models/comment.dart';
|
||||
import 'package:comunic/models/displayed_content.dart';
|
||||
import 'package:comunic/models/new_comment.dart';
|
||||
|
||||
/// Comments helper
|
||||
@ -64,7 +65,7 @@ class CommentsHelper {
|
||||
userID: entry["userID"],
|
||||
postID: entry["postID"],
|
||||
timeSent: entry["time_sent"],
|
||||
content: entry["content"],
|
||||
content: DisplayedString(entry["content"]),
|
||||
imageURL: entry["img_url"],
|
||||
likes: entry["likes"],
|
||||
userLike: entry["userlike"],
|
||||
|
@ -7,6 +7,7 @@ import 'package:comunic/helpers/survey_helper.dart';
|
||||
import 'package:comunic/lists/comments_list.dart';
|
||||
import 'package:comunic/lists/posts_list.dart';
|
||||
import 'package:comunic/models/api_request.dart';
|
||||
import 'package:comunic/models/displayed_content.dart';
|
||||
import 'package:comunic/models/new_post.dart';
|
||||
import 'package:comunic/models/post.dart';
|
||||
|
||||
@ -206,7 +207,7 @@ class PostsHelper {
|
||||
userPageID: map["user_page_id"],
|
||||
groupID: map["group_id"],
|
||||
timeSent: map["post_time"],
|
||||
content: map["content"],
|
||||
content: DisplayedString(map["content"]),
|
||||
visibilityLevel: _APIPostsVisibilityLevelMap[map["visibility_level"]],
|
||||
kind: postKind,
|
||||
fileSize: map["file_size"],
|
||||
|
@ -1,7 +1,8 @@
|
||||
import 'package:comunic/enums/likes_type.dart';
|
||||
import 'package:comunic/models/displayed_content.dart';
|
||||
import 'package:comunic/models/like_element.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:comunic/utils/account_utils.dart' as account;
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
/// Comments
|
||||
///
|
||||
@ -14,7 +15,7 @@ class Comment implements LikeElement {
|
||||
final int userID;
|
||||
final int postID;
|
||||
final int timeSent;
|
||||
String content;
|
||||
DisplayedString content;
|
||||
final String imageURL;
|
||||
int likes;
|
||||
bool userLike;
|
||||
@ -36,7 +37,8 @@ class Comment implements LikeElement {
|
||||
assert(likes != null),
|
||||
assert(userLike != null);
|
||||
|
||||
bool get hasContent => content != null && content.length > 0;
|
||||
bool get hasContent =>
|
||||
content != null && !content.isNull && content.length > 0;
|
||||
|
||||
bool get hasImage => imageURL != null;
|
||||
|
||||
|
38
lib/models/displayed_content.dart
Normal file
38
lib/models/displayed_content.dart
Normal file
@ -0,0 +1,38 @@
|
||||
import 'package:flutter_emoji/flutter_emoji.dart';
|
||||
|
||||
/// Optimized colons Emoji-parsed string
|
||||
///
|
||||
/// @author Pierre Hubert
|
||||
|
||||
class DisplayedString {
|
||||
String _string;
|
||||
String _parseCache;
|
||||
|
||||
DisplayedString(this._string);
|
||||
|
||||
int get length => _string.length;
|
||||
|
||||
bool get isEmpty => _string.isEmpty;
|
||||
|
||||
bool get isNull => _string == null;
|
||||
|
||||
String get content => _string;
|
||||
|
||||
set content(String content) {
|
||||
_string = content;
|
||||
_parseCache = null;
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return _string;
|
||||
}
|
||||
|
||||
String get parsedString {
|
||||
if (_parseCache == null) {
|
||||
_parseCache = EmojiParser().emojify(this._string);
|
||||
}
|
||||
|
||||
return _parseCache;
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ import 'package:comunic/enums/post_kind.dart';
|
||||
import 'package:comunic/enums/post_visibility_level.dart';
|
||||
import 'package:comunic/enums/user_access_levels.dart';
|
||||
import 'package:comunic/lists/comments_list.dart';
|
||||
import 'package:comunic/models/displayed_content.dart';
|
||||
import 'package:comunic/models/like_element.dart';
|
||||
import 'package:comunic/models/survey.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
@ -17,7 +18,7 @@ class Post implements LikeElement {
|
||||
final int userPageID;
|
||||
final int groupID;
|
||||
final int timeSent;
|
||||
String content;
|
||||
DisplayedString content;
|
||||
PostVisibilityLevel visibilityLevel;
|
||||
final PostKind kind;
|
||||
final int fileSize;
|
||||
@ -73,7 +74,7 @@ class Post implements LikeElement {
|
||||
|
||||
bool get isGroupPost => groupID != null && groupID > 0;
|
||||
|
||||
bool get hasContent => content != null;
|
||||
bool get hasContent => content != null && !content.isNull;
|
||||
|
||||
bool get hasComments => comments != null;
|
||||
|
||||
|
@ -521,7 +521,7 @@ class _PostTileState extends State<PostTile> {
|
||||
context: context,
|
||||
title: tr("Update comment content"),
|
||||
message: tr("New content:"),
|
||||
defaultValue: comment.content,
|
||||
defaultValue: comment.content.isNull ? "" : comment.content.content,
|
||||
hint: tr("New content..."),
|
||||
);
|
||||
|
||||
@ -529,7 +529,7 @@ class _PostTileState extends State<PostTile> {
|
||||
return showSimpleSnack(context, tr("Could not update comment content!"));
|
||||
|
||||
setState(() {
|
||||
comment.content = newContent;
|
||||
comment.content.content = newContent;
|
||||
});
|
||||
}
|
||||
|
||||
@ -591,7 +591,7 @@ class _PostTileState extends State<PostTile> {
|
||||
context: context,
|
||||
title: tr("Update post content"),
|
||||
message: tr("Please enter message content: "),
|
||||
defaultValue: widget.post.content == null ? "" : widget.post.content,
|
||||
defaultValue: widget.post.content.isNull == null ? "" : widget.post.content.content,
|
||||
hint: tr("Post content"),
|
||||
);
|
||||
|
||||
@ -602,7 +602,7 @@ class _PostTileState extends State<PostTile> {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() => widget.post.content = newContent);
|
||||
setState(() => widget.post.content.content = newContent);
|
||||
}
|
||||
|
||||
/// Perform the deletion of the post
|
||||
|
@ -1,8 +1,8 @@
|
||||
import 'package:comunic/models/displayed_content.dart';
|
||||
import 'package:comunic/utils/bbcode_parser.dart';
|
||||
import 'package:comunic/utils/input_utils.dart';
|
||||
import 'package:comunic/utils/navigation_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_emoji/flutter_emoji.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
/// Text widget
|
||||
@ -11,8 +11,8 @@ import 'package:url_launcher/url_launcher.dart';
|
||||
///
|
||||
/// @author Pierre Hubert
|
||||
|
||||
class TextWidget extends StatefulWidget {
|
||||
final String content;
|
||||
class TextWidget extends StatelessWidget {
|
||||
final DisplayedString content;
|
||||
final bool parseBBcode;
|
||||
final TextStyle style;
|
||||
|
||||
@ -25,38 +25,28 @@ class TextWidget extends StatefulWidget {
|
||||
assert(parseBBcode != null),
|
||||
super(key: key);
|
||||
|
||||
@override
|
||||
_TextWidgetState createState() => _TextWidgetState();
|
||||
}
|
||||
|
||||
class _TextWidgetState extends State<TextWidget> {
|
||||
Widget _cache;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_cache == null) _cache = doBuild();
|
||||
if (this.content.isNull || this.content.isEmpty) return Text("");
|
||||
|
||||
return _cache;
|
||||
}
|
||||
|
||||
Widget doBuild() {
|
||||
var content = EmojiParser().emojify(this.widget.content);
|
||||
var content = this.content.parsedString;
|
||||
|
||||
// Parse BBcode
|
||||
if (this.widget.parseBBcode)
|
||||
if (parseBBcode)
|
||||
return BBCodeParsedWidget(
|
||||
text: content,
|
||||
parseCallback: (style, text) => _parseLinks(text, style),
|
||||
parseCallback: (style, text) => _parseLinks(context, text, style),
|
||||
);
|
||||
|
||||
// Just parse link
|
||||
return RichText(
|
||||
text: TextSpan(children: _parseLinks(content, widget.style)),
|
||||
text: TextSpan(children: _parseLinks(context, content, style)),
|
||||
);
|
||||
}
|
||||
|
||||
/// Sub parse function
|
||||
List<InlineSpan> _parseLinks(String text, TextStyle style) {
|
||||
List<InlineSpan> _parseLinks(
|
||||
BuildContext context, String text, TextStyle style) {
|
||||
if (style == null) style = TextStyle();
|
||||
|
||||
var buff = StringBuffer();
|
||||
|
Loading…
Reference in New Issue
Block a user