Skip to content

Commit

Permalink
feat: Fix notification issue and make chat only custom
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Sep 5, 2024
1 parent 2e0c968 commit f257dbb
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 120 deletions.
2 changes: 1 addition & 1 deletion lib/app/shared/constants/altme_strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AltMeStrings {
static const String time = 'time';

//page
static const String matrixChatSupportId = '@support:matrix.talao.co';
//static const String matrixChatSupportId = '@support:matrix.talao.co';

//Chat
static const String dashBoardPage = '/dashboardPage';
Expand Down
81 changes: 0 additions & 81 deletions lib/app/shared/constants/parameters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,84 +115,3 @@ class Parameters {
// ThemeMode.light for talao
static const ThemeMode defaultTheme = ThemeMode.dark;
}

final respond = [
{
"token_instance": {
"is_unique": true,
"id": "431",
"holder_address_hash": "0x394c399dbA25B99Ab7708EdB505d755B3aa29997",
"image_url": "example.com/picture.png",
"animation_url": "example.com/video.mp4",
"external_app_url": "d-app.com",
"metadata": {
"year": 2023,
"tags": ["poap", "event"],
"name": "Social Listening Committee #2 Attendees",
"image_url":
"https://assets.poap.xyz/chanel-poap-4c-2023-logo-1675083420470.png",
"home_url": "https://app.poap.xyz/token/6292128",
"external_url": "https://api.poap.tech/metadata/99010/6292128",
"description":
"This is the POAP for attendees of the second Social Listening Committee.",
"attributes": [
{"value": "01-Feb-2023", "trait_type": "startDate"},
{"value": "01-Feb-2023", "trait_type": "endDate"},
{"value": "false", "trait_type": "virtualEvent"},
{"value": "Paris", "trait_type": "city"},
{"value": "France", "trait_type": "country"},
{"value": "https://www.chanel.com", "trait_type": "eventURL"}
]
},
"owner": {
"hash": "0xEb533ee5687044E622C69c58B1B12329F56eD9ad",
"implementation_name": "implementationName",
"name": "contractName",
"is_contract": true,
"private_tags": [
{
"address_hash": "0xEb533ee5687044E622C69c58B1B12329F56eD9ad",
"display_name": "name to show",
"label": "label"
}
],
"watchlist_names": [
{"display_name": "name to show", "label": "label"}
],
"public_tags": [
{
"address_hash": "0xEb533ee5687044E622C69c58B1B12329F56eD9ad",
"display_name": "name to show",
"label": "label"
}
],
"is_verified": true
},
"token": {
"circulating_market_cap": "83606435600.3635",
"icon_url":
"https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xdAC17F958D2ee523a2206206994597C13D831ec7/logo.png",
"name": "Tether USD",
"decimals": "6",
"symbol": "USDT",
"address": "0x394c399dbA25B99Ab7708EdB505d755B3aa29997",
"type": "ERC-20",
"holders": "837494234523",
"exchange_rate": "0.99",
"total_supply": "10000000"
}
},
"value": "10000",
"token_id": "123",
"token": {
"name": "Tether USD",
"decimals": "16",
"symbol": "USDT",
"address": "0x394c399dbA25B99Ab7708EdB505d755B3aa29997",
"type": "ERC-20",
"holders": 837494234523,
"exchange_rate": "0.99",
"total_supply": "10000000"
}
}
];
1 change: 1 addition & 0 deletions lib/app/shared/constants/secure_storage_keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class SecureStorageKeys {
static const String chatSupportRoomId = 'MatrixSupportRoomId';
static const String notificationSupportRoomId =
'MatrixNotificationSupportRoomId';
static const String notificationRoomName = 'notificationRoomName';
static const String isFirstSelectedTokenContracts =
'isFirstSelectedTokenContracts';
static const String selectedContracts = 'selectedContracts';
Expand Down
19 changes: 10 additions & 9 deletions lib/app/view/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,15 @@ class App extends StatelessWidget {
jwtDecode: JWTDecode(),
),
),
BlocProvider<AltmeChatSupportCubit>(
lazy: false,
create: (context) => AltmeChatSupportCubit(
secureStorageProvider: secureStorageProvider,
matrixChat: MatrixChatImpl(),
profileCubit: context.read<ProfileCubit>(),
roomIdStoredKey: SecureStorageKeys.chatSupportRoomId,
),
),
BlocProvider<MatrixNotificationCubit>(
lazy: false,
create: (context) => MatrixNotificationCubit(
Expand All @@ -204,6 +213,7 @@ class App extends StatelessWidget {
profileCubit: context.read<ProfileCubit>(),
credentialsCubit: context.read<CredentialsCubit>(),
matrixNotificationCubit: context.read<MatrixNotificationCubit>(),
altmeChatSupportCubit: context.read<AltmeChatSupportCubit>(),
),
),
BlocProvider<QRCodeScanCubit>(
Expand Down Expand Up @@ -274,15 +284,6 @@ class App extends StatelessWidget {
manageNetworkCubit: context.read<ManageNetworkCubit>(),
),
),
BlocProvider<AltmeChatSupportCubit>(
lazy: false,
create: (context) => AltmeChatSupportCubit(
secureStorageProvider: secureStorageProvider,
matrixChat: MatrixChatImpl(),
profileCubit: context.read<ProfileCubit>(),
roomIdStoredKey: SecureStorageKeys.chatSupportRoomId,
),
),
BlocProvider(
create: (context) => SplashCubit(
secureStorageProvider: secureStorageProvider,
Expand Down
49 changes: 27 additions & 22 deletions lib/chat_room/cubit/chat_room_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,43 +274,48 @@ abstract class ChatRoomCubit extends Cubit<ChatRoomState> {

Future<void> _checkIfRoomNotExistThenCreateIt() async {
if (_roomId == null || _roomId!.isEmpty) {
final p256KeyForWallet =
await getP256KeyToGetAndPresentVC(secureStorageProvider);

final customOidc4vcProfile = profileCubit.state.model.profileSetting
.selfSovereignIdentityOptions.customOidc4vcProfile;

final tokenParameters = TokenParameters(
privateKey: jsonDecode(p256KeyForWallet) as Map<String, dynamic>,
did: '', // just added as it is required field
mediaType: MediaType.basic, // just added as it is required field
clientType:
ClientType.p256JWKThumprint, // just added as it is required field
proofHeaderType: customOidc4vcProfile.proofHeader,
clientId: customOidc4vcProfile.clientId ?? '',
);

final helpCenterOptions =
profileCubit.state.model.profileSetting.helpCenterOptions;

final List<String> invites = [];

if (roomIdStoredKey == SecureStorageKeys.notificationSupportRoomId) {
if (helpCenterOptions.customNotification != null &&
helpCenterOptions.customNotification! &&
helpCenterOptions.customNotificationRoom != null) {
_roomId = await matrixChat
.joinRoom(helpCenterOptions.customNotificationRoom!);
final roomName = helpCenterOptions.customNotificationRoom!;

await secureStorageProvider.set(
SecureStorageKeys.notificationRoomName,
roomName,
);
_roomId = await matrixChat.joinRoom(roomName);
}
} else {
//roomIdStoredKey == SecureStorageKeys.chatSupportRoomId

final p256KeyForWallet =
await getP256KeyToGetAndPresentVC(secureStorageProvider);

final customOidc4vcProfile = profileCubit.state.model.profileSetting
.selfSovereignIdentityOptions.customOidc4vcProfile;

final tokenParameters = TokenParameters(
privateKey: jsonDecode(p256KeyForWallet) as Map<String, dynamic>,
did: '', // just added as it is required field
mediaType: MediaType.basic, // just added as it is required field
clientType:
ClientType.p256JWKThumprint, // just added as it is required field
proofHeaderType: customOidc4vcProfile.proofHeader,
clientId: customOidc4vcProfile.clientId ?? '',
);

final List<String> invites = [];

if (profileCubit.state.model.walletType == WalletType.enterprise &&
helpCenterOptions.customChatSupport &&
helpCenterOptions.customChatSupportName != null) {
invites.add(helpCenterOptions.customChatSupportName!);
} else {
invites.add(AltMeStrings.matrixChatSupportId);
}

_roomId = await matrixChat.createRoomAndInviteSupport(
tokenParameters.thumbprint,
invites,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

Future<void> resetWallet(BuildContext context) async {
await context.read<AltmeChatSupportCubit>().dispose();
await context.read<MatrixNotificationCubit>().dispose();
await context.read<ProfileCubit>().resetProfile();
await context
.read<WalletCubit>()
.resetWallet(context.read<CredentialsCubit>());
await context.read<AltmeChatSupportCubit>().dispose();
await context.read<MatrixNotificationCubit>().dispose();
.resetWallet(context.read<CredentialsCubit>()); // should be at last
}
10 changes: 10 additions & 0 deletions lib/enterprise/cubit/enterprise_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ class EnterpriseCubit extends Cubit<EnterpriseState> {
required this.client,
required this.profileCubit,
required this.credentialsCubit,
required this.altmeChatSupportCubit,
required this.matrixNotificationCubit,
}) : super(const EnterpriseState());

final DioClient client;
final ProfileCubit profileCubit;
final CredentialsCubit credentialsCubit;
final AltmeChatSupportCubit altmeChatSupportCubit;
final MatrixNotificationCubit matrixNotificationCubit;

Future<void> requestTheConfiguration({
Expand Down Expand Up @@ -164,12 +166,19 @@ class EnterpriseCubit extends Cubit<EnterpriseState> {
);
final helpCenterOptions = profileSetting.helpCenterOptions;

if (helpCenterOptions.customChatSupport &&
helpCenterOptions.customChatSupportName != null) {
await altmeChatSupportCubit.init();
}

if (helpCenterOptions.customNotification != null &&
helpCenterOptions.customNotification! &&
helpCenterOptions.customNotificationRoom != null) {
await matrixNotificationCubit.init();
}

// chat is not initiatied at start

emit(
state.copyWith(
status: AppStatus.success,
Expand Down Expand Up @@ -517,6 +526,7 @@ class EnterpriseCubit extends Cubit<EnterpriseState> {

if (roomName != savedRoomName) {
await matrixNotificationCubit.clearRoomIdFromStorage();
await matrixNotificationCubit.dispose();
}

await matrixNotificationCubit.init();
Expand Down
7 changes: 5 additions & 2 deletions lib/onboarding/helper_function/helper_function.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ Future<void> generateAccount({
);

if (profileCubit.state.model.walletType == WalletType.enterprise) {
/// initiate chat if it is enterprise
await altmeChatSupportCubit.init();
final helpCenterOptions =
profileCubit.state.model.profileSetting.helpCenterOptions;

if (helpCenterOptions.customChatSupport &&
helpCenterOptions.customChatSupportName != null) {
await altmeChatSupportCubit.init();
}

if (helpCenterOptions.customNotification != null &&
helpCenterOptions.customNotification! &&
helpCenterOptions.customNotificationRoom != null) {
Expand Down
7 changes: 5 additions & 2 deletions lib/splash/cubit/splash_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,14 @@ class SplashCubit extends Cubit<SplashState> {
if (hasWallet) {
await homeCubit.emitHasWallet();
if (profileCubit.state.model.walletType == WalletType.enterprise) {
await altmeChatSupportCubit.init();

final helpCenterOptions =
profileCubit.state.model.profileSetting.helpCenterOptions;

if (helpCenterOptions.customChatSupport &&
helpCenterOptions.customChatSupportName != null) {
await altmeChatSupportCubit.init();
}

if (helpCenterOptions.customNotification != null &&
helpCenterOptions.customNotification! &&
helpCenterOptions.customNotificationRoom != null) {
Expand Down

0 comments on commit f257dbb

Please sign in to comment.