Skip to content

Commit 94214aa

Browse files
gbogboadePushmadhur-pushGbogboade1
authored
feat: add invite and promote functions to Spaces & integrate in example 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]>
1 parent 3701f57 commit 94214aa

22 files changed

+931
-200
lines changed

example/lib/views/account_provider.dart

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,10 @@ class AccountProvider extends ChangeNotifier {
154154

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

158-
if (type == 'create' ||
159+
if ((type == 'create' &&
160+
from != walletToPCAIP10(pushWallet!.address!)) ||
159161
(type == 'request' &&
160162
recipients.contains(walletToPCAIP10(pushWallet!.address!)))) {
161163
ref.read(requestsProvider).addReqestFromSocket(
@@ -174,9 +176,11 @@ class AccountProvider extends ChangeNotifier {
174176
EVENTS.SPACES_MESSAGES,
175177
(data) async {
176178
final message = data as Map<String, dynamic>;
177-
178179
print(
179180
'SPACES NOTIFICATION EVENTS.SPACES_MESSAGES messageCategory ${message['messageCategory']} messageType ${message['messageType']}');
181+
for (var element in message.keys) {
182+
print('$element -> ${message[element]}');
183+
}
180184

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

192+
//Check if space was ended
188193
if (message['messageCategory'] == 'Chat' &&
189194
message['messageContent'] == CHAT.META_SPACE_END &&
190195
message["fromDID"] != walletToPCAIP10(pushWallet!.address!)) {
191196
ref
192197
.read(liveSpaceProvider)
193198
.onReceiveSpaceEndedData(message["chatId"]);
194199
}
200+
//Check if promotion invite was sent
201+
if (message['messageCategory'] == 'Chat' &&
202+
message['messageContent'] ==
203+
CHAT.META_SPACE_LISTENER_PROMOTE_INVITE) {
204+
try {
205+
final invitedUsers = message["messageObj"]["info"]['affected'];
206+
207+
if (invitedUsers.contains(pushWallet?.address)) {
208+
ref
209+
.read(liveSpaceProvider)
210+
.onReceivePromotionInvite(message["chatId"]);
211+
}
212+
} catch (e) {}
213+
}
195214

196215
if (message['messageCategory'] == 'Chat' &&
197216
(message['messageType'] == MessageType.REACTION)) {

example/lib/views/spaces/__spaces.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ export 'create_space_screen.dart';
22
export 'live_space/live_space_screen.dart';
33

44
export 'live_space/live_space_provider.dart';
5-
export 'live_space/space_request_view.dart';
5+
export 'live_space/space_moderation_dialog.dart';
6+
export 'live_space/send_space_invite_dialog.dart';
67
export 'live_space/tiles.dart';
78

89
export 'your_spaces/your_spaces_provider.dart';

example/lib/views/spaces/live_space/live_space_provider.dart

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:another_flushbar/flushbar.dart';
12
import 'package:push_restapi_dart/push_restapi_dart.dart';
23

34
import 'dart:math' as m;
@@ -63,4 +64,56 @@ class LiveSpaceProvider extends PushSpaceNotifier {
6364
ref.read(spaceRequestsProvider).loadRequests();
6465
}
6566
}
67+
68+
onReceivePromotionInvite(String spaceId) {
69+
if (spaceId == data.spaceId) {
70+
showPromotionDialog(spaceId);
71+
}
72+
}
73+
74+
showPromotionDialog(String spaceId) {
75+
late Flushbar<void> flushBar;
76+
flushBar = Flushbar<void>(
77+
titleText: KText(
78+
'Host has invited you to speak',
79+
size: 14,
80+
color: Colors.white,
81+
weight: FontWeight.w600,
82+
),
83+
messageText: Row(
84+
mainAxisAlignment: MainAxisAlignment.end,
85+
children: [
86+
TextButton(
87+
onPressed: ()async {
88+
flushBar.dismiss();
89+
await rejectPromotionInvite();
90+
},
91+
child: KText(
92+
'Reject',
93+
color: Colors.red,
94+
)),
95+
TextButton(
96+
onPressed: () async {
97+
flushBar.dismiss();
98+
await acceptPromotionInvite();
99+
},
100+
child: KText(
101+
'Accept',
102+
color: Colors.white,
103+
),
104+
),
105+
],
106+
),
107+
margin: EdgeInsets.all(6),
108+
borderRadius: BorderRadius.circular(12),
109+
flushbarStyle: FlushbarStyle.FLOATING,
110+
flushbarPosition: FlushbarPosition.TOP,
111+
duration: Duration(seconds: 30),
112+
backgroundColor: Colors.deepPurple,
113+
);
114+
115+
if (!flushBar.isShowing()) {
116+
flushBar.show(Get.context!);
117+
}
118+
}
66119
}

example/lib/views/spaces/live_space/live_space_screen.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,10 @@ class _LiveSpaceRoomState extends ConsumerState<LiveSpaceRoom>
227227
if (isHost)
228228
InkWell(
229229
onTap: () {
230-
Get.bottomSheet(SpaceMicRequestsView());
230+
Get.bottomSheet(SpaceModerationView());
231231
},
232232
child: Column(
233-
children: [Icon(Icons.waving_hand), Text('Requests')],
233+
children: [Icon(Icons.group_add), Text('Moderate')],
234234
),
235235
),
236236
Spacer(),
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import 'package:flutter/cupertino.dart';
2+
import 'package:push_restapi_dart/push_restapi_dart.dart';
3+
4+
import '../../../__lib.dart';
5+
6+
class SendSpaceInviteDialog extends StatefulWidget {
7+
const SendSpaceInviteDialog(
8+
{super.key, required this.spaceId, required this.isSpeaker});
9+
final String spaceId;
10+
final bool isSpeaker;
11+
12+
@override
13+
State<SendSpaceInviteDialog> createState() => _SendSpaceInviteDialogState();
14+
}
15+
16+
class _SendSpaceInviteDialogState extends State<SendSpaceInviteDialog> {
17+
TextEditingController controller = TextEditingController();
18+
bool isSpeaker = false;
19+
20+
onSend() async {
21+
try {
22+
final address = controller.text.trim();
23+
24+
if (!isValidETHAddress(address)) {
25+
showMyDialog(
26+
context: context, title: 'Send invite', message: 'Invalid Address');
27+
return;
28+
}
29+
30+
showLoadingDialog();
31+
32+
if (isSpeaker) {
33+
await addSpeakers(spaceId: widget.spaceId, speakers: [address]);
34+
} else {
35+
await addListeners(spaceId: widget.spaceId, listeners: [address]);
36+
}
37+
38+
pop();
39+
pop();
40+
showSuccessSnackbar('Invite sent successfully');
41+
} catch (e) {}
42+
}
43+
44+
@override
45+
void initState() {
46+
super.initState();
47+
init();
48+
}
49+
50+
init() {
51+
setState(() {
52+
isSpeaker = widget.isSpeaker;
53+
});
54+
}
55+
56+
@override
57+
Widget build(BuildContext context) {
58+
return Container(
59+
height: 640,
60+
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
61+
decoration: BoxDecoration(
62+
gradient: LinearGradient(
63+
begin: Alignment.topCenter,
64+
end: Alignment.bottomCenter,
65+
colors: [
66+
Colors.white,
67+
Colors.purple.withOpacity(.5),
68+
]),
69+
borderRadius: BorderRadius.only(
70+
topLeft: Radius.circular(36),
71+
topRight: Radius.circular(36),
72+
),
73+
color: Colors.white),
74+
child: Column(
75+
children: [
76+
KText(
77+
'Send Space Invite',
78+
weight: FontWeight.w600,
79+
),
80+
Expanded(
81+
child: ListView(
82+
children: [
83+
SizedBox(height: 24),
84+
InputField(
85+
label: 'Address',
86+
hintText: '0xB6E3Dc6b35..............',
87+
controller: controller,
88+
),
89+
SizedBox(height: 24),
90+
Row(
91+
mainAxisAlignment: MainAxisAlignment.center,
92+
children: [
93+
KText(
94+
'Listerner',
95+
color: Colors.white,
96+
),
97+
SizedBox(width: 10),
98+
CupertinoSwitch(
99+
value: isSpeaker,
100+
onChanged: (value) {
101+
setState(() {
102+
isSpeaker = value;
103+
});
104+
},
105+
),
106+
SizedBox(width: 10),
107+
KText(
108+
'Speaker',
109+
color: Colors.white,
110+
),
111+
],
112+
),
113+
SizedBox(height: 24),
114+
MaterialButton(
115+
color: pushColor,
116+
shape: RoundedRectangleBorder(
117+
borderRadius: BorderRadius.circular(16)),
118+
onPressed: onSend,
119+
textColor: Colors.white,
120+
child: Center(child: Text('Send')),
121+
padding: EdgeInsets.all(16),
122+
),
123+
],
124+
),
125+
),
126+
],
127+
),
128+
);
129+
}
130+
}

0 commit comments

Comments
 (0)