Skip to content

Commit 7789c37

Browse files
committed
Fix json serialization and properties
Newtonsoft does not set readonly fields, so change them all to public.
1 parent aeb9d86 commit 7789c37

23 files changed

+149
-519
lines changed

libsignal-service-dotnet/SignalServiceAccountManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public May<ContactTokenDetails> GetContact(string e164number)// throws IOExcepti
193193

194194
if (contactTokenDetails != null)
195195
{
196-
contactTokenDetails.setNumber(e164number);
196+
contactTokenDetails.Number = e164number;
197197
}
198198

199199
return new May<ContactTokenDetails>(contactTokenDetails);
@@ -211,8 +211,8 @@ public List<ContactTokenDetails> GetContacts(IList<string> e164numbers)
211211

212212
foreach (ContactTokenDetails activeToken in activeTokens)
213213
{
214-
contactTokensMap.TryGetValue(activeToken.getToken(), out string number);
215-
activeToken.setNumber(number);
214+
contactTokensMap.TryGetValue(activeToken.Token, out string number);
215+
activeToken.Number = number;
216216
}
217217

218218
return activeTokens;

libsignal-service-dotnet/SignalServiceMessagePipe.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public SendMessageResponse Send(OutgoingPushMessageList list)
100100
Logger.LogError("Sending message {0} failed: {1}", requestmessage.Id, response.Item2);
101101
throw new IOException("non-successfull response: " + response.Item1 + " " + response.Item2);
102102
}
103-
return JsonUtil.fromJson<SendMessageResponse>(response.Item2);
103+
return JsonUtil.FromJson<SendMessageResponse>(response.Item2);
104104
}
105105
else
106106
{
@@ -133,7 +133,7 @@ public SignalServiceProfile GetProfile(SignalServiceAddress address)
133133
{
134134
throw new IOException("non-successfull response: " + response.Item1 + " " + response.Item2);
135135
}
136-
return JsonUtil.fromJson<SignalServiceProfile>(response.Item2);
136+
return JsonUtil.FromJson<SignalServiceProfile>(response.Item2);
137137
}
138138
else
139139
{

libsignal-service-dotnet/SignalServiceMessageSender.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void SendMessage(SignalServiceAddress recipient, SignalServiceDataMessage
100100
bool silent = message.Group != null && message.Group.Type == SignalServiceGroup.GroupType.REQUEST_INFO;
101101
var resp = SendMessage(recipient, timestamp, content, silent);
102102

103-
if (resp.needsSync)
103+
if (resp.NeedsSync)
104104
{
105105
byte[] syncMessage = CreateMultiDeviceSentTranscriptContent(content, new May<SignalServiceAddress>(recipient), (ulong)timestamp);
106106
SendMessage(localAddress, timestamp, syncMessage, false);
@@ -228,7 +228,7 @@ private void SendMessage(VerifiedMessage message)
228228

229229
SendMessageResponse response = SendMessage(new SignalServiceAddress(message.Destination), message.Timestamp, content, false);
230230

231-
if (response != null && response.needsSync)
231+
if (response != null && response.NeedsSync)
232232
{
233233
byte[] syncMessage = CreateMultiDeviceVerifiedContent(message, nullMessage.ToByteArray());
234234
SendMessage(localAddress, message.Timestamp, syncMessage, false);
@@ -606,7 +606,7 @@ private SendMessageResponse SendMessage(SignalServiceAddress recipient, long tim
606606
Debug.WriteLine("MismatchedDevicesException");
607607
Debug.WriteLine(mde.Message);
608608
Debug.WriteLine(mde.StackTrace);
609-
HandleMismatchedDevices(socket, recipient, mde.getMismatchedDevices());
609+
HandleMismatchedDevices(socket, recipient, mde.MismatchedDevices);
610610
}
611611
catch (StaleDevicesException ste)
612612
{
@@ -815,12 +815,12 @@ private void HandleMismatchedDevices(PushServiceSocket socket, SignalServiceAddr
815815
{
816816
try
817817
{
818-
foreach (uint extraDeviceId in mismatchedDevices.getExtraDevices())
818+
foreach (uint extraDeviceId in mismatchedDevices.ExtraDevices)
819819
{
820820
store.DeleteSession(new SignalProtocolAddress(recipient.E164number, extraDeviceId));
821821
}
822822

823-
foreach (uint missingDeviceId in mismatchedDevices.getMissingDevices())
823+
foreach (uint missingDeviceId in mismatchedDevices.MissingDevices)
824824
{
825825
PreKeyBundle preKey = socket.GetPreKey(recipient, missingDeviceId);
826826

@@ -843,7 +843,7 @@ private void HandleMismatchedDevices(PushServiceSocket socket, SignalServiceAddr
843843

844844
private void HandleStaleDevices(SignalServiceAddress recipient, StaleDevices staleDevices)
845845
{
846-
foreach (uint staleDeviceId in staleDevices.getStaleDevices())
846+
foreach (uint staleDeviceId in staleDevices.Devices)
847847
{
848848
store.DeleteSession(new SignalProtocolAddress(recipient.E164number, staleDeviceId));
849849
}

libsignal-service-dotnet/profiles/SignalServiceProfile.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55

66
namespace libsignalservice.profiles
77
{
8+
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
89
public class SignalServiceProfile
910
{
1011
[JsonProperty("identityKey")]
11-
public string IdentityKey { get; }
12+
public string IdentityKey { get; set; }
1213
[JsonProperty("name")]
13-
public string Name { get; }
14+
public string Name { get; set; }
1415
[JsonProperty("avatar")]
15-
public string Avatar { get; }
16+
public string Avatar { get; set; }
1617
}
18+
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
1719
}
Lines changed: 14 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,26 @@
1-
/**
2-
* Copyright (C) 2015 smndtrl
3-
*
4-
* This program is free software: you can redistribute it and/or modify
5-
* it under the terms of the GNU General Public License as published by
6-
* the Free Software Foundation, either version 3 of the License, or
7-
* (at your option) any later version.
8-
*
9-
* This program is distributed in the hope that it will be useful,
10-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
* GNU General Public License for more details.
13-
*
14-
* You should have received a copy of the GNU General Public License
15-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16-
*/
17-
181
using Newtonsoft.Json;
192
using System;
203

214
namespace libsignalservice.push
22-
{
23-
/**
24-
* A class that represents a contact's registration state.
25-
*/
26-
5+
{
6+
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
277
[JsonObject(MemberSerialization.OptIn)]
288
public class ContactTokenDetails
299
{
30-
[JsonProperty]
31-
private string token;
32-
33-
[JsonProperty]
34-
private string relay;
35-
36-
[JsonProperty]
37-
private string number;
38-
39-
[JsonProperty]
40-
private bool voice;
41-
42-
[JsonProperty]
43-
private bool video;
44-
45-
public ContactTokenDetails()
46-
{
47-
}
48-
49-
/**
50-
* @return The "anonymized" token (truncated hash) that's transmitted to the server.
51-
*/
52-
53-
public string getToken()
54-
{
55-
return token;
56-
}
57-
58-
/**
59-
* @return The federated server this contact is registered with, or null if on your server.
60-
*/
61-
62-
public string getRelay()
63-
{
64-
return relay;
65-
}
66-
67-
/**
68-
* @return Whether this contact supports secure voice calls.
69-
*/
70-
71-
public bool isVoice()
72-
{
73-
return voice;
74-
}
10+
[JsonProperty("token")]
11+
public string Token { get; set; }
7512

76-
public bool isVideo()
77-
{
78-
return video;
79-
}
13+
[JsonProperty("relay")]
14+
public string Relay { get; set; }
8015

81-
public void setNumber(String number)
82-
{
83-
this.number = number;
84-
}
16+
[JsonProperty("number")]
17+
public string Number { get; set; }
8518

86-
/**
87-
* @return This contact's username (e164 formatted number).
88-
*/
19+
[JsonProperty("voice")]
20+
public bool Voice { get; set; }
8921

90-
public string getNumber()
91-
{
92-
return number;
93-
}
94-
}
22+
[JsonProperty("video")]
23+
public bool Video { get; set; }
24+
}
25+
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
9526
}
Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
/**
2-
* Copyright (C) 2015 smndtrl
3-
*
4-
* This program is free software: you can redistribute it and/or modify
5-
* it under the terms of the GNU General Public License as published by
6-
* the Free Software Foundation, either version 3 of the License, or
7-
* (at your option) any later version.
8-
*
9-
* This program is distributed in the hope that it will be useful,
10-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
* GNU General Public License for more details.
13-
*
14-
* You should have received a copy of the GNU General Public License
15-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16-
*/
17-
181
using Newtonsoft.Json;
192
using System.Collections.Generic;
203

@@ -23,16 +6,7 @@ namespace libsignalservice.push
236
[JsonObject(MemberSerialization.OptIn)]
247
internal class ContactTokenDetailsList
258
{
26-
[JsonProperty]
27-
private List<ContactTokenDetails> contacts;
28-
29-
public ContactTokenDetailsList()
30-
{
31-
}
32-
33-
public List<ContactTokenDetails> getContacts()
34-
{
35-
return contacts;
36-
}
9+
[JsonProperty("contacts")]
10+
public List<ContactTokenDetails> Contacts { get; set; }
3711
}
3812
}
Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,11 @@
1-
/**
2-
* Copyright (C) 2015 smndtrl
3-
*
4-
* This program is free software: you can redistribute it and/or modify
5-
* it under the terms of the GNU General Public License as published by
6-
* the Free Software Foundation, either version 3 of the License, or
7-
* (at your option) any later version.
8-
*
9-
* This program is distributed in the hope that it will be useful,
10-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
* GNU General Public License for more details.
13-
*
14-
* You should have received a copy of the GNU General Public License
15-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16-
*/
17-
181
using Newtonsoft.Json;
192
using System;
203

214
namespace libsignalservice.push
225
{
236
internal class DeviceCode
247
{
25-
[JsonProperty]
26-
private String verificationCode;
27-
28-
public String getVerificationCode()
29-
{
30-
return verificationCode;
31-
}
8+
[JsonProperty("verificationCode")]
9+
public String VerificationCode { get; set; }
3210
}
3311
}

libsignal-service-dotnet/push/DeviceId.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace libsignal.push
44
{
5-
public class DeviceId
5+
internal class DeviceId
66
{
7-
[JsonProperty]
8-
public int deviceId { get; set; }
7+
[JsonProperty("deviceId")]
8+
public int NewDeviceId { get; set; }
99
}
1010
}
Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,12 @@
1-
/**
2-
* Copyright (C) 2015 smndtrl
3-
*
4-
* This program is free software: you can redistribute it and/or modify
5-
* it under the terms of the GNU General Public License as published by
6-
* the Free Software Foundation, either version 3 of the License, or
7-
* (at your option) any later version.
8-
*
9-
* This program is distributed in the hope that it will be useful,
10-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
* GNU General Public License for more details.
13-
*
14-
* You should have received a copy of the GNU General Public License
15-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16-
*/
17-
181
using libsignalservice.messages.multidevice;
192
using Newtonsoft.Json;
203
using System.Collections.Generic;
214

225
namespace libsignalservice.push
236
{
24-
public class DeviceInfoList
7+
internal class DeviceInfoList
258
{
26-
[JsonProperty]
27-
private List<DeviceInfo> devices;
28-
29-
public DeviceInfoList()
30-
{
31-
}
32-
33-
public List<DeviceInfo> getDevices()
34-
{
35-
return devices;
36-
}
9+
[JsonProperty("devices")]
10+
public List<DeviceInfo> Devices { get; set; }
3711
}
3812
}
Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,15 @@
1-
/**
2-
* Copyright (C) 2015 smndtrl
3-
*
4-
* This program is free software: you can redistribute it and/or modify
5-
* it under the terms of the GNU General Public License as published by
6-
* the Free Software Foundation, either version 3 of the License, or
7-
* (at your option) any later version.
8-
*
9-
* This program is distributed in the hope that it will be useful,
10-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
* GNU General Public License for more details.
13-
*
14-
* You should have received a copy of the GNU General Public License
15-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16-
*/
17-
181
using Newtonsoft.Json;
192

203
namespace libsignalservice.push
21-
{
4+
{
5+
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
226
public class DeviceLimit
237
{
24-
[JsonProperty]
25-
private int current;
26-
27-
[JsonProperty]
28-
private int max;
29-
30-
public int getCurrent()
31-
{
32-
return current;
33-
}
8+
[JsonProperty("current")]
9+
public int Current { get; set; }
3410

35-
public int getMax()
36-
{
37-
return max;
38-
}
39-
}
11+
[JsonProperty("max")]
12+
public int Max { get; set; }
13+
}
14+
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
4015
}

0 commit comments

Comments
 (0)