|
| 1 | +using libsignal; |
| 2 | +using libsignalservice.push; |
| 3 | +using libsignalservice.util; |
1 | 4 | using System;
|
2 | 5 | using System.IO;
|
| 6 | +using static libsignalservice.messages.multidevice.VerifiedMessage; |
3 | 7 |
|
4 | 8 | namespace libsignalservice.messages.multidevice
|
5 | 9 | {
|
6 | 10 | #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
7 | 11 | public class DeviceContactsInputStream : ChunkedInputStream
|
8 | 12 | {
|
9 |
| - public DeviceContactsInputStream(Stream input) |
10 |
| - : base(input) |
11 |
| - { |
12 |
| - } |
| 13 | + public DeviceContactsInputStream(Stream input) : base(input) { } |
13 | 14 |
|
14 |
| - public DeviceContact read()// throws IOException |
| 15 | + public DeviceContact Read()// throws IOException |
15 | 16 | {
|
16 |
| - /*long detailsLength = readRawVarint32(); |
| 17 | + int detailsLength = ReadRawVarint32(); |
| 18 | + if (detailsLength == -1) |
| 19 | + { |
| 20 | + return null; |
| 21 | + } |
17 | 22 | byte[] detailsSerialized = new byte[(int)detailsLength];
|
18 |
| - Util.readFully(input, detailsSerialized); |
| 23 | + Util.ReadFully(InputStream, detailsSerialized); |
19 | 24 |
|
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; |
24 | 34 |
|
25 |
| - if (details.HasAvatar) |
| 35 | + if (details.AvatarOneofCase == ContactDetails.AvatarOneofOneofCase.Avatar) |
26 | 36 | {
|
27 | 37 | long avatarLength = details.Avatar.Length;
|
28 |
| - IInputStream avatarStream = new LimitedInputStream(input, avatarLength); |
| 38 | + Stream avatarStream = new LimitedInputStream(InputStream, avatarLength); |
29 | 39 | 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); |
30 | 47 |
|
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; |
32 | 75 | }
|
33 | 76 |
|
34 |
| - return new DeviceContact(number, name, avatar);*/ |
35 |
| - throw new NotImplementedException(); |
| 77 | + return new DeviceContact(number, name, avatar, color, verified, profileKey, blocked, expireTimer); |
36 | 78 | }
|
37 | 79 | }
|
38 | 80 | #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
|
|
0 commit comments