Merge branch 'client-enhance-add-profile-method' into 'master'
[Client] Add profile getter See merge request famedly/famedlysdk!131
This commit is contained in:
commit
ae0e096502
|
@ -38,6 +38,7 @@ import 'User.dart';
|
|||
import 'requests/SetPushersRequest.dart';
|
||||
import 'responses/ErrorResponse.dart';
|
||||
import 'responses/PushrulesResponse.dart';
|
||||
import 'utils/Profile.dart';
|
||||
|
||||
typedef AccountDataEventCB = void Function(AccountData accountData);
|
||||
typedef PresenceCB = void Function(Presence presence);
|
||||
|
@ -257,6 +258,19 @@ class Client {
|
|||
await connection.clear();
|
||||
}
|
||||
|
||||
/// Get the combined profile information for this user. This API may be used to
|
||||
/// fetch the user's own profile information or other users; either locally
|
||||
/// or on remote homeservers.
|
||||
Future<Profile> getProfileFromUserId(String userId) async {
|
||||
final dynamic resp = await connection.jsonRequest(
|
||||
type: HTTPType.GET, action: "/client/r0/profile/${userId}");
|
||||
if (resp is ErrorResponse) {
|
||||
connection.onError.add(resp);
|
||||
return null;
|
||||
}
|
||||
return Profile.fromJson(resp);
|
||||
}
|
||||
|
||||
/// Creates a new [RoomList] object.
|
||||
RoomList getRoomList(
|
||||
{onRoomListUpdateCallback onUpdate,
|
||||
|
|
18
lib/src/utils/Profile.dart
Normal file
18
lib/src/utils/Profile.dart
Normal file
|
@ -0,0 +1,18 @@
|
|||
import 'package:famedlysdk/src/utils/MxContent.dart';
|
||||
|
||||
/// Represents a user profile returned by a /profile request.
|
||||
class Profile {
|
||||
/// The user's avatar URL if they have set one, otherwise null.
|
||||
final MxContent avatarUrl;
|
||||
|
||||
/// The user's display name if they have set one, otherwise null.
|
||||
final String displayname;
|
||||
|
||||
/// This API may return keys which are not limited to displayname or avatar_url.
|
||||
final Map<String, dynamic> content;
|
||||
|
||||
Profile.fromJson(Map<String, dynamic> json)
|
||||
: avatarUrl = MxContent(json['avatar_url']),
|
||||
displayname = json['displayname'],
|
||||
content = json;
|
||||
}
|
|
@ -36,6 +36,7 @@ import 'package:famedlysdk/src/sync/EventUpdate.dart';
|
|||
import 'package:famedlysdk/src/sync/RoomUpdate.dart';
|
||||
import 'package:famedlysdk/src/sync/UserUpdate.dart';
|
||||
import 'package:famedlysdk/src/utils/MatrixFile.dart';
|
||||
import 'package:famedlysdk/src/utils/Profile.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'FakeMatrixApi.dart';
|
||||
|
@ -367,6 +368,15 @@ void main() {
|
|||
expect(archive.rooms[0].membership, Membership.leave);
|
||||
});
|
||||
|
||||
test('getProfileFromUserId', () async {
|
||||
final Profile profile =
|
||||
await matrix.getProfileFromUserId("@getme:example.com");
|
||||
expect(profile.avatarUrl.mxc, "mxc://test");
|
||||
expect(profile.displayname, "You got me");
|
||||
expect(profile.content["avatar_url"], profile.avatarUrl.mxc);
|
||||
expect(profile.content["displayname"], profile.displayname);
|
||||
});
|
||||
|
||||
test('Logout when token is unknown', () async {
|
||||
Future<LoginState> loginStateFuture =
|
||||
matrix.connection.onLoginStateChanged.stream.first;
|
||||
|
|
|
@ -234,6 +234,10 @@ class FakeMatrixApi extends MockClient {
|
|||
|
||||
static final Map<String, Map<String, dynamic>> api = {
|
||||
"GET": {
|
||||
"/client/r0/profile/@getme:example.com": (var req) => {
|
||||
"avatar_url": "mxc://test",
|
||||
"displayname": "You got me",
|
||||
},
|
||||
"/client/r0/rooms/!localpart:server.abc/state/m.room.member/@getme:example.com":
|
||||
(var req) => {
|
||||
"avatar_url": "mxc://test",
|
||||
|
|
Loading…
Reference in a new issue