Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement space high level sdk class #102

Merged
merged 3 commits into from
Mar 8, 2024
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
2 changes: 1 addition & 1 deletion examples/demo_app/lib/views/group/add_group_member.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class _AddGroupMemberState extends ConsumerState<AddGroupMember> {
showLoadingDialog();
result = await pushUser.chat.group.add(
chatId: widget.chatId!,
role: widget.isAdmin ? 'ADMIN' : 'MEMBER',
role: widget.isAdmin ? GroupRoles.ADMIN : GroupRoles.MEMBER,
accounts: [address],
);

Expand Down
25 changes: 4 additions & 21 deletions examples/demo_app/lib/views/group/group_members_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ class _MemberActionWidgetState extends ConsumerState<MemberActionWidget> {
showLoadingDialog();
pushUser.chat.group.remove(
chatId: widget.chatId!,
role: 'MEMBER',
role: GroupRoles.MEMBER,
accounts: [widget.item.address],
).then((value) {
pop();
Expand All @@ -351,7 +351,7 @@ class _MemberActionWidgetState extends ConsumerState<MemberActionWidget> {

pushUser.chat.group.remove(
chatId: widget.chatId!,
role: 'ADMIN',
role: GroupRoles.ADMIN,
accounts: [widget.item.address],
).then((value) {
pop();
Expand All @@ -371,7 +371,7 @@ class _MemberActionWidgetState extends ConsumerState<MemberActionWidget> {
showLoadingDialog();
pushUser.chat.group.modify(
chatId: widget.chatId!,
role: 'MEMBER',
role: GroupRoles.MEMBER,
accounts: [widget.item.address],
).then((value) {
pop();
Expand All @@ -391,7 +391,7 @@ class _MemberActionWidgetState extends ConsumerState<MemberActionWidget> {
showLoadingDialog();
pushUser.chat.group.modify(
chatId: widget.chatId!,
role: 'ADMIN',
role: GroupRoles.ADMIN,
accounts: [widget.item.address],
).then((value) {
pop();
Expand All @@ -405,23 +405,6 @@ class _MemberActionWidgetState extends ConsumerState<MemberActionWidget> {
: 'Member promoted successfully',
);
});
// removeMembers(
// chatId: widget.chatId!,
// members: [widget.item.address],
// ).then((value) {
// addAdmins(chatId: widget.chatId!, admins: [widget.item.address])
// .then((value) {
// ref.read(chatRoomProvider).getLatestGroupMembers();
// pop();
// showMyDialog(
// context: context,
// title: 'Remove User',
// message: value == null
// ? 'Cannot promote user'
// : 'Member promoted successfully',
// );
// });
// });
}
}

Expand Down
4 changes: 2 additions & 2 deletions examples/use_cases/lib/chats/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ Future runChatClassUseCases() async {
log('PushAPI.group.add');
final addMember = await userAlice.chat.group.add(
chatId: groupChatId,
role: 'MEMBER',
role: GroupRoles.MEMBER,
accounts: [wallet3Signer.getAddress()],
);
log(addMember);
Expand All @@ -194,7 +194,7 @@ Future runChatClassUseCases() async {
log('PushAPI.group.remove');
final removeMember = await userAlice.chat.group.remove(
chatId: groupChatId,
role: 'MEMBER',
role: GroupRoles.MEMBER,
accounts: [wallet3Signer.getAddress()],
);
log(removeMember);
Expand Down
25 changes: 25 additions & 0 deletions lib/src/chat/src/models/group_access.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,28 @@ class GroupAccess {
return data;
}
}

class SpaceAccess {
bool entry;
bool chat;

SpaceAccess({
required this.entry,
required this.chat,
});

factory SpaceAccess.fromJson(Map<String, dynamic> json) {
return SpaceAccess(
entry: json['entry'] ?? false,
chat: json['chat'] ?? false,
);
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = {
'entry': entry,
'chat': chat,
};
return data;
}
}
6 changes: 6 additions & 0 deletions lib/src/chat/src/models/group_info_dto.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,9 @@ class GroupInfoDTO {
return GroupInfoDTO.fromJson(group.toJson());
}
}

extension GroupExtension on GroupInfoDTO? {
SpaceInfoDTO get toSpaceInfo {
return groupInfoDtoToSpaceInfoDto(this!);
}
}
4 changes: 2 additions & 2 deletions lib/src/chat/src/update_group_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ChatUpdateConfigProfileType {
});
}

Future<GroupDTO> updateGroupConfig({
Future<GroupInfoDTO> updateGroupConfig({
required ChatUpdateConfigProfileType options,
}) async {
options.account ??= getCachedWallet()?.address;
Expand Down Expand Up @@ -76,5 +76,5 @@ Future<GroupDTO> updateGroupConfig({
throw Exception(result);
}

return GroupDTO.fromJson(result);
return GroupInfoDTO.fromJson(result);
}
25 changes: 17 additions & 8 deletions lib/src/helpers/src/converters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,8 @@ SpaceDTO groupDtoToSpaceDto(GroupDTO groupDto) {
);
}

SpaceDTO groupInfoDtoToSpaceDto(GroupInfoDTO groupDto) {
return SpaceDTO(
members: [],
pendingMembers: [],
contractAddressERC20: null,
numberOfERC20: -1,
numberOfNFTTokens: -1,
verificationProof: '',
SpaceInfoDTO groupInfoDtoToSpaceInfoDto(GroupInfoDTO groupDto) {
return SpaceInfoDTO(
spaceImage: groupDto.groupImage,
spaceName: groupDto.groupName,
isPublic: groupDto.isPublic,
Expand All @@ -82,6 +76,21 @@ SpaceDTO groupInfoDtoToSpaceDto(GroupInfoDTO groupDto) {
);
}

SpaceInfoDTO spaceDtoToSpaceInfoDto(SpaceDTO groupDto) {
return SpaceInfoDTO(
spaceImage: groupDto.spaceImage,
spaceName: groupDto.spaceName,
isPublic: groupDto.isPublic,
spaceDescription: groupDto.spaceDescription ?? '',
spaceCreator: groupDto.spaceCreator,
spaceId: groupDto.spaceId,
scheduleAt: groupDto.scheduleAt,
scheduleEnd: groupDto.scheduleEnd,
status: groupDto.status,
meta: groupDto.meta,
);
}

List<String> convertToWalletAddressList(List<MemberDTO> memberList) {
return memberList.map((member) => member.wallet).toList();
}
Expand Down
40 changes: 40 additions & 0 deletions lib/src/models/src/all.dart
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,46 @@ class SpaceDTO {
: null;
}

extension SpaceDTOExtension on SpaceDTO {
SpaceInfoDTO get toSpaceInfo {
return spaceDtoToSpaceInfoDto(this);
}
}

class SpaceInfoDTO {
final String spaceName;
final String? spaceImage;
final String spaceDescription;
final bool isPublic;
final String spaceCreator;
final String spaceId;
final DateTime? scheduleAt;
final DateTime? scheduleEnd;
final ChatStatus? status;
final dynamic rules;
final String? meta;
final String? sessionKey;
final String? encryptedSecret;
final Map<String, SPACE_INVITE_ROLES>? inviteeDetails;

SpaceInfoDTO({
required this.spaceName,
this.spaceImage,
required this.spaceDescription,
required this.isPublic,
required this.spaceCreator,
required this.spaceId,
this.scheduleAt,
this.scheduleEnd,
this.status,
this.rules,
this.meta,
this.sessionKey,
this.encryptedSecret,
this.inviteeDetails,
});
}

class SpaceMemberDTO {
String wallet;
String publicKey;
Expand Down
4 changes: 3 additions & 1 deletion lib/src/pushapi/pushapi.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export 'src/models.dart';
export 'src/models/models.dart';
export 'src/models/spaces_models.dart';
export 'src/pushapi.dart';
export 'src/chat.dart' hide GroupAPI, GroupParticipantsAPI;
export 'src/user.dart';
export 'src/space.dart';
30 changes: 6 additions & 24 deletions lib/src/pushapi/src/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class GroupAPI {
return PUSH_CHAT.getGroupInfo(chatId: chatId);
}

Future<GroupDTO> update({
Future<GroupInfoDTO> update({
required String chatId,
required GroupUpdateOptions options,
}) async {
Expand Down Expand Up @@ -320,21 +320,15 @@ class GroupAPI {
);
}

///role: 'ADMIN' | 'MEMBER';
Future<GroupInfoDTO?> add({
required String chatId,
required String role,
required GroupRoles role,
required List<String> accounts,
}) async {
if (!_hasSigner) {
throw Exception(PushAPI.ensureSignerMessage());
}

final validRoles = ['ADMIN', 'MEMBER'];
if (!validRoles.contains(role)) {
throw Exception('Invalid role provided.');
}

if (accounts.isEmpty) {
throw Exception('accounts array cannot be empty!');
}
Expand All @@ -345,7 +339,7 @@ class GroupAPI {
}
}

if (role == 'ADMIN') {
if (role == GroupRoles.ADMIN) {
return PUSH_CHAT.addAdmins(
chatId: chatId,
admins: accounts,
Expand All @@ -364,21 +358,15 @@ class GroupAPI {
}
}

///role: 'ADMIN' | 'MEMBER';
Future remove({
required String chatId,
required String role,
required GroupRoles role,
required List<String> accounts,
}) async {
if (!_hasSigner) {
throw Exception(PushAPI.ensureSignerMessage());
}

final validRoles = ['ADMIN', 'MEMBER'];
if (!validRoles.contains(role)) {
throw Exception('Invalid role provided.');
}

if (accounts.isEmpty) {
throw Exception('accounts array cannot be empty!');
}
Expand Down Expand Up @@ -425,21 +413,15 @@ class GroupAPI {
return info(chatId: chatId);
}

///role: 'ADMIN' | 'MEMBER';
Future<GroupInfoDTO?> modify({
required String chatId,
required String role,
required GroupRoles role,
required List<String> accounts,
}) async {
if (!_hasSigner) {
throw Exception(PushAPI.ensureSignerMessage());
}

final validRoles = ['ADMIN', 'MEMBER'];
if (!validRoles.contains(role)) {
throw Exception('Invalid role provided.');
}

if (accounts.isEmpty) {
throw Exception('accounts array cannot be empty!');
}
Expand All @@ -453,7 +435,7 @@ class GroupAPI {
return PUSH_CHAT.modifyRoles(
options: ModifyRolesType(
chatId: chatId,
newRole: role,
newRole: role.value,
account: _account,
members: accounts,
pgpPrivateKey: _decryptedPgpPvtKey,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ignore_for_file: constant_identifier_names

import '../../../push_restapi_dart.dart';
import '../../../../push_restapi_dart.dart';

class PushAPIInitializeOptions {
void Function(ProgressHookType)? progressHook;
Expand Down Expand Up @@ -111,3 +111,19 @@ class GroupUpdateOptions {
this.rules,
});
}

enum GroupRoles { MEMBER, ADMIN }

extension GroupRolesExtension on GroupRoles {
String get value {
switch (this) {
case GroupRoles.ADMIN:
return 'ADMIN';
case GroupRoles.MEMBER:
return 'MEMBER';

default:
return 'MEMBER';
}
}
}
Loading