⬆️ Support newer version of server messaging

This commit is contained in:
LittleSheep 2024-05-05 01:53:31 +08:00
parent efc46dbbc5
commit cf0d473a40
10 changed files with 19 additions and 19 deletions

View File

@ -13,7 +13,7 @@ class Channel {
int type; int type;
Account account; Account account;
int accountId; int accountId;
int realmId; int? realmId;
Channel({ Channel({
required this.id, required this.id,
@ -28,7 +28,7 @@ class Channel {
required this.type, required this.type,
required this.account, required this.account,
required this.accountId, required this.accountId,
required this.realmId, this.realmId,
}); });
factory Channel.fromJson(Map<String, dynamic> json) => Channel( factory Channel.fromJson(Map<String, dynamic> json) => Channel(

View File

@ -47,7 +47,7 @@ class ChatProvider extends ChangeNotifier {
Future<Channel> fetchChannel(String alias) async { Future<Channel> fetchChannel(String alias) async {
final Client client = Client(); final Client client = Client();
var uri = getRequestUri('messaging', '/api/channels/$alias'); var uri = getRequestUri('messaging', '/api/channels/global/$alias');
var res = await client.get(uri); var res = await client.get(uri);
if (res.statusCode == 200) { if (res.statusCode == 200) {
final result = jsonDecode(utf8.decode(res.bodyBytes)); final result = jsonDecode(utf8.decode(res.bodyBytes));
@ -63,7 +63,7 @@ class ChatProvider extends ChangeNotifier {
Future<Call?> fetchOngoingCall(String alias) async { Future<Call?> fetchOngoingCall(String alias) async {
final Client client = Client(); final Client client = Client();
var uri = getRequestUri('messaging', '/api/channels/$alias/calls/ongoing'); var uri = getRequestUri('messaging', '/api/channels/global/$alias/calls/ongoing');
var res = await client.get(uri); var res = await client.get(uri);
if (res.statusCode == 200) { if (res.statusCode == 200) {
final result = jsonDecode(utf8.decode(res.bodyBytes)); final result = jsonDecode(utf8.decode(res.bodyBytes));
@ -181,7 +181,7 @@ class ChatCallInstance {
throw Exception('unauthorized'); throw Exception('unauthorized');
} }
var uri = getRequestUri('messaging', '/api/channels/${channel.alias}/calls/ongoing/token'); var uri = getRequestUri('messaging', '/api/channels/global/${channel.alias}/calls/ongoing/token');
var res = await auth.client!.post(uri); var res = await auth.client!.post(uri);
if (res.statusCode == 200) { if (res.statusCode == 200) {

View File

@ -39,8 +39,8 @@ class _ChannelEditorScreenState extends State<ChannelEditorScreen> {
} }
final uri = widget.editing == null final uri = widget.editing == null
? getRequestUri('messaging', '/api/channels') ? getRequestUri('messaging', '/api/channels/global')
: getRequestUri('messaging', '/api/channels/${widget.editing!.id}'); : getRequestUri('messaging', '/api/channels/global/${widget.editing!.id}');
final req = Request(widget.editing == null ? 'POST' : 'PUT', uri); final req = Request(widget.editing == null ? 'POST' : 'PUT', uri);
req.headers['Content-Type'] = 'application/json'; req.headers['Content-Type'] = 'application/json';

View File

@ -37,7 +37,7 @@ class _ChatMemberScreenState extends State<ChatMemberScreen> {
_selfId = prof['id']; _selfId = prof['id'];
var uri = getRequestUri( var uri = getRequestUri(
'messaging', '/api/channels/${widget.channel.alias}/members'); 'messaging', '/api/channels/global/${widget.channel.alias}/members');
var res = await auth.client!.get(uri); var res = await auth.client!.get(uri);
if (res.statusCode == 200) { if (res.statusCode == 200) {
@ -61,7 +61,7 @@ class _ChatMemberScreenState extends State<ChatMemberScreen> {
} }
var uri = getRequestUri( var uri = getRequestUri(
'messaging', '/api/channels/${widget.channel.alias}/kick'); 'messaging', '/api/channels/global/${widget.channel.alias}/kick');
var res = await auth.client!.post( var res = await auth.client!.post(
uri, uri,
@ -92,7 +92,7 @@ class _ChatMemberScreenState extends State<ChatMemberScreen> {
} }
var uri = getRequestUri( var uri = getRequestUri(
'messaging', '/api/channels/${widget.channel.alias}/invite'); 'messaging', '/api/channels/global/${widget.channel.alias}/invite');
var res = await auth.client!.post( var res = await auth.client!.post(
uri, uri,

View File

@ -77,7 +77,7 @@ class _ChatScreenWidgetState extends State<ChatScreenWidget> {
var uri = getRequestUri( var uri = getRequestUri(
'messaging', 'messaging',
'/api/channels/${widget.alias}/messages?take=$take&offset=$offset', '/api/channels/global/${widget.alias}/messages?take=$take&offset=$offset',
); );
var res = await auth.client!.get(uri); var res = await auth.client!.get(uri);

View File

@ -58,7 +58,7 @@ class _ChatListWidgetState extends State<ChatListWidget> {
final auth = context.read<AuthProvider>(); final auth = context.read<AuthProvider>();
if (!await auth.isAuthorized()) return; if (!await auth.isAuthorized()) return;
var uri = getRequestUri('messaging', '/api/channels/me/available'); var uri = getRequestUri('messaging', '/api/channels/global/me/available');
var res = await auth.client!.get(uri); var res = await auth.client!.get(uri);
if (res.statusCode == 200) { if (res.statusCode == 200) {

View File

@ -33,7 +33,7 @@ class _ChannelCallActionState extends State<ChannelCallAction> {
return; return;
} }
var uri = getRequestUri('messaging', '/api/channels/${widget.channel.alias}/calls'); var uri = getRequestUri('messaging', '/api/channels/global/${widget.channel.alias}/calls');
var res = await auth.client!.post(uri); var res = await auth.client!.post(uri);
if (res.statusCode != 200) { if (res.statusCode != 200) {
@ -54,7 +54,7 @@ class _ChannelCallActionState extends State<ChannelCallAction> {
return; return;
} }
var uri = getRequestUri('messaging', '/api/channels/${widget.channel.alias}/calls/ongoing'); var uri = getRequestUri('messaging', '/api/channels/global/${widget.channel.alias}/calls/ongoing');
var res = await auth.client!.delete(uri); var res = await auth.client!.delete(uri);
if (res.statusCode != 200) { if (res.statusCode != 200) {

View File

@ -32,7 +32,7 @@ class _ChannelDeletionState extends State<ChannelDeletion> {
} }
var res = await auth.client!.delete( var res = await auth.client!.delete(
getRequestUri('messaging', '/api/channels/${widget.channel.id}'), getRequestUri('messaging', '/api/channels/global/${widget.channel.id}'),
); );
if (res.statusCode != 200) { if (res.statusCode != 200) {
var message = utf8.decode(res.bodyBytes); var message = utf8.decode(res.bodyBytes);
@ -54,7 +54,7 @@ class _ChannelDeletionState extends State<ChannelDeletion> {
} }
var res = await auth.client!.post( var res = await auth.client!.post(
getRequestUri('messaging', '/api/channels/${widget.channel.alias}/leave'), getRequestUri('messaging', '/api/channels/global/${widget.channel.alias}/leave'),
); );
if (res.statusCode != 200) { if (res.statusCode != 200) {
var message = utf8.decode(res.bodyBytes); var message = utf8.decode(res.bodyBytes);

View File

@ -31,7 +31,7 @@ class _ChatMessageDeletionDialogState extends State<ChatMessageDeletionDialog> {
if (!await auth.isAuthorized()) return; if (!await auth.isAuthorized()) return;
final uri = getRequestUri('messaging', final uri = getRequestUri('messaging',
'/api/channels/${widget.channel}/messages/${widget.item.id}'); '/api/channels/global/${widget.channel}/messages/${widget.item.id}');
setState(() => _isSubmitting = true); setState(() => _isSubmitting = true);
final res = await auth.client!.delete(uri); final res = await auth.client!.delete(uri);

View File

@ -53,8 +53,8 @@ class _ChatMessageEditorState extends State<ChatMessageEditor> {
if (!await auth.isAuthorized()) return; if (!await auth.isAuthorized()) return;
final uri = widget.editing == null final uri = widget.editing == null
? getRequestUri('messaging', '/api/channels/${widget.channel}/messages') ? getRequestUri('messaging', '/api/channels/global/${widget.channel}/messages')
: getRequestUri('messaging', '/api/channels/${widget.channel}/messages/${widget.editing!.id}'); : getRequestUri('messaging', '/api/channels/global/${widget.channel}/messages/${widget.editing!.id}');
final req = Request(widget.editing == null ? 'POST' : 'PUT', uri); final req = Request(widget.editing == null ? 'POST' : 'PUT', uri);
req.headers['Content-Type'] = 'application/json'; req.headers['Content-Type'] = 'application/json';