mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-24 03:26:38 +00:00
redesign user object
This commit is contained in:
parent
624036d00c
commit
5c663c5596
3 changed files with 83 additions and 30 deletions
|
@ -45,14 +45,23 @@ class AddressResolver {
|
||||||
final formattedName = text.substring(1);
|
final formattedName = text.substring(1);
|
||||||
final twitterUser = await TwitterApi.lookupUserByName(userName: formattedName);
|
final twitterUser = await TwitterApi.lookupUserByName(userName: formattedName);
|
||||||
final addressFromBio = extractAddressByType(
|
final addressFromBio = extractAddressByType(
|
||||||
raw: twitterUser.description ?? '', type: CryptoCurrency.fromString(ticker));
|
raw: twitterUser.data.description, type: CryptoCurrency.fromString(ticker));
|
||||||
final addressFromPinnedTweet = extractAddressByType(
|
|
||||||
raw: twitterUser.pinnedTweet ?? '', type: CryptoCurrency.fromString(ticker));
|
|
||||||
if (addressFromBio != null) {
|
if (addressFromBio != null) {
|
||||||
return ParsedAddress.fetchTwitterAddress(address: addressFromBio, name: text);
|
return ParsedAddress.fetchTwitterAddress(address: addressFromBio, name: text);
|
||||||
}
|
}
|
||||||
if (addressFromPinnedTweet != null) {
|
final tweets = twitterUser.includes?.tweets;
|
||||||
return ParsedAddress.fetchTwitterAddress(address: addressFromPinnedTweet, name: text);
|
if (tweets != null) {
|
||||||
|
var subString = StringBuffer();
|
||||||
|
tweets.forEach((item) {
|
||||||
|
subString.writeln(item.text);
|
||||||
|
});
|
||||||
|
final userTweetsText = subString.toString();
|
||||||
|
final addressFromPinnedTweet =
|
||||||
|
extractAddressByType(raw: userTweetsText, type: CryptoCurrency.fromString(ticker));
|
||||||
|
|
||||||
|
if (addressFromPinnedTweet != null) {
|
||||||
|
return ParsedAddress.fetchTwitterAddress(address: addressFromPinnedTweet, name: text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!text.startsWith('@') && text.contains('@') && !text.contains('.')) {
|
if (!text.startsWith('@') && text.contains('@') && !text.contains('.')) {
|
||||||
|
|
|
@ -32,16 +32,6 @@ class TwitterApi {
|
||||||
throw Exception(responseJSON['errors'][0]['detail']);
|
throw Exception(responseJSON['errors'][0]['detail']);
|
||||||
}
|
}
|
||||||
|
|
||||||
final user = responseJSON['data'] as Map<String, dynamic>;
|
return TwitterUser.fromJson(responseJSON);
|
||||||
|
|
||||||
try {
|
|
||||||
if (responseJSON['includes'] != null) {
|
|
||||||
user['pinnedTweet'] = responseJSON['includes']['tweets'][0]['text'];
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
print('responseJSON[includes][tweets][0][text] $e');
|
|
||||||
}
|
|
||||||
|
|
||||||
return TwitterUser.fromJson(user);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,73 @@
|
||||||
class TwitterUser {
|
class TwitterUser {
|
||||||
TwitterUser({required this.id, required this.username, required this.name, this.description,
|
TwitterUser({
|
||||||
this.pinnedTweet});
|
required this.data,
|
||||||
|
this.includes,
|
||||||
|
});
|
||||||
|
|
||||||
final String id;
|
late final Data data;
|
||||||
final String username;
|
late final Includes? includes;
|
||||||
final String name;
|
|
||||||
final String? description;
|
|
||||||
final String? pinnedTweet;
|
|
||||||
|
|
||||||
factory TwitterUser.fromJson(Map<String, dynamic> json) {
|
TwitterUser.fromJson(Map<String, dynamic> json) {
|
||||||
return TwitterUser(
|
data = Data.fromJson(json['data'] as Map<String, dynamic>);
|
||||||
id: json['id'] as String,
|
includes = json['includes'] != null
|
||||||
username: json['username'] as String,
|
? Includes.fromJson(json['includes'] as Map<String, dynamic>)
|
||||||
name: json['name'] as String,
|
: null;
|
||||||
description: json['description'] as String?,
|
}
|
||||||
pinnedTweet: json['pinnedTweet'] as String?);
|
}
|
||||||
|
|
||||||
|
class Data {
|
||||||
|
Data({
|
||||||
|
required this.name,
|
||||||
|
required this.id,
|
||||||
|
required this.pinnedTweetId,
|
||||||
|
required this.description,
|
||||||
|
required this.username,
|
||||||
|
});
|
||||||
|
|
||||||
|
late final String name;
|
||||||
|
late final String id;
|
||||||
|
late final String? pinnedTweetId;
|
||||||
|
late final String description;
|
||||||
|
late final String username;
|
||||||
|
|
||||||
|
Data.fromJson(Map<String, dynamic> json) {
|
||||||
|
name = json['name'] as String;
|
||||||
|
id = json['id'] as String;
|
||||||
|
pinnedTweetId = json['pinned_tweet_id'] as String?;
|
||||||
|
description = json['description'] as String;
|
||||||
|
username = json['username'] as String;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Includes {
|
||||||
|
Includes({
|
||||||
|
required this.tweets,
|
||||||
|
});
|
||||||
|
|
||||||
|
late final List<Tweets> tweets;
|
||||||
|
|
||||||
|
Includes.fromJson(Map<String, dynamic> json) {
|
||||||
|
tweets = List.from(json['tweets'] as Iterable<dynamic>)
|
||||||
|
.map((e) => Tweets.fromJson(e as Map<String, dynamic>))
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Tweets {
|
||||||
|
Tweets({
|
||||||
|
required this.editHistoryTweetIds,
|
||||||
|
required this.id,
|
||||||
|
required this.text,
|
||||||
|
});
|
||||||
|
|
||||||
|
late final List<String> editHistoryTweetIds;
|
||||||
|
late final String id;
|
||||||
|
late final String text;
|
||||||
|
|
||||||
|
Tweets.fromJson(Map<String, dynamic> json) {
|
||||||
|
editHistoryTweetIds =
|
||||||
|
List.castFrom<dynamic, String>(json['edit_history_tweet_ids'] as List<dynamic>);
|
||||||
|
id = json['id'] as String;
|
||||||
|
text = json['text'] as String;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue