Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/stream_feeds/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
## NEXT RELEASE
- Fix for updating poll votes from web socket events.

## 0.1.0
- Initial release of Feeds V3 SDK for Dart and Flutter.
2 changes: 2 additions & 0 deletions packages/stream_feeds/lib/src/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export 'models/feed_member_request_data.dart';
export 'models/feeds_config.dart';
export 'models/follow_data.dart';
export 'models/poll_data.dart';
export 'models/poll_option_data.dart';
export 'models/poll_vote_data.dart';
export 'models/push_notifications_config.dart';
export 'models/request/activity_add_comment_request.dart'
show ActivityAddCommentRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import '../../generated/api/models.dart';
core.WsEvent? pollAnswerCastedFeedEventResolver(core.WsEvent event) {
if (event is PollVoteCastedFeedEvent) {
final pollVote = event.pollVote;
if (pollVote.isAnswer ?? false) return null;
if (!(pollVote.isAnswer ?? false)) return null;

// If the event is a PollVoteCastedFeedEvent and the pollVote indicates
// an answer was casted, we can resolve it to a PollAnswerCastedFeedEvent.
Expand All @@ -24,7 +24,7 @@ core.WsEvent? pollAnswerCastedFeedEventResolver(core.WsEvent event) {

if (event is PollVoteChangedFeedEvent) {
final pollVote = event.pollVote;
if (pollVote.isAnswer ?? false) return null;
if (!(pollVote.isAnswer ?? false)) return null;

// If the event is a PollVoteChangedFeedEvent and the pollVote indicates
// an answer was casted, we can resolve it to a PollAnswerCastedFeedEvent.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import '../../generated/api/models.dart';
core.WsEvent? pollAnswerRemovedFeedEventResolver(core.WsEvent event) {
if (event is PollVoteRemovedFeedEvent) {
final pollVote = event.pollVote;
if (pollVote.isAnswer ?? false) return null;
if (!(pollVote.isAnswer ?? false)) return null;

// If the event is a PollVoteRemovedFeedEvent and the poll vote indicates an
// answer was removed, we can resolve it to a PollAnswerRemovedFeedEvent.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// ignore_for_file: avoid_redundant_argument_values

import 'package:stream_feeds/src/resolvers/resolvers.dart';
import 'package:stream_feeds/stream_feeds.dart';
import 'package:test/test.dart';

void main() {
group('pollAnswerCastedFeedEventResolver PollVoteCastedFeedEvent', () {
test('resolves Answer when answer is true', () {
final event = createPollVoteCastedFeedEvent(isAnswer: true);
final resolvedEvent = pollAnswerCastedFeedEventResolver(event);
expect(resolvedEvent, isA<PollAnswerCastedFeedEvent>());
});

test('does not resolve Answer when answer is false', () {
final event = createPollVoteCastedFeedEvent(isAnswer: false);
final resolvedEvent = pollAnswerCastedFeedEventResolver(event);
expect(resolvedEvent, isNull);
});
test('does not resolve Answer when answer is null', () {
final event = createPollVoteCastedFeedEvent(isAnswer: null);
final resolvedEvent = pollAnswerCastedFeedEventResolver(event);
expect(resolvedEvent, isNull);
});
});
group('pollAnswerCastedFeedEventResolver PollVoteChangedFeedEvent', () {
test('resolves Answer when answer is true', () {
final event = createPollVoteChangedFeedEvent(isAnswer: true);
final resolvedEvent = pollAnswerCastedFeedEventResolver(event);
expect(resolvedEvent, isA<PollAnswerCastedFeedEvent>());
});
test('does not resolve Answer when answer is false', () {
final event = createPollVoteChangedFeedEvent(isAnswer: false);
final resolvedEvent = pollAnswerCastedFeedEventResolver(event);
expect(resolvedEvent, isNull);
});
test('does not resolve Answer when answer is null', () {
final event = createPollVoteChangedFeedEvent(isAnswer: null);
final resolvedEvent = pollAnswerCastedFeedEventResolver(event);
expect(resolvedEvent, isNull);
});
});
}

PollVoteCastedFeedEvent createPollVoteCastedFeedEvent({bool? isAnswer}) {
return PollVoteCastedFeedEvent(
createdAt: DateTime.now(),
custom: const {},
fid: '1',
poll: PollResponseData(
createdAt: DateTime.now(),
updatedAt: DateTime.now(),
id: '1',
allowAnswers: true,
allowUserSuggestedOptions: true,
answersCount: 1,
createdById: '1',
custom: const {},
description: '1',
enforceUniqueVote: true,
latestAnswers: const [],
latestVotesByOption: const {},
maxVotesAllowed: 1,
name: '1',
options: const [],
ownVotes: const [],
voteCount: 1,
voteCountsByOption: const {},
votingVisibility: '1',
),
type: 'poll.vote.casted',
pollVote: PollVoteResponseData(
createdAt: DateTime.now(),
updatedAt: DateTime.now(),
id: '1',
optionId: '1',
pollId: '1',
isAnswer: isAnswer,
),
);
}

PollVoteChangedFeedEvent createPollVoteChangedFeedEvent({bool? isAnswer}) {
return PollVoteChangedFeedEvent(
createdAt: DateTime.now(),
custom: const {},
fid: '1',
poll: PollResponseData(
createdAt: DateTime.now(),
updatedAt: DateTime.now(),
id: '1',
allowAnswers: true,
allowUserSuggestedOptions: true,
answersCount: 1,
createdById: '1',
custom: const {},
description: '1',
enforceUniqueVote: true,
latestAnswers: const [],
latestVotesByOption: const {},
maxVotesAllowed: 1,
name: '1',
options: const [],
ownVotes: const [],
voteCount: 1,
voteCountsByOption: const {},
votingVisibility: '1',
),
pollVote: PollVoteResponseData(
createdAt: DateTime.now(),
updatedAt: DateTime.now(),
id: '1',
optionId: '1',
pollId: '1',
isAnswer: isAnswer,
),
type: 'poll.vote.changed',
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// ignore_for_file: avoid_redundant_argument_values

import 'package:stream_feeds/src/resolvers/resolvers.dart';
import 'package:stream_feeds/stream_feeds.dart';
import 'package:test/test.dart';

void main() {
group('pollAnswerRemovedFeedEventResolver', () {
test('resolves Answer when answer is true', () {
final event = createPollVoteRemovedFeedEvent(isAnswer: true);
final resolvedEvent = pollAnswerRemovedFeedEventResolver(event);
expect(resolvedEvent, isA<PollAnswerRemovedFeedEvent>());
});
});

test('does not resolve Answer when answer is false', () {
final event = createPollVoteRemovedFeedEvent(isAnswer: false);
final resolvedEvent = pollAnswerRemovedFeedEventResolver(event);
expect(resolvedEvent, isNull);
});
test('does not resolve Answer when answer is null', () {
final event = createPollVoteRemovedFeedEvent(isAnswer: null);
final resolvedEvent = pollAnswerRemovedFeedEventResolver(event);
expect(resolvedEvent, isNull);
});
}

PollVoteRemovedFeedEvent createPollVoteRemovedFeedEvent({bool? isAnswer}) {
return PollVoteRemovedFeedEvent(
createdAt: DateTime.now(),
custom: const {},
fid: '1',
poll: PollResponseData(
createdAt: DateTime.now(),
updatedAt: DateTime.now(),
id: '1',
allowAnswers: true,
allowUserSuggestedOptions: true,
answersCount: 1,
createdById: '1',
custom: const {},
description: '1',
enforceUniqueVote: true,
latestAnswers: const [],
latestVotesByOption: const {},
maxVotesAllowed: 1,
name: '1',
options: const [],
ownVotes: const [],
voteCount: 1,
voteCountsByOption: const {},
votingVisibility: '1',
),
pollVote: PollVoteResponseData(
createdAt: DateTime.now(),
updatedAt: DateTime.now(),
id: '1',
optionId: '1',
pollId: '1',
isAnswer: isAnswer,
),
type: 'poll.vote.removed',
);
}
1 change: 1 addition & 0 deletions sample_app/lib/screens/user_feed/feed/user_feed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class UserFeed extends StatelessWidget {
),
],
UserFeedItem(
feed: userFeed,
data: activity,
user: baseActivity.user,
text: baseActivity.text ?? '',
Expand Down
14 changes: 14 additions & 0 deletions sample_app/lib/screens/user_feed/feed/user_feed_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import '../../../widgets/action_button.dart';
import '../../../widgets/attachment_gallery/attachment_metadata.dart';
import '../../../widgets/attachments/attachments.dart';
import '../../../widgets/user_avatar.dart';
import '../polls/show_poll/show_poll_widget.dart';

class UserFeedItem extends StatelessWidget {
const UserFeedItem({
super.key,
required this.feed,
required this.user,
required this.text,
required this.attachments,
Expand All @@ -37,6 +39,7 @@ class UserFeedItem extends StatelessWidget {
final VoidCallback? onBookmarkClick;
final VoidCallback? onDeleteClick;
final ValueChanged<String>? onEditSave;
final Feed feed;

@override
Widget build(BuildContext context) {
Expand All @@ -48,6 +51,7 @@ class UserFeedItem extends StatelessWidget {
data: data,
text: text,
attachments: attachments,
feed: feed,
),
const SizedBox(height: 8),
Center(
Expand All @@ -72,12 +76,14 @@ class _UserContent extends StatelessWidget {
required this.data,
required this.text,
required this.attachments,
required this.feed,
});

final UserData user;
final ActivityData data;
final String text;
final List<Attachment> attachments;
final Feed feed;

@override
Widget build(BuildContext context) {
Expand All @@ -102,6 +108,8 @@ class _UserContent extends StatelessWidget {
),
const SizedBox(height: 8),
_ActivityBody(
feed: feed,
activity: data,
user: user,
text: text,
attachments: attachments,
Expand All @@ -117,12 +125,16 @@ class _UserContent extends StatelessWidget {

class _ActivityBody extends StatelessWidget {
const _ActivityBody({
required this.activity,
required this.user,
required this.text,
required this.attachments,
required this.data,
required this.feed,
});

final Feed feed;
final ActivityData activity;
final UserData user;
final String text;
final List<Attachment> attachments;
Expand All @@ -136,6 +148,8 @@ class _ActivityBody extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (text.isNotEmpty) Text(text),
if (data.poll case final poll?)
ShowPollWidget(poll: poll, activity: activity, feed: feed),
if (attachments.isNotEmpty) ...[
AttachmentGrid(
attachments: attachments,
Expand Down
Loading