Skip to content

Commit

Permalink
Merge pull request #22 from knocklabs/matgar26/fix-text-block
Browse files Browse the repository at this point in the history
Add rendered field to TextContentBlock and update tests
  • Loading branch information
matgar26 authored May 10, 2024
2 parents 668f5cb + 46cbb92 commit 9e4781b
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 31 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.5

- fix: add `rendered` property to `TextContentBlock`

## 0.1.4

- fix: ensure preferences can handle both conditions and channel types
Expand Down
29 changes: 22 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@ A client-side Flutter library to interact with user-facing Knock features, such
See the [documentation](https://docs.knock.app/notification-feeds/bring-your-own-ui) for usage examples.

### iOS

To receive push notifications via APNS (Apple Push Notification Service) you will need to enable the push notification capability in your application. You can find instructions on how to do this at https://developer.apple.com/documentation/usernotifications/registering_your_app_with_apns.

#### Example App

To test APNS integration in the example app, you will need to open `example/ios` in Xcode and select your Development Team and choose Bundle Identifier unique to you.

### Android
To receive push notifications via FCM (Firebase Cloud Messaging) you will need to add Firebase and related dependencies to your application. You can find instructions on how to do this at: https://firebase.google.com/docs/android/setup.

To receive push notifications via FCM (Firebase Cloud Messaging) you will need to add Firebase and related dependencies to your application. You can find instructions on how to do this at: https://firebase.google.com/docs/android/setup.

Note: If you've added Firebase to your Flutter app (https://firebase.google.com/docs/flutter/setup?platform=android), you should only need to add a dependency on `firebase_messaging` (https://firebase.google.com/docs/cloud-messaging/flutter/client).

1) In your project's `android/build.gradle` add:
1. In your project's `android/build.gradle` add:

```
buildscript {
dependencies {
Expand All @@ -30,7 +34,8 @@ buildscript {
}
```

2) In your project's `android/app/build.gradle` add:
2. In your project's `android/app/build.gradle` add:

```
plugins {
...
Expand All @@ -46,23 +51,33 @@ dependencies {
}
```

3) Add `google-services.json` provided by your Firebase project to `app/google-services.json`.
3. Add `google-services.json` provided by your Firebase project to `app/google-services.json`.

#### Example App

To test FCM integration in the example app, you will need to create a Firebase project and add an appropriate `google-services.json` file to `example/app/google-services.json`.

## Package Development

### Code generation
Code generation is limited to supporting JSON serialization/deserization of API messages. If you need to

Code generation is limited to supporting JSON serialization/deserization of API messages. If you need to
adust the generated code you will want to run this command from the top level directory.

```
dart run build_runner build --delete-conflicting-outputs
flutter pub run build_runner build
```

If you need to update the generated platform channel messages you will want to run this command from the top level directory.

```
flutter pub run pigeon --input pigeons/messages.dart
```

Note: Generated files are checked into version control because they are part of the released packaged.
Note: Generated files are checked into version control because they are part of the released packaged.

### Release (Internal)

Manually update changelog.md file.
Create PR
After your PR is merged, run /release status knock-flutter in slack to start the release process
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ class _FeedItemWidget extends StatelessWidget {
'p': Style(padding: HtmlPaddings.zero, margin: Margins.zero)
},
),
text: (name, content) => Html(
text: (name, content, rendered) => Html(
data: content,
style: {
'body': Style(margin: Margins.zero),
Expand Down
1 change: 1 addition & 0 deletions lib/src/model/feed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class ContentBlock with _$ContentBlock {
const factory ContentBlock.text({
required String name,
required String content,
required String rendered,
}) = TextContentBlock;

const factory ContentBlock.buttonSet({
Expand Down
60 changes: 39 additions & 21 deletions lib/src/model/feed.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1190,22 +1190,23 @@ mixin _$ContentBlock {
TResult when<TResult extends Object?>({
required TResult Function(String name, String content, String rendered)
markdown,
required TResult Function(String name, String content) text,
required TResult Function(String name, String content, String rendered)
text,
required TResult Function(String name, List<BlockActionButton> buttons)
buttonSet,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(String name, String content, String rendered)? markdown,
TResult? Function(String name, String content)? text,
TResult? Function(String name, String content, String rendered)? text,
TResult? Function(String name, List<BlockActionButton> buttons)? buttonSet,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(String name, String content, String rendered)? markdown,
TResult Function(String name, String content)? text,
TResult Function(String name, String content, String rendered)? text,
TResult Function(String name, List<BlockActionButton> buttons)? buttonSet,
required TResult orElse(),
}) =>
Expand Down Expand Up @@ -1371,7 +1372,8 @@ class _$MarkdownContentBlockImpl extends MarkdownContentBlock {
TResult when<TResult extends Object?>({
required TResult Function(String name, String content, String rendered)
markdown,
required TResult Function(String name, String content) text,
required TResult Function(String name, String content, String rendered)
text,
required TResult Function(String name, List<BlockActionButton> buttons)
buttonSet,
}) {
Expand All @@ -1382,7 +1384,7 @@ class _$MarkdownContentBlockImpl extends MarkdownContentBlock {
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(String name, String content, String rendered)? markdown,
TResult? Function(String name, String content)? text,
TResult? Function(String name, String content, String rendered)? text,
TResult? Function(String name, List<BlockActionButton> buttons)? buttonSet,
}) {
return markdown?.call(name, content, rendered);
Expand All @@ -1392,7 +1394,7 @@ class _$MarkdownContentBlockImpl extends MarkdownContentBlock {
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(String name, String content, String rendered)? markdown,
TResult Function(String name, String content)? text,
TResult Function(String name, String content, String rendered)? text,
TResult Function(String name, List<BlockActionButton> buttons)? buttonSet,
required TResult orElse(),
}) {
Expand Down Expand Up @@ -1472,7 +1474,7 @@ abstract class _$$TextContentBlockImplCopyWith<$Res>
__$$TextContentBlockImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({String name, String content});
$Res call({String name, String content, String rendered});
}

/// @nodoc
Expand All @@ -1488,6 +1490,7 @@ class __$$TextContentBlockImplCopyWithImpl<$Res>
$Res call({
Object? name = null,
Object? content = null,
Object? rendered = null,
}) {
return _then(_$TextContentBlockImpl(
name: null == name
Expand All @@ -1498,6 +1501,10 @@ class __$$TextContentBlockImplCopyWithImpl<$Res>
? _value.content
: content // ignore: cast_nullable_to_non_nullable
as String,
rendered: null == rendered
? _value.rendered
: rendered // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
Expand All @@ -1506,7 +1513,10 @@ class __$$TextContentBlockImplCopyWithImpl<$Res>
@JsonSerializable()
class _$TextContentBlockImpl extends TextContentBlock {
const _$TextContentBlockImpl(
{required this.name, required this.content, final String? $type})
{required this.name,
required this.content,
required this.rendered,
final String? $type})
: $type = $type ?? 'text',
super._();

Expand All @@ -1517,13 +1527,15 @@ class _$TextContentBlockImpl extends TextContentBlock {
final String name;
@override
final String content;
@override
final String rendered;

@JsonKey(name: 'runtimeType')
final String $type;

@override
String toString() {
return 'ContentBlock.text(name: $name, content: $content)';
return 'ContentBlock.text(name: $name, content: $content, rendered: $rendered)';
}

@override
Expand All @@ -1532,12 +1544,14 @@ class _$TextContentBlockImpl extends TextContentBlock {
(other.runtimeType == runtimeType &&
other is _$TextContentBlockImpl &&
(identical(other.name, name) || other.name == name) &&
(identical(other.content, content) || other.content == content));
(identical(other.content, content) || other.content == content) &&
(identical(other.rendered, rendered) ||
other.rendered == rendered));
}

@JsonKey(ignore: true)
@override
int get hashCode => Object.hash(runtimeType, name, content);
int get hashCode => Object.hash(runtimeType, name, content, rendered);

@JsonKey(ignore: true)
@override
Expand All @@ -1551,33 +1565,34 @@ class _$TextContentBlockImpl extends TextContentBlock {
TResult when<TResult extends Object?>({
required TResult Function(String name, String content, String rendered)
markdown,
required TResult Function(String name, String content) text,
required TResult Function(String name, String content, String rendered)
text,
required TResult Function(String name, List<BlockActionButton> buttons)
buttonSet,
}) {
return text(name, content);
return text(name, content, rendered);
}

@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(String name, String content, String rendered)? markdown,
TResult? Function(String name, String content)? text,
TResult? Function(String name, String content, String rendered)? text,
TResult? Function(String name, List<BlockActionButton> buttons)? buttonSet,
}) {
return text?.call(name, content);
return text?.call(name, content, rendered);
}

@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(String name, String content, String rendered)? markdown,
TResult Function(String name, String content)? text,
TResult Function(String name, String content, String rendered)? text,
TResult Function(String name, List<BlockActionButton> buttons)? buttonSet,
required TResult orElse(),
}) {
if (text != null) {
return text(name, content);
return text(name, content, rendered);
}
return orElse();
}
Expand Down Expand Up @@ -1627,7 +1642,8 @@ class _$TextContentBlockImpl extends TextContentBlock {
abstract class TextContentBlock extends ContentBlock {
const factory TextContentBlock(
{required final String name,
required final String content}) = _$TextContentBlockImpl;
required final String content,
required final String rendered}) = _$TextContentBlockImpl;
const TextContentBlock._() : super._();

factory TextContentBlock.fromJson(Map<String, dynamic> json) =
Expand All @@ -1636,6 +1652,7 @@ abstract class TextContentBlock extends ContentBlock {
@override
String get name;
String get content;
String get rendered;
@override
@JsonKey(ignore: true)
_$$TextContentBlockImplCopyWith<_$TextContentBlockImpl> get copyWith =>
Expand Down Expand Up @@ -1739,7 +1756,8 @@ class _$ButtonSetContentBlockImpl extends ButtonSetContentBlock {
TResult when<TResult extends Object?>({
required TResult Function(String name, String content, String rendered)
markdown,
required TResult Function(String name, String content) text,
required TResult Function(String name, String content, String rendered)
text,
required TResult Function(String name, List<BlockActionButton> buttons)
buttonSet,
}) {
Expand All @@ -1750,7 +1768,7 @@ class _$ButtonSetContentBlockImpl extends ButtonSetContentBlock {
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(String name, String content, String rendered)? markdown,
TResult? Function(String name, String content)? text,
TResult? Function(String name, String content, String rendered)? text,
TResult? Function(String name, List<BlockActionButton> buttons)? buttonSet,
}) {
return buttonSet?.call(name, buttons);
Expand All @@ -1760,7 +1778,7 @@ class _$ButtonSetContentBlockImpl extends ButtonSetContentBlock {
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(String name, String content, String rendered)? markdown,
TResult Function(String name, String content)? text,
TResult Function(String name, String content, String rendered)? text,
TResult Function(String name, List<BlockActionButton> buttons)? buttonSet,
required TResult orElse(),
}) {
Expand Down
2 changes: 2 additions & 0 deletions lib/src/model/feed.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions test/src/model/feed_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ void main() {
"type": "markdown"
},
{
"content": "{{ vars.app_url }}",
"content": "https://pavecommute.app/home/challenges/history/summary/{{challengeId}}?p=1",
"name": "action_url",
"rendered": "https://pavecommute.app/home/challenges/history/summary/3?p=1",
"type": "text"
},
{
Expand Down Expand Up @@ -306,8 +307,11 @@ void main() {
'<p>Hey <strong>Ellie</strong> - John Hammond added a new comment.</p>',
),
ContentBlock.text(
content: '{{ vars.app_url }}',
content:
'https://pavecommute.app/home/challenges/history/summary/{{challengeId}}?p=1',
name: 'action_url',
rendered:
'https://pavecommute.app/home/challenges/history/summary/3?p=1',
),
ContentBlock.buttonSet(
name: 'actions',
Expand Down

0 comments on commit 9e4781b

Please sign in to comment.