This repository has been archived by the owner on Jun 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #796 from RocketChat/beta
[RELEASE] Merge beta into master
- Loading branch information
Showing
60 changed files
with
1,256 additions
and
384 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
83 changes: 83 additions & 0 deletions
83
Rocket.Chat/API/Requests/Subscription/SubscriptionMessagesRequest.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// | ||
// SubscriptionMembersRequest.swift | ||
// Rocket.Chat | ||
// | ||
// Created by Matheus Cardoso on 9/21/17. | ||
// Copyright © 2017 Rocket.Chat. All rights reserved. | ||
// | ||
|
||
import SwiftyJSON | ||
import Foundation | ||
|
||
typealias SubscriptionMessagesResult = APIResult<SubscriptionMessagesRequest> | ||
|
||
fileprivate extension SubscriptionType { | ||
var path: String { | ||
switch self { | ||
case .channel: | ||
return "/api/v1/channels.messages" | ||
case .group: | ||
return "/api/v1/groups.messages" | ||
case .directMessage: | ||
return "/api/v1/dm.messages" | ||
} | ||
} | ||
} | ||
|
||
class SubscriptionMessagesRequest: APIRequest { | ||
var path: String { | ||
return type.path | ||
} | ||
|
||
var query: String? | ||
|
||
let roomId: String? | ||
let roomName: String? | ||
let type: SubscriptionType | ||
|
||
init(roomId: String, type: SubscriptionType = .channel, query: String? = nil) { | ||
self.type = type | ||
self.roomId = roomId | ||
self.roomName = nil | ||
|
||
if let query = query { | ||
self.query = "roomId=\(roomId)&query=\(query)" | ||
} else { | ||
self.query = "roomId=\(roomId)" | ||
} | ||
} | ||
|
||
init(roomName: String, type: SubscriptionType = .channel) { | ||
self.type = type | ||
self.roomName = roomName | ||
self.roomId = nil | ||
|
||
if let query = query { | ||
self.query = "roomName=\(roomName)&query=\(query)" | ||
} else { | ||
self.query = "roomName=\(roomName)" | ||
} | ||
} | ||
} | ||
|
||
extension APIResult where T == SubscriptionMessagesRequest { | ||
var messages: [Message?]? { | ||
return raw?["messages"].arrayValue.map { | ||
let message = Message() | ||
message.map($0, realm: nil) | ||
return message | ||
} | ||
} | ||
|
||
var count: Int? { | ||
return raw?["count"].int | ||
} | ||
|
||
var offset: Int? { | ||
return raw?["offset"].int | ||
} | ||
|
||
var total: Int? { | ||
return raw?["total"].int | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.