[Event] Fix types
This commit is contained in:
parent
1ccd945473
commit
c72f38d5ec
|
@ -26,6 +26,7 @@ import 'package:famedlysdk/famedlysdk.dart';
|
|||
import 'package:famedlysdk/src/utils/Receipt.dart';
|
||||
import './Room.dart';
|
||||
|
||||
/// All data exchanged over Matrix is expressed as an "event". Typically each client action (e.g. sending a message) correlates with exactly one event.
|
||||
class Event {
|
||||
/// The Matrix ID for this event in the format '$localpart:server.abc'. Please not
|
||||
/// that account data, presence and other events may not have an eventId.
|
||||
|
@ -215,32 +216,46 @@ class Event {
|
|||
return EventTypes.GuestAccess;
|
||||
case "m.room.history_visibility":
|
||||
return EventTypes.HistoryVisibility;
|
||||
case "m.sticker":
|
||||
return EventTypes.Sticker;
|
||||
case "m.room.message":
|
||||
switch (content["msgtype"] ?? "m.text") {
|
||||
case "m.text":
|
||||
if (content.containsKey("m.relates_to")) {
|
||||
return EventTypes.Reply;
|
||||
}
|
||||
return EventTypes.Text;
|
||||
case "m.notice":
|
||||
return EventTypes.Notice;
|
||||
case "m.emote":
|
||||
return EventTypes.Emote;
|
||||
case "m.image":
|
||||
return EventTypes.Image;
|
||||
case "m.video":
|
||||
return EventTypes.Video;
|
||||
case "m.audio":
|
||||
return EventTypes.Audio;
|
||||
case "m.file":
|
||||
return EventTypes.File;
|
||||
case "m.location":
|
||||
return EventTypes.Location;
|
||||
}
|
||||
return EventTypes.Message;
|
||||
}
|
||||
return EventTypes.Unknown;
|
||||
}
|
||||
|
||||
///
|
||||
MessageTypes get messageType {
|
||||
switch (content["msgtype"] ?? "m.text") {
|
||||
case "m.text":
|
||||
if (content.containsKey("m.relates_to")) {
|
||||
return MessageTypes.Reply;
|
||||
}
|
||||
return MessageTypes.Text;
|
||||
case "m.notice":
|
||||
return MessageTypes.Notice;
|
||||
case "m.emote":
|
||||
return MessageTypes.Emote;
|
||||
case "m.image":
|
||||
return MessageTypes.Image;
|
||||
case "m.video":
|
||||
return MessageTypes.Video;
|
||||
case "m.audio":
|
||||
return MessageTypes.Audio;
|
||||
case "m.file":
|
||||
return MessageTypes.File;
|
||||
case "m.sticker":
|
||||
return MessageTypes.Sticker;
|
||||
case "m.location":
|
||||
return MessageTypes.Location;
|
||||
default:
|
||||
if (type == EventTypes.Message) {
|
||||
return MessageTypes.Text;
|
||||
}
|
||||
return MessageTypes.None;
|
||||
}
|
||||
}
|
||||
|
||||
void setRedactionEvent(Event redactedBecause) {
|
||||
unsigned = {
|
||||
"redacted_because": redactedBecause.toJson(),
|
||||
|
@ -350,17 +365,24 @@ class Event {
|
|||
room.redactEvent(eventId, reason: reason, txid: txid);
|
||||
}
|
||||
|
||||
enum EventTypes {
|
||||
enum MessageTypes {
|
||||
Text,
|
||||
Emote,
|
||||
Notice,
|
||||
Image,
|
||||
Video,
|
||||
Audio,
|
||||
Redaction,
|
||||
File,
|
||||
Location,
|
||||
Reply,
|
||||
Sticker,
|
||||
None,
|
||||
}
|
||||
|
||||
enum EventTypes {
|
||||
Message,
|
||||
Sticker,
|
||||
Redaction,
|
||||
RoomAliases,
|
||||
RoomCanonicalAlias,
|
||||
RoomCreate,
|
||||
|
|
|
@ -66,7 +66,7 @@ void main() {
|
|||
expect(event.text, body);
|
||||
expect(event.formattedText, formatted_body);
|
||||
expect(event.getBody(), body);
|
||||
expect(event.type, EventTypes.Text);
|
||||
expect(event.type, EventTypes.Message);
|
||||
jsonObj["state_key"] = "";
|
||||
Event state = Event.fromJson(jsonObj, null);
|
||||
expect(state.eventId, id);
|
||||
|
@ -125,31 +125,31 @@ void main() {
|
|||
|
||||
jsonObj["content"]["msgtype"] = "m.notice";
|
||||
event = Event.fromJson(jsonObj, null);
|
||||
expect(event.type, EventTypes.Notice);
|
||||
expect(event.messageType, MessageTypes.Notice);
|
||||
|
||||
jsonObj["content"]["msgtype"] = "m.emote";
|
||||
event = Event.fromJson(jsonObj, null);
|
||||
expect(event.type, EventTypes.Emote);
|
||||
expect(event.messageType, MessageTypes.Emote);
|
||||
|
||||
jsonObj["content"]["msgtype"] = "m.image";
|
||||
event = Event.fromJson(jsonObj, null);
|
||||
expect(event.type, EventTypes.Image);
|
||||
expect(event.messageType, MessageTypes.Image);
|
||||
|
||||
jsonObj["content"]["msgtype"] = "m.video";
|
||||
event = Event.fromJson(jsonObj, null);
|
||||
expect(event.type, EventTypes.Video);
|
||||
expect(event.messageType, MessageTypes.Video);
|
||||
|
||||
jsonObj["content"]["msgtype"] = "m.audio";
|
||||
event = Event.fromJson(jsonObj, null);
|
||||
expect(event.type, EventTypes.Audio);
|
||||
expect(event.messageType, MessageTypes.Audio);
|
||||
|
||||
jsonObj["content"]["msgtype"] = "m.file";
|
||||
event = Event.fromJson(jsonObj, null);
|
||||
expect(event.type, EventTypes.File);
|
||||
expect(event.messageType, MessageTypes.File);
|
||||
|
||||
jsonObj["content"]["msgtype"] = "m.location";
|
||||
event = Event.fromJson(jsonObj, null);
|
||||
expect(event.type, EventTypes.Location);
|
||||
expect(event.messageType, MessageTypes.Location);
|
||||
|
||||
jsonObj["type"] = "m.room.message";
|
||||
jsonObj["content"]["msgtype"] = "m.text";
|
||||
|
@ -158,7 +158,7 @@ void main() {
|
|||
"event_id": "1234",
|
||||
};
|
||||
event = Event.fromJson(jsonObj, null);
|
||||
expect(event.type, EventTypes.Reply);
|
||||
expect(event.messageType, MessageTypes.Reply);
|
||||
});
|
||||
|
||||
test("redact", () async {
|
||||
|
|
Loading…
Reference in a new issue