Browse Source

Added GetJumpUrl() to MessageHelper, IMessage, RestMessage, and SocketMessage

Used a Get method instead of a property to be consistent with GetAvatarUrl and other GetUrl methods. The `"https://discordapp.com/"` can be exchanged with `DiscordConfig.CDNUrl` and the links work fine still. Except this removes the embed preview from the links. This has been tested in both dms and guilds by checking the value of `GetJumpUrl()` on received and sent messages. I think I got all occurrences of where this should be implemented.
pull/1098/head
Casino Boyale 7 years ago
parent
commit
82b2965534
4 changed files with 16 additions and 3 deletions
  1. +3
    -1
      src/Discord.Net.Core/Entities/Messages/IMessage.cs
  2. +6
    -0
      src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs
  3. +3
    -1
      src/Discord.Net.Rest/Entities/Messages/RestMessage.cs
  4. +4
    -1
      src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs

+ 3
- 1
src/Discord.Net.Core/Entities/Messages/IMessage.cs View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic; using System.Collections.Generic;


namespace Discord namespace Discord
@@ -15,6 +15,8 @@ namespace Discord
bool IsPinned { get; } bool IsPinned { get; }
/// <summary> Returns the content for this message. </summary> /// <summary> Returns the content for this message. </summary>
string Content { get; } string Content { get; }
/// <summary> Returns a jump url for this message. </summary>
string GetJumpUrl();
/// <summary> Gets the time this message was sent. </summary> /// <summary> Gets the time this message was sent. </summary>
DateTimeOffset Timestamp { get; } DateTimeOffset Timestamp { get; }
/// <summary> Gets the time of this message's last edit, if any. </summary> /// <summary> Gets the time of this message's last edit, if any. </summary>


+ 6
- 0
src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs View File

@@ -93,6 +93,12 @@ namespace Discord.Rest
await client.ApiClient.RemovePinAsync(msg.Channel.Id, msg.Id, options).ConfigureAwait(false); await client.ApiClient.RemovePinAsync(msg.Channel.Id, msg.Id, options).ConfigureAwait(false);
} }


public static string GetJumpUrl(IMessage msg)
{
var channel = msg.Channel;
return $"https://discordapp.com/channels/{(channel is IDMChannel ? "@me" : $"{(channel as IGuildChannel).GuildId}")}/{channel.Id}/{msg.Id}";
}

public static ImmutableArray<ITag> ParseTags(string text, IMessageChannel channel, IGuild guild, IReadOnlyCollection<IUser> userMentions) public static ImmutableArray<ITag> ParseTags(string text, IMessageChannel channel, IGuild guild, IReadOnlyCollection<IUser> userMentions)
{ {
var tags = ImmutableArray.CreateBuilder<ITag>(); var tags = ImmutableArray.CreateBuilder<ITag>();


+ 3
- 1
src/Discord.Net.Rest/Entities/Messages/RestMessage.cs View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Linq; using System.Linq;
@@ -63,6 +63,8 @@ namespace Discord.Rest


public override string ToString() => Content; public override string ToString() => Content;


public string GetJumpUrl() => MessageHelper.GetJumpUrl(this);

MessageType IMessage.Type => MessageType.Default; MessageType IMessage.Type => MessageType.Default;
IUser IMessage.Author => Author; IUser IMessage.Author => Author;
IReadOnlyCollection<IAttachment> IMessage.Attachments => Attachments; IReadOnlyCollection<IAttachment> IMessage.Attachments => Attachments;


+ 4
- 1
src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs View File

@@ -1,4 +1,4 @@
using Discord.Rest;
using Discord.Rest;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
@@ -58,6 +58,9 @@ namespace Discord.WebSocket
=> MessageHelper.DeleteAsync(this, Discord, options); => MessageHelper.DeleteAsync(this, Discord, options);


public override string ToString() => Content; public override string ToString() => Content;

public string GetJumpUrl() => MessageHelper.GetJumpUrl(this);

internal SocketMessage Clone() => MemberwiseClone() as SocketMessage; internal SocketMessage Clone() => MemberwiseClone() as SocketMessage;


//IMessage //IMessage


Loading…
Cancel
Save