Skip to content

Commit a31371a

Browse files
committed
Add contact blocking
It's not fully integrated but it's most of the way there
1 parent 6a8e47b commit a31371a

14 files changed

+416
-8
lines changed

Signal-Windows.Lib/IncomingMessages.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,12 @@ private void HandleSignalMessage(SignalServiceEnvelope envelope, SignalServiceCo
572572
author = SignalDBContext.GetOrCreateContactLocked(envelope.GetSource(), timestamp);
573573
}
574574

575+
if (author != null && author.Blocked)
576+
{
577+
// Don't save blocked messages
578+
return;
579+
}
580+
575581
List<SignalAttachment> attachments = new List<SignalAttachment>();
576582
SignalMessage message = new SignalMessage()
577583
{

Signal-Windows.Lib/Migrations/SignalDB/20180521001340_m6.Designer.cs

Lines changed: 260 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Microsoft.EntityFrameworkCore.Migrations;
4+
5+
namespace Signal_Windows.Migrations
6+
{
7+
public partial class m6 : Migration
8+
{
9+
protected override void Up(MigrationBuilder migrationBuilder)
10+
{
11+
migrationBuilder.AddColumn<bool>(
12+
name: "Blocked",
13+
table: "SignalConversation",
14+
nullable: false,
15+
defaultValue: false);
16+
}
17+
18+
protected override void Down(MigrationBuilder migrationBuilder)
19+
{
20+
migrationBuilder.DropColumn(
21+
name: "Blocked",
22+
table: "SignalConversation");
23+
}
24+
}
25+
}

Signal-Windows.Lib/Migrations/SignalDB/SignalDBContextModelSnapshot.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)
193193
{
194194
b.HasBaseType("Signal_Windows.Models.SignalConversation");
195195

196+
b.Property<bool>("Blocked");
197+
196198
b.Property<string>("Color");
197199

198200
b.ToTable("SignalContact");

Signal-Windows.Lib/Models/SignalContact.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace Signal_Windows.Models
55
public class SignalContact : SignalConversation
66
{
77
public string Color { get; set; }
8+
public bool Blocked { get; set; }
89
public List<GroupMembership> GroupMemberships { get; set; }
910
}
1011
}

Signal-Windows.Lib/Signal-Windows.Lib.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@
109109
<Compile Include="Events\SignalMessageEventArgs.cs" />
110110
<Compile Include="GlobalSettingsManager.cs" />
111111
<Compile Include="IncomingMessages.cs" />
112+
<Compile Include="Migrations\SignalDB\20180521001340_m6.cs" />
113+
<Compile Include="Migrations\SignalDB\20180521001340_m6.designer.cs">
114+
<DependentUpon>20180521001340_m6.cs</DependentUpon>
115+
</Compile>
112116
<Compile Include="Util\LibUtils.cs" />
113117
<Compile Include="Migrations\LibsignalDB\20170806145530_ls1.cs" />
114118
<Compile Include="Migrations\LibsignalDB\20170806145530_ls1.Designer.cs">

Signal-Windows.Lib/Storage/DB.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,23 @@ public static void InsertOrUpdateConversationLocked(SignalConversation conversat
14111411
}
14121412
}
14131413
}
1414+
1415+
public static void UpdateBlockStatus(SignalContact contact)
1416+
{
1417+
lock (DBLock)
1418+
{
1419+
using (var ctx = new SignalDBContext())
1420+
{
1421+
var c = ctx.Contacts.SingleOrDefault(b => b.ThreadId == contact.ThreadId);
1422+
if (c == null)
1423+
{
1424+
throw new Exception("Could not find contact!");
1425+
}
1426+
c.Blocked = contact.Blocked;
1427+
ctx.SaveChanges();
1428+
}
1429+
}
1430+
}
14141431
#endregion Contacts
14151432
}
14161433
}

Signal-Windows/Controls/Conversation.xaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
<ColumnDefinition Width="50"/>
102102
</Grid.ColumnDefinitions>
103103
<StackPanel Grid.Column="0" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
104+
<FontIcon Glyph="&#xE25B;" FontSize="11" Visibility="{x:Bind Blocked, Mode=OneWay}"/>
104105
<TextBlock Name="Displayname" IsTextSelectionEnabled="True" HorizontalAlignment="Center" Text="{x:Bind ThreadDisplayName, Mode=OneWay}" />
105106
<TextBlock Name="Separator" xml:space="preserve" Visibility="{x:Bind SeparatorVisibility, Mode=OneWay}">&#160;&#160;&#x2022;&#160;&#160;</TextBlock>
106107
<TextBlock Name="Username" IsTextSelectionEnabled="True" HorizontalAlignment="Center" Text="{x:Bind ThreadUsername, Mode=OneWay}" Visibility="{x:Bind ThreadUsernameVisibility, Mode=OneWay}" />
@@ -131,10 +132,11 @@
131132
<ColumnDefinition Width="*"/>
132133
<ColumnDefinition Width="Auto"/>
133134
</Grid.ColumnDefinitions>
134-
<TextBox Grid.Column="0" Name="InputTextBox" VerticalAlignment="Center" KeyDown="TextBox_KeyDown" PlaceholderText="Type a message" BorderBrush="{x:Null}" BorderThickness="0" TextWrapping="Wrap" TextChanged="InputTextBox_TextChanged" InputScope="Chat" />
135-
<Button x:Name="SendMessageButton" Grid.Column="1" Click="SendMessageButton_Click" IsEnabled="{x:Bind SendButtonEnabled, Mode=OneWay}" Background="{x:Bind SendButtonBackground}" VerticalAlignment="Bottom" Width="50" VerticalContentAlignment="Stretch" MinHeight="50">
135+
<TextBox Grid.Column="0" Name="InputTextBox" VerticalAlignment="Center" KeyDown="TextBox_KeyDown" PlaceholderText="Type a message" BorderBrush="{x:Null}" BorderThickness="0" TextWrapping="Wrap" TextChanged="InputTextBox_TextChanged" InputScope="Chat" Visibility="{x:Bind SendMessageVisible, Mode=OneWay}"/>
136+
<Button x:Name="SendMessageButton" Grid.Column="1" Click="SendMessageButton_Click" IsEnabled="{x:Bind SendButtonEnabled, Mode=OneWay}" Background="{x:Bind SendButtonBackground}" VerticalAlignment="Bottom" Width="50" VerticalContentAlignment="Stretch" MinHeight="50" Visibility="{x:Bind SendMessageVisible, Mode=OneWay}">
136137
<SymbolIcon Symbol="Send"/>
137138
</Button>
139+
<Button x:Name="UnblockButton" Content="Unblock" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.ColumnSpan="2" Height="50" Visibility="{x:Bind Blocked, Mode=OneWay}" Click="UnblockButton_Click"/>
138140
</Grid>
139141
</Grid>
140142
</UserControl>

0 commit comments

Comments
 (0)