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

feat: implement encrypted one-on-one and group conversation #509

Merged
46 changes: 41 additions & 5 deletions lib/app/features/chat/messages/views/pages/messages_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,56 @@ import 'package:ion/app/extensions/extensions.dart';
import 'package:ion/app/features/chat/components/messaging_header/messaging_header.dart';
import 'package:ion/app/features/chat/messages/providers/chat_messages_provider.c.dart';
import 'package:ion/app/features/chat/messages/views/components/components.dart';
import 'package:ion/app/features/chat/model/chat_type.dart';
import 'package:ion/app/features/chat/model/conversation_data.c.dart';
import 'package:ion/app/features/chat/providers/e2ee_group_conversation_management_provider.c.dart';
import 'package:ion/app/features/chat/views/components/messages_list.dart';
import 'package:ion/app/features/core/views/pages/error_modal.dart';
import 'package:ion/app/router/app_routes.c.dart';
import 'package:ion/app/router/utils/show_simple_bottom_sheet.dart';
import 'package:ion/app/services/keyboard/keyboard.dart';
import 'package:ion/generated/assets.gen.dart';

const String hasPrivacyModalShownKey = 'hasPrivacyModalShownKey';

class MessagesPage extends HookConsumerWidget {
const MessagesPage({super.key});
const MessagesPage(this.conversationData, {super.key});

final ConversationData conversationData;

@override
Widget build(BuildContext context, WidgetRef ref) {
final isEmpty = useMemoized(() => Random().nextBool(), []);
final messages = ref.watch(chatMessagesProvider);

// TODO: Should be called if there is no conversation messages yet in DB
useCallback(() async {
final ee2eGroupConversationService =
ref.read(e2EEGroupConversationManagementProvider.notifier);

if (conversationData.type == ChatType.chat) {
await ee2eGroupConversationService.createOneOnOneConversation(conversationData.members);
} else if (conversationData.type == ChatType.group && conversationData.mediaImage != null) {
await ee2eGroupConversationService.createGroup(
subject: conversationData.name,
groupImage: conversationData.mediaImage!,
participantsPubkeys: conversationData.members,
);
}
});

ref.listen(
e2EEGroupConversationManagementProvider,
(previous, next) async {
if (next is AsyncError) {
await showSimpleBottomSheet<void>(
context: context,
child: ErrorModal(error: next.error),
);
}
},
);

return GestureDetector(
onTap: () => hideKeyboard(context),
child: Scaffold(
Expand All @@ -36,11 +71,12 @@ class MessagesPage extends HookConsumerWidget {
child: Column(
children: [
MessagingHeader(
imageUrl: 'https://i.pravatar.cc/150?u=@anna',
isVerified: true,
name: 'Selena Maringue',
imageUrl: conversationData.imageUrl,
name: conversationData.name,
subtitle: Text(
'@selenamaringue',
conversationData.type == ChatType.chat
? conversationData.nickname ?? ''
: conversationData.members.length.toString(),
style: context.theme.appTextThemes.caption.copyWith(
color: context.theme.appColors.quaternaryText,
),
Expand Down
19 changes: 19 additions & 0 deletions lib/app/features/chat/model/conversation_data.c.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: ice License 1.0

import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:ion/app/features/chat/model/chat_type.dart';
import 'package:ion/app/services/media_service/media_service.c.dart';

part 'conversation_data.c.freezed.dart';

@freezed
class ConversationData with _$ConversationData {
const factory ConversationData({
required String name,
required ChatType type,
required List<String> members,
String? nickname,
String? imageUrl,
MediaFile? mediaImage,
}) = _ConversationData;
}
18 changes: 0 additions & 18 deletions lib/app/features/chat/model/group.c.dart

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import 'package:riverpod_annotation/riverpod_annotation.dart';
part 'conversation_message_actions_provider.c.g.dart';

@Riverpod(keepAlive: true)
Future<Raw<ConversationMessageActionsService>> conversationMessageActionsService(
Raw<Future<ConversationMessageActionsService>> conversationMessageActionsService(
Ref ref,
) async {
final databaseService = ref.watch(conversationsDBServiceProvider);
final conversationMessageManagementService =
ref.watch(conversationMessageManagementServiceProvider).requireValue;
await ref.watch(conversationMessageManagementServiceProvider);

final eventSigner = await ref.watch(currentUserIonConnectEventSignerProvider.future);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import 'package:riverpod_annotation/riverpod_annotation.dart';
part 'conversation_message_management_provider.c.g.dart';

@Riverpod(keepAlive: true)
Future<Raw<ConversationMessageManagementService>> conversationMessageManagementService(
Raw<Future<ConversationMessageManagementService>> conversationMessageManagementService(
Ref ref,
) async {
final eventSigner = await ref.watch(currentUserIonConnectEventSignerProvider.future);
Expand Down Expand Up @@ -238,6 +238,12 @@ class ConversationMessageManagementService {
sig: null,
);

final expirationTag = EntityExpiration(
value: DateTime.now().add(
Duration(hours: env.get<int>(EnvVariable.STORY_EXPIRATION_HOURS)),
),
).toTag();

Logger.log('Event message $eventMessage');

final seal = await sealService.createSeal(
Expand All @@ -253,6 +259,7 @@ class ConversationMessageManagementService {
receiverPubkey,
signer,
PrivateDirectMessageEntity.kind,
expirationTag: expirationTag,
);

Logger.log('Wrap message $wrap');
Expand Down

This file was deleted.

Loading