Skip to content

Commit 87626d6

Browse files
committed
Implement DeviceContactsInputStream
1 parent dcfee16 commit 87626d6

File tree

2 files changed

+60
-18
lines changed

2 files changed

+60
-18
lines changed

libsignal-service-dotnet/messages/multidevice/DeviceContact.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ public class DeviceContact
1010
public VerifiedMessage Verified { get; }
1111
public byte[] ProfileKey { get; }
1212
public bool Blocked { get; }
13-
public int? ExpirationTimer { get; }
13+
public uint? ExpirationTimer { get; }
1414

15-
public DeviceContact(string number, string name, SignalServiceAttachmentStream avatar, string color, VerifiedMessage verified, byte[] profileKey, bool blocked, int? expirationTimer)
15+
public DeviceContact(string number, string name, SignalServiceAttachmentStream avatar, string color, VerifiedMessage verified, byte[] profileKey, bool blocked, uint? expirationTimer)
1616
{
1717
Number = number;
1818
Name = name;

libsignal-service-dotnet/messages/multidevice/DeviceContactsInputStream.cs

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,80 @@
1+
using libsignal;
2+
using libsignalservice.push;
3+
using libsignalservice.util;
14
using System;
25
using System.IO;
6+
using static libsignalservice.messages.multidevice.VerifiedMessage;
37

48
namespace libsignalservice.messages.multidevice
59
{
610
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
711
public class DeviceContactsInputStream : ChunkedInputStream
812
{
9-
public DeviceContactsInputStream(Stream input)
10-
: base(input)
11-
{
12-
}
13+
public DeviceContactsInputStream(Stream input) : base(input) { }
1314

14-
public DeviceContact read()// throws IOException
15+
public DeviceContact Read()// throws IOException
1516
{
16-
/*long detailsLength = readRawVarint32();
17+
int detailsLength = ReadRawVarint32();
18+
if (detailsLength == -1)
19+
{
20+
return null;
21+
}
1722
byte[] detailsSerialized = new byte[(int)detailsLength];
18-
Util.readFully(input, detailsSerialized);
23+
Util.ReadFully(InputStream, detailsSerialized);
1924

20-
SignalServiceProtos.ContactDetails details = SignalServiceProtos.ContactDetails.ParseFrom(detailsSerialized);
21-
String number = details.Number;
22-
May<String> name = details.Name == null ? May<string>.NoValue : new May<string>(details.Name);
23-
May<TextSecureAttachmentStream> avatar = May<TextSecureAttachmentStream>.NoValue;
25+
var details = ContactDetails.Parser.ParseFrom(detailsSerialized);
26+
string number = details.Number;
27+
string name = details.Name;
28+
SignalServiceAttachmentStream avatar = null;
29+
string color = details.ColorOneofCase == ContactDetails.ColorOneofOneofCase.Color ? details.Color : null;
30+
VerifiedMessage verified = null;
31+
byte[] profileKey = null;
32+
bool blocked = false;
33+
uint? expireTimer = null;
2434

25-
if (details.HasAvatar)
35+
if (details.AvatarOneofCase == ContactDetails.AvatarOneofOneofCase.Avatar)
2636
{
2737
long avatarLength = details.Avatar.Length;
28-
IInputStream avatarStream = new LimitedInputStream(input, avatarLength);
38+
Stream avatarStream = new LimitedInputStream(InputStream, avatarLength);
2939
String avatarContentType = details.Avatar.ContentType;
40+
avatar = new SignalServiceAttachmentStream(avatarStream, avatarContentType, avatarLength, null, false, null);
41+
}
42+
43+
if (details.VerifiedOneofCase == ContactDetails.VerifiedOneofOneofCase.Verified)
44+
{
45+
string destination = details.Verified.Destination;
46+
IdentityKey identityKey = new IdentityKey(details.Verified.IdentityKey.ToByteArray(), 0);
3047

31-
avatar = new May<TextSecureAttachmentStream>(new TextSecureAttachmentStream(avatarStream, avatarContentType, avatarLength));
48+
VerifiedState state;
49+
switch (details.Verified.State)
50+
{
51+
case Verified.Types.State.Verified:
52+
state = VerifiedState.Verified;
53+
break;
54+
case Verified.Types.State.Unverified:
55+
state = VerifiedState.Unverified;
56+
break;
57+
case Verified.Types.State.Default:
58+
state = VerifiedState.Default;
59+
break;
60+
default:
61+
throw new InvalidMessageException("Unknown state: " + details.Verified.State);
62+
}
63+
64+
verified = new VerifiedMessage(destination, identityKey, state, Util.CurrentTimeMillis());
65+
}
66+
67+
if (details.ProfileKeyOneofCase == ContactDetails.ProfileKeyOneofOneofCase.ProfileKey)
68+
{
69+
profileKey = details.ProfileKey.ToByteArray();
70+
}
71+
72+
if (details.ExpireTimerOneofCase == ContactDetails.ExpireTimerOneofOneofCase.ExpireTimer && details.ExpireTimer > 0)
73+
{
74+
expireTimer = details.ExpireTimer;
3275
}
3376

34-
return new DeviceContact(number, name, avatar);*/
35-
throw new NotImplementedException();
77+
return new DeviceContact(number, name, avatar, color, verified, profileKey, blocked, expireTimer);
3678
}
3779
}
3880
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member

0 commit comments

Comments
 (0)