mirror of https://github.com/oxen-io/session-ios
				
				
				
			Merge pull request #104 from RyanRory/sync-closed-group
Closed group functionality and synchronisationpull/130/head
						commit
						eebff42412
					
				@ -1 +1 @@
 | 
			
		||||
Subproject commit 2870e676deec6a7ddb931edb6f0284f1f5b36085
 | 
			
		||||
Subproject commit 67dbced37481e0011a3df1397ed57711384a4957
 | 
			
		||||
@ -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
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
					Loading…
					
					
				
		Reference in New Issue