Skip to content

Commit e1b9abe

Browse files
committed
Update last message timestamp in conversation list element
1 parent a46fcd9 commit e1b9abe

File tree

4 files changed

+56
-36
lines changed

4 files changed

+56
-36
lines changed

Signal-Windows/Controls/ConversationListElement.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<ColumnDefinition Width="Auto"/>
2525
</Grid.ColumnDefinitions>
2626
<TextBlock Grid.Column="0" Name="ConversationDisplayName" FontSize="15" FontWeight="SemiLight" Text="Sanders Lauture" TextTrimming="CharacterEllipsis"/>
27-
<TextBlock x:Name="LastActiveTextBlock" Grid.Column="1" Text="11:11p" FontSize="11" Foreground="#999999" TextTrimming="CharacterEllipsis"/>
27+
<TextBlock x:Name="LastActiveTextBlock" Grid.Column="1" Text="{x:Bind LastMessageTimestamp, Mode=OneWay}" FontSize="11" Foreground="#999999" TextTrimming="CharacterEllipsis"/>
2828
</Grid>
2929
<TextBlock Text="{x:Bind LastMessage, Mode=OneWay}" FontSize="12"/>
3030
</StackPanel>

Signal-Windows/Controls/ConversationListElement.xaml.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ public string Initials
106106
}
107107
}
108108

109+
private string _LastMessageTimestamp = string.Empty;
110+
public string LastMessageTimestamp
111+
{
112+
get { return _LastMessageTimestamp; }
113+
set { _LastMessageTimestamp = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(LastMessageTimestamp))); }
114+
}
115+
109116
private void ThreadListItem_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
110117
{
111118
if (Model != null)
@@ -116,6 +123,7 @@ private void ThreadListItem_DataContextChanged(FrameworkElement sender, DataCont
116123
LastMessage = Model.LastMessage?.Content.Content;
117124
Initials = Model.ThreadDisplayName.Length == 0 ? "#" : Model.ThreadDisplayName.Substring(0, 1);
118125
FillBrush = Model is SignalContact ? Utils.GetBrushFromColor(((SignalContact)Model).Color) : Utils.Blue;
126+
LastMessageTimestamp = Utils.GetTimestamp(Model.LastActiveTimestamp);
119127
}
120128
}
121129

@@ -126,6 +134,7 @@ public void UpdateConversationDisplay(SignalConversation thread)
126134
ConversationDisplayName.Text = thread.ThreadDisplayName;
127135
UnreadCount = thread.UnreadCount;
128136
LastMessage = Model.LastMessage?.Content.Content;
137+
LastMessageTimestamp = Utils.GetTimestamp(Model.LastActiveTimestamp);
129138
}
130139
}
131140
}

Signal-Windows/Controls/Message.xaml.cs

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -91,44 +91,10 @@ private void UpdateUI()
9191
HorizontalAlignment = HorizontalAlignment.Left;
9292
FooterPanel.HorizontalAlignment = HorizontalAlignment.Left;
9393
}
94-
DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeSeconds(Model.Message.ComposedTimestamp / 1000);
95-
DateTime dt = dateTimeOffset.UtcDateTime.ToLocalTime();
96-
DateTime now = DateTimeOffset.Now.LocalDateTime;
97-
if (GetMidnightDateTime(now) - GetMidnightDateTime(dt) < TimeSpan.FromDays(7))
98-
{
99-
if (now.Day == dt.Day)
100-
{
101-
// on the same day
102-
FancyTimestampBlock.Text = dt.ToString("t");
103-
}
104-
else
105-
{
106-
// within the last week
107-
FancyTimestampBlock.Text = $"{dt.ToString("ddd")}, {dt.ToString("t")}";
108-
}
109-
110-
}
111-
else
112-
{
113-
if (now.Year == dt.Year)
114-
{
115-
// greater than one week and in the same year
116-
FancyTimestampBlock.Text = $"{dt.ToString("M")}, {dt.ToString("t")}";
117-
}
118-
else
119-
{
120-
// not in the same year
121-
FancyTimestampBlock.Text = dt.ToString("g");
122-
}
123-
}
94+
FancyTimestampBlock.Text = Utils.GetTimestamp(Model.Message.ComposedTimestamp);
12495
}
12596
}
12697

127-
private DateTime GetMidnightDateTime(DateTime dateTime)
128-
{
129-
return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, 0, 0, 0, dateTime.Kind);
130-
}
131-
13298
private void MessageBox_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
13399
{
134100
UpdateUI();

Signal-Windows/Utils.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,51 @@ public static PageStyle GetViewStyle(Size s)
151151
}
152152
}
153153

154+
public static string GetTimestamp(long timestamp)
155+
{
156+
DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeSeconds(timestamp / 1000);
157+
DateTime dt = dateTimeOffset.UtcDateTime.ToLocalTime();
158+
return GetTimestamp(dt);
159+
}
160+
161+
public static string GetTimestamp(DateTime dateTime)
162+
{
163+
string formattedTimestamp = string.Empty;
164+
DateTime now = DateTimeOffset.Now.LocalDateTime;
165+
if (GetMidnightDateTime(now) - GetMidnightDateTime(dateTime) < TimeSpan.FromDays(7))
166+
{
167+
if (now.Day == dateTime.Day)
168+
{
169+
// on the same day
170+
formattedTimestamp = dateTime.ToString("t");
171+
}
172+
else
173+
{
174+
// within the last week
175+
formattedTimestamp = $"{dateTime.ToString("ddd")}, {dateTime.ToString("t")}";
176+
}
177+
}
178+
else
179+
{
180+
if (now.Year == dateTime.Year)
181+
{
182+
// greater than one week and in the same year
183+
formattedTimestamp = $"{dateTime.ToString("M")}, {dateTime.ToString("t")}";
184+
}
185+
else
186+
{
187+
// not in the same year
188+
formattedTimestamp = dateTime.ToString("g");
189+
}
190+
}
191+
return formattedTimestamp;
192+
}
193+
194+
public static DateTime GetMidnightDateTime(DateTime dateTime)
195+
{
196+
return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, 0, 0, 0, dateTime.Kind);
197+
}
198+
154199
public static string GetCountryISO()
155200
{
156201
var c = CultureInfo.CurrentCulture.Name;

0 commit comments

Comments
 (0)