Skip to content

Commit 8211272

Browse files
committed
display previously downloaded jpeg, png and gif images
1 parent eab872d commit 8211272

File tree

5 files changed

+55
-7
lines changed

5 files changed

+55
-7
lines changed

Signal-Windows.Lib/SignalLibHandle.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ private void StartAttachmentDownloads(SignalMessage message)
486486
// this is the recommended way to call CreateDownload
487487
// see https://docs.microsoft.com/en-us/uwp/api/windows.networking.backgroundtransfer.backgrounddownloader#Methods
488488
DownloadOperation download = downloader.CreateDownload(new Uri(RetrieveAttachmentUrl(attachmentPointer)), tmpDownload);
489+
attachment.FileName = "" + download.Guid;
489490
SignalDBContext.UpdateAttachmentFileName(attachment);
490491
Downloads.Add(download);
491492
Task.Run(async () =>
@@ -511,6 +512,7 @@ private async Task HandleSuccessfullDownload(SignalAttachment attachment, IStora
511512
Logger.LogInformation("Deleting tmpFile {0}", tmpDownload.Name);
512513
await tmpDownload.DeleteAsync();
513514
attachment.Status = SignalAttachmentStatus.Finished;
515+
SignalDBContext.UpdateAttachmentStatus(attachment);
514516
DispatchAttachmentStatusChanged(download, attachment);
515517
}
516518

Signal-Windows.Lib/Storage/DB.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,21 @@ internal static void UpdateAttachmentFileName(SignalAttachment attachment)
935935
}
936936
}
937937

938+
internal static void UpdateAttachmentStatus(SignalAttachment attachment)
939+
{
940+
lock (DBLock)
941+
{
942+
using (var ctx = new SignalDBContext())
943+
{
944+
var savedAttachment = ctx.Attachments
945+
.Where(a => a.Id == attachment.Id)
946+
.First();
947+
savedAttachment.Status = attachment.Status;
948+
ctx.SaveChanges();
949+
}
950+
}
951+
}
952+
938953
#endregion Attachments
939954

940955
#region Threads

Signal-Windows/Controls/Attachment.xaml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,18 @@
1616
</Grid.ColumnDefinitions>
1717
<Ellipse Fill="#FF9B9B9B" Width="50" Height="50"/>
1818
<SymbolIcon Symbol="Page2"/>
19-
<StackPanel Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="8,0,0,0">
20-
<TextBlock Text="{x:Bind FileName, Mode=OneWay}" Style="{StaticResource BodyTextBlockStyle}"/>
21-
<TextBlock Text="{x:Bind FileSize, Mode=OneWay}" Style="{StaticResource CaptionTextBlockStyle}"/>
19+
<StackPanel Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="8,0,0,0">
20+
<StackPanel Name="ImageStackPanel" Visibility="Visible">
21+
<Image>
22+
<Image.Source>
23+
<BitmapImage UriSource="{x:Bind ImagePath, Mode=TwoWay}"/>
24+
</Image.Source>
25+
</Image>
26+
</StackPanel>
27+
<StackPanel Name="DefaultStackPanel" Visibility="Visible">
28+
<TextBlock Text="{x:Bind FileName, Mode=OneWay}" Style="{StaticResource BodyTextBlockStyle}"/>
29+
<TextBlock Text="{x:Bind FileSize, Mode=OneWay}" Style="{StaticResource CaptionTextBlockStyle}"/>
30+
</StackPanel>
2231
</StackPanel>
2332
</Grid>
2433
</UserControl>

Signal-Windows/Controls/Attachment.xaml.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Signal_Windows.Models;
88
using Windows.Foundation;
99
using Windows.Foundation.Collections;
10+
using Windows.Storage;
1011
using Windows.UI.Xaml;
1112
using Windows.UI.Xaml.Controls;
1213
using Windows.UI.Xaml.Controls.Primitives;
@@ -35,12 +36,18 @@ public string FileSize
3536
{
3637
get { return fileSize; }
3738
set { fileSize = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(FileSize))); }
39+
}
40+
41+
private Uri imagePath;
42+
public Uri ImagePath
43+
{
44+
get { return imagePath; }
45+
set { imagePath = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ImagePath))); }
3846
}
3947

4048
public SignalAttachment Model
4149
{
4250
get { return DataContext as SignalAttachment; }
43-
set { DataContext = value; }
4451
}
4552

4653
public Attachment()
@@ -54,8 +61,23 @@ private void Attachment_DataContextChanged(FrameworkElement sender, DataContextC
5461
if (Model != null)
5562
{
5663
FileName = Model.FileName;
57-
FileSize = Utils.BytesToString(Model.Size);
64+
FileSize = Utils.BytesToString(Model.Size);
65+
if (Model.Status == SignalAttachmentStatus.Finished)
66+
{
67+
if (IMAGE_TYPES.Contains(Model.ContentType))
68+
{
69+
var path = ApplicationData.Current.LocalCacheFolder.Path + @"\Attachments\" + Model.Id + ".plain";
70+
ImagePath = new Uri(path);
71+
}
72+
}
5873
}
59-
}
74+
}
75+
76+
private static HashSet<string> IMAGE_TYPES = new HashSet<string>()
77+
{
78+
"image/jpeg",
79+
"image/png",
80+
"image/gif"
81+
};
6082
}
6183
}

Signal-Windows/Controls/Message.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<ItemsControl>
1919
<local:Attachment DataContext="{x:Bind Attachment, Mode=OneWay}" Visibility="{x:Bind HasAttachment, Mode=OneWay}"/>
2020
<TextBlock Name="MessageAuthor" FontWeight="Bold" />
21-
<TextBlock Name="MessageContentTextBlock" TextWrapping="Wrap" MaxWidth="300" IsTextSelectionEnabled="True" FontSize="14" Foreground="Black" />
21+
<TextBlock Name="MessageContentTextBlock" TextWrapping="Wrap" MaxWidth="300" IsTextSelectionEnabled="True" FontSize="14" Foreground="Black" HorizontalAlignment="Left" />
2222
<Grid Name="FooterPanel" MaxWidth="300">
2323
<Grid.ColumnDefinitions>
2424
<ColumnDefinition Width="Auto"/>

0 commit comments

Comments
 (0)