Skip to content

Commit 225b5e0

Browse files
committed
Added merging for external images.
These will now be marged and treated the same way the existing image ids are, which is mostly useless information. This fixes issue #276
1 parent f40bf03 commit 225b5e0

File tree

1 file changed

+48
-45
lines changed

1 file changed

+48
-45
lines changed

DiscordRPC/Entities/Assets.cs

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ namespace DiscordRPC
1111
[Serializable]
1212
public class Assets
1313
{
14+
private const string EXTERNAL_KEY_PREFIX = "mp:external";
15+
16+
#region Large Image
1417
/// <summary>
1518
/// Name of the uploaded image for the large profile artwork.
1619
/// <para>Max 256 characters.</para>
@@ -25,25 +28,12 @@ public string LargeImageKey
2528
if (!BaseRichPresence.ValidateString(value, out _largeimagekey, false, 256))
2629
throw new StringOutOfRangeException(256);
2730

28-
//Get if this is a external link
29-
_islargeimagekeyexternal = _largeimagekey?.StartsWith("mp:external/") ?? false;
30-
3131
//Reset the large image ID
32-
_largeimageID = null;
32+
LargeImageID = null;
3333
}
3434
}
3535
private string _largeimagekey;
3636

37-
/// <summary>
38-
/// Gets if the large square image is from an external link
39-
/// </summary>
40-
[JsonIgnore]
41-
public bool IsLargeImageKeyExternal
42-
{
43-
get { return _islargeimagekeyexternal; }
44-
}
45-
private bool _islargeimagekeyexternal;
46-
4737
/// <summary>
4838
/// The tooltip for the large square image. For example, "Summoners Rift" or "Horizon Lunar Colony".
4939
/// <para>Max 128 characters.</para>
@@ -79,6 +69,20 @@ public string LargeImageUrl
7969
}
8070
private string _largeimageurl;
8171

72+
/// <summary>
73+
/// The ID of the large image. This is only set after Update Presence and will automatically become null when <see cref="LargeImageKey"/> is changed.
74+
/// </summary>
75+
[JsonIgnore]
76+
public string LargeImageID { get; private set; }
77+
78+
/// <summary>
79+
/// Gets if the large square image is from an external link
80+
/// </summary>
81+
[JsonIgnore]
82+
public bool IsLargeImageKeyExternal { get; private set; }
83+
#endregion
84+
85+
#region Small Image
8286
/// <summary>
8387
/// Name of the uploaded image for the small profile artwork.
8488
/// <para>Max 256 characters.</para>
@@ -93,25 +97,12 @@ public string SmallImageKey
9397
if (!BaseRichPresence.ValidateString(value, out _smallimagekey, false, 256))
9498
throw new StringOutOfRangeException(256);
9599

96-
//Get if this is a external link
97-
_issmallimagekeyexternal = _smallimagekey?.StartsWith("mp:external/") ?? false;
98-
99100
//Reset the small image id
100-
_smallimageID = null;
101+
SmallImageID = null;
101102
}
102103
}
103104
private string _smallimagekey;
104105

105-
/// <summary>
106-
/// Gets if the small profile artwork is from an external link
107-
/// </summary>
108-
[JsonIgnore]
109-
public bool IsSmallImageKeyExternal
110-
{
111-
get { return _issmallimagekeyexternal; }
112-
}
113-
private bool _issmallimagekeyexternal;
114-
115106
/// <summary>
116107
/// The tooltip for the small circle image. For example, "LvL 6" or "Ultimate 85%".
117108
/// <para>Max 128 characters.</para>
@@ -148,18 +139,18 @@ public string SmallImageUrl
148139
private string _smallimageurl;
149140

150141
/// <summary>
151-
/// The ID of the large image. This is only set after Update Presence and will automatically become null when <see cref="LargeImageKey"/> is changed.
142+
/// The ID of the small image. This is only set after Update Presence and will automatically become null when <see cref="SmallImageKey"/> is changed.
152143
/// </summary>
153144
[JsonIgnore]
154-
public ulong? LargeImageID { get { return _largeimageID; } }
155-
private ulong? _largeimageID;
145+
public string SmallImageID { get; private set; }
156146

157147
/// <summary>
158-
/// The ID of the small image. This is only set after Update Presence and will automatically become null when <see cref="SmallImageKey"/> is changed.
148+
/// Gets if the small profile artwork is from an external link
159149
/// </summary>
160150
[JsonIgnore]
161-
public ulong? SmallImageID { get { return _smallimageID; } }
162-
private ulong? _smallimageID;
151+
public bool IsSmallImageKeyExternal { get; private set; }
152+
#endregion
153+
163154

164155
/// <summary>
165156
/// Merges this asset with the other, taking into account for ID's instead of keys.
@@ -173,30 +164,42 @@ internal void Merge(Assets other)
173164
_largeimagetext = other._largeimagetext;
174165
_largeimageurl = other._largeimageurl;
175166

176-
//Convert large ID
177-
ulong largeID;
178-
if (ulong.TryParse(other._largeimagekey, out largeID))
167+
//Convert the Large Key
168+
if (other._largeimagekey.StartsWith(EXTERNAL_KEY_PREFIX))
179169
{
180-
_largeimageID = largeID;
170+
IsLargeImageKeyExternal = true;
171+
LargeImageID = other._largeimagekey;
172+
}
173+
else if (ulong.TryParse(other._largeimagekey, out _))
174+
{
175+
IsLargeImageKeyExternal = false;
176+
LargeImageID = other._largeimagekey;
181177
}
182178
else
183179
{
180+
IsLargeImageKeyExternal = false;
181+
LargeImageID = null;
184182
_largeimagekey = other._largeimagekey;
185-
_largeimageID = null;
186183
}
187184

188-
//Convert the small ID
189-
ulong smallID;
190-
if (ulong.TryParse(other._smallimagekey, out smallID))
185+
//Convert the Small Key
186+
// TODO: Make this a function
187+
if (other._smallimagekey.StartsWith(EXTERNAL_KEY_PREFIX))
188+
{
189+
IsSmallImageKeyExternal = true;
190+
SmallImageID = other._smallimagekey;
191+
}
192+
else if (ulong.TryParse(other._smallimagekey, out _))
191193
{
192-
_smallimageID = smallID;
194+
IsSmallImageKeyExternal = false;
195+
SmallImageID = other._smallimagekey;
193196
}
194197
else
195198
{
199+
IsSmallImageKeyExternal = false;
200+
SmallImageID = null;
196201
_smallimagekey = other._smallimagekey;
197-
_smallimageID = null;
198202
}
199203
}
200204
}
201-
202205
}

0 commit comments

Comments
 (0)