fix crash of nil exception in group chats

pull/78/head
Ryan ZHAO 5 years ago
parent cba69b8ec8
commit 7987b7b4b9

@ -1362,7 +1362,10 @@ NS_ASSUME_NONNULL_BEGIN
if (groupId.length > 0) { if (groupId.length > 0) {
NSMutableSet *newMemberIds = [NSMutableSet setWithArray:dataMessage.group.members]; NSMutableSet *newMemberIds = [NSMutableSet setWithArray:dataMessage.group.members];
NSMutableSet *removedMemberIds = [NSMutableSet setWithArray:dataMessage.group.removedMembers]; NSMutableSet *removedMemberIds = [NSMutableSet new];
if (dataMessage.group.removedMembers) {
removedMemberIds = [NSMutableSet setWithArray:dataMessage.group.removedMembers];
}
//Ryan TODO: validate the recipientId //Ryan TODO: validate the recipientId
// for (NSString *recipientId in newMemberIds) { // for (NSString *recipientId in newMemberIds) {
// if (!recipientId.isValidE164) { // if (!recipientId.isValidE164) {

@ -955,8 +955,9 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
TSOutgoingMessage *message = messageSend.message; TSOutgoingMessage *message = messageSend.message;
NSString *contactID = messageSend.recipient.recipientId; NSString *contactID = messageSend.recipient.recipientId;
BOOL isGroupMessage = messageSend.thread.isGroupThread; BOOL isGroupMessage = messageSend.thread.isGroupThread;
BOOL isPublicChatMessage = isGroupMessage && ((TSGroupThread *)messageSend.thread).isPublicChat;
BOOL isDeviceLinkMessage = [message isKindOfClass:LKDeviceLinkMessage.class]; BOOL isDeviceLinkMessage = [message isKindOfClass:LKDeviceLinkMessage.class];
if (isGroupMessage || isDeviceLinkMessage) { if (isPublicChatMessage || isDeviceLinkMessage) {
[self sendMessage:messageSend]; [self sendMessage:messageSend];
} else { } else {
BOOL isSilentMessage = message.isSilent || [message isKindOfClass:LKEphemeralMessage.class] || [message isKindOfClass:OWSOutgoingSyncMessage.class]; BOOL isSilentMessage = message.isSilent || [message isKindOfClass:LKEphemeralMessage.class] || [message isKindOfClass:OWSOutgoingSyncMessage.class];
@ -983,6 +984,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
NSArray *slaveDestinations = [destinations filtered:^BOOL(LKDestination *destination) { NSArray *slaveDestinations = [destinations filtered:^BOOL(LKDestination *destination) {
return [destination.kind isEqual:@"slave"]; return [destination.kind isEqual:@"slave"];
}]; }];
OWSLogInfo(@"Slave deveice for %@ %@", contactID, [slaveDestinations count] > 0 ? slaveDestinations[0] : @"None");
// Send to slave destinations (using a best attempt approach (i.e. ignoring the message send result) for now) // Send to slave destinations (using a best attempt approach (i.e. ignoring the message send result) for now)
for (LKDestination *slaveDestination in slaveDestinations) { for (LKDestination *slaveDestination in slaveDestinations) {
TSContactThread *thread = [TSContactThread getOrCreateThreadWithContactId:slaveDestination.hexEncodedPublicKey]; TSContactThread *thread = [TSContactThread getOrCreateThreadWithContactId:slaveDestination.hexEncodedPublicKey];
@ -1003,7 +1005,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
- (void)sendMessage:(OWSMessageSend *)messageSend - (void)sendMessage:(OWSMessageSend *)messageSend
{ {
OWSLogInfo(@"message send here %@ %@", messageSend.message.body, messageSend.recipient.recipientId);
OWSAssertDebug(messageSend); OWSAssertDebug(messageSend);
OWSAssertDebug(messageSend.thread || [messageSend.message isKindOfClass:[OWSOutgoingSyncMessage class]]); OWSAssertDebug(messageSend.thread || [messageSend.message isKindOfClass:[OWSOutgoingSyncMessage class]]);

Loading…
Cancel
Save