-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement PushStream highlevel api in SDK (#95)
* 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]> * Delete .DS_Store * 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]> * feat: add PushApi class * feat: add list,latest,history and send to Chat in PushApi clases * feat: add Chat Api class functions * feat: add all Chat class API functions * chore: add demo_app and use_cases modules to example * feat: add chat functions * feat: add chat use cases * chore: remove unneccesary log * feat: add stream highlevel api in SDK * chore: fix merge conflict * chore: remove unusd code * remove DS_Store file --------- Co-authored-by: Gbogboade Ayomide <[email protected]> Co-authored-by: Madhur Gupta <[email protected]>
- Loading branch information
1 parent
234a17c
commit 722711e
Showing
19 changed files
with
999 additions
and
135 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,117 +1,4 @@ | ||
import '../../push_restapi_dart.dart'; | ||
|
||
class PushAPI { | ||
late final Signer? _signer; | ||
late final String _account; | ||
late final String? _decryptedPgpPvtKey; | ||
final String? pgpPublicKey; | ||
final bool readMode; | ||
|
||
void Function(ProgressHookType)? progressHook; | ||
|
||
late Chat chat; | ||
PushAPI({ | ||
Signer? signer, | ||
required String account, | ||
String? decryptedPgpPvtKey, | ||
this.pgpPublicKey, | ||
this.progressHook, | ||
this.readMode = false, | ||
ENV env = ENV.staging, | ||
bool showHttpLog = false, | ||
}) { | ||
_signer = signer; | ||
_account = account; | ||
_decryptedPgpPvtKey = decryptedPgpPvtKey; | ||
|
||
initPush( | ||
env: env, | ||
showHttpLog: showHttpLog, | ||
); | ||
|
||
chat = Chat( | ||
signer: _signer, | ||
account: _account, | ||
decryptedPgpPvtKey: _decryptedPgpPvtKey, | ||
pgpPublicKey: pgpPublicKey, | ||
progressHook: progressHook, | ||
); | ||
} | ||
|
||
static Future<PushAPI> initialize( | ||
{Signer? signer, PushAPIInitializeOptions? options}) async { | ||
if (signer == null && options?.account == null) { | ||
throw Exception("Either 'signer' or 'account' must be provided."); | ||
} | ||
|
||
final readMode = signer != null; | ||
|
||
// Get account | ||
// Derives account from signer if not provided | ||
String? derivedAccount; | ||
|
||
if (signer != null) { | ||
derivedAccount = getAccountAddress( | ||
getWallet(address: options?.account, signer: signer)); | ||
} else { | ||
derivedAccount = options?.account; | ||
} | ||
|
||
if (derivedAccount == null) { | ||
throw Exception('Account could not be derived.'); | ||
} | ||
|
||
String? decryptedPGPPrivateKey; | ||
String? pgpPublicKey; | ||
|
||
/** | ||
* Decrypt PGP private key | ||
* If user exists, decrypts the PGP private key | ||
* If user does not exist, creates a new user and returns the decrypted PGP private key | ||
*/ | ||
final user = await getUser(address: derivedAccount); | ||
|
||
if (readMode) { | ||
if (user != null && user.encryptedPrivateKey != null) { | ||
decryptedPGPPrivateKey = await decryptPGPKey( | ||
toUpgrade: options?.autoUpgrade, | ||
progressHook: options?.progressHook, | ||
additionalMeta: options?.versionMeta, | ||
encryptedPGPPrivateKey: user.encryptedPrivateKey!, | ||
wallet: getWallet(address: options?.account, signer: signer), | ||
); | ||
pgpPublicKey = user.publicKey; | ||
} else { | ||
final newUser = await createUser( | ||
signer: signer, | ||
progressHook: options?.progressHook ?? (_) {}, | ||
version: options?.version ?? ENCRYPTION_TYPE.PGP_V3, | ||
); | ||
decryptedPGPPrivateKey = newUser.decryptedPrivateKey; | ||
pgpPublicKey = newUser.publicKey; | ||
} | ||
} | ||
|
||
final api = PushAPI( | ||
account: derivedAccount, | ||
signer: signer, | ||
decryptedPgpPvtKey: decryptedPGPPrivateKey, | ||
pgpPublicKey: pgpPublicKey, | ||
readMode: readMode, | ||
showHttpLog: options?.showHttpLog ?? false, | ||
); | ||
|
||
return api; | ||
} | ||
|
||
//TODO initStream | ||
Future initStream() async {} | ||
|
||
Future<User?> info({String? overrideAccount}) async { | ||
return getUser(address: overrideAccount ?? _account); | ||
} | ||
|
||
static String ensureSignerMessage() { | ||
return 'Operation not allowed in read-only mode. Signer is required.'; | ||
} | ||
} | ||
export 'src/models.dart'; | ||
export 'src/pushapi.dart'; | ||
export 'src/chat.dart' hide GroupAPI, GroupParticipantsAPI; | ||
export 'src/user.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import '../../../push_restapi_dart.dart'; | ||
|
||
class PushAPI { | ||
late final Signer? _signer; | ||
late final String _account; | ||
late final String? _decryptedPgpPvtKey; | ||
final String? pgpPublicKey; | ||
final bool readMode; | ||
|
||
void Function(ProgressHookType)? progressHook; | ||
|
||
late Chat chat; | ||
late PushStream stream; | ||
PushAPI({ | ||
Signer? signer, | ||
required String account, | ||
String? decryptedPgpPvtKey, | ||
this.pgpPublicKey, | ||
this.progressHook, | ||
this.readMode = false, | ||
ENV env = ENV.staging, | ||
bool showHttpLog = false, | ||
}) { | ||
_signer = signer; | ||
_account = account; | ||
_decryptedPgpPvtKey = decryptedPgpPvtKey; | ||
|
||
initPush( | ||
env: env, | ||
showHttpLog: showHttpLog, | ||
); | ||
|
||
chat = Chat( | ||
signer: _signer, | ||
account: _account, | ||
decryptedPgpPvtKey: _decryptedPgpPvtKey, | ||
pgpPublicKey: pgpPublicKey, | ||
progressHook: progressHook, | ||
); | ||
} | ||
|
||
static Future<PushAPI> initialize({ | ||
Signer? signer, | ||
PushAPIInitializeOptions? options, | ||
}) async { | ||
if (signer == null && options?.account == null) { | ||
throw Exception("Either 'signer' or 'account' must be provided."); | ||
} | ||
|
||
final readMode = signer != null; | ||
|
||
// Get account | ||
// Derives account from signer if not provided | ||
String? derivedAccount; | ||
|
||
if (signer != null) { | ||
derivedAccount = getAccountAddress( | ||
getWallet(address: options?.account, signer: signer)); | ||
} else { | ||
derivedAccount = options?.account; | ||
} | ||
|
||
if (derivedAccount == null) { | ||
throw Exception('Account could not be derived.'); | ||
} | ||
|
||
String? decryptedPGPPrivateKey; | ||
String? pgpPublicKey; | ||
|
||
/** | ||
* Decrypt PGP private key | ||
* If user exists, decrypts the PGP private key | ||
* If user does not exist, creates a new user and returns the decrypted PGP private key | ||
*/ | ||
final user = await getUser(address: derivedAccount); | ||
|
||
if (readMode) { | ||
if (user != null && user.encryptedPrivateKey != null) { | ||
decryptedPGPPrivateKey = await decryptPGPKey( | ||
toUpgrade: options?.autoUpgrade, | ||
progressHook: options?.progressHook, | ||
additionalMeta: options?.versionMeta, | ||
encryptedPGPPrivateKey: user.encryptedPrivateKey!, | ||
wallet: getWallet(address: options?.account, signer: signer), | ||
); | ||
pgpPublicKey = user.publicKey; | ||
} else { | ||
final newUser = await createUser( | ||
signer: signer, | ||
progressHook: options?.progressHook ?? (_) {}, | ||
version: options?.version ?? ENCRYPTION_TYPE.PGP_V3, | ||
); | ||
decryptedPGPPrivateKey = newUser.decryptedPrivateKey; | ||
pgpPublicKey = newUser.publicKey; | ||
} | ||
} | ||
|
||
final api = PushAPI( | ||
account: derivedAccount, | ||
signer: signer, | ||
decryptedPgpPvtKey: decryptedPGPPrivateKey, | ||
pgpPublicKey: pgpPublicKey, | ||
readMode: readMode, | ||
showHttpLog: options?.showHttpLog ?? false, | ||
); | ||
|
||
return api; | ||
} | ||
|
||
Future<PushStream> initStream( | ||
{required List<STREAM> listen, | ||
PushStreamInitializeOptions? options}) async { | ||
stream = await PushStream.initialize( | ||
account: _account, | ||
listen: listen, | ||
decryptedPgpPvtKey: _decryptedPgpPvtKey, | ||
options: options, | ||
progressHook: progressHook, | ||
signer: _signer, | ||
); | ||
|
||
return stream; | ||
} | ||
|
||
Future<User?> info({String? overrideAccount}) async { | ||
return getUser(address: overrideAccount ?? _account); | ||
} | ||
|
||
static String ensureSignerMessage() { | ||
return 'Operation not allowed in read-only mode. Signer is required.'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import '../../../push_restapi_dart.dart'; | ||
|
||
class UserAPI { | ||
late final String _account; | ||
UserAPI({ | ||
required String account, | ||
}) { | ||
_account = account; | ||
} | ||
|
||
Future<User?> info({String? overrideAccount}) async { | ||
return getUser(address: overrideAccount ?? _account); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export 'src/push_stream.dart'; | ||
export 'src/models/models.dart'; | ||
export 'src/models/notification_model.dart'; | ||
export 'src/data_modifier.dart'; |
Oops, something went wrong.