add group parser
This commit is contained in:
parent
1a156c604a
commit
b5ce94c6ab
|
@ -0,0 +1,34 @@
|
|||
|
||||
@objc public final class GroupParser : NSObject {
|
||||
private let data: Data
|
||||
|
||||
@objc public init(data: Data) {
|
||||
self.data = data
|
||||
}
|
||||
|
||||
@objc public func parseGroupModels() -> [TSGroupModel] {
|
||||
var index = 0
|
||||
var result: [TSGroupModel] = []
|
||||
while index < data.endIndex {
|
||||
var uncheckedSize: UInt32? = try? data[index..<(index+4)].withUnsafeBytes { $0.pointee }
|
||||
if let size = uncheckedSize, size >= data.count, let intermediate = try? data[index..<(index+4)].reversed() {
|
||||
uncheckedSize = Data(intermediate).withUnsafeBytes { $0.pointee }
|
||||
}
|
||||
guard let size = uncheckedSize, size < data.count else { break }
|
||||
let sizeAsInt = Int(size)
|
||||
index += 4
|
||||
guard index + sizeAsInt < data.count else { break }
|
||||
let protoAsData = data[index..<(index+sizeAsInt)]
|
||||
guard let proto = try? SSKProtoGroupDetails.parseData(protoAsData) else { break }
|
||||
index += sizeAsInt
|
||||
var groupModel = TSGroupModel.init(title: proto.name,
|
||||
memberIds: proto.members,
|
||||
image: nil,
|
||||
groupId: proto.id,
|
||||
groupType: GroupType.closedGroup,
|
||||
adminIds: proto.admins)
|
||||
result.append(groupModel)
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
|
@ -1107,6 +1107,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
OWSLogInfo(@"[Loki] Received group sync message.");
|
||||
NSData *data = syncMessage.groups.data;
|
||||
// TODO: decode the data and handle the group info
|
||||
GroupParser *parser = [[GroupParser alloc] initWithData:data];
|
||||
}
|
||||
} else {
|
||||
OWSLogWarn(@"Ignoring unsupported sync message.");
|
||||
|
|
Loading…
Reference in New Issue