feat: Added new API endpoint

This commit is contained in:
Deven Joshi
2021-06-02 15:55:39 +05:30
parent 71b7facc0c
commit 39d82c75ad
2 changed files with 57 additions and 19 deletions
+24 -11
View File
@@ -1347,6 +1347,18 @@ class StreamChatClient {
return decode(response.data, UpdateMessageResponse.fromJson);
}
/// Partially update the given message
/// Use 'set' in map to set values
/// User 'unset' in map to unset values
Future<UpdateMessageResponse> partiallyUpdateMessage(
String id, Map data) async {
final response = await put(
'/messages/${id}',
data: data,
);
return decode(response.data, UpdateMessageResponse.fromJson);
}
/// Deletes the given message
Future<EmptyResponse> deleteMessage(Message message) async {
final response = await delete('/messages/${message.id}');
@@ -1385,20 +1397,21 @@ class StreamChatClient {
)
.toUtc();
}
return updateMessage(
message.copyWith(
pinned: true,
pinExpires: pinExpires,
),
);
return partiallyUpdateMessage(message.id, {
'set': {
'pinned': true,
if (pinExpires != null) 'pin_expires': pinExpires.toIso8601String(),
}
});
}
/// Unpins provided message
Future<UpdateMessageResponse> unpinMessage(Message message) => updateMessage(
message.copyWith(
pinned: false,
),
);
Future<UpdateMessageResponse> unpinMessage(Message message) =>
partiallyUpdateMessage(message.id, {
'set': {
'pinned': false,
}
});
}
/// The class that handles the state of the channel listening to the events