Skip to content

Commit

Permalink
feat: add invite and promote functions to Spaces & integrate in examp…
Browse files Browse the repository at this point in the history
…le app (#64)

* Add inviteToPromote method in Space class

* Add acceptPromotionInvite, rejectPromotionInvite and _completePromotionInvite in Space class

* Revert naming of META_SPACE_SPEAKER_PRIVILEGE

* Add socket handling logic for promotion invites & code cleanup

* feat: add spaces request screen

* feat: add popular spaces

* feat: add spaces tabs

* feat: add new chat tab

* feat: add new accounts view

* feat: add end() method in Space class

* chore: rename get_spaces.dart to spaces.dart

* update: refactor by_you to hosted_by_you

* chore: rename byYou to hostedByYou

* chore: combine your_spaces files

* chore: rename trendingSpaces to trending & fix typo in popular_space_provider

* chore: delete unuseed file

* feat: add pendingInvites get property in Space class

* Fix error in space invites dialog

* feat: add end space

* feat: add auto end space logic for speakers and listerners

* feat: add promotion invite

* fix listener not promoted on accept promotion invite

* fix: only show group requests for members and not creator

---------

Co-authored-by: Madhur Gupta <[email protected]>
Co-authored-by: Gbogboade Ayomide <[email protected]>
  • Loading branch information
3 people authored Dec 13, 2023
1 parent 3701f57 commit 94214aa
Show file tree
Hide file tree
Showing 22 changed files with 931 additions and 200 deletions.
23 changes: 21 additions & 2 deletions example/lib/views/account_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,10 @@ class AccountProvider extends ChangeNotifier {

final type = (groupInfo as Map<String, dynamic>)['eventType'];
final recipients = (groupInfo['to'] as List?) ?? [];
final from = groupInfo['from'];

if (type == 'create' ||
if ((type == 'create' &&
from != walletToPCAIP10(pushWallet!.address!)) ||
(type == 'request' &&
recipients.contains(walletToPCAIP10(pushWallet!.address!)))) {
ref.read(requestsProvider).addReqestFromSocket(
Expand All @@ -174,9 +176,11 @@ class AccountProvider extends ChangeNotifier {
EVENTS.SPACES_MESSAGES,
(data) async {
final message = data as Map<String, dynamic>;

print(
'SPACES NOTIFICATION EVENTS.SPACES_MESSAGES messageCategory ${message['messageCategory']} messageType ${message['messageType']}');
for (var element in message.keys) {
print('$element -> ${message[element]}');
}

// Check if the message is a chat meta message or chat user activity message
if (message['messageCategory'] == 'Chat' &&
Expand All @@ -185,13 +189,28 @@ class AccountProvider extends ChangeNotifier {
ref.read(liveSpaceProvider).onReceiveMetaMessage(message);
}

//Check if space was ended
if (message['messageCategory'] == 'Chat' &&
message['messageContent'] == CHAT.META_SPACE_END &&
message["fromDID"] != walletToPCAIP10(pushWallet!.address!)) {
ref
.read(liveSpaceProvider)
.onReceiveSpaceEndedData(message["chatId"]);
}
//Check if promotion invite was sent
if (message['messageCategory'] == 'Chat' &&
message['messageContent'] ==
CHAT.META_SPACE_LISTENER_PROMOTE_INVITE) {
try {
final invitedUsers = message["messageObj"]["info"]['affected'];

if (invitedUsers.contains(pushWallet?.address)) {
ref
.read(liveSpaceProvider)
.onReceivePromotionInvite(message["chatId"]);
}
} catch (e) {}
}

if (message['messageCategory'] == 'Chat' &&
(message['messageType'] == MessageType.REACTION)) {
Expand Down
3 changes: 2 additions & 1 deletion example/lib/views/spaces/__spaces.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ export 'create_space_screen.dart';
export 'live_space/live_space_screen.dart';

export 'live_space/live_space_provider.dart';
export 'live_space/space_request_view.dart';
export 'live_space/space_moderation_dialog.dart';
export 'live_space/send_space_invite_dialog.dart';
export 'live_space/tiles.dart';

export 'your_spaces/your_spaces_provider.dart';
Expand Down
53 changes: 53 additions & 0 deletions example/lib/views/spaces/live_space/live_space_provider.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:another_flushbar/flushbar.dart';
import 'package:push_restapi_dart/push_restapi_dart.dart';

import 'dart:math' as m;
Expand Down Expand Up @@ -63,4 +64,56 @@ class LiveSpaceProvider extends PushSpaceNotifier {
ref.read(spaceRequestsProvider).loadRequests();
}
}

onReceivePromotionInvite(String spaceId) {
if (spaceId == data.spaceId) {
showPromotionDialog(spaceId);
}
}

showPromotionDialog(String spaceId) {
late Flushbar<void> flushBar;
flushBar = Flushbar<void>(
titleText: KText(
'Host has invited you to speak',
size: 14,
color: Colors.white,
weight: FontWeight.w600,
),
messageText: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: ()async {
flushBar.dismiss();
await rejectPromotionInvite();
},
child: KText(
'Reject',
color: Colors.red,
)),
TextButton(
onPressed: () async {
flushBar.dismiss();
await acceptPromotionInvite();
},
child: KText(
'Accept',
color: Colors.white,
),
),
],
),
margin: EdgeInsets.all(6),
borderRadius: BorderRadius.circular(12),
flushbarStyle: FlushbarStyle.FLOATING,
flushbarPosition: FlushbarPosition.TOP,
duration: Duration(seconds: 30),
backgroundColor: Colors.deepPurple,
);

if (!flushBar.isShowing()) {
flushBar.show(Get.context!);
}
}
}
4 changes: 2 additions & 2 deletions example/lib/views/spaces/live_space/live_space_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,10 @@ class _LiveSpaceRoomState extends ConsumerState<LiveSpaceRoom>
if (isHost)
InkWell(
onTap: () {
Get.bottomSheet(SpaceMicRequestsView());
Get.bottomSheet(SpaceModerationView());
},
child: Column(
children: [Icon(Icons.waving_hand), Text('Requests')],
children: [Icon(Icons.group_add), Text('Moderate')],
),
),
Spacer(),
Expand Down
130 changes: 130 additions & 0 deletions example/lib/views/spaces/live_space/send_space_invite_dialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import 'package:flutter/cupertino.dart';
import 'package:push_restapi_dart/push_restapi_dart.dart';

import '../../../__lib.dart';

class SendSpaceInviteDialog extends StatefulWidget {
const SendSpaceInviteDialog(
{super.key, required this.spaceId, required this.isSpeaker});
final String spaceId;
final bool isSpeaker;

@override
State<SendSpaceInviteDialog> createState() => _SendSpaceInviteDialogState();
}

class _SendSpaceInviteDialogState extends State<SendSpaceInviteDialog> {
TextEditingController controller = TextEditingController();
bool isSpeaker = false;

onSend() async {
try {
final address = controller.text.trim();

if (!isValidETHAddress(address)) {
showMyDialog(
context: context, title: 'Send invite', message: 'Invalid Address');
return;
}

showLoadingDialog();

if (isSpeaker) {
await addSpeakers(spaceId: widget.spaceId, speakers: [address]);
} else {
await addListeners(spaceId: widget.spaceId, listeners: [address]);
}

pop();
pop();
showSuccessSnackbar('Invite sent successfully');
} catch (e) {}
}

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

init() {
setState(() {
isSpeaker = widget.isSpeaker;
});
}

@override
Widget build(BuildContext context) {
return Container(
height: 640,
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.white,
Colors.purple.withOpacity(.5),
]),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(36),
topRight: Radius.circular(36),
),
color: Colors.white),
child: Column(
children: [
KText(
'Send Space Invite',
weight: FontWeight.w600,
),
Expanded(
child: ListView(
children: [
SizedBox(height: 24),
InputField(
label: 'Address',
hintText: '0xB6E3Dc6b35..............',
controller: controller,
),
SizedBox(height: 24),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
KText(
'Listerner',
color: Colors.white,
),
SizedBox(width: 10),
CupertinoSwitch(
value: isSpeaker,
onChanged: (value) {
setState(() {
isSpeaker = value;
});
},
),
SizedBox(width: 10),
KText(
'Speaker',
color: Colors.white,
),
],
),
SizedBox(height: 24),
MaterialButton(
color: pushColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16)),
onPressed: onSend,
textColor: Colors.white,
child: Center(child: Text('Send')),
padding: EdgeInsets.all(16),
),
],
),
),
],
),
);
}
}
Loading

0 comments on commit 94214aa

Please sign in to comment.