Skip to content

Commit

Permalink
libs ..
Browse files Browse the repository at this point in the history
  • Loading branch information
sorydima committed Dec 11, 2024
1 parent 87a91ab commit cf64d50
Show file tree
Hide file tree
Showing 23 changed files with 659 additions and 565 deletions.
58 changes: 16 additions & 42 deletions lib/pages/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,23 @@ import 'package:rechainonline/utils/matrix_sdk_extensions/event_extension.dart';
import 'package:rechainonline/utils/matrix_sdk_extensions/filtered_timeline_extension.dart';
import 'package:rechainonline/utils/matrix_sdk_extensions/matrix_locals.dart';
import 'package:rechainonline/utils/platform_infos.dart';
import 'package:rechainonline/utils/show_scaffold_dialog.dart';
import 'package:rechainonline/widgets/future_loading_dialog.dart';
import 'package:rechainonline/widgets/matrix.dart';
import 'package:rechainonline/widgets/share_scaffold_dialog.dart';
import '../../utils/account_bundles.dart';
import '../../utils/localized_exception_extension.dart';
import 'send_file_dialog.dart';
import 'send_location_dialog.dart';

class ChatPage extends StatelessWidget {
final String roomId;
final List<ShareItem>? shareItems;
final String? shareText;
final String? eventId;

const ChatPage({
super.key,
required this.roomId,
this.eventId,
this.shareItems,
this.shareText,
});

@override
Expand All @@ -71,21 +69,21 @@ class ChatPage extends StatelessWidget {
return ChatPageWithRoom(
key: Key('chat_page_${roomId}_$eventId'),
room: room,
shareItems: shareItems,
shareText: shareText,
eventId: eventId,
);
}
}

class ChatPageWithRoom extends StatefulWidget {
final Room room;
final List<ShareItem>? shareItems;
final String? shareText;
final String? eventId;

const ChatPageWithRoom({
super.key,
required this.room,
this.shareItems,
this.shareText,
this.eventId,
});

Expand Down Expand Up @@ -226,42 +224,18 @@ class ChatController extends State<ChatPageWithRoom>

void _loadDraft() async {
final prefs = await SharedPreferences.getInstance();
final draft = prefs.getString('draft_$roomId');
final draft = widget.shareText ?? prefs.getString('draft_$roomId');
if (draft != null && draft.isNotEmpty) {
sendController.text = draft;
}
}

void _shareItems([_]) {
final shareItems = widget.shareItems;
if (shareItems == null || shareItems.isEmpty) return;
for (final item in shareItems) {
if (item is FileShareItem) continue;
if (item is TextShareItem) room.sendTextEvent(item.value);
if (item is ContentShareItem) room.sendEvent(item.value);
}
final files = shareItems
.whereType<FileShareItem>()
.map((item) => item.value)
.toList();
if (files.isEmpty) return;
showAdaptiveDialog(
context: context,
builder: (c) => SendFileDialog(
files: files,
room: room,
outerContext: context,
),
);
}

@override
void initState() {
scrollController.addListener(_updateScrollController);
inputFocus.addListener(_inputFocusListener);

_loadDraft();
WidgetsBinding.instance.addPostFrameCallback(_shareItems);
super.initState();
_displayChatDetailsColumn = ValueNotifier(
Matrix.of(context).store.getBool(SettingKeys.displayChatDetailsColumn) ??
Expand Down Expand Up @@ -847,17 +821,17 @@ class ChatController extends State<ChatPageWithRoom>
}

void forwardEventsAction() async {
if (selectedEvents.isEmpty) return;
await showScaffoldDialog(
context: context,
builder: (context) => ShareScaffoldDialog(
items: selectedEvents
.map((event) => ContentShareItem(event.content))
.toList(),
),
);
if (!mounted) return;
if (selectedEvents.length == 1) {
Matrix.of(context).shareContent =
selectedEvents.first.getDisplayEvent(timeline!).content;
} else {
Matrix.of(context).shareContent = {
'msgtype': 'm.text',
'body': _getSelectedEventString(),
};
}
setState(() => selectedEvents.clear());
context.go('/rooms');
}

void sendAgainAction() {
Expand Down
64 changes: 29 additions & 35 deletions lib/pages/chat/events/audio_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
return '${duration.inMinutes.toString().padLeft(2, '0')}:${(duration.inSeconds % 60).toString().padLeft(2, '0')}';
}

List<int>? _getWaveform() {
List<int> _getWaveform() {
final eventWaveForm = widget.event.content
.tryGetMap<String, dynamic>('org.matrix.msc1767.audio')
?.tryGetList<int>('waveform');
if (eventWaveForm == null || eventWaveForm.isEmpty) {
return null;
return List<int>.filled(AudioPlayerWidget.wavesCount, 500);
}
while (eventWaveForm.length < AudioPlayerWidget.wavesCount) {
for (var i = 0; i < eventWaveForm.length; i = i + 2) {
Expand All @@ -200,7 +200,7 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
return eventWaveForm.map((i) => i > 1024 ? 1024 : i).toList();
}

late final List<int>? _waveform;
late final List<int> waveform;

void _toggleSpeed() async {
final audioPlayer = this.audioPlayer;
Expand Down Expand Up @@ -229,13 +229,12 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
@override
void initState() {
super.initState();
_waveform = _getWaveform();
waveform = _getWaveform();
}

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final waveform = _waveform;

final statusText = this.statusText ??= _durationString ?? '00:00';
final audioPlayer = this.audioPlayer;
Expand Down Expand Up @@ -291,48 +290,43 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
Expanded(
child: Stack(
children: [
if (waveform != null)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
children: [
for (var i = 0;
i < AudioPlayerWidget.wavesCount;
i++)
Expanded(
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
children: [
for (var i = 0;
i < AudioPlayerWidget.wavesCount;
i++)
Expanded(
child: Container(
height: 32,
alignment: Alignment.center,
child: Container(
height: 32,
alignment: Alignment.center,
child: Container(
margin: const EdgeInsets.symmetric(
horizontal: 1,
),
decoration: BoxDecoration(
color: i < wavePosition
? widget.color
: widget.color.withAlpha(128),
borderRadius: BorderRadius.circular(64),
),
height: 32 * (waveform[i] / 1024),
margin: const EdgeInsets.symmetric(
horizontal: 1,
),
decoration: BoxDecoration(
color: i < wavePosition
? widget.color
: widget.color.withAlpha(128),
borderRadius: BorderRadius.circular(64),
),
height: 32 * (waveform[i] / 1024),
),
),
],
),
),
],
),
),
SizedBox(
height: 32,
child: Slider(
thumbColor: widget.event.senderId ==
widget.event.room.client.userID
? theme.colorScheme.onPrimary
: theme.colorScheme.primary,
activeColor: waveform == null
? widget.color
: Colors.transparent,
inactiveColor: waveform == null
? widget.color.withAlpha(128)
: Colors.transparent,
activeColor: Colors.transparent,
inactiveColor: Colors.transparent,
max: maxPosition,
value: currentPosition,
onChanged: (position) => audioPlayer == null
Expand Down
3 changes: 0 additions & 3 deletions lib/pages/chat/send_file_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ class SendFileDialogState extends State<SendFileDialog> {
scaffoldMessenger.showLoadingSnackBar(l10n.generatingVideoThumbnail);
thumbnail = await xfile.getVideoThumbnail();
} else {
if (length > maxUploadSize) {
throw FileTooBigMatrixException(length, maxUploadSize);
}
// Else we just create a MatrixFile
file = MatrixFile(
bytes: await xfile.readAsBytes(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ChatAccessSettingsController extends State<ChatAccessSettings> {
joinRules.remove(JoinRules.knock);
}

// Not yet supported in REChain:
// Not yet supported in REChain.Online:
joinRules.remove(JoinRules.restricted);
joinRules.remove(JoinRules.knockRestricted);

Expand Down
6 changes: 3 additions & 3 deletions lib/pages/chat_access_settings/chat_access_settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ class _AliasListTile extends StatelessWidget {
'https://matrix.to/#/$alias',
context,
),
child: SelectableText(
alias,
child: Text(
'https://matrix.to/#/$alias',
style: TextStyle(
decoration: TextDecoration.underline,
decorationColor: theme.colorScheme.primary,
Expand Down Expand Up @@ -276,4 +276,4 @@ extension JoinRulesDisplayString on JoinRules {
return l10n.knockRestricted;
}
}
}
}
Loading

0 comments on commit cf64d50

Please sign in to comment.