@@ -186,71 +186,75 @@ private void HandleMessage(SignalServiceEnvelope envelope)
186
186
}
187
187
else if ( content . SynchronizeMessage . Groups != null )
188
188
{
189
- //return ;
189
+ Logger . LogInformation ( "HandleMessage() handling groups sync message from device {0}" , envelope . GetSourceDevice ( ) ) ;
190
190
int read ;
191
191
var avatarBuffer = new byte [ 4096 ] ;
192
192
var groups = content . SynchronizeMessage . Groups ;
193
- var tmpFile = LibUtils . CreateTmpFile ( "groups_sync" ) ;
194
- var plaintextStream = MessageReceiver . RetrieveAttachment ( groups . AsPointer ( ) , tmpFile , 10000 , null ) ;
195
- var deviceGroupsStream = new DeviceGroupsInputStream ( plaintextStream ) ;
196
- var groupsList = new List < ( SignalGroup , IList < string > ) > ( ) ;
197
- DeviceGroup g ;
198
- while ( ( g = deviceGroupsStream . Read ( ) ) != null )
193
+ using ( var tmpFile = LibUtils . CreateTmpFile ( "groups_sync" ) )
199
194
{
200
- if ( g . Avatar != null )
195
+ var plaintextStream = MessageReceiver . RetrieveAttachment ( groups . AsPointer ( ) , tmpFile , 10000 , null ) ;
196
+ var deviceGroupsStream = new DeviceGroupsInputStream ( plaintextStream ) ;
197
+ var groupsList = new List < ( SignalGroup , IList < string > ) > ( ) ;
198
+ DeviceGroup g ;
199
+ while ( ( g = deviceGroupsStream . Read ( ) ) != null )
201
200
{
202
- SignalServiceAttachmentStream ssas = g . Avatar . AsStream ( ) ;
203
- while ( ( read = ssas . InputStream . Read ( avatarBuffer , 0 , avatarBuffer . Length ) ) > 0 )
201
+ if ( g . Avatar != null )
204
202
{
203
+ SignalServiceAttachmentStream ssas = g . Avatar . AsStream ( ) ;
204
+ while ( ( read = ssas . InputStream . Read ( avatarBuffer , 0 , avatarBuffer . Length ) ) > 0 )
205
+ {
205
206
207
+ }
206
208
}
209
+ var group = new SignalGroup ( )
210
+ {
211
+ ThreadDisplayName = g . Name ,
212
+ ThreadId = Base64 . EncodeBytes ( g . Id ) ,
213
+ GroupMemberships = new List < GroupMembership > ( ) ,
214
+ CanReceive = true ,
215
+ ExpiresInSeconds = g . ExpirationTimer != null ? g . ExpirationTimer . Value : 0
216
+ } ;
217
+ groupsList . Add ( ( group , g . Members ) ) ;
207
218
}
208
- var group = new SignalGroup ( )
209
- {
210
- ThreadDisplayName = g . Name ,
211
- ThreadId = Base64 . EncodeBytes ( g . Id ) ,
212
- GroupMemberships = new List < GroupMembership > ( ) ,
213
- CanReceive = true ,
214
- ExpiresInSeconds = g . ExpirationTimer != null ? g . ExpirationTimer . Value : 0
215
- } ;
216
- groupsList . Add ( ( group , g . Members ) ) ;
219
+ List < SignalConversation > newConversations = SignalDBContext . InsertOrUpdateGroups ( groupsList ) ;
220
+ SignalLibHandle . Instance . DispatchAddOrUpdateConversations ( newConversations ) ;
217
221
}
218
- List < SignalConversation > newConversations = SignalDBContext . InsertOrUpdateGroups ( groupsList ) ;
219
- SignalLibHandle . Instance . DispatchAddOrUpdateConversations ( newConversations ) ;
220
222
}
221
223
else if ( content . SynchronizeMessage . Contacts != null && content . SynchronizeMessage . Contacts . Complete ) //TODO incomplete updates
222
224
{
223
- //return ;
225
+ Logger . LogInformation ( "HandleMessage() handling contacts sync message from device {0}" , envelope . GetSourceDevice ( ) ) ;
224
226
int read ;
225
227
var avatarBuffer = new byte [ 4096 ] ;
226
228
ContactsMessage contacts = content . SynchronizeMessage . Contacts ;
227
- var tmpFile = LibUtils . CreateTmpFile ( "contacts_sync" ) ;
228
- var plaintextStream = MessageReceiver . RetrieveAttachment ( contacts . Contacts . AsPointer ( ) , tmpFile , 10000 , null ) ;
229
- var deviceContactsStream = new DeviceContactsInputStream ( plaintextStream ) ;
230
- List < SignalContact > contactsList = new List < SignalContact > ( ) ;
231
- DeviceContact c ;
232
- while ( ( c = deviceContactsStream . Read ( ) ) != null )
229
+ using ( var tmpFile = LibUtils . CreateTmpFile ( "contacts_sync" ) )
233
230
{
234
- if ( c . Avatar != null )
231
+ var plaintextStream = MessageReceiver . RetrieveAttachment ( contacts . Contacts . AsPointer ( ) , tmpFile , 10000 , null ) ;
232
+ var deviceContactsStream = new DeviceContactsInputStream ( plaintextStream ) ;
233
+ List < SignalContact > contactsList = new List < SignalContact > ( ) ;
234
+ DeviceContact c ;
235
+ while ( ( c = deviceContactsStream . Read ( ) ) != null )
235
236
{
236
- SignalServiceAttachmentStream ssas = c . Avatar . AsStream ( ) ;
237
- while ( ( read = ssas . InputStream . Read ( avatarBuffer , 0 , avatarBuffer . Length ) ) > 0 )
237
+ if ( c . Avatar != null )
238
238
{
239
+ SignalServiceAttachmentStream ssas = c . Avatar . AsStream ( ) ;
240
+ while ( ( read = ssas . InputStream . Read ( avatarBuffer , 0 , avatarBuffer . Length ) ) > 0 )
241
+ {
239
242
243
+ }
240
244
}
245
+ SignalContact contact = new SignalContact ( )
246
+ {
247
+ ThreadDisplayName = c . Name ,
248
+ ThreadId = c . Number ,
249
+ Color = c . Color ,
250
+ CanReceive = true ,
251
+ ExpiresInSeconds = c . ExpirationTimer != null ? c . ExpirationTimer . Value : 0
252
+ } ;
253
+ contactsList . Add ( contact ) ;
241
254
}
242
- SignalContact contact = new SignalContact ( )
243
- {
244
- ThreadDisplayName = c . Name ,
245
- ThreadId = c . Number ,
246
- Color = c . Color ,
247
- CanReceive = true ,
248
- ExpiresInSeconds = c . ExpirationTimer != null ? c . ExpirationTimer . Value : 0
249
- } ;
250
- contactsList . Add ( contact ) ;
255
+ var newConversations = SignalDBContext . InsertOrUpdateContacts ( contactsList ) ;
256
+ SignalLibHandle . Instance . DispatchAddOrUpdateConversations ( newConversations ) ;
251
257
}
252
- var newConversations = SignalDBContext . InsertOrUpdateContacts ( contactsList ) ;
253
- SignalLibHandle . Instance . DispatchAddOrUpdateConversations ( newConversations ) ;
254
258
}
255
259
}
256
260
else if ( content . ReadMessage != null )
0 commit comments