Update slack
This commit is contained in:
parent
cca078eb43
commit
21683b88bb
5 changed files with 164 additions and 6 deletions
|
|
@ -6,6 +6,7 @@ part 'app_data.g.dart';
|
|||
class AppData {
|
||||
AppData();
|
||||
|
||||
late String name;
|
||||
late String version;
|
||||
late String gitHash;
|
||||
late String buildDate;
|
||||
|
|
|
|||
|
|
@ -7,11 +7,13 @@ part of 'app_data.dart';
|
|||
// **************************************************************************
|
||||
|
||||
AppData _$AppDataFromJson(Map<String, dynamic> json) => AppData()
|
||||
..name = json['name'] as String
|
||||
..version = json['version'] as String
|
||||
..gitHash = json['gitHash'] as String
|
||||
..buildDate = json['buildDate'] as String;
|
||||
|
||||
Map<String, dynamic> _$AppDataToJson(AppData instance) => <String, dynamic>{
|
||||
'name': instance.name,
|
||||
'version': instance.version,
|
||||
'gitHash': instance.gitHash,
|
||||
'buildDate': instance.buildDate,
|
||||
|
|
|
|||
|
|
@ -9,6 +9,10 @@ import 'package:http/http.dart';
|
|||
import 'package:http_parser/src/media_type.dart';
|
||||
part 'slack_data.g.dart';
|
||||
|
||||
enum SlackBlockType { header, section }
|
||||
|
||||
enum SlackTextType { mrkdwn, plain_text }
|
||||
|
||||
enum SlackActionType { button, select }
|
||||
|
||||
enum SlackActionStyle { danger, primary }
|
||||
|
|
@ -16,7 +20,16 @@ enum SlackActionStyle { danger, primary }
|
|||
@JsonSerializable()
|
||||
class DataSlack {
|
||||
String? message;
|
||||
late List<SlackAttachment> attachments;
|
||||
List<SlackBlock> blocks = [];
|
||||
List<SlackAttachment> attachments = [];
|
||||
|
||||
String getBlocks() {
|
||||
var list = [];
|
||||
for (var item in blocks) {
|
||||
list.add(item.toJson());
|
||||
}
|
||||
return jsonEncode(list);
|
||||
}
|
||||
|
||||
String getAttachments() {
|
||||
var list = [];
|
||||
|
|
@ -33,6 +46,71 @@ class DataSlack {
|
|||
Map<String, dynamic> toJson() => _$DataSlackToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class SlackBlock {
|
||||
late SlackBlockType type;
|
||||
|
||||
SlackBlock();
|
||||
|
||||
factory SlackBlock.fromJson(Map<String, dynamic> json) =>
|
||||
_$SlackBlockFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$SlackBlockToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class SlackBlockHeader extends SlackBlock {
|
||||
late SlackBlockText text;
|
||||
|
||||
SlackBlockHeader() {
|
||||
super.type = SlackBlockType.header;
|
||||
text = SlackBlockText();
|
||||
text.type = SlackTextType.plain_text;
|
||||
}
|
||||
|
||||
factory SlackBlockHeader.fromJson(Map<String, dynamic> json) =>
|
||||
_$SlackBlockHeaderFromJson(json);
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$SlackBlockHeaderToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class SlackBlockSection extends SlackBlock {
|
||||
List<SlackBlockSectionField> fields = [];
|
||||
|
||||
SlackBlockSection() {
|
||||
super.type = SlackBlockType.section;
|
||||
}
|
||||
|
||||
factory SlackBlockSection.fromJson(Map<String, dynamic> json) =>
|
||||
_$SlackBlockSectionFromJson(json);
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$SlackBlockSectionToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class SlackBlockSectionField {
|
||||
SlackTextType type = SlackTextType.mrkdwn;
|
||||
String? text;
|
||||
|
||||
SlackBlockSectionField();
|
||||
|
||||
factory SlackBlockSectionField.fromJson(Map<String, dynamic> json) =>
|
||||
_$SlackBlockSectionFieldFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$SlackBlockSectionFieldToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class SlackBlockText {
|
||||
SlackTextType type = SlackTextType.mrkdwn;
|
||||
String? text;
|
||||
|
||||
SlackBlockText();
|
||||
|
||||
factory SlackBlockText.fromJson(Map<String, dynamic> json) =>
|
||||
_$SlackBlockTextFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$SlackBlockTextToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class SlackAttachment {
|
||||
String? fallback;
|
||||
|
|
|
|||
|
|
@ -8,15 +8,86 @@ part of 'slack_data.dart';
|
|||
|
||||
DataSlack _$DataSlackFromJson(Map<String, dynamic> json) => DataSlack()
|
||||
..message = json['message'] as String?
|
||||
..blocks = (json['blocks'] as List<dynamic>)
|
||||
.map((e) => SlackBlock.fromJson(e as Map<String, dynamic>))
|
||||
.toList()
|
||||
..attachments = (json['attachments'] as List<dynamic>)
|
||||
.map((e) => SlackAttachment.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
|
||||
Map<String, dynamic> _$DataSlackToJson(DataSlack instance) => <String, dynamic>{
|
||||
'message': instance.message,
|
||||
'blocks': instance.blocks,
|
||||
'attachments': instance.attachments,
|
||||
};
|
||||
|
||||
SlackBlock _$SlackBlockFromJson(Map<String, dynamic> json) =>
|
||||
SlackBlock()..type = $enumDecode(_$SlackBlockTypeEnumMap, json['type']);
|
||||
|
||||
Map<String, dynamic> _$SlackBlockToJson(SlackBlock instance) =>
|
||||
<String, dynamic>{
|
||||
'type': _$SlackBlockTypeEnumMap[instance.type]!,
|
||||
};
|
||||
|
||||
const _$SlackBlockTypeEnumMap = {
|
||||
SlackBlockType.header: 'header',
|
||||
SlackBlockType.section: 'section',
|
||||
};
|
||||
|
||||
SlackBlockHeader _$SlackBlockHeaderFromJson(Map<String, dynamic> json) =>
|
||||
SlackBlockHeader()
|
||||
..type = $enumDecode(_$SlackBlockTypeEnumMap, json['type'])
|
||||
..text = SlackBlockText.fromJson(json['text'] as Map<String, dynamic>);
|
||||
|
||||
Map<String, dynamic> _$SlackBlockHeaderToJson(SlackBlockHeader instance) =>
|
||||
<String, dynamic>{
|
||||
'type': _$SlackBlockTypeEnumMap[instance.type]!,
|
||||
'text': instance.text,
|
||||
};
|
||||
|
||||
SlackBlockSection _$SlackBlockSectionFromJson(Map<String, dynamic> json) =>
|
||||
SlackBlockSection()
|
||||
..type = $enumDecode(_$SlackBlockTypeEnumMap, json['type'])
|
||||
..fields = (json['fields'] as List<dynamic>)
|
||||
.map(
|
||||
(e) => SlackBlockSectionField.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
|
||||
Map<String, dynamic> _$SlackBlockSectionToJson(SlackBlockSection instance) =>
|
||||
<String, dynamic>{
|
||||
'type': _$SlackBlockTypeEnumMap[instance.type]!,
|
||||
'fields': instance.fields,
|
||||
};
|
||||
|
||||
SlackBlockSectionField _$SlackBlockSectionFieldFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
SlackBlockSectionField()
|
||||
..type = $enumDecode(_$SlackTextTypeEnumMap, json['type'])
|
||||
..text = json['text'] as String?;
|
||||
|
||||
Map<String, dynamic> _$SlackBlockSectionFieldToJson(
|
||||
SlackBlockSectionField instance) =>
|
||||
<String, dynamic>{
|
||||
'type': _$SlackTextTypeEnumMap[instance.type]!,
|
||||
'text': instance.text,
|
||||
};
|
||||
|
||||
const _$SlackTextTypeEnumMap = {
|
||||
SlackTextType.mrkdwn: 'mrkdwn',
|
||||
SlackTextType.plain_text: 'plain_text',
|
||||
};
|
||||
|
||||
SlackBlockText _$SlackBlockTextFromJson(Map<String, dynamic> json) =>
|
||||
SlackBlockText()
|
||||
..type = $enumDecode(_$SlackTextTypeEnumMap, json['type'])
|
||||
..text = json['text'] as String?;
|
||||
|
||||
Map<String, dynamic> _$SlackBlockTextToJson(SlackBlockText instance) =>
|
||||
<String, dynamic>{
|
||||
'type': _$SlackTextTypeEnumMap[instance.type]!,
|
||||
'text': instance.text,
|
||||
};
|
||||
|
||||
SlackAttachment _$SlackAttachmentFromJson(Map<String, dynamic> json) =>
|
||||
SlackAttachment()
|
||||
..fallback = json['fallback'] as String?
|
||||
|
|
|
|||
|
|
@ -39,8 +39,15 @@ class SlackSender {
|
|||
? ''
|
||||
: Uri.encodeComponent(' ${message.message!}');
|
||||
buffer.write('&text=$targetUser$sendMessage');
|
||||
buffer
|
||||
.write('&attachments=${Uri.encodeComponent(message.getAttachments())}');
|
||||
if (message.blocks.isNotEmpty) {
|
||||
var json = message.getBlocks();
|
||||
print(json);
|
||||
buffer.write('&blocks=${Uri.encodeComponent(message.getBlocks())}');
|
||||
}
|
||||
if (message.attachments.isNotEmpty) {
|
||||
buffer.write(
|
||||
'&attachments=${Uri.encodeComponent(message.getAttachments())}');
|
||||
}
|
||||
buffer.write('&link_names=true');
|
||||
print(buffer.toString());
|
||||
return buffer.toString();
|
||||
|
|
@ -152,7 +159,6 @@ class SlackSender {
|
|||
buildType == SlackBuildType.android ? ":android1: " : ":ios0: ";
|
||||
String osColor = buildType == SlackBuildType.ios ? "#ED145B" : "#81CA3F";
|
||||
var message = DataSlack();
|
||||
message.attachments = [];
|
||||
var attachments = message.attachments;
|
||||
|
||||
var attachment = SlackAttachment();
|
||||
|
|
@ -180,7 +186,7 @@ class SlackSender {
|
|||
}
|
||||
|
||||
String buildTypeToString(SlackBuildType type) {
|
||||
var typeStr = type.toString().replaceAll('SlackBuildType.', '');
|
||||
return toPascal(typeStr);
|
||||
var typeStr = type.name;
|
||||
return typeStr == 'ios' ? 'iOS' : toPascal(typeStr);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue