Skip to content

Commit aeb9d86

Browse files
committed
Make QuotedAttachment an explicit data type
1 parent 46eebf3 commit aeb9d86

File tree

5 files changed

+418
-109
lines changed

5 files changed

+418
-109
lines changed

libsignal-service-dotnet/SignalServiceMessageSender.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
using System.Diagnostics;
1717
using System.IO;
1818
using System.Threading;
19+
using static libsignalservice.messages.SignalServiceDataMessage;
20+
using static libsignalservice.push.DataMessage.Types.Quote.Types;
1921
using static libsignalservice.push.SyncMessage.Types;
2022

2123
namespace libsignalservice
@@ -300,25 +302,22 @@ private byte[] CreateMessageContent(SignalServiceDataMessage message)// throws I
300302
Author = message.Quote.Author.E164number,
301303
Text = message.Quote.Text
302304
};
303-
foreach (SignalServiceAttachment attachment in message.Quote.Attachments)
305+
foreach (SignalServiceQuotedAttachment attachment in message.Quote.Attachments)
304306
{
305-
if (attachment.IsPointer())
307+
QuotedAttachment protoAttachment = new QuotedAttachment()
306308
{
307-
var pointer = attachment.AsPointer();
308-
var protoPointer = new AttachmentPointer()
309-
{
310-
ContentType = pointer.ContentType
311-
};
312-
if (pointer.FileName != null)
313-
{
314-
protoPointer.FileName = pointer.FileName;
315-
}
316-
quote.Attachments.Add(protoPointer);
309+
ContentType = attachment.ContentType
310+
};
311+
if (attachment.FileName != null)
312+
{
313+
protoAttachment.FileName = attachment.FileName;
317314
}
318-
else
315+
316+
if (attachment.Thumbnail != null)
319317
{
320-
quote.Attachments.Add(CreateAttachmentPointer(attachment.AsStream()));
318+
protoAttachment.Thumbnail = CreateAttachmentPointer(attachment.Thumbnail.AsStream());
321319
}
320+
quote.Attachments.Add(protoAttachment);
322321
}
323322
dataMessage.Quote = quote;
324323
}

libsignal-service-dotnet/crypto/SignalServiceCipher.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
using System;
1212
using System.Collections.Generic;
13+
using static libsignalservice.messages.SignalServiceDataMessage;
1314
using static libsignalservice.push.DataMessage;
1415

1516
namespace libsignalservice.crypto
@@ -341,11 +342,13 @@ private SignalServiceDataMessage.SignalServiceQuote CreateQuote(SignalServiceEnv
341342
if (content.QuoteOneofCase != QuoteOneofOneofCase.Quote)
342343
return null;
343344

344-
List<SignalServiceAttachment> attachments = new List<SignalServiceAttachment>();
345+
List<SignalServiceQuotedAttachment> attachments = new List<SignalServiceQuotedAttachment>();
345346

346-
foreach (AttachmentPointer pointer in content.Quote.Attachments)
347+
foreach (var pointer in content.Quote.Attachments)
347348
{
348-
attachments.Add(CreateAttachmentPointer(envelope, pointer));
349+
attachments.Add(new SignalServiceQuotedAttachment(pointer.ContentType,
350+
pointer.FileName,
351+
pointer.ThumbnailOneofCase == Types.Quote.Types.QuotedAttachment.ThumbnailOneofOneofCase.Thumbnail ? CreateAttachmentPointer(envelope, pointer.Thumbnail) : null));
349352
}
350353

351354
return new SignalServiceDataMessage.SignalServiceQuote((long) content.Quote.Id,

libsignal-service-dotnet/messages/SignalServiceDataMessage.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,30 @@ public class SignalServiceQuote
3535
public long Id { get; }
3636
public SignalServiceAddress Author { get; }
3737
public string Text { get; }
38-
public List<SignalServiceAttachment> Attachments { get; }
38+
public List<SignalServiceQuotedAttachment> Attachments { get; }
3939

40-
public SignalServiceQuote(long id, SignalServiceAddress author, string text, List<SignalServiceAttachment> attachments)
40+
public SignalServiceQuote(long id, SignalServiceAddress author, string text, List<SignalServiceQuotedAttachment> attachments)
4141
{
4242
Id = id;
4343
Author = author;
4444
Text = text;
4545
Attachments = attachments;
4646
}
4747
}
48+
49+
public class SignalServiceQuotedAttachment
50+
{
51+
public string ContentType { get; }
52+
public string FileName { get; }
53+
public SignalServiceAttachment Thumbnail { get; }
54+
55+
public SignalServiceQuotedAttachment(string contentType, string filename, SignalServiceAttachment thumbnail)
56+
{
57+
ContentType = contentType;
58+
FileName = filename;
59+
Thumbnail = thumbnail;
60+
}
61+
}
4862
}
4963
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
5064
}

libsignal-service-dotnet/protobuf/SignalService.proto

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,15 @@ message DataMessage {
7373
}
7474

7575
message Quote {
76+
message QuotedAttachment {
77+
oneof contentType_oneof { string contentType = 1; }
78+
oneof fileName_oneof { string fileName = 2;}
79+
oneof thumbnail_oneof { AttachmentPointer thumbnail = 3; }
80+
}
7681
oneof id_oneof { uint64 id = 1; }
7782
oneof author_oneof { string author = 2; }
7883
oneof text_oneof { string text = 3; }
79-
repeated AttachmentPointer attachments = 4;
84+
repeated QuotedAttachment attachments = 4;
8085
}
8186

8287
oneof body_oneof { string body = 1; }

0 commit comments

Comments
 (0)