Merge branch 'event-fix-types' into 'master'
[Event] Fix types See merge request famedly/famedlysdk!146
This commit is contained in:
commit
d8f43e6858
|
@ -26,6 +26,7 @@ import 'package:famedlysdk/famedlysdk.dart';
|
||||||
import 'package:famedlysdk/src/utils/Receipt.dart';
|
import 'package:famedlysdk/src/utils/Receipt.dart';
|
||||||
import './Room.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 {
|
class Event {
|
||||||
/// The Matrix ID for this event in the format '$localpart:server.abc'. Please not
|
/// 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.
|
/// that account data, presence and other events may not have an eventId.
|
||||||
|
@ -215,30 +216,44 @@ class Event {
|
||||||
return EventTypes.GuestAccess;
|
return EventTypes.GuestAccess;
|
||||||
case "m.room.history_visibility":
|
case "m.room.history_visibility":
|
||||||
return EventTypes.HistoryVisibility;
|
return EventTypes.HistoryVisibility;
|
||||||
|
case "m.sticker":
|
||||||
|
return EventTypes.Sticker;
|
||||||
case "m.room.message":
|
case "m.room.message":
|
||||||
|
return EventTypes.Message;
|
||||||
|
}
|
||||||
|
return EventTypes.Unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
MessageTypes get messageType {
|
||||||
switch (content["msgtype"] ?? "m.text") {
|
switch (content["msgtype"] ?? "m.text") {
|
||||||
case "m.text":
|
case "m.text":
|
||||||
if (content.containsKey("m.relates_to")) {
|
if (content.containsKey("m.relates_to")) {
|
||||||
return EventTypes.Reply;
|
return MessageTypes.Reply;
|
||||||
}
|
}
|
||||||
return EventTypes.Text;
|
return MessageTypes.Text;
|
||||||
case "m.notice":
|
case "m.notice":
|
||||||
return EventTypes.Notice;
|
return MessageTypes.Notice;
|
||||||
case "m.emote":
|
case "m.emote":
|
||||||
return EventTypes.Emote;
|
return MessageTypes.Emote;
|
||||||
case "m.image":
|
case "m.image":
|
||||||
return EventTypes.Image;
|
return MessageTypes.Image;
|
||||||
case "m.video":
|
case "m.video":
|
||||||
return EventTypes.Video;
|
return MessageTypes.Video;
|
||||||
case "m.audio":
|
case "m.audio":
|
||||||
return EventTypes.Audio;
|
return MessageTypes.Audio;
|
||||||
case "m.file":
|
case "m.file":
|
||||||
return EventTypes.File;
|
return MessageTypes.File;
|
||||||
|
case "m.sticker":
|
||||||
|
return MessageTypes.Sticker;
|
||||||
case "m.location":
|
case "m.location":
|
||||||
return EventTypes.Location;
|
return MessageTypes.Location;
|
||||||
|
default:
|
||||||
|
if (type == EventTypes.Message) {
|
||||||
|
return MessageTypes.Text;
|
||||||
}
|
}
|
||||||
|
return MessageTypes.None;
|
||||||
}
|
}
|
||||||
return EventTypes.Unknown;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setRedactionEvent(Event redactedBecause) {
|
void setRedactionEvent(Event redactedBecause) {
|
||||||
|
@ -350,17 +365,24 @@ class Event {
|
||||||
room.redactEvent(eventId, reason: reason, txid: txid);
|
room.redactEvent(eventId, reason: reason, txid: txid);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum EventTypes {
|
enum MessageTypes {
|
||||||
Text,
|
Text,
|
||||||
Emote,
|
Emote,
|
||||||
Notice,
|
Notice,
|
||||||
Image,
|
Image,
|
||||||
Video,
|
Video,
|
||||||
Audio,
|
Audio,
|
||||||
Redaction,
|
|
||||||
File,
|
File,
|
||||||
Location,
|
Location,
|
||||||
Reply,
|
Reply,
|
||||||
|
Sticker,
|
||||||
|
None,
|
||||||
|
}
|
||||||
|
|
||||||
|
enum EventTypes {
|
||||||
|
Message,
|
||||||
|
Sticker,
|
||||||
|
Redaction,
|
||||||
RoomAliases,
|
RoomAliases,
|
||||||
RoomCanonicalAlias,
|
RoomCanonicalAlias,
|
||||||
RoomCreate,
|
RoomCreate,
|
||||||
|
|
|
@ -66,7 +66,7 @@ void main() {
|
||||||
expect(event.text, body);
|
expect(event.text, body);
|
||||||
expect(event.formattedText, formatted_body);
|
expect(event.formattedText, formatted_body);
|
||||||
expect(event.getBody(), body);
|
expect(event.getBody(), body);
|
||||||
expect(event.type, EventTypes.Text);
|
expect(event.type, EventTypes.Message);
|
||||||
jsonObj["state_key"] = "";
|
jsonObj["state_key"] = "";
|
||||||
Event state = Event.fromJson(jsonObj, null);
|
Event state = Event.fromJson(jsonObj, null);
|
||||||
expect(state.eventId, id);
|
expect(state.eventId, id);
|
||||||
|
@ -125,31 +125,31 @@ void main() {
|
||||||
|
|
||||||
jsonObj["content"]["msgtype"] = "m.notice";
|
jsonObj["content"]["msgtype"] = "m.notice";
|
||||||
event = Event.fromJson(jsonObj, null);
|
event = Event.fromJson(jsonObj, null);
|
||||||
expect(event.type, EventTypes.Notice);
|
expect(event.messageType, MessageTypes.Notice);
|
||||||
|
|
||||||
jsonObj["content"]["msgtype"] = "m.emote";
|
jsonObj["content"]["msgtype"] = "m.emote";
|
||||||
event = Event.fromJson(jsonObj, null);
|
event = Event.fromJson(jsonObj, null);
|
||||||
expect(event.type, EventTypes.Emote);
|
expect(event.messageType, MessageTypes.Emote);
|
||||||
|
|
||||||
jsonObj["content"]["msgtype"] = "m.image";
|
jsonObj["content"]["msgtype"] = "m.image";
|
||||||
event = Event.fromJson(jsonObj, null);
|
event = Event.fromJson(jsonObj, null);
|
||||||
expect(event.type, EventTypes.Image);
|
expect(event.messageType, MessageTypes.Image);
|
||||||
|
|
||||||
jsonObj["content"]["msgtype"] = "m.video";
|
jsonObj["content"]["msgtype"] = "m.video";
|
||||||
event = Event.fromJson(jsonObj, null);
|
event = Event.fromJson(jsonObj, null);
|
||||||
expect(event.type, EventTypes.Video);
|
expect(event.messageType, MessageTypes.Video);
|
||||||
|
|
||||||
jsonObj["content"]["msgtype"] = "m.audio";
|
jsonObj["content"]["msgtype"] = "m.audio";
|
||||||
event = Event.fromJson(jsonObj, null);
|
event = Event.fromJson(jsonObj, null);
|
||||||
expect(event.type, EventTypes.Audio);
|
expect(event.messageType, MessageTypes.Audio);
|
||||||
|
|
||||||
jsonObj["content"]["msgtype"] = "m.file";
|
jsonObj["content"]["msgtype"] = "m.file";
|
||||||
event = Event.fromJson(jsonObj, null);
|
event = Event.fromJson(jsonObj, null);
|
||||||
expect(event.type, EventTypes.File);
|
expect(event.messageType, MessageTypes.File);
|
||||||
|
|
||||||
jsonObj["content"]["msgtype"] = "m.location";
|
jsonObj["content"]["msgtype"] = "m.location";
|
||||||
event = Event.fromJson(jsonObj, null);
|
event = Event.fromJson(jsonObj, null);
|
||||||
expect(event.type, EventTypes.Location);
|
expect(event.messageType, MessageTypes.Location);
|
||||||
|
|
||||||
jsonObj["type"] = "m.room.message";
|
jsonObj["type"] = "m.room.message";
|
||||||
jsonObj["content"]["msgtype"] = "m.text";
|
jsonObj["content"]["msgtype"] = "m.text";
|
||||||
|
@ -158,7 +158,7 @@ void main() {
|
||||||
"event_id": "1234",
|
"event_id": "1234",
|
||||||
};
|
};
|
||||||
event = Event.fromJson(jsonObj, null);
|
event = Event.fromJson(jsonObj, null);
|
||||||
expect(event.type, EventTypes.Reply);
|
expect(event.messageType, MessageTypes.Reply);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("redact", () async {
|
test("redact", () async {
|
||||||
|
|
Loading…
Reference in a new issue