diff --git a/Hangouts/Client.swift b/Hangouts/Client.swift index d953eaf..2f143ba 100755 --- a/Hangouts/Client.swift +++ b/Hangouts/Client.swift @@ -116,7 +116,7 @@ public final class Client { // The first time this is called, we need to retrieve the user's email address. if self.email == nil { self.getSelfInfo { - self.email = $0!.self_entity!.properties.emails[0] as? String + self.email = $0!.self_entity!.properties!.email[0] as? String } } @@ -236,7 +236,7 @@ public final class Client { for conv_state in conv_states { let participants = conv_state.conversation!.participant_data required_user_ids = required_user_ids.union(Set(participants.map { - UserID(chatID: $0.id.chat_id as! String, gaiaID: $0.id.gaia_id as! String) + UserID(chatID: $0.id!.chat_id as! String, gaiaID: $0.id!.gaia_id as! String) })) } diff --git a/Hangouts/Conversation.swift b/Hangouts/Conversation.swift index 5604202..849a2b1 100755 --- a/Hangouts/Conversation.swift +++ b/Hangouts/Conversation.swift @@ -363,8 +363,8 @@ public class Conversation { get { return conversation.participant_data.map { self.user_list[UserID( - chatID: $0.id.chat_id as! String, - gaiaID: $0.id.gaia_id as! String + chatID: $0.id!.chat_id as! String, + gaiaID: $0.id!.gaia_id as! String )] } } diff --git a/Hangouts/ConversationList.swift b/Hangouts/ConversationList.swift index cccbabd..2303048 100755 --- a/Hangouts/ConversationList.swift +++ b/Hangouts/ConversationList.swift @@ -136,13 +136,13 @@ public class ConversationList { // Receive ClientSetTypingNotification and update the conversation public func handle_set_typing_notification(set_typing_notification: SET_TYPING_NOTIFICATION) { - let conv_id = set_typing_notification.conversation_id.id + let conv_id = set_typing_notification.conversation_id!.id if let conv = conv_dict[conv_id as! String] { let res = parseTypingStatusMessage(set_typing_notification) delegate?.conversationList(self, didChangeTypingStatusTo: res.status) let user = user_list[UserID( - chatID: set_typing_notification.user_id.chat_id as! String, - gaiaID: set_typing_notification.user_id.gaia_id as! String + chatID: set_typing_notification.sender_id!.chat_id as! String, + gaiaID: set_typing_notification.sender_id!.gaia_id as! String )] conv.handleTypingStatus(res.status, forUser: user) } else { @@ -203,7 +203,7 @@ public class ConversationList { handle_watermark_notification(watermark_notification) } if let event_notification = update.event_notification { - on_client_event(event_notification.event) + on_client_event(event_notification.event!) } } } \ No newline at end of file diff --git a/Hangouts/Event.swift b/Hangouts/Event.swift index 292eda8..3ac2d26 100755 --- a/Hangouts/Event.swift +++ b/Hangouts/Event.swift @@ -232,10 +232,10 @@ public typealias WatermarkNotification = (convID: String, userID: UserID, readTi // message is sent the typing status will not change to stopped. internal func parseTypingStatusMessage(p: SET_TYPING_NOTIFICATION) -> TypingStatusMessage { return TypingStatusMessage( - convID: p.conversation_id.id as! String, - userID: UserID(chatID: p.user_id.chat_id as! String, gaiaID: p.user_id.gaia_id as! String), + convID: p.conversation_id!.id as! String, + userID: UserID(chatID: p.sender_id!.chat_id as! String, gaiaID: p.sender_id!.gaia_id as! String), timestamp: from_timestamp(p.timestamp)!, - status: p.status + status: p.type! ) } diff --git a/Hangouts/Messages.swift b/Hangouts/Messages.swift index 5aec91b..d04b76d 100755 --- a/Hangouts/Messages.swift +++ b/Hangouts/Messages.swift @@ -726,7 +726,7 @@ public typealias GetSelfInfoResponse = GET_SELF_INFO_RESPONSE @objc(RESPONSE_HEADER) public class RESPONSE_HEADER : Message { - public var status: ResponseStatus? + public var status: NSNumber? // ResponseStatus? public var field1: AnyObject? public var field2: AnyObject? public var request_trace_id: NSString = "" @@ -1068,10 +1068,10 @@ public class UserConversationState: Message { public class ConversationParticipantData: Message { public var id: ParticipantId? public var fallback_name: NSString? - public var invitation_status: InvitationStatus? + public var invitation_status: NSNumber? // InvitationStatus? public var field4: AnyObject? - public var participant_type: ParticipantType? - public var new_invitation_status: InvitationStatus? + public var participant_type: NSNumber? // ParticipantType? + public var new_invitation_status: NSNumber? // InvitationStatus? } public typealias CONVERSATION_PARTICIPANT_DATA = ConversationParticipantData @@ -1153,6 +1153,7 @@ public class RequestHeader: Message { @objc(Entity) public class Entity: Message { + public var field1: AnyObject? public var field2: AnyObject? public var field3: AnyObject? public var field4: AnyObject? @@ -1164,16 +1165,16 @@ public class Entity: Message { public var properties: EntityProperties? public var field11: AnyObject? public var field12: AnyObject? - public var entity_type: ParticipantType? + public var entity_type: AnyObject? // ParticipantType? public var field14: AnyObject? public var field15: AnyObject? - public var had_past_hangout_state: PastHangoutState? + public var had_past_hangout_state: AnyObject? // PastHangoutState? } public typealias ENTITY = Entity @objc(EntityProperties) public class EntityProperties: Message { - public var type: ProfileType? + public var type: NSNumber? // ProfileType? public var display_name: NSString? public var first_name: NSString? public var photo_url: NSString? @@ -1183,8 +1184,8 @@ public class EntityProperties: Message { public var field8: AnyObject? public var field9: AnyObject? public var in_users_domain: NSNumber? - public var gender: Gender? - public var photo_url_status: PhotoUrlStatus? + public var gender: NSNumber? // Gender? + public var photo_url_status: NSNumber? // PhotoUrlStatus? public var field13: AnyObject? public var field14: AnyObject? public var canonical_email: NSString? diff --git a/Hangouts/PBLite.swift b/Hangouts/PBLite.swift index 8bfa8a4..4a1da7c 100755 --- a/Hangouts/PBLite.swift +++ b/Hangouts/PBLite.swift @@ -91,9 +91,9 @@ public class PBLiteSerialization { } /* TODO: Use Swift reflection to unwrap [AnyObject]. */ + /* TODO: Add all Message classes here. */ + //return Mirror(reflecting: arr).types[0] as! Message.Type public class func getArrayMessageType(arr: Any) -> Message.Type? { - //let mirror = Mirror(reflecting: arr) - //return mirror.types[0] as! Message.Type if arr is [CONVERSATION_ID] { return CONVERSATION_ID.self } if arr is [CONVERSATION_STATE] { return CONVERSATION_STATE.self } if arr is [PARTICIPANT_ID] { return PARTICIPANT_ID.self } @@ -110,7 +110,48 @@ public class PBLiteSerialization { /* TODO: Use Swift reflection to unwrap [AnyObject]. */ public class func getArrayEnumType(arr: Any) -> Enum.Type? { + if arr is [ActiveClientState] { return ConversationView.self } + if arr is [FocusType] { return FocusType.self } + if arr is [FocusDevice] { return FocusDevice.self } + if arr is [TypingType] { return TypingType.self } + if arr is [ClientPresenceStateType] { return ClientPresenceStateType.self } + if arr is [NotificationLevel] { return NotificationLevel.self } + if arr is [SegmentType] { return SegmentType.self } + if arr is [ItemType] { return ItemType.self } + if arr is [MediaType] { return MediaType.self } + if arr is [MembershipChangeType] { return MembershipChangeType.self } + if arr is [HangoutEventType] { return HangoutEventType.self } + if arr is [OffTheRecordToggle] { return OffTheRecordToggle.self } + if arr is [OffTheRecordStatus] { return OffTheRecordStatus.self } + if arr is [SourceType] { return SourceType.self } + if arr is [EventType] { return EventType.self } + if arr is [ConversationType] { return ConversationType.self } + if arr is [ConversationStatus] { return ConversationStatus.self } if arr is [ConversationView] { return ConversationView.self } + if arr is [DeliveryMediumType] { return DeliveryMediumType.self } + if arr is [ParticipantType] { return ParticipantType.self } + if arr is [InvitationStatus] { return InvitationStatus.self } + if arr is [ForceHistory] { return ForceHistory.self } + if arr is [NetworkType] { return NetworkType.self } + if arr is [BlockState] { return BlockState.self } + if arr is [ReplyToInviteType] { return ReplyToInviteType.self } + if arr is [ClientID] { return ClientID.self } + if arr is [ClientBuildType] { return ClientBuildType.self } + if arr is [ResponseStatus] { return ResponseStatus.self } + if arr is [PastHangoutState] { return PastHangoutState.self } + if arr is [PhotoURLStatus] { return PhotoURLStatus.self } + if arr is [Gender] { return Gender.self } + if arr is [ProfileType] { return ProfileType.self } + if arr is [ConfigurationBitType] { return ConfigurationBitType.self } + if arr is [RichPresenceType] { return RichPresenceType.self } + if arr is [FieldMask] { return FieldMask.self } + if arr is [DeleteType] { return DeleteType.self } + if arr is [SyncFilter] { return SyncFilter.self } + if arr is [SoundState] { return SoundState.self } + if arr is [CallerIDSettingsMask] { return CallerIDSettingsMask.self } + if arr is [PhoneVerificationStatus] { return PhoneVerificationStatus.self } + if arr is [PhoneDiscoverabilityStatus] { return PhoneDiscoverabilityStatus.self } + if arr is [PhoneValidationResult] { return PhoneValidationResult.self } return nil } @@ -159,6 +200,7 @@ public class PBLiteSerialization { // Unwrapping an optional enum } else if let type = _unwrapOptionalType(property) as? Enum.Type { + print("TEST \(propertyName): \(type)") let val: (AnyObject?) = type.init(value: (arr[i] as! NSNumber)) instance.setValue(val, forKey: propertyName) diff --git a/Hangouts/User.swift b/Hangouts/User.swift index 7de001a..e17b641 100755 --- a/Hangouts/User.swift +++ b/Hangouts/User.swift @@ -44,15 +44,15 @@ public struct User: Hashable, Equatable { // Initialize a User from an Entity. // If selfUser is nil, assume this is the self user. public init(entity: ENTITY, selfUser: UserID?) { - let userID = UserID(chatID: entity.id.chat_id as! String, - gaiaID: entity.id.gaia_id as! String) + let userID = UserID(chatID: entity.id!.chat_id as! String, + gaiaID: entity.id!.gaia_id as! String) let isSelf = (selfUser != nil ? (selfUser == userID) : true) self.init(userID: userID, - fullName: entity.properties.display_name as String?, - firstName: entity.properties.first_name as String?, - photoURL: entity.properties.photo_url as String?, - emails: entity.properties.emails.map { $0 as! String }, + fullName: entity.properties!.display_name as String?, + firstName: entity.properties!.first_name as String?, + photoURL: entity.properties!.photo_url as String?, + emails: entity.properties!.email.map { $0 as! String }, isSelf: isSelf ) } @@ -60,8 +60,8 @@ public struct User: Hashable, Equatable { // Initialize from ClientConversationParticipantData. // If selfUser is nil, assume this is the self user. public init(data: CONVERSATION_PARTICIPANT_DATA, selfUser: UserID?) { - let userID = UserID(chatID: data.id.chat_id as! String, - gaiaID: data.id.gaia_id as! String) + let userID = UserID(chatID: data.id!.chat_id as! String, + gaiaID: data.id!.gaia_id as! String) let isSelf = (selfUser != nil ? (selfUser == userID) : true) self.init(userID: userID,