diff --git a/lib/models/message.dart b/lib/models/message.dart index 245c3fd..e4ef550 100644 --- a/lib/models/message.dart +++ b/lib/models/message.dart @@ -67,6 +67,9 @@ class Message { @JsonKey(name: 'reactions', includeIfNull: false) Map reactions; + @JsonKey(name: 'drid', includeIfNull: false) + String drid; + factory Message.fromJson(Map json) => _$MessageFromJson(json); diff --git a/lib/models/models.g.dart b/lib/models/models.g.dart index 655d4a2..8589302 100644 --- a/lib/models/models.g.dart +++ b/lib/models/models.g.dart @@ -17,10 +17,8 @@ Channel _$ChannelFromJson(Map json) { ..sysMes = json['sysMes'] as bool ..isDefault = json['default'] as bool ..broadcast = json['broadcast'] as bool - ..timestamp = json['ts'] == null ? null : _fromJsonToDateTime(json['ts']) - ..updatedAt = json['_updatedAt'] == null - ? null - : _fromJsonToDateTime(json['_updatedAt']) + ..timestamp = _fromJsonToDateTime(json['ts']) + ..updatedAt = _fromJsonToDateTime(json['_updatedAt']) ..topic = json['topic'] as String ..user = json['u'] == null ? null @@ -85,7 +83,7 @@ Map _$ChannelSubscriptionToJson( 't': instance.type, 'u': instance.user, 'roles': instance.roles, - 'unread': instance.unread + 'unread': instance.unread, }; Pagination _$PaginationFromJson(Map json) { @@ -99,7 +97,7 @@ Map _$PaginationToJson(Pagination instance) => { 'count': instance.count, 'offset': instance.offset, - 'total': instance.total + 'total': instance.total, }; RoomMessageHistory _$RoomMessageHistoryFromJson(Map json) { @@ -114,7 +112,7 @@ RoomMessageHistory _$RoomMessageHistoryFromJson(Map json) { Map _$RoomMessageHistoryToJson(RoomMessageHistory instance) => { 'unreadNotLoaded': instance.unreadNotLoaded, - 'messages': instance.messages + 'messages': instance.messages, }; Message _$MessageFromJson(Map json) { @@ -127,13 +125,10 @@ Message _$MessageFromJson(Map json) { ? null : User.fromJson(json['editedBy'] as Map) ..groupable = json['groupable'] as bool - ..editedAt = - json['editedAt'] == null ? null : _fromJsonToDateTime(json['editedAt']) - ..timestamp = json['ts'] == null ? null : _fromJsonToDateTime(json['ts']) + ..editedAt = _fromJsonToDateTime(json['editedAt']) + ..timestamp = _fromJsonToDateTime(json['ts']) ..type = json['t'] as String - ..updatedAt = json['_updatedAt'] == null - ? null - : _fromJsonToDateTime(json['_updatedAt']) + ..updatedAt = _fromJsonToDateTime(json['_updatedAt']) ..mentions = (json['mentions'] as List) ?.map( (e) => e == null ? null : User.fromJson(e as Map)) @@ -148,20 +143,19 @@ Message _$MessageFromJson(Map json) { ..postMessage = json['postMessage'] == null ? null : PostMessage.fromJson(json['postMessage'] as Map) - ..reactions = (json['reactions'] as Map)?.map((k, e) => - MapEntry( - k, - e == null - ? null - : ReactionItem.fromJson(e as Map))); + ..reactions = (json['reactions'] as Map)?.map( + (k, e) => MapEntry(k, + e == null ? null : ReactionItem.fromJson(e as Map)), + ) + ..drid = json['drid'] as String; } Map _$MessageToJson(Message instance) { final val = { '_id': instance.id, 'rid': instance.roomId, - 'msg': instance.msg, 'token': instance.token, + 'msg': instance.msg, }; void writeNotNull(String key, dynamic value) { @@ -181,6 +175,7 @@ Map _$MessageToJson(Message instance) { writeNotNull('attachments', instance.attachments); writeNotNull('postMessage', instance.postMessage); writeNotNull('reactions', instance.reactions); + writeNotNull('drid', instance.drid); return val; } @@ -191,7 +186,9 @@ ReactionItem _$ReactionItemFromJson(Map json) { } Map _$ReactionItemToJson(ReactionItem instance) => - {'usernames': instance.usernames}; + { + 'usernames': instance.usernames, + }; PostMessage _$PostMessageFromJson(Map json) { return PostMessage() @@ -232,7 +229,7 @@ Attachment _$AttachmentFromJson(Map json) { return Attachment() ..color = json['color'] as String ..text = json['text'] as String - ..timestamp = json['ts'] == null ? null : _fromJsonToDateTime(json['ts']) + ..timestamp = _fromJsonToDateTime(json['ts']) ..thumbUrl = json['thumb_url'] as String ..messageLink = json['message_link'] as String ..collapsed = json['collapsed'] as bool @@ -291,7 +288,7 @@ Map _$AttachmentFieldToJson(AttachmentField instance) => { 'short': instance.short, 'title': instance.title, - 'value': instance.value + 'value': instance.value, }; User _$UserFromJson(Map json) { @@ -310,5 +307,5 @@ Map _$UserToJson(User instance) => { 'username': instance.userName, 'status': instance.status, 'token': instance.token, - 'tokenExpires': instance.tokenExpires + 'tokenExpires': instance.tokenExpires, }; diff --git a/lib/rest/chat.dart b/lib/rest/chat.dart index fabdf26..af9d864 100644 --- a/lib/rest/chat.dart +++ b/lib/rest/chat.dart @@ -1,6 +1,23 @@ part of rest; abstract class _ClientChatMixin implements _ClientWrapper { + Future> getRoomDiscussions(String roomId) { + Completer> completer = Completer(); + http.get('${_getUrl()}/chat.getDiscussions?roomId=${roomId}', headers: { + 'X-User-Id': _auth._id, + 'X-Auth-Token': _auth._token, + }).then((response) { + _hackResponseHeader(response); + final rawRoomsList = (json.decode(response.body)['messages'] ?? []) as List; + final rooms = []; + for (var raw in rawRoomsList) { + rooms.add(Message.fromJson(raw)); + } + completer.complete(rooms); + }).catchError((error) => completer.completeError(error)); + return completer.future; + } + Future sendMessage(Message message) { Completer completer = Completer(); http