Skip to content

Commit

Permalink
Merge pull request #1719 from 100mslive/FLUT-239
Browse files Browse the repository at this point in the history
Added option to view ended polls
  • Loading branch information
Decoder07 authored Feb 29, 2024
2 parents 42200f3 + 9ac4ad4 commit a42ae7e
Show file tree
Hide file tree
Showing 24 changed files with 873 additions and 338 deletions.
9 changes: 4 additions & 5 deletions packages/hms_room_kit/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,10 @@ packages:
hmssdk_flutter:
dependency: transitive
description:
name: hmssdk_flutter
sha256: "5dedf840502cf20f5d22f5718c9cf620c6694f73b48156cc17015ecde0237bb7"
url: "https://pub.dev"
source: hosted
version: "1.9.11"
path: "../../hmssdk_flutter"
relative: true
source: path
version: "1.9.12"
http:
dependency: transitive
description:
Expand Down
123 changes: 70 additions & 53 deletions packages/hms_room_kit/lib/src/meeting/meeting_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ class MeetingStore extends ChangeNotifier
getAudioDevicesList();
notifyListeners();
setViewControllers();
// fetchPollList(HMSPollState.stopped);
fetchPollList(HMSPollState.stopped);
// if (Platform.isIOS &&
// HMSRoomLayout.roleLayoutData?.screens?.conferencing?.defaultConf !=
// null) {
Expand Down Expand Up @@ -2272,9 +2272,13 @@ class MeetingStore extends ChangeNotifier
_hmsSDKInteractor.stopPoll(poll: poll);
}

void fetchLeaderboard(HMSPoll poll) async {
void fetchLeaderboard(HMSPoll poll,
{int count = 5, int startIndex = 0}) async {
var data = await _hmsSDKInteractor.fetchLeaderboard(
poll: poll, count: 5, startIndex: 0, includeCurrentPeer: true);
poll: poll,
count: count,
startIndex: startIndex,
includeCurrentPeer: !(localPeer?.role.permissions.pollWrite ?? true));

if (data is HMSPollLeaderboardResponse) {
var pollIndex = pollQuestions
Expand All @@ -2288,62 +2292,66 @@ class MeetingStore extends ChangeNotifier
notifyListeners();
}

// void fetchPollList(HMSPollState state) async {
// var data = await _hmsSDKInteractor.fetchPollList(hmsPollState: state);
void fetchPollList(HMSPollState state) async {
var data = await _hmsSDKInteractor.fetchPollList(hmsPollState: state);

// if (data is List<HMSPoll>) {
// for (var element in data) {
// pollQuestions.add(HMSPollStore(poll: element));
// }
// sortPollQuestions();
// } else {
// log("fetchPollList error: $data");
// }
// }
if (data is List<HMSPoll>) {
for (var element in data) {
int index = pollQuestions.indexWhere(
(currentPoll) => currentPoll.poll.pollId == element.pollId);
if (index == -1) {
pollQuestions.add(HMSPollStore(poll: element));
}
}
sortPollQuestions();
} else {
log("fetchPollList error: $data");
}
}

// void fetchPollQuestions(HMSPoll poll) async {
// var data = await _hmsSDKInteractor.fetchPollQuestions(hmsPoll: poll);
void fetchPollQuestions(HMSPoll poll) async {
var data = await _hmsSDKInteractor.fetchPollQuestions(hmsPoll: poll);

// if (data is List<HMSPollQuestion>) {
// int index = pollQuestions
// .indexWhere((element) => element.poll.pollId == poll.pollId);
if (data is List<HMSPollQuestion>) {
int index = pollQuestions
.indexWhere((element) => element.poll.pollId == poll.pollId);

// if (index != -1) {
// var newPoll = HMSPoll(
// pollId: poll.pollId,
// title: poll.title,
// anonymous: poll.anonymous,
// category: poll.category,
// createdBy: poll.createdBy,
// duration: poll.duration,
// pollUserTrackingMode: poll.pollUserTrackingMode,
// questionCount: data.length,
// questions: data,
// result: poll.result,
// rolesThatCanViewResponses: poll.rolesThatCanViewResponses,
// rolesThatCanVote: poll.rolesThatCanVote,
// startedAt: poll.startedAt,
// startedBy: poll.startedBy,
// state: poll.state,
// stoppedAt: poll.stoppedAt,
// stoppedBy: poll.stoppedBy);
// pollQuestions[index].updateState(newPoll);
// }
// }
// }
if (index != -1) {
var newPoll = HMSPoll(
pollId: poll.pollId,
title: poll.title,
anonymous: poll.anonymous,
category: poll.category,
createdBy: poll.createdBy,
duration: poll.duration,
pollUserTrackingMode: poll.pollUserTrackingMode,
questionCount: data.length,
questions: data,
result: poll.result,
rolesThatCanViewResponses: poll.rolesThatCanViewResponses,
rolesThatCanVote: poll.rolesThatCanVote,
startedAt: poll.startedAt,
startedBy: poll.startedBy,
state: poll.state,
stoppedAt: poll.stoppedAt,
stoppedBy: poll.stoppedBy);
pollQuestions[index].updateState(newPoll);
}
}
}

// void getPollResults(HMSPoll poll) async {
// var data = await _hmsSDKInteractor.getPollResults(hmsPoll: poll);
void getPollResults(HMSPoll poll) async {
var data = await _hmsSDKInteractor.getPollResults(hmsPoll: poll);

// if (data is HMSPoll) {
// int index = pollQuestions
// .indexWhere((element) => element.poll.pollId == poll.pollId);
if (data is HMSPoll) {
int index = pollQuestions
.indexWhere((element) => element.poll.pollId == poll.pollId);

// if (index != -1) {
// pollQuestions[index].updateState(data);
// }
// }
// }
if (index != -1) {
pollQuestions[index].updateState(data);
}
}
}

//Get onSuccess or onException callbacks for HMSActionResultListenerMethod
@override
Expand Down Expand Up @@ -2750,7 +2758,11 @@ class MeetingStore extends ChangeNotifier
void sortPollQuestions() {
pollQuestions.sort((a, b) {
if (a.poll.state != b.poll.state) {
return a.poll.state == HMSPollState.started ? 1 : -1;
return a.poll.state == HMSPollState.started
? 1
: a.poll.state == HMSPollState.created
? 2
: -1;
} else {
if (a.poll.startedAt != null && b.poll.startedAt != null) {
return a.poll.startedAt!.compareTo(b.poll.startedAt!);
Expand Down Expand Up @@ -2822,6 +2834,11 @@ class MeetingStore extends ChangeNotifier
hlsViewerPolls.add(store);
}
}
} else {
pollQuestions[index].updateState(poll);
sortPollQuestions();
toasts.add(HMSToastModel(pollQuestions[index],
hmsToastType: HMSToastsType.pollStartedToast));
}
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ class _AppUtilitiesBottomSheetState extends State<AppUtilitiesBottomSheet> {
false))
MoreOptionItem(
onTap: () {
meetingStore.fetchPollList(HMSPollState.created);
Navigator.pop(context);
showModalBottomSheet(
isScrollControlled: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:math' as math;

///Package imports
import 'package:flutter/material.dart';
import 'package:hms_room_kit/src/widgets/poll_widgets/leaderboard_widgets/leaderboard_voter_summary.dart';
import 'package:hms_room_kit/src/widgets/poll_widgets/leaderboard_widgets/quiz_leaderboard.dart';
import 'package:hmssdk_flutter/hmssdk_flutter.dart';
import 'package:provider/provider.dart';
Expand Down Expand Up @@ -182,6 +183,40 @@ class _PollVoteBottomSheetState extends State<PollVoteBottomSheet> {
const SizedBox(
height: 8,
),
if (!(context
.read<MeetingStore>()
.localPeer
?.role
.permissions
.pollWrite ??
true) &&
hmsPollStore.poll.category == HMSPollCategory.quiz &&
hmsPollStore.poll.state == HMSPollState.stopped)
Builder(builder: (context) {
var localPeerUserId =
context.read<MeetingStore>().localPeer?.customerUserId;
var index = hmsPollStore.pollLeaderboardResponse?.entries
?.indexWhere((element) =>
element.peer?.userId == localPeerUserId) ??
-1;
HMSPollLeaderboardEntry? localPeerEntry;
if (index != -1) {
localPeerEntry =
hmsPollStore.pollLeaderboardResponse?.entries?[index];
}
return Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: LeaderboardVoterSummary(
showYourRank: false,
correctAnswers: localPeerEntry?.correctResponses,
totalQuestions: hmsPollStore.poll.questions?.length,
questionsAttempted: localPeerEntry?.totalResponses,
showPoints: false,
avgTimeInMilliseconds:
localPeerEntry?.duration?.inMilliseconds,
),
);
}),
Selector<HMSPollStore, HMSPoll>(
selector: (_, pollStore) => pollStore.poll,
builder: (_, poll, __) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import 'package:flutter/material.dart';
import 'package:hms_room_kit/src/widgets/poll_widgets/leaderboard_widgets/summary_box.dart';

class LeaderboardCreatorSummary extends StatelessWidget {
final double? votedPercent;
final String? votedDescription;
final double? correctPercent;
final String? correctDescription;
final int? avgTimeInMilliseconds;
final double? avgScore;

const LeaderboardCreatorSummary(
{super.key,
this.votedPercent,
this.votedDescription,
this.correctPercent,
this.correctDescription,
this.avgTimeInMilliseconds,
this.avgScore});

@override
Widget build(BuildContext context) {
return Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: SummaryBox(
title: "VOTED",
subtitle: (votedPercent == null || votedDescription == null)
? "-"
: "${votedPercent!.toStringAsFixed(2)}% ($votedDescription)"),
),
const SizedBox(
width: 10,
),
Expanded(
child: SummaryBox(
title: "CORRECT ANSWERS",
subtitle: (correctPercent == null ||
correctDescription == null)
? "-"
: "${correctPercent!.toStringAsFixed(2)}% ($correctDescription)"),
)
],
),
const SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
if (avgTimeInMilliseconds != null && avgTimeInMilliseconds! > 0)
Expanded(
child: SummaryBox(
title: "AVG. TIME TAKEN",
subtitle: avgTimeInMilliseconds == null
? "-"
: "${avgTimeInMilliseconds! / 1000}s"),
),
if (avgScore != null && avgScore! > 0)
const SizedBox(
width: 10,
),
Expanded(
child: SummaryBox(
title: "AVG. SCORE",
subtitle: avgScore == null
? "-"
: avgScore!.toStringAsPrecision(2)),
)
],
),
],
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ class LeaderBoardEntryWidget extends StatelessWidget {
final HMSPollLeaderboardEntry entry;
final HMSPollStore pollStore;
final int totalScore;
final Color? tileColor;

const LeaderBoardEntryWidget(
{super.key,
required this.entry,
required this.totalScore,
required this.pollStore});
required this.pollStore,
this.tileColor});

Color getPositionBadgeColor() {
switch (entry.position) {
Expand Down Expand Up @@ -54,8 +56,7 @@ class LeaderBoardEntryWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ListTile(
tileColor: HMSThemeColors.surfaceDefault,
style: ListTileStyle.list,
tileColor: tileColor ?? HMSThemeColors.surfaceDefault,
dense: true,
contentPadding: const EdgeInsets.symmetric(horizontal: 16),
horizontalTitleGap: 0,
Expand Down
Loading

0 comments on commit a42ae7e

Please sign in to comment.