Initial commit: JustAMessenger v0.1.0
Серверная часть (Go): - WebSocket сервер с бинарным протоколом - XChaCha20-Poly1305 шифрование - zstd сжатие с дедупликацией (64KB чанки) - SQLite хранилище (WAL режим) - Управление гильдиями, каналами, ролями - Федерация между серверами (ed25519) - REST API + WebSocket endpoints Клиентская часть (Flutter): - Material Design 3 тёмная тема (Discord-like) - WebSocket соединение с сервером - Экраны: сплэш, логин, домашний, гильдии, чат - Модели: пользователи, гильдии, каналы, сообщения, роли - Сервисы: соединение, API, криптография, тема - Виджеты: иконки гильдий, сообщения, ввод чата - Web сборка (PWA) Документация: - AGENTS.md — контекст для ИИ ассистентов - docs/protocol.md — спецификация протокола
This commit is contained in:
@@ -0,0 +1,162 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../services/theme_service.dart';
|
||||
|
||||
class ChatInput extends StatefulWidget {
|
||||
final TextEditingController controller;
|
||||
final VoidCallback? onSend;
|
||||
final String channelId;
|
||||
final void Function(String)? onSendMessage;
|
||||
|
||||
const ChatInput({
|
||||
super.key,
|
||||
required this.controller,
|
||||
this.onSend,
|
||||
this.onSendMessage,
|
||||
required this.channelId,
|
||||
});
|
||||
|
||||
@override
|
||||
State<ChatInput> createState() => _ChatInputState();
|
||||
}
|
||||
|
||||
class _ChatInputState extends State<ChatInput> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
decoration: const BoxDecoration(
|
||||
color: ThemeService.surfaceSecondary,
|
||||
border: Border(top: BorderSide(color: Color(0xFF3F4147))),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add_circle_outline,
|
||||
color: ThemeService.textSecondary, size: 24),
|
||||
onPressed: _showAttachmentMenu,
|
||||
tooltip: 'Attach',
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: widget.controller,
|
||||
maxLines: 5,
|
||||
minLines: 1,
|
||||
textCapitalization: TextCapitalization.sentences,
|
||||
style: const TextStyle(
|
||||
color: ThemeService.textPrimary,
|
||||
fontSize: 15,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Message #${widget.channelId.split('-').first}',
|
||||
hintStyle: const TextStyle(
|
||||
color: ThemeService.textMuted,
|
||||
fontSize: 15,
|
||||
),
|
||||
filled: true,
|
||||
fillColor: ThemeService.surfacePrimary,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 12, vertical: 10),
|
||||
isDense: true,
|
||||
),
|
||||
onSubmitted: (text) => widget.onSendMessage?.call(text),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.mic_none,
|
||||
color: ThemeService.textSecondary, size: 24),
|
||||
onPressed: _startVoiceRecording,
|
||||
tooltip: 'Voice message',
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.send_rounded,
|
||||
color: ThemeService.primary, size: 24),
|
||||
onPressed: () => widget.onSendMessage
|
||||
?.call(widget.controller.text),
|
||||
tooltip: 'Send',
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showAttachmentMenu() {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
backgroundColor: ThemeService.surfaceSecondary,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(12)),
|
||||
),
|
||||
builder: (ctx) => SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text(
|
||||
'Attach',
|
||||
style: TextStyle(
|
||||
color: ThemeService.textPrimary,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
_attachmentButton(Icons.photo, 'Image', () => Navigator.pop(ctx)),
|
||||
_attachmentButton(Icons.videocam, 'Video', () => Navigator.pop(ctx)),
|
||||
_attachmentButton(Icons.description, 'File', () => Navigator.pop(ctx)),
|
||||
_attachmentButton(Icons.mic, 'Voice', () => Navigator.pop(ctx)),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _attachmentButton(IconData icon, String label, VoidCallback onTap) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
width: 56,
|
||||
height: 56,
|
||||
decoration: BoxDecoration(
|
||||
color: ThemeService.surfacePrimary,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
child: Icon(icon, color: ThemeService.textSecondary, size: 28),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
color: ThemeService.textSecondary,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _startVoiceRecording() {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Voice recording coming soon...'),
|
||||
duration: Duration(seconds: 1),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../services/theme_service.dart';
|
||||
|
||||
class GuildIcon extends StatelessWidget {
|
||||
final String name;
|
||||
final String? icon;
|
||||
final bool selected;
|
||||
final double size;
|
||||
|
||||
const GuildIcon({
|
||||
super.key,
|
||||
required this.name,
|
||||
this.icon,
|
||||
this.selected = false,
|
||||
this.size = 48,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final borderRadius = selected ? 14.0 : 24.0;
|
||||
|
||||
return Stack(
|
||||
children: [
|
||||
if (selected)
|
||||
Positioned(
|
||||
left: -8,
|
||||
top: 0,
|
||||
bottom: 0,
|
||||
child: Container(
|
||||
width: 4,
|
||||
height: size * 0.4,
|
||||
decoration: BoxDecoration(
|
||||
color: ThemeService.textPrimary,
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: size * 0.25),
|
||||
child: Container(
|
||||
width: size,
|
||||
height: size,
|
||||
decoration: BoxDecoration(
|
||||
color: selected
|
||||
? ThemeService.primary
|
||||
: ThemeService.surfacePrimary,
|
||||
borderRadius: BorderRadius.circular(borderRadius),
|
||||
),
|
||||
child: Center(
|
||||
child: icon != null
|
||||
? ClipRRect(
|
||||
borderRadius: BorderRadius.circular(borderRadius),
|
||||
child: Image.network(
|
||||
icon!,
|
||||
width: size,
|
||||
height: size,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (_, __, ___) => _buildInitial(),
|
||||
),
|
||||
)
|
||||
: _buildInitial(),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInitial() {
|
||||
return Text(
|
||||
name.isNotEmpty ? name[0].toUpperCase() : '?',
|
||||
style: TextStyle(
|
||||
color: selected ? Colors.white : ThemeService.textSecondary,
|
||||
fontSize: size * 0.4,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,268 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../services/theme_service.dart';
|
||||
import '../models/message.dart';
|
||||
|
||||
class MessageBubble extends StatelessWidget {
|
||||
final Message message;
|
||||
final bool showAuthor;
|
||||
final void Function(Message)? onReply;
|
||||
|
||||
const MessageBubble({
|
||||
super.key,
|
||||
required this.message,
|
||||
this.showAuthor = true,
|
||||
this.onReply,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final text = message.content != null
|
||||
? utf8.decode(message.content!)
|
||||
: '';
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 2, bottom: 2),
|
||||
child: InkWell(
|
||||
onLongPress: () => _showContextMenu(context),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(left: showAuthor ? 0 : 48),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (showAuthor) ...[
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
decoration: BoxDecoration(
|
||||
color: ThemeService.primary.withValues(alpha: 0.8),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
(message.authorUsername ?? '?')[0].toUpperCase(),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
message.authorUsername ?? 'Unknown',
|
||||
style: const TextStyle(
|
||||
color: ThemeService.textPrimary,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
_formatTime(message.createdAt),
|
||||
style: const TextStyle(
|
||||
color: ThemeService.textMuted,
|
||||
fontSize: 11,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
],
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 40),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (message.replyTo != null)
|
||||
Container(
|
||||
padding: const EdgeInsets.all(6),
|
||||
margin: const EdgeInsets.only(bottom: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: ThemeService.surfaceTertiary,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
border: Border(
|
||||
left: BorderSide(
|
||||
color: ThemeService.primary.withValues(alpha: 0.5),
|
||||
width: 3,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
'Replying to a message',
|
||||
style: const TextStyle(
|
||||
color: ThemeService.textMuted,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: message.messageType == 'voice'
|
||||
? _buildVoiceMessage()
|
||||
: message.messageType == 'image'
|
||||
? _buildImageMessage(text)
|
||||
: Text(
|
||||
text,
|
||||
style: const TextStyle(
|
||||
color: ThemeService.textPrimary,
|
||||
fontSize: 15,
|
||||
height: 1.4,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (message.editedAt != null)
|
||||
Text(
|
||||
'(edited)',
|
||||
style: const TextStyle(
|
||||
color: ThemeService.textMuted,
|
||||
fontSize: 11,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildVoiceMessage() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: ThemeService.surfaceTertiary,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.play_arrow, color: ThemeService.primary, size: 24),
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
width: 120,
|
||||
height: 4,
|
||||
decoration: BoxDecoration(
|
||||
color: ThemeService.textMuted.withValues(alpha: 0.3),
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const Text(
|
||||
'0:12',
|
||||
style: TextStyle(
|
||||
color: ThemeService.textMuted,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildImageMessage(String url) {
|
||||
return ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Image.network(
|
||||
url,
|
||||
width: 300,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (_, __, ___) => Container(
|
||||
height: 100,
|
||||
color: ThemeService.surfaceTertiary,
|
||||
child: const Center(
|
||||
child: Icon(Icons.broken_image, color: ThemeService.textMuted),
|
||||
),
|
||||
),
|
||||
loadingBuilder: (_, child, progress) {
|
||||
if (progress == null) return child;
|
||||
return Container(
|
||||
width: 300,
|
||||
height: 200,
|
||||
color: ThemeService.surfaceTertiary,
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(
|
||||
value: progress.expectedTotalBytes != null
|
||||
? progress.cumulativeBytesLoaded /
|
||||
progress.expectedTotalBytes!
|
||||
: null,
|
||||
strokeWidth: 2,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showContextMenu(BuildContext context) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
backgroundColor: ThemeService.surfaceSecondary,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(12)),
|
||||
),
|
||||
builder: (ctx) => SafeArea(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.reply, color: ThemeService.textSecondary),
|
||||
title: const Text('Reply',
|
||||
style: TextStyle(color: ThemeService.textPrimary)),
|
||||
onTap: () {
|
||||
Navigator.pop(ctx);
|
||||
onReply?.call(message);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.copy, color: ThemeService.textSecondary),
|
||||
title: const Text('Copy',
|
||||
style: TextStyle(color: ThemeService.textPrimary)),
|
||||
onTap: () {
|
||||
Navigator.pop(ctx);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.push_pin, color: ThemeService.textSecondary),
|
||||
title: const Text('Pin',
|
||||
style: TextStyle(color: ThemeService.textPrimary)),
|
||||
onTap: () => Navigator.pop(ctx),
|
||||
),
|
||||
ListTile(
|
||||
leading:
|
||||
const Icon(Icons.delete, color: ThemeService.danger),
|
||||
title: const Text('Delete',
|
||||
style: TextStyle(color: ThemeService.danger)),
|
||||
onTap: () => Navigator.pop(ctx),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _formatTime(DateTime dt) {
|
||||
final now = DateTime.now();
|
||||
final diff = now.difference(dt);
|
||||
|
||||
if (diff.inDays == 0) {
|
||||
return '${dt.hour.toString().padLeft(2, '0')}:${dt.minute.toString().padLeft(2, '0')}';
|
||||
} else if (diff.inDays == 1) {
|
||||
return 'Yesterday';
|
||||
} else {
|
||||
return '${dt.day}/${dt.month}/${dt.year}';
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user