not-nullptr / Aerochat

Native rewrite of Aerochat, a WLM 09 themed Discord client
Mozilla Public License 2.0
112 stars 5 forks source link

Gifs for Chat & Image Previewer #18

Closed nullgato closed 1 week ago

nullgato commented 1 week ago

This PR adds .gif support for the chat windows as well as image previewer with the use of the XamlAnimatedGif library.

It also changes some code regarding variables for attachments where previously we check if something is a gif or otherwise, but in having support for other media I've replaced this with a new enum type called MediaType on AttachmentViewModel and ImagePreviewerViewModel that sets the type based on a file's mime with the use of the MimeTypeMap library. It also uses MediaType for bindings in Chat.xaml.

MediaType mediaType;

if (attachment.Width <= 0 || attachment.Height <= 0)
    mediaType = MediaType.Unknown;
else
{
    var fileNameSects = attachment.FileName.Split('.');
    string mimeType = MimeTypeMap.GetMimeType(fileNameSects[fileNameSects.Length - 1]);
    if (mimeType.Contains("image"))
        mediaType = attachment.FileName.Contains(".gif") ? MediaType.Gif : MediaType.Image;
    else if (mimeType.Contains("video"))
        mediaType = MediaType.Video;
    else if (mimeType.Contains("audio"))
        mediaType = MediaType.Audio;
    else mediaType = MediaType.Unknown;
}
not-nullptr commented 1 week ago

image this pr seems to leak memory :(

nullgato commented 1 week ago

Tragic :( This seems to be caused by MediaElement which is used to play multiple forms of media, but I was specifically using it for video embeds since Tenor gifs are sent as videos for some reason.

I was also having a hell of a time with this for other video attachments. Sadly video is going to be incredibly hard from what I've seen because there aren't many options for video and the ones I've found all have paths leading to memory leakage and have to be used very carefully.

Anyway, I think this PR is updated? Sorry for not being good with how PRs work. I removed the MediaElement causing the issue, but normal user-sent gifs should still work great.

nullgato commented 1 week ago

Closed because I've gotten out of sync with latest, will remake