Skip to content

Commit

Permalink
Chat scalability changes v1 (#87)
Browse files Browse the repository at this point in the history
* Scalability changes: modify update group methods (#67)

* feat: add getGroupInfo function

* chore: add deprecation notice to getGroupByName

* feat: add getGroupMemberCount function

* feat: add getGroupMembers functions

* feat: add getAllGroupMembers function

* feat: add getGroupMemberStatus function

* feat: ad getGroupMembersPublicKeys function

* feat: add getAllGroupMembersPublicKeys function

* feat: add updateGroupConfig, updateGroupMembers, updateGroupProfile

* feat: add  addMembers, removeMembers,  addAdmins, removeAdmins

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

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

This reverts commit 0268196.

* chore: add ConnectedUser extends User

---------

Co-authored-by: Gbogboade Ayomide <[email protected]>

* Scalability changes: add pgpv2 encryption in approve request (#68)

* feat: add getGroupInfo function

* chore: add deprecation notice to getGroupByName

* feat: add getGroupMemberCount function

* feat: add getGroupMembers functions

* feat: add getAllGroupMembers function

* feat: add getGroupMemberStatus function

* feat: ad getGroupMembersPublicKeys function

* feat: add getAllGroupMembersPublicKeys function

* feat: add updateGroupConfig, updateGroupMembers, updateGroupProfile

* feat: add  addMembers, removeMembers,  addAdmins, removeAdmins

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

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

This reverts commit 0268196.

* chore: add ConnectedUser extends User

* feat: add scalability changes to approve request

---------

Co-authored-by: Gbogboade Ayomide <[email protected]>

* Implement scalability changes in encryption and decryption of messages (#70)

* feat: implement scalability changes for send message

* chore: remove unused code for update group profile

* chore: add scalability changes for decrypt

---------

Co-authored-by: Gbogboade Ayomide <[email protected]>

* Remove the user property from the ConnectedUser class (#75)

* feat: add scalability changes fo updarte group

* chore: add fromUser constructor for ConnectedUser

---------

Co-authored-by: Gbogboade Ayomide <[email protected]>
Co-authored-by: Madhur Gupta <[email protected]>

* Update example app to incorporate scalability changes (#80)

* feat: add update group info screen

* feat: implement group scalability changes in example app

* feat: disconnect socket when account logs out

---------

Co-authored-by: Gbogboade Ayomide <[email protected]>
Co-authored-by: Madhur Gupta <[email protected]>
  • Loading branch information
3 people authored Dec 22, 2023
1 parent 94214aa commit 782b30c
Show file tree
Hide file tree
Showing 83 changed files with 1,485 additions and 778 deletions.
Binary file removed .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions example/lib/test_functions/chat/__chats.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ export 'get_all_group_members.dart';
export 'get_group_member_status.dart';
export 'get_group_members_public_keys.dart';
export 'get_all_group_members_public_keys.dart';
export 'update_group_config.dart';
export 'update_group_profile.dart';
export 'update_group_members.dart';
4 changes: 2 additions & 2 deletions example/lib/test_functions/chat/create_group_public.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:ethers/signers/wallet.dart' as ether;

import '../../models/signer.dart';

void testCreateGroupPublic() async {
Future testCreateGroupPublic() async {
final ethersWallet = ether.Wallet.fromPrivateKey(
"c41b72d56258e50595baa969eb0949c5cee9926ac55f7bad21fe327236772e0c");

Expand All @@ -23,6 +23,6 @@ void testCreateGroupPublic() async {

print(result);
if (result != null) {
print('testCreateGroup response: ${result}');
print('testCreateGroup response: ${result.chatId}');
}
}
8 changes: 4 additions & 4 deletions example/lib/test_functions/chat/fetch_chats.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ testAES() {

testSign() async {
try {
final result = await signMessageWithPGP(
message: 'message',
publicKey: '',
privateKeyArmored: 'privateKeyArmored');
final result = await signMessageWithPGPCore(
message: 'message',
privateKeyArmored: 'privateKeyArmored',
);

print('testSign: result $result');
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions example/lib/test_functions/chat/send.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ void testSend() async {
print('pgpPrivateKey: $pgpPrivateKey');

final options = ChatSendOptions(
accountAddress: ethersWallet.address,
account: ethersWallet.address,
pgpPrivateKey: pgpPrivateKey,
messageContent: 'Testing send() from Dart SDK for w2w chat',
receiverAddress: '0x69e666767Ba3a661369e1e2F572EdE7ADC926029',
to: '0x69e666767Ba3a661369e1e2F572EdE7ADC926029',
);

final result = await send(options);
Expand Down
5 changes: 2 additions & 3 deletions example/lib/test_functions/chat/send_composite.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ Future<void> testSendComposite() async {
}

final options = ChatSendOptions(
accountAddress: ethersWallet.address,
account: ethersWallet.address,
pgpPrivateKey: pgpPrivateKey,
message: CompositeMessage(content: [
NestedContent(type: MessageType.TEXT, content: "inner message 1"),
NestedContent(type: MessageType.TEXT, content: "inner message 2")
]),
receiverAddress:
'83e6aaf9fb44c5929ea965d2b0c4e98fd8b6094b72f51989123f81e6cf69f298',
to: '83e6aaf9fb44c5929ea965d2b0c4e98fd8b6094b72f51989123f81e6cf69f298',
);

final result = await send(options);
Expand Down
12 changes: 6 additions & 6 deletions example/lib/test_functions/chat/send_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ Future<void> testSendFile() async {
}

final options = ChatSendOptions(
accountAddress: ethersWallet.address,
account: ethersWallet.address,
pgpPrivateKey: pgpPrivateKey,
message: FileMessage(
content: "data:text/plain;base64,VmVuZ2VhbmNlMjM0NUAjJCU=",
name: "something.txt",
type: "text/plain"),
receiverAddress:
'83e6aaf9fb44c5929ea965d2b0c4e98fd8b6094b72f51989123f81e6cf69f298',
content: "data:text/plain;base64,VmVuZ2VhbmNlMjM0NUAjJCU=",
name: "something.txt",
type: "text/plain",
),
to: '83e6aaf9fb44c5929ea965d2b0c4e98fd8b6094b72f51989123f81e6cf69f298',
);

final result = await send(options);
Expand Down
5 changes: 2 additions & 3 deletions example/lib/test_functions/chat/send_group.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ Future<void> testSendToGroup() async {
print('pgpPrivateKey: $pgpPrivateKey');

final options = ChatSendOptions(
accountAddress: ethersWallet.address,
account: ethersWallet.address,
pgpPrivateKey: pgpPrivateKey,
messageContent: 'Testing send() from Dart SDK for group chat',
receiverAddress:
'83e6aaf9fb44c5929ea965d2b0c4e98fd8b6094b72f51989123f81e6cf69f298',
to: '83e6aaf9fb44c5929ea965d2b0c4e98fd8b6094b72f51989123f81e6cf69f298',
);

final result = await send(options);
Expand Down
14 changes: 8 additions & 6 deletions example/lib/test_functions/chat/send_group_meta.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ Future<void> testSendToGroupMeta() async {
}

final options = ChatSendOptions(
accountAddress: ethersWallet.address,
account: ethersWallet.address,
pgpPrivateKey: pgpPrivateKey,
message: MetaMessage(
info: Info(
affected: [ethersWallet.address!], arbitrary: {'key': 'value'}),
content: CHAT.META_GROUP_CREATE),
receiverAddress:
'83e6aaf9fb44c5929ea965d2b0c4e98fd8b6094b72f51989123f81e6cf69f298',
info: Info(
affected: [ethersWallet.address!],
arbitrary: {'key': 'value'},
),
content: CHAT.META_GROUP_CREATE,
),
to: '83e6aaf9fb44c5929ea965d2b0c4e98fd8b6094b72f51989123f81e6cf69f298',
);

final result = await send(options);
Expand Down
5 changes: 2 additions & 3 deletions example/lib/test_functions/chat/send_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@ Future<void> testSendImage() async {
}

final options = ChatSendOptions(
accountAddress: ethersWallet.address,
account: ethersWallet.address,
pgpPrivateKey: pgpPrivateKey,
message: ImageMessage(
name: "something.png",
content:
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAARMAAAC3CAMAAAAGjUrGAAAAjVBMVEX///+8AC27ACq6ACC6ACK7ACe6AB65ABu+AC+8ACi7ACX88/W3AAC4ABP77/K5ABf23eTy0NfwytLrwcjimqnXdInLVmjFQFTBI0G/CTTtvcjclKC4AA756OzPU23XeYvEMUvKSWHTaX6/FDjosLvZgZHFNE/z1dzlqLTQYHXKQV7orLrWfIrPVm/nvMFRtU1mAAADLklEQVR42u3d2XKjMBCFYbcQBuQFEydesGNDvGT3+z/eXEzNzaCpyQJKNf6/RziFpHZby2AAAAAAAA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b0c4e98fd8b6094b72f51989123f81e6cf69f298',
to: '83e6aaf9fb44c5929ea965d2b0c4e98fd8b6094b72f51989123f81e6cf69f298',
);

final result = await send(options);
Expand Down
5 changes: 2 additions & 3 deletions example/lib/test_functions/chat/send_media_embed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ Future<void> testSendMediaEmbed() async {
}

final options = ChatSendOptions(
accountAddress: ethersWallet.address,
account: ethersWallet.address,
pgpPrivateKey: pgpPrivateKey,
message: SendMessage(
type: MessageType.MEDIA_EMBED,
content:
"https://media2.giphy.com/media/p0L1rezLH2Tja/giphy.gif?cid=c918c0ff667b3vbiu4i4e5d1t9sqssx8uvy10reprq8yds23&ep=v1_gifs_trending&rid=giphy.gif&ct=g"),
receiverAddress:
'83e6aaf9fb44c5929ea965d2b0c4e98fd8b6094b72f51989123f81e6cf69f298',
to: '83e6aaf9fb44c5929ea965d2b0c4e98fd8b6094b72f51989123f81e6cf69f298',
);

final result = await send(options);
Expand Down
4 changes: 2 additions & 2 deletions example/lib/test_functions/chat/send_reaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ Future<void> testSendReaction() async {
}

final options = ChatSendOptions(
accountAddress: ethersWallet.address,
account: ethersWallet.address,
pgpPrivateKey: pgpPrivateKey,
message: ReactionMessage(
content: CHAT.REACTION_THUMBSUP, reference: referenceLink),
receiverAddress: groupId,
to: groupId,
);

final result = await send(options);
Expand Down
4 changes: 2 additions & 2 deletions example/lib/test_functions/chat/send_reply.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ Future<void> testSendReply() async {
}

final options = ChatSendOptions(
accountAddress: ethersWallet.address,
account: ethersWallet.address,
pgpPrivateKey: pgpPrivateKey,
message: ReplyMessage(
content: NestedContent(
type: MessageType.TEXT,
content: "reply message sent from the Dart SDK"),
reference: referenceLink),
receiverAddress: groupId,
to: groupId,
);

final result = await send(options);
Expand Down
10 changes: 10 additions & 0 deletions example/lib/test_functions/chat/update_group_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:push_restapi_dart/push_restapi_dart.dart';

void testUpdateGroupConfig() async {
final result = await updateGroupConfig(
scheduleAt: DateTime.now().add(Duration(hours: 3)),
chatId:
'64434400c9a61256451f025f1f8c7b34d9651af4a03ca063126e137572fb85ca');

print(result);
}
11 changes: 11 additions & 0 deletions example/lib/test_functions/chat/update_group_members.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:push_restapi_dart/push_restapi_dart.dart';

void testUpdateGroupMembers() async {
final result = await updateGroupMembers(
chatId:
'a279ff975a104e8b04806bee18edc2c489b619663d6b192cbb07b4bbfd616e45',
upsert:
UpsertDTO(admins: ['0x29b8276AA5bc432e03745eF275ded9074faB5970']));

print(result);
}
12 changes: 12 additions & 0 deletions example/lib/test_functions/chat/update_group_profile.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:push_restapi_dart/push_restapi_dart.dart';

void testUpdateGroupProfile() async {
final result = await updateGroupProfile(
groupImage:
'https://tmpfiles.org/dl/3250024/screenshot2023-11-26at8.51.05pm.png',
chatId:
'64434400c9a61256451f025f1f8c7b34d9651af4a03ca063126e137572fb85ca',
groupName: 'Ayo New name');

print(result);
}
4 changes: 2 additions & 2 deletions example/lib/test_functions/payload/send_notification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void testSendVideoCallNotification() async {

// 5. Decrypt keys in Grp
final pgpPrivateKey = await push.decryptPGPKey(
encryptedPGPPrivateKey: user?.encryptedPrivateKey as String,
encryptedPGPPrivateKey: user.encryptedPrivateKey as String,
wallet: push.getWallet(signer: signer),
);

Expand All @@ -47,7 +47,7 @@ void testSendVideoCallNotification() async {
senderType: 1,
signer: signer,
pgpPrivateKey: pgpPrivateKey,
pgpPublicKey: user?.publicKey,
pgpPublicKey: user.publicKey,
chatId: group?.chatId,
type: push.NOTIFICATION_TYPE.BROADCAST, // broadcast
identityType: push.IDENTITY_TYPE.DIRECT_PAYLOAD, // direct payload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ Future<void> testSendLiveSpaceDataMeta() async {
content: content);

final options = ChatSendOptions(
accountAddress: ethersWallet.address,
account: ethersWallet.address,
pgpPrivateKey: pgpPrivateKey,
message: metaMessage,
receiverAddress:
'spaces:cff80fae9b898b9f5d679bfa7ef4dfcb7d31b9d1c12e032f4ec6d84a575e62cb',
to: 'spaces:cff80fae9b898b9f5d679bfa7ef4dfcb7d31b9d1c12e032f4ec6d84a575e62cb',
);

final result = await send(options);
Expand Down
5 changes: 2 additions & 3 deletions example/lib/test_functions/space/send_live_space_data_ua.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ Future<void> testSendLiveSpaceDataUA() async {
content: content);

final options = ChatSendOptions(
accountAddress: ethersWallet.address,
account: ethersWallet.address,
pgpPrivateKey: pgpPrivateKey,
message: userActivityMessage,
receiverAddress:
'spaces:cff80fae9b898b9f5d679bfa7ef4dfcb7d31b9d1c12e032f4ec6d84a575e62cb',
to: 'spaces:cff80fae9b898b9f5d679bfa7ef4dfcb7d31b9d1c12e032f4ec6d84a575e62cb',
);

final result = await send(options);
Expand Down
5 changes: 2 additions & 3 deletions example/lib/test_functions/space/send_space_reaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ Future<void> testSendSpaceReaction() async {
content: content);

final options = ChatSendOptions(
accountAddress: ethersWallet.address,
account: ethersWallet.address,
pgpPrivateKey: pgpPrivateKey,
message: reactionMessage,
receiverAddress:
'spaces:cff80fae9b898b9f5d679bfa7ef4dfcb7d31b9d1c12e032f4ec6d84a575e62cb',
to: 'spaces:cff80fae9b898b9f5d679bfa7ef4dfcb7d31b9d1c12e032f4ec6d84a575e62cb',
);

final result = await send(options);
Expand Down
2 changes: 1 addition & 1 deletion example/lib/test_functions/user/test_create_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void testCreateRandomUser() async {
},
);

print(result?.did);
print(result.did);
} catch (e) {
print(e);
}
Expand Down
24 changes: 15 additions & 9 deletions example/lib/views/account_provider.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '../__lib.dart';
import 'package:push_restapi_dart/push_restapi_dart.dart';

import 'package:socket_io_client/socket_io_client.dart' as io;
import 'package:ethers/signers/wallet.dart' as ether;

final accountProvider = ChangeNotifierProvider((ref) => AccountProvider(ref));
Expand Down Expand Up @@ -97,6 +97,7 @@ class AccountProvider extends ChangeNotifier {
}
}

io.Socket? pushSDKSocket;
Future<void> creatSocketConnection() async {
try {
final options = SocketInputOptions(
Expand All @@ -109,26 +110,26 @@ class AccountProvider extends ChangeNotifier {
),
);

final pushSDKSocket = await createSocketConnection(options);
pushSDKSocket = await createSocketConnection(options);
if (pushSDKSocket == null) {
throw Exception('PushSDKSocket Connection Failed');
}

pushSDKSocket.connect();
pushSDKSocket!.connect();

pushSDKSocket.on(
pushSDKSocket!.on(
EVENTS.CONNECT,
(data) async {
print(' NOTIFICATION EVENTS.CONNECT: $data');
},
);
// To get messages in realtime
pushSDKSocket.on(EVENTS.CHAT_RECEIVED_MESSAGE, (message) {
pushSDKSocket!.on(EVENTS.CHAT_RECEIVED_MESSAGE, (message) {
print('CHAT NOTIFICATION EVENTS.CHAT_RECEIVED_MESSAGE: $message');
ref.read(conversationsProvider).onReceiveSocket(message);
});

pushSDKSocket.on(EVENTS.SPACES, (groupInfo) {
pushSDKSocket!.on(EVENTS.SPACES, (groupInfo) {
print('SPACES NOTIFICATION EVENTS.SPACES: $groupInfo');

final type = (groupInfo as Map<String, dynamic>)['eventType'];
Expand All @@ -149,7 +150,7 @@ class AccountProvider extends ChangeNotifier {
});

// To get group creation or updation events
pushSDKSocket.on(EVENTS.CHAT_GROUPS, (groupInfo) {
pushSDKSocket!.on(EVENTS.CHAT_GROUPS, (groupInfo) {
print('CHAT NOTIFICATION EVENTS.CHAT_GROUPS: $groupInfo');

final type = (groupInfo as Map<String, dynamic>)['eventType'];
Expand All @@ -172,7 +173,7 @@ class AccountProvider extends ChangeNotifier {
});

// To get realtime updates for spaces
pushSDKSocket.on(
pushSDKSocket!.on(
EVENTS.SPACES_MESSAGES,
(data) async {
final message = data as Map<String, dynamic>;
Expand Down Expand Up @@ -228,7 +229,7 @@ class AccountProvider extends ChangeNotifier {
},
);

pushSDKSocket.on(
pushSDKSocket!.on(
EVENTS.DISCONNECT,
(data) {
print(' NOTIFICATION EVENTS.DISCONNECT: $data');
Expand All @@ -241,6 +242,11 @@ class AccountProvider extends ChangeNotifier {

logOut() {
pushWallet = null;
if (pushSDKSocket != null) {
pushSDKSocket!.close();
pushSDKSocket = null;
}

notifyListeners();
}
}
Expand Down
Loading

0 comments on commit 782b30c

Please sign in to comment.