diff --git a/lib/models/gitlab.dart b/lib/models/gitlab.dart index f460350..812ec4b 100644 --- a/lib/models/gitlab.dart +++ b/lib/models/gitlab.dart @@ -63,7 +63,7 @@ class GitlabTodoTarget { String title; GitlabUser author; String description; - String createdAt; + DateTime createdAt; GitlabTodoTarget(); @@ -75,9 +75,9 @@ class GitlabTodoTarget { class GitlabIssueNote { GitlabUser author; String body; - + bool system; + DateTime createdAt; GitlabIssueNote(); - factory GitlabIssueNote.fromJson(Map json) => _$GitlabIssueNoteFromJson(json); } diff --git a/lib/models/gitlab.g.dart b/lib/models/gitlab.g.dart index e442b3e..29a904b 100644 --- a/lib/models/gitlab.g.dart +++ b/lib/models/gitlab.g.dart @@ -99,7 +99,9 @@ GitlabTodoTarget _$GitlabTodoTargetFromJson(Map json) { ? null : GitlabUser.fromJson(json['author'] as Map) ..description = json['description'] as String - ..createdAt = json['created_at'] as String; + ..createdAt = json['created_at'] == null + ? null + : DateTime.parse(json['created_at'] as String); } Map _$GitlabTodoTargetToJson(GitlabTodoTarget instance) => @@ -109,7 +111,7 @@ Map _$GitlabTodoTargetToJson(GitlabTodoTarget instance) => 'title': instance.title, 'author': instance.author, 'description': instance.description, - 'created_at': instance.createdAt, + 'created_at': instance.createdAt?.toIso8601String(), }; GitlabIssueNote _$GitlabIssueNoteFromJson(Map json) { @@ -117,13 +119,19 @@ GitlabIssueNote _$GitlabIssueNoteFromJson(Map json) { ..author = json['author'] == null ? null : GitlabUser.fromJson(json['author'] as Map) - ..body = json['body'] as String; + ..body = json['body'] as String + ..system = json['system'] as bool + ..createdAt = json['created_at'] == null + ? null + : DateTime.parse(json['created_at'] as String); } Map _$GitlabIssueNoteToJson(GitlabIssueNote instance) => { 'author': instance.author, 'body': instance.body, + 'system': instance.system, + 'created_at': instance.createdAt?.toIso8601String(), }; GitlabProject _$GitlabProjectFromJson(Map json) { diff --git a/lib/screens/gitlab_issue.dart b/lib/screens/gitlab_issue.dart index d5cba39..316efcf 100644 --- a/lib/screens/gitlab_issue.dart +++ b/lib/screens/gitlab_issue.dart @@ -3,6 +3,7 @@ import 'package:git_touch/models/gitlab.dart'; import 'package:git_touch/scaffolds/refresh_stateful.dart'; import 'package:git_touch/utils/utils.dart'; import 'package:git_touch/widgets/avatar.dart'; +import 'package:git_touch/widgets/comment_item.dart'; import 'package:git_touch/widgets/markdown_view.dart'; import 'package:provider/provider.dart'; import 'package:git_touch/models/auth.dart'; @@ -37,7 +38,7 @@ class GitlabIssueScreen extends StatelessWidget { Provider.of(context) .fetchGitlab('/projects/$projectId/$type/$iid'), Provider.of(context) - .fetchGitlab('/projects/$projectId/$type/$iid/notes'), + .fetchGitlab('/projects/$projectId/$type/$iid/notes?sort=asc'), Provider.of(context) .fetchGitlab('/projects/$projectId/$type/$iid/award_emoji'), ]); @@ -56,46 +57,45 @@ class GitlabIssueScreen extends StatelessWidget { children: [ Container( padding: CommonStyle.padding, - child: Column( - children: [ - Text(issue.title), - Row( - children: [ - Avatar( - url: issue.author.avatarUrl, - linkUrl: '/user/${issue.author}', - ), - Expanded( - child: Text(issue.description), - ), - ], - ), - Text(timeago.format(DateTime.parse(issue.createdAt))) - ], + child: CommentItem( + avatar: Avatar( + url: issue.author.avatarUrl, + linkUrl: '/gitlab/user/${issue.author.id}', + ), + createdAt: issue.createdAt, + body: issue.description, + login: issue.author.username, ), ), CommonStyle.border, Column( - children: notes.map((note) { - return Container( - padding: CommonStyle.padding, - child: Column( - children: [ - Row( - children: [ - Avatar(url: note.author.avatarUrl), - Expanded( - child: Column( - children: [Text(note.author.name)], - ), - ) - ], + children: [ + for (var note in notes) + if (note.system) + Container( + padding: CommonStyle.padding, + child: Text.rich( + TextSpan(children: [ + WidgetSpan(child: Avatar(url: note.author.avatarUrl)), + TextSpan(text: note.author.name), + TextSpan(text: note.body), + ]), ), - MarkdownView(note.body), - ], - ), - ); - }).toList(), + ) + else + Container( + padding: CommonStyle.padding, + child: CommentItem( + avatar: Avatar( + url: note.author.avatarUrl, + linkUrl: '/gitlab/user/${note.author.id}', + ), + createdAt: note.createdAt, + body: note.body, + login: note.author.username, + ), + ) + ], ) ], ); diff --git a/lib/screens/gitlab_user.dart b/lib/screens/gitlab_user.dart index 6df4359..982ace5 100644 --- a/lib/screens/gitlab_user.dart +++ b/lib/screens/gitlab_user.dart @@ -30,13 +30,14 @@ class GitlabUserScreen extends StatelessWidget { fetchData: () async { final auth = Provider.of(context); final _id = id ?? auth.activeAccount.gitlabId; - final v0 = await auth.fetchGitlab('/users/$_id'); - final user = GitlabUser.fromJson(v0); - final v1 = await auth.fetchGitlab('/users/$_id/projects'); - final projects = - (v1 as List).map((v) => GitlabUserProject.fromJson(v)).toList(); - - return Tuple2(user, projects); + final res = await Future.wait([ + auth.fetchGitlab('/users/$_id'), + auth.fetchGitlab('/users/$_id/projects'), + ]); + return Tuple2( + GitlabUser.fromJson(res[0]), + [for (var v in res[1]) GitlabUserProject.fromJson(v)], + ); }, action: isViewer ? ActionEntry(