MM-17157 Only send notification receipt if server url and session token are set (#3375)

This commit is contained in:
Elias Nahum 2019-10-10 08:48:38 +03:00 committed by GitHub
parent 9507cdf4ef
commit d4c682bddd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 73 additions and 47 deletions

View file

@ -166,8 +166,18 @@ export default function configureAppStore(initialState) {
profilesInChannel[channelId] = Array.from(profilesInChannel[channelId]);
});
let url;
if (state.entities.users.currentUserId) {
url = state.entities.general.credentials.url || state.views.selectServer.serverUrl;
}
const entities = {
...state.entities,
general: {
credentials: {
url,
},
},
channels: {
...state.entities.channels,
channelsInTeam,

View file

@ -83,7 +83,7 @@ class ShareViewController: SLComposeServiceViewController {
extractDataFromContext()
if sessionToken == nil {
if sessionToken == nil || serverURL == nil {
showErrorMessage(title: "", message: "Authentication required: Please first login using the app.", VC: self)
}
}

View file

@ -144,19 +144,29 @@
}
-(NSString *)getServerUrl {
NSDictionary *general = [self.entities objectForKey:@"general"];
NSDictionary *credentials = [general objectForKey:@"credentials"];
NSDictionary *general = [self.entities objectForKey:@"general"];
NSDictionary *credentials = [general objectForKey:@"credentials"];
return [credentials objectForKey:@"url"];
if (credentials) {
return [credentials objectForKey:@"url"];
}
return nil;
}
-(NSString *)getToken {
NSDictionary *options = @{
@"accessGroup": APP_GROUP_ID
};
NSDictionary *credentials = [self.keychain getInternetCredentialsForServer:[self getServerUrl] withOptions:options];
NSString* serverUrl = [self getServerUrl];
if (serverUrl) {
NSDictionary *credentials = [self.keychain getInternetCredentialsForServer:[self getServerUrl] withOptions:options];
return [credentials objectForKey:@"password"];
return [credentials objectForKey:@"password"];
}
return nil;
}
-(UInt64)scanValueFromConfig:(NSDictionary *)config key:(NSString *)key {

View file

@ -16,33 +16,36 @@ import os.log
let _ = store.getEntities(true)
let serverURL = store.getServerUrl()
let sessionToken = store.getToken()
let urlString = "\(serverURL!)/api/v4/posts"
guard let uploadSessionData = UploadSessionManager.shared.getUploadSessionData(identifier: identifier) else {return}
guard let url = URL(string: urlString) else {return}
if uploadSessionData.message != "" || uploadSessionData.fileIds.count > 0 {
let jsonObject: [String: Any] = [
"channel_id": uploadSessionData.channelId as Any,
"message": uploadSessionData.message as Any,
"file_ids": uploadSessionData.fileIds
]
if !JSONSerialization.isValidJSONObject(jsonObject) {return}
if (serverURL != nil && sessionToken != nil) {
let urlString = "\(serverURL!)/api/v4/posts"
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("Bearer \(sessionToken!)", forHTTPHeaderField: "Authorization")
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
request.httpBody = try? JSONSerialization.data(withJSONObject: jsonObject, options: .prettyPrinted)
guard let uploadSessionData = UploadSessionManager.shared.getUploadSessionData(identifier: identifier) else {return}
guard let url = URL(string: urlString) else {return}
if #available(iOS 12.0, *) {
os_log(OSLogType.default, "Mattermost will post identifier=%{public}@", identifier)
if uploadSessionData.message != "" || uploadSessionData.fileIds.count > 0 {
let jsonObject: [String: Any] = [
"channel_id": uploadSessionData.channelId as Any,
"message": uploadSessionData.message as Any,
"file_ids": uploadSessionData.fileIds
]
if !JSONSerialization.isValidJSONObject(jsonObject) {return}
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("Bearer \(sessionToken!)", forHTTPHeaderField: "Authorization")
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
request.httpBody = try? JSONSerialization.data(withJSONObject: jsonObject, options: .prettyPrinted)
if #available(iOS 12.0, *) {
os_log(OSLogType.default, "Mattermost will post identifier=%{public}@", identifier)
}
URLSession(configuration: .ephemeral).dataTask(with: request).resume()
UploadSessionManager.shared.removeUploadSessionData(identifier: identifier)
UploadSessionManager.shared.clearTempDirectory()
}
URLSession(configuration: .ephemeral).dataTask(with: request).resume()
UploadSessionManager.shared.removeUploadSessionData(identifier: identifier)
UploadSessionManager.shared.clearTempDirectory()
}
}
@ -131,24 +134,27 @@ import os.log
if (entities != nil) {
let serverURL = store.getServerUrl()
let sessionToken = store.getToken()
let urlString = "\(serverURL!)/api/v4/notifications/ack"
let jsonObject: [String: Any] = [
"id": notificationId as Any,
"received_at": receivedAt,
"platform": "ios",
"type": type as Any
]
if !JSONSerialization.isValidJSONObject(jsonObject) {return}
guard let url = URL(string: urlString) else {return}
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("Bearer \(sessionToken!)", forHTTPHeaderField: "Authorization")
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
request.httpBody = try? JSONSerialization.data(withJSONObject: jsonObject, options: .prettyPrinted)
URLSession(configuration: .ephemeral).dataTask(with: request).resume()
if (serverURL != nil && sessionToken != nil) {
let urlString = "\(serverURL!)/api/v4/notifications/ack"
let jsonObject: [String: Any] = [
"id": notificationId as Any,
"received_at": receivedAt,
"platform": "ios",
"type": type as Any
]
if !JSONSerialization.isValidJSONObject(jsonObject) {return}
guard let url = URL(string: urlString) else {return}
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("Bearer \(sessionToken!)", forHTTPHeaderField: "Authorization")
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
request.httpBody = try? JSONSerialization.data(withJSONObject: jsonObject, options: .prettyPrinted)
URLSession(configuration: .ephemeral).dataTask(with: request).resume()
}
}
}
}