1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2025-06-19 00:05:16 +00:00

Use WebSocket to update likes

This commit is contained in:
2020-04-18 15:24:57 +02:00
parent 526f698bf4
commit 469e1e1f92
4 changed files with 76 additions and 17 deletions

View File

@ -1,3 +1,5 @@
import 'dart:convert';
import 'package:flutter/widgets.dart';
/// WebSocket message
@ -14,12 +16,21 @@ class WsMessage {
@required this.title,
@required this.data,
}) : assert(id != null),
assert(title != null);
assert(title != null),
assert(title.length > 0);
/// Construct a message from a JSON document (messages coming from the server)
static WsMessage fromJSON(final Map<dynamic, dynamic> m) {
return WsMessage(id: m["id"], title: m["title"], data: m["data"]);
}
/// Turn a message into a JSON object to send it to the API
String toJSON() =>
jsonEncode({
"id": id,
"title": title,
"data": data,
});
bool get hasId => this.id != null && this.id.isNotEmpty;
}