Ignore unknown group messages

otherwise when (e.g.) android adds a new group type they'll be shown as
empty bubbles.

// FREEBIE
pull/1/head
Michael Kirk 9 years ago
parent 1ba082356a
commit df756423f2

@ -35,7 +35,7 @@ PODS:
- ProtocolBuffers (1.9.10) - ProtocolBuffers (1.9.10)
- Reachability (3.2) - Reachability (3.2)
- SAMKeychain (1.5.0) - SAMKeychain (1.5.0)
- SignalServiceKit (0.7.0): - SignalServiceKit (0.7.1):
- '25519' - '25519'
- AFNetworking - AFNetworking
- AxolotlKit - AxolotlKit
@ -130,7 +130,7 @@ SPEC CHECKSUMS:
ProtocolBuffers: d088180c10072b3d24a9939a6314b7b9bcc2340b ProtocolBuffers: d088180c10072b3d24a9939a6314b7b9bcc2340b
Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96 Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96
SAMKeychain: 1fc9ae02f576365395758b12888c84704eebc423 SAMKeychain: 1fc9ae02f576365395758b12888c84704eebc423
SignalServiceKit: f32dd13f4bdc46276e2e090719f3a88288fd78ad SignalServiceKit: 0cd25c4d4c96b541723bfc74f46695cc94e05d5f
SocketRocket: 3f77ec2104cc113add553f817ad90a77114f5d43 SocketRocket: 3f77ec2104cc113add553f817ad90a77114f5d43
SQLCipher: 4c768761421736a247ed6cf412d9045615d53dff SQLCipher: 4c768761421736a247ed6cf412d9045615d53dff
TwistedOakCollapsingFutures: f359b90f203e9ab13dfb92c9ff41842a7fe1cd0c TwistedOakCollapsingFutures: f359b90f203e9ab13dfb92c9ff41842a7fe1cd0c

@ -8,7 +8,7 @@
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = "SignalServiceKit" s.name = "SignalServiceKit"
s.version = "0.7.1" s.version = "0.7.2"
s.summary = "An Objective-C library for communicating with the Signal messaging service." s.summary = "An Objective-C library for communicating with the Signal messaging service."
s.description = <<-DESC s.description = <<-DESC

@ -397,6 +397,8 @@ NS_ASSUME_NONNULL_BEGIN
failure:^(NSError *error) { failure:^(NSError *error) {
DDLogError(@"%@ Failed to send Groups response syncMessage with error: %@", self.tag, error); DDLogError(@"%@ Failed to send Groups response syncMessage with error: %@", self.tag, error);
}]; }];
} else {
DDLogWarn(@"%@ ignoring unsupported sync request message", self.tag);
} }
} else if (syncMessage.read.count > 0) { } else if (syncMessage.read.count > 0) {
DDLogInfo(@"%@ Received %ld read receipt(s)", self.tag, (u_long)syncMessage.read.count); DDLogInfo(@"%@ Received %ld read receipt(s)", self.tag, (u_long)syncMessage.read.count);
@ -487,37 +489,48 @@ NS_ASSUME_NONNULL_BEGIN
TSGroupThread *gThread = [TSGroupThread getOrCreateThreadWithGroupModel:model transaction:transaction]; TSGroupThread *gThread = [TSGroupThread getOrCreateThreadWithGroupModel:model transaction:transaction];
[gThread saveWithTransaction:transaction]; [gThread saveWithTransaction:transaction];
if (dataMessage.group.type == OWSSignalServiceProtosGroupContextTypeUpdate) { switch (dataMessage.group.type) {
NSString *updateGroupInfo = [gThread.groupModel getInfoStringAboutUpdateTo:model contactsManager:self.contactsManager]; case OWSSignalServiceProtosGroupContextTypeUpdate: {
gThread.groupModel = model; NSString *updateGroupInfo =
[gThread saveWithTransaction:transaction]; [gThread.groupModel getInfoStringAboutUpdateTo:model contactsManager:self.contactsManager];
[[[TSInfoMessage alloc] initWithTimestamp:timestamp gThread.groupModel = model;
inThread:gThread [gThread saveWithTransaction:transaction];
messageType:TSInfoMessageTypeGroupUpdate [[[TSInfoMessage alloc] initWithTimestamp:timestamp
customMessage:updateGroupInfo] saveWithTransaction:transaction]; inThread:gThread
} else if (dataMessage.group.type == OWSSignalServiceProtosGroupContextTypeQuit) { messageType:TSInfoMessageTypeGroupUpdate
NSString *nameString = [self.contactsManager nameStringForPhoneIdentifier:envelope.source]; customMessage:updateGroupInfo] saveWithTransaction:transaction];
break;
NSString *updateGroupInfo = }
[NSString stringWithFormat:NSLocalizedString(@"GROUP_MEMBER_LEFT", @""), nameString]; case OWSSignalServiceProtosGroupContextTypeQuit: {
NSMutableArray *newGroupMembers = [NSMutableArray arrayWithArray:gThread.groupModel.groupMemberIds]; NSString *nameString = [self.contactsManager nameStringForPhoneIdentifier:envelope.source];
[newGroupMembers removeObject:envelope.source];
gThread.groupModel.groupMemberIds = newGroupMembers; NSString *updateGroupInfo =
[NSString stringWithFormat:NSLocalizedString(@"GROUP_MEMBER_LEFT", @""), nameString];
[gThread saveWithTransaction:transaction]; NSMutableArray *newGroupMembers = [NSMutableArray arrayWithArray:gThread.groupModel.groupMemberIds];
[[[TSInfoMessage alloc] initWithTimestamp:timestamp [newGroupMembers removeObject:envelope.source];
inThread:gThread gThread.groupModel.groupMemberIds = newGroupMembers;
messageType:TSInfoMessageTypeGroupUpdate
customMessage:updateGroupInfo] saveWithTransaction:transaction]; [gThread saveWithTransaction:transaction];
} else { [[[TSInfoMessage alloc] initWithTimestamp:timestamp
incomingMessage = [[TSIncomingMessage alloc] initWithTimestamp:timestamp inThread:gThread
inThread:gThread messageType:TSInfoMessageTypeGroupUpdate
authorId:envelope.source customMessage:updateGroupInfo] saveWithTransaction:transaction];
messageBody:body break;
attachmentIds:attachmentIds }
expiresInSeconds:dataMessage.expireTimer]; case OWSSignalServiceProtosGroupContextTypeDeliver: {
incomingMessage = [[TSIncomingMessage alloc] initWithTimestamp:timestamp
[incomingMessage saveWithTransaction:transaction]; inThread:gThread
authorId:envelope.source
messageBody:body
attachmentIds:attachmentIds
expiresInSeconds:dataMessage.expireTimer];
[incomingMessage saveWithTransaction:transaction];
break;
}
default: {
DDLogWarn(@"%@ Ignoring unknown group message type:%d", self.tag, dataMessage.group.type);
}
} }
thread = gThread; thread = gThread;

@ -164,7 +164,7 @@ static uint32_t const OWSFingerprintDefaultHashIterations = 5200;
NSMutableArray<NSString *> *lines = [NSMutableArray new]; NSMutableArray<NSString *> *lines = [NSMutableArray new];
uint lineLength = self.text.length / 3; NSUInteger lineLength = self.text.length / 3;
for (uint i = 0; i < 3; i++) { for (uint i = 0; i < 3; i++) {
NSString *line = [input substringWithRange:NSMakeRange(i * lineLength, lineLength)]; NSString *line = [input substringWithRange:NSMakeRange(i * lineLength, lineLength)];

@ -160,6 +160,33 @@ NS_ASSUME_NONNULL_BEGIN
XCTAssertEqualObjects(@"Newly created Group with Avatar Name", groupThread.name); XCTAssertEqualObjects(@"Newly created Group with Avatar Name", groupThread.name);
} }
- (void)testUnknownGroupMessageIsIgnored
{
NSData *groupIdData = [Cryptography generateRandomBytes:32];
TSGroupThread *groupThread = [TSGroupThread getOrCreateThreadWithGroupIdData:groupIdData];
// Sanity check
XCTAssertEqual(0, groupThread.numberOfInteractions);
TSMessagesManager *messagesManager = [self messagesManagerWithSender:[OWSFakeMessageSender new]];
OWSSignalServiceProtosEnvelopeBuilder *envelopeBuilder = [OWSSignalServiceProtosEnvelopeBuilder new];
OWSSignalServiceProtosGroupContextBuilder *groupContextBuilder = [OWSSignalServiceProtosGroupContextBuilder new];
groupContextBuilder.name = @"Newly created Group with Avatar Name";
groupContextBuilder.id = groupIdData;
// e.g. some future feature sent from another device that we don't yet support.
groupContextBuilder.type = 666;
OWSSignalServiceProtosDataMessageBuilder *messageBuilder = [OWSSignalServiceProtosDataMessageBuilder new];
messageBuilder.group = [groupContextBuilder build];
[messagesManager handleIncomingEnvelope:[envelopeBuilder build] withDataMessage:[messageBuilder build]];
XCTAssertEqual(0, groupThread.numberOfInteractions);
}
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

Loading…
Cancel
Save