Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
devpurevee committed Dec 12, 2018
2 parents 288c19d + 4ff8054 commit ae4b614
Show file tree
Hide file tree
Showing 10 changed files with 216 additions and 131 deletions.
2 changes: 1 addition & 1 deletion ErxesSDK.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Pod::Spec.new do |s|
s.name = 'ErxesSDK'
s.version = '0.1.5'
s.version = '0.1.6'
s.summary = 'A short description of erxes-ios-sdk.'
s.swift_version = '4.0'
s.description = 'erxes for IOS SDK, for integrating erxes into your iOS application https://erxes.io/'
Expand Down
131 changes: 121 additions & 10 deletions ErxesSDK/Classes/API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,50 @@

import Apollo

public struct AttachmentInput: GraphQLMapConvertible {
public var graphQLMap: GraphQLMap

public init(url: String, name: String, type: String, size: Optional<Double?> = nil) {
graphQLMap = ["url": url, "name": name, "type": type, "size": size]
}

public var url: String {
get {
return graphQLMap["url"] as! String
}
set {
graphQLMap.updateValue(newValue, forKey: "url")
}
}

public var name: String {
get {
return graphQLMap["name"] as! String
}
set {
graphQLMap.updateValue(newValue, forKey: "name")
}
}

public var type: String {
get {
return graphQLMap["type"] as! String
}
set {
graphQLMap.updateValue(newValue, forKey: "type")
}
}

public var size: Optional<Double?> {
get {
return graphQLMap["size"] as! Optional<Double?>
}
set {
graphQLMap.updateValue(newValue, forKey: "size")
}
}
}

public final class ConnectMutation: GraphQLMutation {
public static let operationString =
"mutation Connect($brandCode: String!, $email: String, $phone: String, $isUser: Boolean!, $data: JSON) {\n messengerConnect(brandCode: $brandCode, email: $email, phone: $phone, isUser: $isUser, data: $data) {\n __typename\n integrationId\n messengerData\n uiOptions\n customerId\n }\n}"
Expand Down Expand Up @@ -163,15 +207,15 @@ public final class ReadConversationMessagesMutation: GraphQLMutation {

public final class InsertMessageMutation: GraphQLMutation {
public static let operationString =
"mutation insertMessage($integrationId: String!, $customerId: String!, $message: String, $conversationId: String, $attachments: [JSON]) {\n insertMessage(integrationId: $integrationId, customerId: $customerId, message: $message, conversationId: $conversationId, attachments: $attachments) {\n __typename\n _id\n conversationId\n }\n}"
"mutation insertMessage($integrationId: String!, $customerId: String!, $message: String, $conversationId: String, $attachments: [AttachmentInput]) {\n insertMessage(integrationId: $integrationId, customerId: $customerId, message: $message, conversationId: $conversationId, attachments: $attachments) {\n __typename\n _id\n conversationId\n }\n}"

public var integrationId: String
public var customerId: String
public var message: String?
public var conversationId: String?
public var attachments: [JSON?]?
public var attachments: [AttachmentInput?]?

public init(integrationId: String, customerId: String, message: String? = nil, conversationId: String? = nil, attachments: [JSON?]? = nil) {
public init(integrationId: String, customerId: String, message: String? = nil, conversationId: String? = nil, attachments: [AttachmentInput?]? = nil) {
self.integrationId = integrationId
self.customerId = customerId
self.message = message
Expand Down Expand Up @@ -346,7 +390,7 @@ public final class UnreadCountQuery: GraphQLQuery {

public final class MessagesQuery: GraphQLQuery {
public static let operationString =
"query Messages($conversationId: String!) {\n messages(conversationId: $conversationId) {\n __typename\n _id\n user {\n __typename\n details {\n __typename\n avatar\n fullName\n }\n }\n customerId\n content\n createdAt\n attachments\n }\n}"
"query Messages($conversationId: String!) {\n messages(conversationId: $conversationId) {\n __typename\n _id\n user {\n __typename\n details {\n __typename\n avatar\n fullName\n }\n }\n customerId\n content\n createdAt\n attachments {\n __typename\n url\n name\n type\n size\n }\n }\n}"

public var conversationId: String

Expand Down Expand Up @@ -394,7 +438,7 @@ public final class MessagesQuery: GraphQLQuery {
GraphQLField("customerId", type: .scalar(String.self)),
GraphQLField("content", type: .scalar(String.self)),
GraphQLField("createdAt", type: .scalar(Int.self)),
GraphQLField("attachments", type: .list(.scalar(JSON.self))),
GraphQLField("attachments", type: .list(.object(Attachment.selections))),
]

public var snapshot: Snapshot
Expand All @@ -403,8 +447,8 @@ public final class MessagesQuery: GraphQLQuery {
self.snapshot = snapshot
}

public init(id: String, user: User? = nil, customerId: String? = nil, content: String? = nil, createdAt: Int? = nil, attachments: [JSON?]? = nil) {
self.init(snapshot: ["__typename": "ConversationMessage", "_id": id, "user": user.flatMap { $0.snapshot }, "customerId": customerId, "content": content, "createdAt": createdAt, "attachments": attachments])
public init(id: String, user: User? = nil, customerId: String? = nil, content: String? = nil, createdAt: Int? = nil, attachments: [Attachment?]? = nil) {
self.init(snapshot: ["__typename": "ConversationMessage", "_id": id, "user": user.flatMap { $0.snapshot }, "customerId": customerId, "content": content, "createdAt": createdAt, "attachments": attachments.flatMap { $0.map { $0.flatMap { $0.snapshot } } }])
}

public var __typename: String {
Expand Down Expand Up @@ -461,12 +505,12 @@ public final class MessagesQuery: GraphQLQuery {
}
}

public var attachments: [JSON?]? {
public var attachments: [Attachment?]? {
get {
return snapshot["attachments"] as? [JSON?]
return (snapshot["attachments"] as? [Snapshot?]).flatMap { $0.map { $0.flatMap { Attachment(snapshot: $0) } } }
}
set {
snapshot.updateValue(newValue, forKey: "attachments")
snapshot.updateValue(newValue.flatMap { $0.map { $0.flatMap { $0.snapshot } } }, forKey: "attachments")
}
}

Expand Down Expand Up @@ -553,6 +597,73 @@ public final class MessagesQuery: GraphQLQuery {
}
}
}

public struct Attachment: GraphQLSelectionSet {
public static let possibleTypes = ["Attachment"]

public static let selections: [GraphQLSelection] = [
GraphQLField("__typename", type: .nonNull(.scalar(String.self))),
GraphQLField("url", type: .nonNull(.scalar(String.self))),
GraphQLField("name", type: .nonNull(.scalar(String.self))),
GraphQLField("type", type: .nonNull(.scalar(String.self))),
GraphQLField("size", type: .scalar(Double.self)),
]

public var snapshot: Snapshot

public init(snapshot: Snapshot) {
self.snapshot = snapshot
}

public init(url: String, name: String, type: String, size: Double? = nil) {
self.init(snapshot: ["__typename": "Attachment", "url": url, "name": name, "type": type, "size": size])
}

public var __typename: String {
get {
return snapshot["__typename"]! as! String
}
set {
snapshot.updateValue(newValue, forKey: "__typename")
}
}

public var url: String {
get {
return snapshot["url"]! as! String
}
set {
snapshot.updateValue(newValue, forKey: "url")
}
}

public var name: String {
get {
return snapshot["name"]! as! String
}
set {
snapshot.updateValue(newValue, forKey: "name")
}
}

public var type: String {
get {
return snapshot["type"]! as! String
}
set {
snapshot.updateValue(newValue, forKey: "type")
}
}

public var size: Double? {
get {
return snapshot["size"] as? Double
}
set {
snapshot.updateValue(newValue, forKey: "size")
}
}
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions ErxesSDK/Classes/Global/Model/Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct Attachment:Codable {
var url:String?
var type:String?
var size:Int?
var name:String?
}

struct Message: Codable {
Expand Down
33 changes: 12 additions & 21 deletions ErxesSDK/Classes/Queries/mutation.graphql
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
mutation Connect($brandCode: String!, $email: String, $phone:String $isUser: Boolean!) {
messengerConnect(brandCode: $brandCode, email: $email , phone:$phone, isUser: $isUser) {
integrationId
messengerData
uiOptions
customerId
}
mutation Connect($brandCode: String!, $email: String, $phone:String, $isUser: Boolean!, $data:JSON) {
messengerConnect(brandCode: $brandCode, email: $email , phone:$phone, isUser: $isUser, data:$data) {
integrationId
messengerData
uiOptions
customerId
}
}

mutation ReadConversationMessages($conversationId: String!) {
readConversationMessages(conversationId: $conversationId)
readConversationMessages(conversationId: $conversationId)
}

mutation EndConversation($customerId: String,$brandCode: String!) {
endConversation(customerId: $customerId,brandCode: $brandCode) {
customerId
}
mutation insertMessage($integrationId: String!, $customerId: String!, $message: String, $conversationId: String, $attachments:[AttachmentInput]) {
insertMessage(integrationId: $integrationId, customerId: $customerId, message: $message, conversationId: $conversationId, attachments:$attachments){
_id
conversationId
}

mutation insertMessage($integrationId: String!, $customerId: String!, $message: String, $conversationId: String, $attachments:[JSON]) {
insertMessage(integrationId: $integrationId, customerId: $customerId, message: $message, conversationId: $conversationId, attachments:$attachments) {
_id
conversationId
}
}

mutation ReadMessage($conversationId: String!) {
readConversationMessages(conversationId: $conversationId)
}
Loading

0 comments on commit ae4b614

Please sign in to comment.