From c6bcf4e84df8bfe801d419ced74267ebe225e4da Mon Sep 17 00:00:00 2001 From: fa0311 Date: Thu, 30 Jun 2022 20:48:08 +0900 Subject: [PATCH] add #44 --- lib/api/data_class.dart | 105 +++++++++++++++++++++++++++++++++++++++- lib/api/main.dart | 14 +++++- lib/widgets/drawer.dart | 11 ++++- 3 files changed, 126 insertions(+), 4 deletions(-) diff --git a/lib/api/data_class.dart b/lib/api/data_class.dart index dd2c6147e..169f61e7e 100644 --- a/lib/api/data_class.dart +++ b/lib/api/data_class.dart @@ -12,7 +12,7 @@ class VRChatStatus { message = json[status]['message']; statusCode = json[status]['status_code']; } - } on NoSuchMethodError catch (e) { + } on NoSuchMethodError { return; } } @@ -38,6 +38,108 @@ class VRChatLogin { } } +class VRChatUserOverload { + late dynamic source; + late VRChatStatus vrchatStatus; + late String id; + late String username; + late String displayName; + late String userIcon; + late String bio; + late List bioLinks; + late String profilePicOverride; + late String statusDescription; + late List> pastDisplayNames; + late bool hasEmail; + late bool hasPendingEmail; + late String obfuscatedEmail; + late String obfuscatedPendingEmail; + late bool emailVerified; + late bool hasBirthday; + late bool unsubscribe; + late List statusHistory; + late bool statusFirstTime; + late List friends; + late String friendGroupNames; + late String currentAvatarImageUrl; + late String currentAvatarThumbnailImageUrl; + late String currentAvatar; + late String currentAvatarAssetUrl; + late String fallbackAvatar; + late DateTime? accountDeletionDate; + late int acceptedTOSVersion; + late String steamId; + late dynamic steamDetails; //default {} + late String oculusId; + late bool hasLoggedInFromClient; + late String homeLocation; + late bool twoFactorAuthEnabled; + late String twoFactorAuthEnabledDate; + late String state; + late List tags; + late String developerType; + late String lastLogin; + late String lastPlatform; + late bool allowAvatarCopying; + late String status; + late String dateJoined; + late bool isFriend; + late String friendKey; + late String lastActivity; + + VRChatUserOverload.fromJson(dynamic json) { + source = json; + vrchatStatus = VRChatStatus.fromJson(json); + if (vrchatStatus.status == "error") return; + + id = json['id']; + username = json['username']; + displayName = json['displayName']; + userIcon = json['userIcon']; + bio = json['bio']; + bioLinks = json['bioLinks'].cast(); + profilePicOverride = json['profilePicOverride']; + statusDescription = json['statusDescription']; + pastDisplayNames = json['pastDisplayNames']; + hasEmail = json['hasEmail']; + hasPendingEmail = json['hasPendingEmail']; + obfuscatedEmail = json['obfuscatedEmail']; + obfuscatedPendingEmail = json['obfuscatedPendingEmail']; + emailVerified = json['emailVerified']; + hasBirthday = json['hasBirthday']; + unsubscribe = json['unsubscribe']; + statusHistory = json['statusHistory'].cast(); + statusFirstTime = json['statusFirstTime']; + friends = json['friends'].cast(); + friendGroupNames = json['friendGroupNames']; + currentAvatarImageUrl = json['currentAvatarImageUrl']; + currentAvatarThumbnailImageUrl = json['currentAvatarThumbnailImageUrl']; + currentAvatar = json['currentAvatar']; + currentAvatarAssetUrl = json['currentAvatarAssetUrl']; + fallbackAvatar = json['fallbackAvatar']; + accountDeletionDate = json['accountDeletionDate']; + acceptedTOSVersion = json['acceptedTOSVersion']; + steamId = json['steamId']; + steamDetails = json['steamDetails']; + oculusId = json['oculusId']; + hasLoggedInFromClient = json['hasLoggedInFromClient']; + homeLocation = json['homeLocation']; + twoFactorAuthEnabled = json['twoFactorAuthEnabled']; + twoFactorAuthEnabledDate = json['twoFactorAuthEnabledDate']; + state = json['state']; + tags = json['tags'].cast(); + developerType = json['developerType']; + lastLogin = json['last_login']; + lastPlatform = json['last_platform']; + allowAvatarCopying = json['allowAvatarCopying']; + status = json['status']; + dateJoined = json['date_joined']; + isFriend = json['isFriend']; + friendKey = json['friendKey']; + lastActivity = json['last_activity']; + } +} + class VRChatUsers { dynamic source; late VRChatStatus vrchatStatus; @@ -90,6 +192,7 @@ class VRChatUser { VRChatUser.fromJson(Map json) { source = json; vrchatStatus = VRChatStatus.fromJson(json); + if (vrchatStatus.status == "error") return; id = json['id']; username = json['username']; displayName = json['displayName']; diff --git a/lib/api/main.dart b/lib/api/main.dart index 5ac8721a9..7f6be0743 100644 --- a/lib/api/main.dart +++ b/lib/api/main.dart @@ -233,13 +233,23 @@ class VRChatAPI { // Change - Future> changeName(String uid, String username, String password) { + Future changeName(String uid, String username, String password) { return vrchatSession.put( endpoint( 'api/1/users/$uid', apiKey(), ), {"currentPassword": password, "displayName": username}, - ); + ).then((value) => VRChatUserOverload.fromJson(value)); + } + + Future changeBio(String uid, String bio) { + return vrchatSession.put( + endpoint( + 'api/1/users/$uid', + apiKey(), + ), + {"bio": bio}, + ).then((value) => VRChatUserOverload.fromJson(value)); } } diff --git a/lib/widgets/drawer.dart b/lib/widgets/drawer.dart index 894b38738..ac0a9c8fe 100644 --- a/lib/widgets/drawer.dart +++ b/lib/widgets/drawer.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; // Package imports: import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:vrchat_mobile_client/api/main.dart'; // Project imports: import 'package:vrchat_mobile_client/assets/storage.dart'; @@ -124,7 +125,15 @@ Drawer drawer(BuildContext context) { TextButton( onPressed: () => Navigator.pop(context), child: Text(AppLocalizations.of(context)!.close), - ) + ), + TextButton( + onPressed: () => { + getLoginSession("login_session").then((cookie) { + VRChatAPI(cookie: cookie ?? "").changeName("aaa", "aaa", "aaa").then((value) => print(value)); + }) + }, + child: Text(AppLocalizations.of(context)!.close), + ), ], ), ),