Implement Scanner-View

This commit is contained in:
2025-04-13 00:17:06 +02:00
parent c0b8a8a3f4
commit 95353735b0
19 changed files with 961 additions and 179 deletions

View File

@@ -71,13 +71,15 @@ class Channel extends HiveObject implements FieldDebuggable {
];
}
ChannelPreview toPreview() {
ChannelPreview toPreview(Subscription? sub) {
return ChannelPreview(
channelID: this.channelID,
ownerUserID: this.ownerUserID,
internalName: this.internalName,
displayName: this.displayName,
descriptionName: this.descriptionName,
messagesSent: this.messagesSent,
subscription: sub,
);
}
}
@@ -109,6 +111,8 @@ class ChannelPreview {
final String internalName;
final String displayName;
final String? descriptionName;
final int messagesSent;
final Subscription? subscription;
const ChannelPreview({
required this.channelID,
@@ -116,6 +120,8 @@ class ChannelPreview {
required this.internalName,
required this.displayName,
required this.descriptionName,
required this.messagesSent,
required this.subscription,
});
factory ChannelPreview.fromJson(Map<String, dynamic> json) {
@@ -125,6 +131,8 @@ class ChannelPreview {
internalName: json['internal_name'] as String,
displayName: json['display_name'] as String,
descriptionName: json['description_name'] as String?,
messagesSent: json['messages_sent'] as int,
subscription: json['subscription'] == null ? null : Subscription.fromJson(json['subscription'] as Map<String, dynamic>),
);
}
}

View File

@@ -1,6 +1,6 @@
import 'package:simplecloudnotifier/models/channel.dart';
enum ScanResultMode { ChannelSubscribe, MessageSend, Channel }
enum ScanResultMode { ChannelSubscribe, MessageSend, Channel, Error }
abstract class ScanResult {
ScanResultMode get mode;
@@ -12,10 +12,10 @@ abstract class ScanResult {
final v = Uri.tryParse(lines[0]);
if (v != null && v.queryParameters.containsKey('preset_user_id') && v.queryParameters.containsKey('preset_user_key')) {
return ScanResultMessageSend(userID: v.queryParameters['preset_user_id']!, userKey: v.queryParameters['preset_user_key']);
return ScanResultMessageSend(userID: v.queryParameters['preset_user_id']!, userKey: v.queryParameters['preset_user_key'], url: lines[0]);
}
if (v != null && v.queryParameters.containsKey('preset_user_id') && v.queryParameters.containsKey('preset_user_key')) {
return ScanResultMessageSend(userID: v.queryParameters['preset_user_id']!, userKey: null);
return ScanResultMessageSend(userID: v.queryParameters['preset_user_id']!, userKey: null, url: lines[0]);
}
}
@@ -24,12 +24,12 @@ abstract class ScanResult {
}
if (lines.length == 5 && lines[0] == '@scn.channel' && lines[1] == 'v1') {
if (lines.length != 4) return null;
if (lines.length != 5) return null;
return ScanResultChannel(channelDisplayName: lines[2], ownerUserID: lines[3], channelID: lines[4]);
}
return null;
return ScanResultError(message: 'Invalid QR code');
}
static String createChannelQR(Channel channel) {
@@ -44,8 +44,9 @@ abstract class ScanResult {
class ScanResultMessageSend extends ScanResult {
final String userID;
final String? userKey;
final String url;
ScanResultMessageSend({required this.userID, required this.userKey});
ScanResultMessageSend({required this.userID, required this.userKey, required this.url});
@override
ScanResultMode get mode => ScanResultMode.MessageSend;
@@ -73,3 +74,12 @@ class ScanResultChannelSubscribe extends ScanResult {
@override
ScanResultMode get mode => ScanResultMode.ChannelSubscribe;
}
class ScanResultError extends ScanResult {
final String message;
ScanResultError({required this.message});
@override
ScanResultMode get mode => ScanResultMode.Error;
}

View File

@@ -0,0 +1,55 @@
class SendMessageResponse {
final bool success;
final int errorID;
final int errorHighlight;
final String message;
final bool suppressSend;
final int messageCount;
final int quota;
final bool isPro;
final int quotaMax;
final String scnMessageID;
SendMessageResponse({
required this.success,
required this.errorID,
required this.errorHighlight,
required this.message,
required this.suppressSend,
required this.messageCount,
required this.quota,
required this.isPro,
required this.quotaMax,
required this.scnMessageID,
});
factory SendMessageResponse.fromJson(Map<String, dynamic> json) {
return SendMessageResponse(
success: json['success'] as bool,
errorID: json['error'] as int,
errorHighlight: json['errhighlight'] as int,
message: json['message'] as String,
suppressSend: json['suppress_send'] as bool,
messageCount: json['messagecount'] as int,
quota: json['quota'] as int,
isPro: json['is_pro'] as bool,
quotaMax: json['quota_max'] as int,
scnMessageID: json['scn_msg_id'] as String,
);
}
Map<String, dynamic> toJson() {
return {
'success': success,
'error': errorID,
'errhighlight': errorHighlight,
'message': message,
'suppress_send': suppressSend,
'messagecount': messageCount,
'quota': quota,
'is_pro': isPro,
'quota_max': quotaMax,
'scn_msg_id': scnMessageID,
};
}
}