Skip to content

Commit

Permalink
Merge pull request #1686 from 100mslive/FLUT-156
Browse files Browse the repository at this point in the history
FLUT-156: Send to picker based on layout API
  • Loading branch information
Decoder07 authored Jan 11, 2024
2 parents b308470 + 645e819 commit 947e7d8
Show file tree
Hide file tree
Showing 12 changed files with 931 additions and 348 deletions.
14 changes: 14 additions & 0 deletions packages/hms_room_kit/lib/src/assets/icons/everyone.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
188 changes: 109 additions & 79 deletions packages/hms_room_kit/lib/src/hls_viewer/overlay_chat_component.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
//Dart imports

///Package imports
import 'package:flutter/material.dart';
import 'package:flutter_linkify/flutter_linkify.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:hms_room_kit/src/widgets/bottom_sheets/chat_utilities_bottom_sheet.dart';
import 'package:hms_room_kit/src/widgets/chat_widgets/chat_text_field.dart';
import 'package:hms_room_kit/src/widgets/chat_widgets/pin_chat_widget.dart';
import 'package:hmssdk_flutter/hmssdk_flutter.dart';
import 'package:provider/provider.dart';
import 'package:tuple/tuple.dart';
Expand All @@ -17,6 +12,10 @@ import 'package:hms_room_kit/hms_room_kit.dart';
import 'package:hms_room_kit/src/meeting/meeting_store.dart';
import 'package:hms_room_kit/src/enums/session_store_keys.dart';
import 'package:hms_room_kit/src/layout_api/hms_room_layout.dart';
import 'package:hms_room_kit/src/widgets/bottom_sheets/chat_utilities_bottom_sheet.dart';
import 'package:hms_room_kit/src/widgets/chat_widgets/chat_text_field.dart';
import 'package:hms_room_kit/src/widgets/chat_widgets/pin_chat_widget.dart';
import 'package:hms_room_kit/src/widgets/chat_widgets/recipient_selector_chip.dart';

///[OverlayChatComponent] is a component that is used to show the chat
class OverlayChatComponent extends StatefulWidget {
Expand All @@ -29,13 +28,34 @@ class OverlayChatComponent extends StatefulWidget {

class _OverlayChatComponentState extends State<OverlayChatComponent> {
final ScrollController _scrollController = ScrollController();
String currentlySelectedValue = "Choose a Recipient";
String? currentlySelectedpeerId;

@override
void dispose() {
_scrollController.dispose();
super.dispose();
}

@override
void initState() {
super.initState();
setRecipientChipValue();
}

///This function sets the recipient chip value
void setRecipientChipValue() {
dynamic currentValue = context.read<MeetingStore>().recipientSelectorValue;
if (currentValue is HMSPeer) {
currentlySelectedValue = currentValue.name;
currentlySelectedpeerId = currentValue.peerId;
} else if (currentValue is HMSRole) {
currentlySelectedValue = currentValue.name;
} else if (currentValue is String) {
currentlySelectedValue = currentValue;
}
}

///This function scrolls to the end of the list
void _scrollToEnd() {
WidgetsBinding.instance.addPostFrameCallback((_) =>
Expand All @@ -44,13 +64,55 @@ class _OverlayChatComponentState extends State<OverlayChatComponent> {
curve: Curves.easeInOut));
}

///This function updates the selected value
void _updateValueChoose(String newValue, String? peerId) {
currentlySelectedValue = newValue;
currentlySelectedpeerId = peerId;
}

///This function returns the message type text for public, group and private messages
String messageTypeText(HMSMessageRecipient? hmsMessageRecipient) {
if (hmsMessageRecipient == null) return "";
if ((hmsMessageRecipient.recipientPeer != null) &&
(hmsMessageRecipient.recipientRoles == null)) {
if (hmsMessageRecipient.recipientPeer is HMSLocalPeer) {
return "to You (DM)";
} else {
return "to ${hmsMessageRecipient.recipientPeer?.name} (DM)";
}
} else if ((hmsMessageRecipient.recipientPeer == null) &&
(hmsMessageRecipient.recipientRoles != null)) {
return "to ${hmsMessageRecipient.recipientRoles?.first.name} (Group)";
}
return "";
}

///This function sends the message
void _sendMessage(TextEditingController messageTextController) async {
MeetingStore meetingStore = context.read<MeetingStore>();
List<HMSRole> hmsRoles = meetingStore.roles;
String message = messageTextController.text.trim();
if (message.isEmpty) return;
meetingStore.sendBroadcastMessage(message);
messageTextController.clear();

List<String> rolesName = <String>[];
for (int i = 0; i < hmsRoles.length; i++) {
rolesName.add(hmsRoles[i].name);
}

if (currentlySelectedValue == "Everyone") {
meetingStore.sendBroadcastMessage(message);
} else if (rolesName.contains(currentlySelectedValue)) {
List<HMSRole> selectedRoles = [];
selectedRoles.add(
hmsRoles.firstWhere((role) => role.name == currentlySelectedValue));
meetingStore.sendGroupMessage(message, selectedRoles);
} else if (currentlySelectedpeerId != null &&
meetingStore.localPeer!.peerId != currentlySelectedpeerId) {
var peer = await meetingStore.getPeer(peerId: currentlySelectedpeerId!);
if (peer != null) {
meetingStore.sendDirectMessage(message, peer);
}
}
}

@override
Expand Down Expand Up @@ -80,13 +142,41 @@ class _OverlayChatComponentState extends State<OverlayChatComponent> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
HMSTitleText(
text: data.item1[index].sender?.name ??
"Anonymous",
textColor: Colors.white,
fontSize: 14,
lineHeight: 20,
letterSpacing: 0.1,
Row(
children: [
Container(
constraints: BoxConstraints(
maxWidth: MediaQuery.of(context)
.size
.width *
0.5),
child: HMSTitleText(
text: data.item1[index].sender
?.name ??
"Anonymous",
textColor: Colors.white,
fontSize: 14,
lineHeight: 20,
letterSpacing: 0.1,
),
),
const SizedBox(
width: 4,
),
Container(
constraints: BoxConstraints(
maxWidth: MediaQuery.of(context)
.size
.width *
0.5),
child: HMSSubtitleText(
text: messageTypeText(data
.item1[index]
.hmsMessageRecipient),
textColor: HMSThemeColors
.onSurfaceMediumEmphasis),
),
],
),
const SizedBox(
height: 2,
Expand Down Expand Up @@ -177,71 +267,11 @@ class _OverlayChatComponentState extends State<OverlayChatComponent> {
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
///This will be added in future versions
///
Row(
children: [
Padding(
padding: const EdgeInsets.only(right: 8.0),
child: HMSTitleText(
text: "TO",
textColor: HMSThemeColors
.onSurfaceMediumEmphasis,
fontSize: 12,
fontWeight: FontWeight.w400,
lineHeight: 16,
letterSpacing: 0.4,
),
),
Container(
height: 24,
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(
Radius.circular(4)),
color: HMSThemeColors.backgroundDim
.withOpacity(0.64)),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 4.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.only(
right: 4.0),
child: SvgPicture.asset(
"packages/hms_room_kit/lib/src/assets/icons/participants.svg",
height: 16,
width: 16,
colorFilter: ColorFilter.mode(
HMSThemeColors
.onSurfaceMediumEmphasis,
BlendMode.srcIn),
),
),
HMSTitleText(
text: "Everyone",
fontSize: 12,
lineHeight: 16,
letterSpacing: 0.4,
fontWeight: FontWeight.w400,
textColor: HMSThemeColors
.onPrimaryHighEmphasis),
Padding(
padding: const EdgeInsets.only(
left: 4.0),
child: Icon(
Icons.keyboard_arrow_down,
color: HMSThemeColors
.onPrimaryHighEmphasis,
size: 12,
),
),
],
),
))
],
ReceipientSelectorChip(
currentlySelectedValue: currentlySelectedValue,
updateSelectedValue: _updateValueChoose,
chipColor:
HMSThemeColors.backgroundDim.withAlpha(64),
),
const SizedBox(),
if (HMSRoomLayout.chatData?.realTimeControls
Expand Down
30 changes: 30 additions & 0 deletions packages/hms_room_kit/lib/src/meeting/meeting_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ class MeetingStore extends ChangeNotifier
///[blackListedUserIds] is the list of user ids which are blacklisted from chat
List<String> blackListedUserIds = [];

///[recipientSelectorValue] is the value of the recipient selector chip
dynamic recipientSelectorValue = "Choose a Recipient";

bool isPipActive = false;

// bool isPipAutoEnabled = true;
Expand Down Expand Up @@ -279,6 +282,7 @@ class MeetingStore extends ChangeNotifier
WidgetsBinding.instance.addObserver(this);
setMeetingModeUsingLayoutApi();
_hmsSDKInteractor.join(config: roomConfig);
setRecipientSelectorValue();
meetingUrl = roomCode;
return null;
}
Expand Down Expand Up @@ -1367,6 +1371,12 @@ class MeetingStore extends ChangeNotifier
participantsInMeetingMap["Hand Raised"]
?.removeWhere((oldPeer) => oldPeer.peer.peerId == peer.peerId);
}

///If peer is removed from room but selected in the recipient selector
///we reset it to "Choose a Recipient"
if (recipientSelectorValue == peer) {
recipientSelectorValue = "Choose a Recipient";
}
notifyListeners();
}

Expand Down Expand Up @@ -2001,6 +2011,26 @@ class MeetingStore extends ChangeNotifier
metadata: data);
}

///[setReipientSelectorValue] method is used to set the value of recipient selector
void setRecipientSelectorValue() {
if (HMSRoomLayout.chatData?.isPublicChatEnabled ?? false) {
recipientSelectorValue = "Everyone";
return;
} else if (HMSRoomLayout.chatData?.rolesWhitelist.isNotEmpty ?? false) {
if (localPeer != null) {
recipientSelectorValue = HMSRoomLayout.chatData?.rolesWhitelist
.firstWhere((role) => role != localPeer?.role.name) ??
localPeer!.role.name;
return;
}
} else if (HMSRoomLayout.chatData?.isPrivateChatEnabled ?? false) {
if (peers.length > 1) {
recipientSelectorValue = peers[1];
}
}
notifyListeners();
}

void getSessionMetadata(String key) async {
dynamic result = await _hmsSessionStore?.getSessionMetadataForKey(key: key);
if (result is HMSException) {
Expand Down
Loading

0 comments on commit 947e7d8

Please sign in to comment.