| | 1 | | using DCL.UserProfiles; |
| | 2 | | using System; |
| | 3 | | using System.Collections.Generic; |
| | 4 | |
|
| | 5 | | [Serializable] |
| | 6 | | public class UserProfileModel |
| | 7 | | { |
| | 8 | | [Serializable] |
| | 9 | | public class Link |
| | 10 | | { |
| | 11 | | public string title; |
| | 12 | | public string url; |
| | 13 | |
|
| 0 | 14 | | public Link() |
| | 15 | | { |
| 0 | 16 | | } |
| | 17 | |
|
| 27 | 18 | | public Link(string title, string url) |
| | 19 | | { |
| 27 | 20 | | this.title = title; |
| 27 | 21 | | this.url = url; |
| 27 | 22 | | } |
| | 23 | |
|
| | 24 | | public override bool Equals(object obj) => |
| 0 | 25 | | obj is Link link && Equals(link); |
| | 26 | |
|
| | 27 | | private bool Equals(Link other) => |
| 0 | 28 | | title == other.title && url == other.url; |
| | 29 | |
|
| | 30 | | public override int GetHashCode() => |
| 0 | 31 | | HashCode.Combine(title, url); |
| | 32 | | } |
| | 33 | |
|
| | 34 | | [Serializable] |
| | 35 | | public class Snapshots |
| | 36 | | { |
| | 37 | | public string face256; |
| | 38 | | public string body; |
| | 39 | |
|
| | 40 | | public bool Equals(Snapshots snapshots) |
| | 41 | | { |
| 0 | 42 | | if (snapshots == null) return false; |
| 0 | 43 | | if (snapshots.face256 != face256) return false; |
| 0 | 44 | | if (snapshots.body != body) return false; |
| 0 | 45 | | return true; |
| | 46 | | } |
| | 47 | | } |
| | 48 | |
|
| | 49 | | [Serializable] |
| | 50 | | public class ParcelsWithAccess |
| | 51 | | { |
| | 52 | | public int x; |
| | 53 | | public int y; |
| | 54 | | public LandRole landRole; |
| | 55 | |
|
| | 56 | | [Serializable] |
| | 57 | | public enum LandRole |
| | 58 | | { |
| | 59 | | OWNER = 0, |
| | 60 | | OPERATOR = 1 |
| | 61 | | } |
| | 62 | |
|
| | 63 | | public bool Equals(ParcelsWithAccess parcelsWithAccess) |
| | 64 | | { |
| 0 | 65 | | if (parcelsWithAccess == null) return false; |
| 0 | 66 | | if (parcelsWithAccess.x != x) return false; |
| 0 | 67 | | if (parcelsWithAccess.y != y) return false; |
| 0 | 68 | | if (parcelsWithAccess.landRole != landRole) return false; |
| 0 | 69 | | return true; |
| | 70 | | } |
| | 71 | | } |
| | 72 | |
|
| | 73 | | public string userId; |
| | 74 | | public string ethAddress; |
| | 75 | | public string name; |
| | 76 | | public string email; |
| | 77 | | public string description; |
| | 78 | | public string baseUrl; |
| | 79 | | public ParcelsWithAccess[] parcelsWithAccess; |
| | 80 | | public ulong created_at; |
| | 81 | | public ulong updated_at; |
| | 82 | | public int version; |
| | 83 | | public AvatarModel avatar; |
| 1481 | 84 | | public Snapshots snapshots = new (); |
| 0 | 85 | | public UserProfileModel Clone() => (UserProfileModel)MemberwiseClone(); |
| | 86 | |
|
| 1481 | 87 | | public bool hasConnectedWeb3 = true; |
| | 88 | |
|
| | 89 | | public int tutorialFlagsMask; |
| 1481 | 90 | | public List<string> blocked = new (); |
| 1481 | 91 | | public List<string> muted = new (); |
| | 92 | | public int tutorialStep; |
| | 93 | | public bool hasClaimedName; |
| | 94 | | public List<Link> links; |
| 2995 | 95 | | public AdditionalInfo AdditionalInfo { get; set; } = new (); |
| | 96 | |
|
| | 97 | | public static UserProfileModel FallbackModel(string name, int id) |
| | 98 | | { |
| 0 | 99 | | var fallbackId = $"{name}_{id}"; |
| | 100 | |
|
| 0 | 101 | | return new UserProfileModel |
| | 102 | | { |
| | 103 | | // Required fields (otherwise exceptions will be thrown by UserProfile.OnUpdate subscribers) |
| | 104 | | userId = fallbackId, |
| | 105 | | name = name, |
| | 106 | | description = "There was a problem with loading this profile. This is a fallback profile", |
| | 107 | |
|
| | 108 | | avatar = AvatarModel.FallbackModel(name, id), |
| | 109 | |
|
| | 110 | | // Optional (exceptions-free) fields |
| | 111 | | ethAddress = fallbackId, |
| | 112 | | email = fallbackId, |
| | 113 | | baseUrl = fallbackId, |
| | 114 | | }; |
| | 115 | | } |
| | 116 | |
|
| | 117 | | public bool Equals(UserProfileModel model) |
| | 118 | | { |
| 0 | 119 | | if (model == null) return false; |
| 0 | 120 | | if (model.userId != userId) return false; |
| 0 | 121 | | if (model.ethAddress != ethAddress) return false; |
| 0 | 122 | | if (model.name != name) return false; |
| 0 | 123 | | if (model.email != email) return false; |
| 0 | 124 | | if (model.description != description) return false; |
| 0 | 125 | | if (model.baseUrl != baseUrl) return false; |
| 0 | 126 | | if (model.created_at != created_at) return false; |
| 0 | 127 | | if (model.updated_at != updated_at) return false; |
| 0 | 128 | | if (model.version != version) return false; |
| 0 | 129 | | if (!model.avatar.Equals(avatar)) return false; |
| | 130 | |
|
| 0 | 131 | | if (model.parcelsWithAccess != null) |
| | 132 | | { |
| 0 | 133 | | if (!model.parcelsWithAccess.Equals(parcelsWithAccess)) |
| 0 | 134 | | return false; |
| | 135 | | } |
| 0 | 136 | | else if (parcelsWithAccess != null) |
| 0 | 137 | | return false; |
| | 138 | |
|
| 0 | 139 | | if (model.hasConnectedWeb3 != hasConnectedWeb3) return false; |
| 0 | 140 | | if (model.tutorialFlagsMask != tutorialFlagsMask) return false; |
| 0 | 141 | | if (model.tutorialFlagsMask != tutorialFlagsMask) return false; |
| | 142 | |
|
| 0 | 143 | | if (model.blocked != null && blocked != null) |
| | 144 | | { |
| | 145 | | // We're comparing only the lenght of the 'blocked' list because we found several cases where it is too big |
| | 146 | | // Also, taking into account that this list should be removed from the profile data in the catalysts, we dec |
| 0 | 147 | | if (model.blocked.Count != blocked.Count) |
| 0 | 148 | | return false; |
| | 149 | | } |
| 0 | 150 | | else if (model.blocked != null || blocked != null) |
| 0 | 151 | | return false; |
| | 152 | |
|
| 0 | 153 | | if (model.muted != null && muted != null) |
| | 154 | | { |
| | 155 | | // We're comparing only the lenght of the 'muted' list because we found several cases where it is too big an |
| | 156 | | // Also, taking into account that this list should be removed from the profile data in the catalysts, we dec |
| 0 | 157 | | if (model.muted.Count != muted.Count) |
| 0 | 158 | | return false; |
| | 159 | | } |
| 0 | 160 | | else if (model.muted != null || muted != null) |
| 0 | 161 | | return false; |
| | 162 | |
|
| 0 | 163 | | if (model.tutorialStep != tutorialStep) return false; |
| 0 | 164 | | if (model.hasClaimedName != hasClaimedName) return false; |
| | 165 | |
|
| 0 | 166 | | if (model.links != null && links != null) |
| | 167 | | { |
| 0 | 168 | | if (model.links.Count != links.Count) |
| 0 | 169 | | return false; |
| | 170 | | } |
| 0 | 171 | | else if (model.links != null || links != null) |
| 0 | 172 | | return false; |
| | 173 | |
|
| 0 | 174 | | if (!AdditionalInfo.Equals(model.AdditionalInfo)) |
| 0 | 175 | | return false; |
| | 176 | |
|
| 0 | 177 | | return true; |
| | 178 | | } |
| | 179 | |
|
| | 180 | | public string ComposeCorrectUrl(string url) |
| | 181 | | { |
| 130 | 182 | | if (string.IsNullOrEmpty(url)) |
| 68 | 183 | | return url; |
| | 184 | |
|
| 62 | 185 | | if (!url.StartsWith("Qm") && !url.StartsWith("ba")) |
| 62 | 186 | | return url; |
| | 187 | |
|
| 0 | 188 | | return baseUrl + url; |
| | 189 | | } |
| | 190 | | } |