2019-06-09 11:57:33 +00:00
|
|
|
/*
|
2020-06-03 10:16:01 +00:00
|
|
|
* Famedly Matrix SDK
|
|
|
|
* Copyright (C) 2019, 2020 Famedly GmbH
|
2019-06-09 11:57:33 +00:00
|
|
|
*
|
2020-06-03 10:16:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2019-06-09 11:57:33 +00:00
|
|
|
*
|
2020-06-03 10:16:01 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
2019-06-09 11:57:33 +00:00
|
|
|
*
|
2020-06-03 10:16:01 +00:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2019-06-09 11:57:33 +00:00
|
|
|
*/
|
|
|
|
|
2020-02-15 08:58:08 +00:00
|
|
|
import '../../famedlysdk.dart';
|
2020-06-03 10:16:01 +00:00
|
|
|
import '../../matrix_api.dart';
|
2020-02-15 08:58:08 +00:00
|
|
|
|
2019-06-09 10:16:48 +00:00
|
|
|
/// Represents a new event (e.g. a message in a room) or an update for an
|
|
|
|
/// already known event.
|
|
|
|
class EventUpdate {
|
|
|
|
/// Usually 'timeline', 'state' or whatever.
|
2019-06-21 10:18:54 +00:00
|
|
|
final String type;
|
2019-06-09 10:16:48 +00:00
|
|
|
|
|
|
|
/// Most events belong to a room. If not, this equals to eventType.
|
|
|
|
final String roomID;
|
|
|
|
|
|
|
|
/// See (Matrix Room Events)[https://matrix.org/docs/spec/client_server/r0.4.0.html#room-events]
|
|
|
|
/// and (Matrix Events)[https://matrix.org/docs/spec/client_server/r0.4.0.html#id89] for more
|
|
|
|
/// informations.
|
2019-06-21 10:18:54 +00:00
|
|
|
final String eventType;
|
2019-06-09 10:16:48 +00:00
|
|
|
|
|
|
|
// The json payload of the content of this event.
|
2019-06-26 17:03:15 +00:00
|
|
|
final Map<String, dynamic> content;
|
2019-06-09 10:16:48 +00:00
|
|
|
|
2020-05-15 18:40:17 +00:00
|
|
|
// the order where to stort this event
|
|
|
|
final double sortOrder;
|
|
|
|
|
2020-05-22 10:12:18 +00:00
|
|
|
EventUpdate(
|
|
|
|
{this.eventType, this.roomID, this.type, this.content, this.sortOrder});
|
2020-02-15 08:58:08 +00:00
|
|
|
|
2020-06-04 11:39:51 +00:00
|
|
|
Future<EventUpdate> decrypt(Room room, {bool store = false}) async {
|
|
|
|
if (eventType != EventTypes.Encrypted || !room.client.encryptionEnabled) {
|
2020-02-15 08:58:08 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
try {
|
2020-06-04 11:39:51 +00:00
|
|
|
var decrpytedEvent = await room.client.encryption.decryptRoomEvent(
|
|
|
|
room.id, Event.fromJson(content, room, sortOrder),
|
|
|
|
store: store, updateType: type);
|
2020-02-15 08:58:08 +00:00
|
|
|
return EventUpdate(
|
2020-06-03 10:16:01 +00:00
|
|
|
eventType: decrpytedEvent.type,
|
2020-02-15 08:58:08 +00:00
|
|
|
roomID: roomID,
|
|
|
|
type: type,
|
|
|
|
content: decrpytedEvent.toJson(),
|
2020-05-15 18:40:17 +00:00
|
|
|
sortOrder: sortOrder,
|
2020-02-15 08:58:08 +00:00
|
|
|
);
|
|
|
|
} catch (e) {
|
2020-03-30 09:08:38 +00:00
|
|
|
print('[LibOlm] Could not decrypt megolm event: ' + e.toString());
|
2020-02-15 08:58:08 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
2019-06-09 10:16:48 +00:00
|
|
|
}
|