Skip to content

Commit

Permalink
Merge pull request #2878 from TalaoDAO/matrix-notification
Browse files Browse the repository at this point in the history
Matrix notification
  • Loading branch information
bibash28 authored Sep 6, 2024
2 parents 4ef22fa + feb04bf commit 095e5ab
Show file tree
Hide file tree
Showing 46 changed files with 756 additions and 185 deletions.
Binary file added assets/icon/notification.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 matrixSupportId = '@support:matrix.talao.co';
//static const String matrixChatSupportId = '@support:matrix.talao.co';

//Chat
static const String dashBoardPage = '/dashboardPage';
Expand Down
1 change: 1 addition & 0 deletions lib/app/shared/constants/icon_strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class IconStrings {
static const String home = '$base/empty-wallet.png';
static const String discover = '$base/discover.png';
static const String settings = '$base/settings.png';
static const String notification = '$base/notification.png';
static const String advanceSettings = '$base/advance-settings.png';
static const String export = '$base/export.png';
static const String copy = '$base/copy.png';
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"
}
}
];
5 changes: 4 additions & 1 deletion lib/app/shared/constants/secure_storage_keys.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
class SecureStorageKeys {
static const String isUserRegisteredMatrix = 'isUserRegisteredMatrix';
static const String supportRoomId = 'MatrixSupportRoomId';
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
15 changes: 15 additions & 0 deletions lib/app/shared/helper_functions/helper_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,21 @@ String birthDateFormater(int birthData) {
return formattedBirthdate;
}

String chatTimeFormatter(int birthData) {
final String birthdate = birthData.toString();

// Parse the input string
final DateTime parsedBirthdate = DateTime.parse(
'${birthdate.substring(0, 4)}-${birthdate.substring(4, 6)}-${birthdate.substring(6, 8)}', // ignore: lines_longer_than_80_chars
);

// Format the parsed date
final DateFormat formatter = DateFormat('dd:MM:yyyy');
final String formattedBirthdate = formatter.format(parsedBirthdate);

return formattedBirthdate;
}

String getSignatureType(String circuitId) {
if (circuitId == 'credentialAtomicQuerySigV2' ||
circuitId == 'credentialAtomicQuerySigV2OnChain') {
Expand Down
50 changes: 32 additions & 18 deletions lib/app/view/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import 'package:altme/kyc_verification/cubit/kyc_verification_cubit.dart';
import 'package:altme/l10n/l10n.dart';
import 'package:altme/lang/cubit/lang_cubit.dart';
import 'package:altme/lang/cubit/lang_state.dart';
import 'package:altme/matrix_notification/cubit/matrix_notification_cubit.dart';
import 'package:altme/onboarding/cubit/onboarding_cubit.dart';
import 'package:altme/polygon_id/cubit/polygon_id_cubit.dart';
import 'package:altme/query_by_example/query_by_example.dart';
Expand Down Expand Up @@ -169,16 +170,6 @@ class App extends StatelessWidget {
walletCubit: context.read<WalletCubit>(),
),
),
BlocProvider<EnterpriseCubit>(
create: (context) => EnterpriseCubit(
client: DioClient(
secureStorageProvider: secureStorageProvider,
dio: Dio(),
),
profileCubit: context.read<ProfileCubit>(),
credentialsCubit: context.read<CredentialsCubit>(),
),
),
BlocProvider<ScanCubit>(
create: (context) => ScanCubit(
client: DioClient(
Expand All @@ -195,6 +186,36 @@ 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(
secureStorageProvider: secureStorageProvider,
matrixChat: MatrixChatImpl(),
profileCubit: context.read<ProfileCubit>(),
roomIdStoredKey: SecureStorageKeys.notificationSupportRoomId,
),
),
BlocProvider<EnterpriseCubit>(
create: (context) => EnterpriseCubit(
client: DioClient(
secureStorageProvider: secureStorageProvider,
dio: Dio(),
),
profileCubit: context.read<ProfileCubit>(),
credentialsCubit: context.read<CredentialsCubit>(),
matrixNotificationCubit: context.read<MatrixNotificationCubit>(),
altmeChatSupportCubit: context.read<AltmeChatSupportCubit>(),
),
),
BlocProvider<QRCodeScanCubit>(
create: (context) => QRCodeScanCubit(
client: DioClient(
Expand Down Expand Up @@ -263,14 +284,6 @@ class App extends StatelessWidget {
manageNetworkCubit: context.read<ManageNetworkCubit>(),
),
),
BlocProvider<AltmeChatSupportCubit>(
lazy: false,
create: (context) => AltmeChatSupportCubit(
secureStorageProvider: getSecureStorage,
matrixChat: MatrixChatImpl(),
profileCubit: context.read<ProfileCubit>(),
),
),
BlocProvider(
create: (context) => SplashCubit(
secureStorageProvider: secureStorageProvider,
Expand All @@ -283,6 +296,7 @@ class App extends StatelessWidget {
dio: Dio(),
),
altmeChatSupportCubit: context.read<AltmeChatSupportCubit>(),
matrixNotificationCubit: context.read<MatrixNotificationCubit>(),
profileCubit: context.read<ProfileCubit>(),
),
),
Expand Down
88 changes: 57 additions & 31 deletions lib/chat_room/cubit/chat_room_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ abstract class ChatRoomCubit extends Cubit<ChatRoomState> {
required this.secureStorageProvider,
required this.matrixChat,
required this.profileCubit,
required this.roomIdStoredKey,
}) : super(const ChatRoomState());

final SecureStorageProvider secureStorageProvider;
Expand All @@ -36,6 +37,7 @@ abstract class ChatRoomCubit extends Cubit<ChatRoomState> {
//
final MatrixChatImpl matrixChat;
final ProfileCubit profileCubit;
final String roomIdStoredKey;

Stream<int> get unreadMessageCountStream {
_notificationStreamController ??= StreamController<int>.broadcast();
Expand Down Expand Up @@ -132,6 +134,16 @@ abstract class ChatRoomCubit extends Cubit<ChatRoomState> {
);
}

Future<String?> getRoomIdFromStorage() async {
final savedRoomId = await matrixChat.getRoomIdFromStorage(roomIdStoredKey);
return savedRoomId;
}

Future<void> clearRoomIdFromStorage() async {
_roomId = null;
await matrixChat.clearRoomIdInStorage(roomIdStoredKey);
}

Future<void> init() async {
try {
emit(state.copyWith(status: AppStatus.loading));
Expand All @@ -140,7 +152,8 @@ abstract class ChatRoomCubit extends Cubit<ChatRoomState> {

List<Message> retrivedMessageFromDB = [];
await _checkIfRoomNotExistThenCreateIt();
final savedRoomId = await matrixChat.getRoomIdFromStorage();
final savedRoomId =
await matrixChat.getRoomIdFromStorage(roomIdStoredKey);
if (savedRoomId != null) {
_roomId = savedRoomId;
await matrixChat.enableRoomEncyption(savedRoomId);
Expand Down Expand Up @@ -216,8 +229,6 @@ abstract class ChatRoomCubit extends Cubit<ChatRoomState> {
);
}

setMessagesAsRead();

await Future<void>.delayed(const Duration(seconds: 1))
.then((val) => _getUnreadMessageCount());
}
Expand Down Expand Up @@ -264,41 +275,56 @@ 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) {
final roomName = helpCenterOptions.customNotificationRoom!;

await secureStorageProvider.set(
SecureStorageKeys.notificationRoomName,
roomName,
);

if (profileCubit.state.model.walletType == WalletType.enterprise &&
helpCenterOptions.customChatSupport &&
helpCenterOptions.customChatSupportName != null) {
invites.add(helpCenterOptions.customChatSupportName!);
_roomId = await matrixChat.joinRoom(roomName);
}
} else {
invites.add(AltMeStrings.matrixSupportId);
}
//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 ?? '',
);

_roomId = await matrixChat.createRoomAndInviteSupport(
tokenParameters.thumbprint,
invites,
);
final List<String> invites = [];

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

_roomId = await matrixChat.createRoomAndInviteSupport(
tokenParameters.thumbprint,
invites,
);
}

await matrixChat.setRoomIdInStorage(_roomId!);
await matrixChat.setRoomIdInStorage(roomIdStoredKey, _roomId!);
_getUnreadMessageCount();
await _subscribeToEventsOfRoom();
}
Expand Down
Loading

0 comments on commit 095e5ab

Please sign in to comment.