зеркало из https://github.com/nextcloud/talk-ios.git
Share geo-location rich object.
Signed-off-by: Ivan Sein <ivan@nextcloud.com>
This commit is contained in:
Родитель
3242adc41b
Коммит
5a2b8f7808
|
@ -275,6 +275,9 @@
|
|||
2CB6ACBF26385A3800D3D641 /* ShareLocationViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2CB6ACBB26385A3800D3D641 /* ShareLocationViewController.xib */; };
|
||||
2CB6ACC026385A3800D3D641 /* ShareLocationViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2CB6ACBB26385A3800D3D641 /* ShareLocationViewController.xib */; };
|
||||
2CB6ACC126385A3800D3D641 /* ShareLocationViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2CB6ACBB26385A3800D3D641 /* ShareLocationViewController.xib */; };
|
||||
2CB6ACCA26401D5200D3D641 /* GeoLocationRichObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 2CB6ACC926401D5100D3D641 /* GeoLocationRichObject.m */; };
|
||||
2CB6ACCB26401D5200D3D641 /* GeoLocationRichObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 2CB6ACC926401D5100D3D641 /* GeoLocationRichObject.m */; };
|
||||
2CB6ACCC26401D5200D3D641 /* GeoLocationRichObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 2CB6ACC926401D5100D3D641 /* GeoLocationRichObject.m */; };
|
||||
2CBF82AE1FC888FC00636459 /* NCPushNotification.m in Sources */ = {isa = PBXBuildFile; fileRef = 2CBF82AD1FC888FC00636459 /* NCPushNotification.m */; };
|
||||
2CBF82B21FCC7DBA00636459 /* CCCertificate.m in Sources */ = {isa = PBXBuildFile; fileRef = 2CBF82B11FCC7DBA00636459 /* CCCertificate.m */; };
|
||||
2CBF82B61FD0939600636459 /* NCAPISessionManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 2CBF82B51FD0939600636459 /* NCAPISessionManager.m */; };
|
||||
|
@ -769,6 +772,8 @@
|
|||
2CB6ACB926385A3800D3D641 /* ShareLocationViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ShareLocationViewController.h; sourceTree = "<group>"; };
|
||||
2CB6ACBA26385A3800D3D641 /* ShareLocationViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ShareLocationViewController.m; sourceTree = "<group>"; };
|
||||
2CB6ACBB26385A3800D3D641 /* ShareLocationViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ShareLocationViewController.xib; sourceTree = "<group>"; };
|
||||
2CB6ACC826401D5100D3D641 /* GeoLocationRichObject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeoLocationRichObject.h; sourceTree = "<group>"; };
|
||||
2CB6ACC926401D5100D3D641 /* GeoLocationRichObject.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GeoLocationRichObject.m; sourceTree = "<group>"; };
|
||||
2CBF82AC1FC888FC00636459 /* NCPushNotification.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NCPushNotification.h; sourceTree = "<group>"; };
|
||||
2CBF82AD1FC888FC00636459 /* NCPushNotification.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NCPushNotification.m; sourceTree = "<group>"; };
|
||||
2CBF82B01FCC7DBA00636459 /* CCCertificate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCCertificate.h; sourceTree = "<group>"; };
|
||||
|
@ -1425,6 +1430,8 @@
|
|||
2CB6ACB926385A3800D3D641 /* ShareLocationViewController.h */,
|
||||
2CB6ACBA26385A3800D3D641 /* ShareLocationViewController.m */,
|
||||
2CB6ACBB26385A3800D3D641 /* ShareLocationViewController.xib */,
|
||||
2CB6ACC826401D5100D3D641 /* GeoLocationRichObject.h */,
|
||||
2CB6ACC926401D5100D3D641 /* GeoLocationRichObject.m */,
|
||||
);
|
||||
name = Maps;
|
||||
sourceTree = "<group>";
|
||||
|
@ -1899,6 +1906,7 @@
|
|||
2CC007B420D7AE990096D91F /* ResultMultiSelectionTableViewController.m in Sources */,
|
||||
2CA1CCC31F166CC5002FE6A2 /* NCRoom.m in Sources */,
|
||||
2C06BF5D20A89F510031EB46 /* NCRoomsManager.m in Sources */,
|
||||
2CB6ACCA26401D5200D3D641 /* GeoLocationRichObject.m in Sources */,
|
||||
2C415F9B2136BDD6005F7F37 /* FileMessageTableViewCell.m in Sources */,
|
||||
2C8A2BCE221FEEFE00DE6D2C /* DirectoryTableViewCell.m in Sources */,
|
||||
2C78EF9C1F826B22008AFA74 /* NCCallController.m in Sources */,
|
||||
|
@ -2004,6 +2012,7 @@
|
|||
1F4DD3ED2571C688007DC98E /* EmojiUtils.swift in Sources */,
|
||||
2C62AFF824C1BDA5007E460A /* QuotedMessageView.m in Sources */,
|
||||
2C62B02424C1BDCF007E460A /* NCAppBranding.m in Sources */,
|
||||
2CB6ACCC26401D5200D3D641 /* GeoLocationRichObject.m in Sources */,
|
||||
2C62B00624C1BDB9007E460A /* LoginViewController.m in Sources */,
|
||||
2C62AFEF24C1BD9F007E460A /* ChatMessageTableViewCell.m in Sources */,
|
||||
2C62B02A24C1BDCF007E460A /* VideoResolutionsViewController.m in Sources */,
|
||||
|
@ -2209,6 +2218,7 @@
|
|||
1F3D3B23255F109E00230DAE /* BarButtonItemWithActivity.m in Sources */,
|
||||
2CC001D024A37ACA00A20167 /* RoomTableViewCell.m in Sources */,
|
||||
2CB6ACBD26385A3800D3D641 /* ShareLocationViewController.m in Sources */,
|
||||
2CB6ACCB26401D5200D3D641 /* GeoLocationRichObject.m in Sources */,
|
||||
2CC0015D24A257B800A20167 /* NCSettingsController.m in Sources */,
|
||||
2CC0017424A3796400A20167 /* NCAPISessionManager.m in Sources */,
|
||||
2CC0016324A25B7400A20167 /* NCDatabaseManager.m in Sources */,
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
/**
|
||||
* @copyright Copyright (c) 2020 Ivan Sein <ivan@nextcloud.com>
|
||||
*
|
||||
* @author Ivan Sein <ivan@nextcloud.com>
|
||||
*
|
||||
* @license GNU GPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
extern NSString * const GeoLocationRichObjectType;
|
||||
|
||||
@interface GeoLocationRichObject : NSObject
|
||||
|
||||
@property (nonatomic, copy) NSString *objectType;
|
||||
@property (nonatomic, copy) NSString *objectId;
|
||||
@property (nonatomic, copy) NSString *latitude;
|
||||
@property (nonatomic, copy) NSString *longitude;
|
||||
@property (nonatomic, copy) NSString *name;
|
||||
|
||||
+ (instancetype)geoLocationRichObjectWithLatitude:(double)latitude longitude:(double)longitude name:(NSString *)name;
|
||||
- (NSDictionary *)richObjectDictionary;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
|
@ -0,0 +1,72 @@
|
|||
/**
|
||||
* @copyright Copyright (c) 2020 Ivan Sein <ivan@nextcloud.com>
|
||||
*
|
||||
* @author Ivan Sein <ivan@nextcloud.com>
|
||||
*
|
||||
* @license GNU GPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#import "GeoLocationRichObject.h"
|
||||
|
||||
NSString * const GeoLocationRichObjectType = @"geo-location";
|
||||
|
||||
@implementation GeoLocationRichObject
|
||||
|
||||
+ (instancetype)geoLocationRichObjectWithLatitude:(double)latitude longitude:(double)longitude name:(NSString *)name
|
||||
{
|
||||
GeoLocationRichObject *object = [[self alloc] init];
|
||||
NSString *latitudeString = [[NSNumber numberWithDouble:latitude] stringValue];
|
||||
NSString *longitudeString = [[NSNumber numberWithDouble:longitude] stringValue];
|
||||
object.objectType = GeoLocationRichObjectType;
|
||||
object.objectId = [NSString stringWithFormat:@"geo:%@,%@", latitudeString, longitudeString];
|
||||
object.latitude = latitudeString;
|
||||
object.longitude = longitudeString;
|
||||
object.name = name;
|
||||
return object;
|
||||
}
|
||||
|
||||
- (NSDictionary *)metaData
|
||||
{
|
||||
return @{
|
||||
@"latitude": self.latitude,
|
||||
@"longitude": self.longitude,
|
||||
@"name": self.name
|
||||
};
|
||||
}
|
||||
|
||||
- (NSDictionary *)richObjectDictionary
|
||||
{
|
||||
NSError *error;
|
||||
NSString *jsonString = nil;
|
||||
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:[self metaData]
|
||||
options:0
|
||||
error:&error];
|
||||
|
||||
if (!jsonData) {
|
||||
NSLog(@"Got an error: %@", error);
|
||||
} else {
|
||||
jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
||||
}
|
||||
|
||||
return @{
|
||||
@"objectType": self.objectType,
|
||||
@"objectId": self.objectId,
|
||||
@"metaData": jsonString
|
||||
};
|
||||
}
|
||||
|
||||
@end
|
|
@ -141,6 +141,7 @@ extern NSInteger const kReceivedChatMessagesLimit;
|
|||
- (NSURLSessionDataTask *)sendChatMessage:(NSString *)message toRoom:(NSString *)token displayName:(NSString *)displayName replyTo:(NSInteger)replyTo referenceId:(NSString *)referenceId forAccount:(TalkAccount *)account withCompletionBlock:(SendChatMessagesCompletionBlock)block;
|
||||
- (NSURLSessionDataTask *)getMentionSuggestionsInRoom:(NSString *)token forString:(NSString *)string forAccount:(TalkAccount *)account withCompletionBlock:(GetMentionSuggestionsCompletionBlock)block;
|
||||
- (NSURLSessionDataTask *)deleteChatMessageInRoom:(NSString *)token withMessageId:(NSInteger)messageId forAccount:(TalkAccount *)account withCompletionBlock:(DeleteChatMessageCompletionBlock)block;
|
||||
- (NSURLSessionDataTask *)shareRichObject:(NSDictionary *)richObject inRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(SendChatMessagesCompletionBlock)block;
|
||||
|
||||
// Signaling Controller
|
||||
- (NSURLSessionDataTask *)sendSignalingMessages:(NSString *)messages toRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(SendSignalingMessagesCompletionBlock)block;
|
||||
|
|
|
@ -967,6 +967,25 @@ NSInteger const kReceivedChatMessagesLimit = 100;
|
|||
return task;
|
||||
}
|
||||
|
||||
- (NSURLSessionDataTask *)shareRichObject:(NSDictionary *)richObject inRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(SendChatMessagesCompletionBlock)block
|
||||
{
|
||||
NSString *URLString = [self getRequestURLForAccount:account withEndpoint:[NSString stringWithFormat:@"chat/%@/share", token]];
|
||||
NCAPISessionManager *apiSessionManager = [_apiSessionManagers objectForKey:account.accountId];
|
||||
NSURLSessionDataTask *task = [apiSessionManager POST:URLString parameters:richObject progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
||||
if (block) {
|
||||
block(nil);
|
||||
}
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
NSInteger statusCode = [self getResponseStatusCode:task.response];
|
||||
[self checkResponseStatusCode:statusCode forAccount:account];
|
||||
if (block) {
|
||||
block(error);
|
||||
}
|
||||
}];
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
#pragma mark - Signaling Controller
|
||||
|
||||
- (NSURLSessionDataTask *)sendSignalingMessages:(NSString *)messages toRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(SendSignalingMessagesCompletionBlock)block;
|
||||
|
|
|
@ -61,6 +61,7 @@
|
|||
#import "ShareItem.h"
|
||||
#import "NCChatFileController.h"
|
||||
#import "ShareLocationViewController.h"
|
||||
#import "GeoLocationRichObject.h"
|
||||
#import <NCCommunication/NCCommunication.h>
|
||||
#import <QuickLook/QuickLook.h>
|
||||
|
||||
|
@ -73,8 +74,7 @@ typedef enum NCChatMessageAction {
|
|||
kNCChatMessageActionOpenFileInNextcloud
|
||||
} NCChatMessageAction;
|
||||
|
||||
@interface NCChatViewController () <UIGestureRecognizerDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIDocumentPickerDelegate, ShareConfirmationViewControllerDelegate, FileMessageTableViewCellDelegate, NCChatFileControllerDelegate, QLPreviewControllerDelegate, QLPreviewControllerDataSource,
|
||||
ChatMessageTableViewCellDelegate>
|
||||
@interface NCChatViewController () <UIGestureRecognizerDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIDocumentPickerDelegate, ShareConfirmationViewControllerDelegate, FileMessageTableViewCellDelegate, NCChatFileControllerDelegate, QLPreviewControllerDelegate, QLPreviewControllerDataSource, ChatMessageTableViewCellDelegate, ShareLocationViewControllerDelegate>
|
||||
|
||||
@property (nonatomic, strong) NCChatController *chatController;
|
||||
@property (nonatomic, strong) NCChatTitleView *titleView;
|
||||
|
@ -972,6 +972,7 @@ NSString * const NCChatViewControllerReplyPrivatelyNotification = @"NCChatViewCo
|
|||
- (void)presentShareLocation
|
||||
{
|
||||
ShareLocationViewController *shareLocationVC = [[ShareLocationViewController alloc] init];
|
||||
shareLocationVC.delegate = self;
|
||||
NCNavigationController *shareLocationNC = [[NCNavigationController alloc] initWithRootViewController:shareLocationVC];
|
||||
[self presentViewController:shareLocationNC animated:YES completion:nil];
|
||||
}
|
||||
|
@ -1148,6 +1149,20 @@ NSString * const NCChatViewControllerReplyPrivatelyNotification = @"NCChatViewCo
|
|||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
}
|
||||
|
||||
#pragma mark - ShareLocationViewController Delegate
|
||||
|
||||
-(void)shareLocationViewController:(ShareLocationViewController *)viewController didSelectLocationWithLatitude:(double)latitude longitude:(double)longitude andName:(NSString *)name
|
||||
{
|
||||
GeoLocationRichObject *richObject = [GeoLocationRichObject geoLocationRichObjectWithLatitude:latitude longitude:longitude name:name];
|
||||
TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
|
||||
[[NCAPIController sharedInstance] shareRichObject:richObject.richObjectDictionary inRoom:_room.token forAccount:activeAccount withCompletionBlock:^(NSError *error) {
|
||||
if (error) {
|
||||
NSLog(@"Error sharing rich object: %@", error);
|
||||
}
|
||||
}];
|
||||
[viewController dismissViewControllerAnimated:YES completion:nil];
|
||||
}
|
||||
|
||||
#pragma mark - Gesture recognizer
|
||||
|
||||
-(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer
|
||||
|
|
|
@ -25,8 +25,16 @@
|
|||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class ShareLocationViewController;
|
||||
@protocol ShareLocationViewControllerDelegate <NSObject>
|
||||
|
||||
- (void)shareLocationViewController:(ShareLocationViewController *)viewController didSelectLocationWithLatitude:(double)latitude longitude:(double)longitude andName:(NSString *)name;
|
||||
|
||||
@end
|
||||
|
||||
@interface ShareLocationViewController : UIViewController
|
||||
|
||||
@property (nonatomic, weak) id<ShareLocationViewControllerDelegate> delegate;
|
||||
@property (weak, nonatomic) IBOutlet MKMapView *mapView;
|
||||
@property (weak, nonatomic) IBOutlet UITableView *tableView;
|
||||
@property (weak, nonatomic) IBOutlet UIButton *myLocationButton;
|
||||
|
|
|
@ -24,7 +24,9 @@
|
|||
|
||||
#import <CoreLocation/CoreLocation.h>
|
||||
|
||||
#import "GeoLocationRichObject.h"
|
||||
#import "NCAppBranding.h"
|
||||
#import "NCAPIController.h"
|
||||
#import "NCUtils.h"
|
||||
|
||||
typedef enum ShareLocationSection {
|
||||
|
@ -282,20 +284,20 @@ typedef enum ShareLocationSection {
|
|||
{
|
||||
// Search result table view
|
||||
if (tableView == _resultTableViewController.tableView) {
|
||||
MKMapItem *nearbyPlace = [_searchedPlaces objectAtIndex:indexPath.row];
|
||||
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"NearbyLocationCellIdentifier"];
|
||||
MKMapItem *searchedPlace = [_searchedPlaces objectAtIndex:indexPath.row];
|
||||
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"SearchedLocationCellIdentifier"];
|
||||
[cell.imageView setImage:[[UIImage imageNamed:@"location"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
|
||||
cell.imageView.tintColor = [NCAppBranding placeholderColor];
|
||||
cell.textLabel.text = nearbyPlace.name;
|
||||
cell.textLabel.text = searchedPlace.name;
|
||||
NSString *subtitle = nil;
|
||||
if (nearbyPlace.placemark.thoroughfare && nearbyPlace.placemark.subThoroughfare) {
|
||||
subtitle = [NSString stringWithFormat:@"%@ %@, ", nearbyPlace.placemark.thoroughfare, nearbyPlace.placemark.subThoroughfare];
|
||||
if (searchedPlace.placemark.thoroughfare && searchedPlace.placemark.subThoroughfare) {
|
||||
subtitle = [NSString stringWithFormat:@"%@ %@, ", searchedPlace.placemark.thoroughfare, searchedPlace.placemark.subThoroughfare];
|
||||
}
|
||||
if (nearbyPlace.placemark.locality) {
|
||||
subtitle = [subtitle stringByAppendingString:[NSString stringWithFormat:@"%@, ", nearbyPlace.placemark.locality]];
|
||||
if (searchedPlace.placemark.locality) {
|
||||
subtitle = [subtitle stringByAppendingString:[NSString stringWithFormat:@"%@, ", searchedPlace.placemark.locality]];
|
||||
}
|
||||
if (nearbyPlace.placemark.country) {
|
||||
subtitle = [subtitle stringByAppendingString:[NSString stringWithFormat:@"%@", nearbyPlace.placemark.country]];;
|
||||
if (searchedPlace.placemark.country) {
|
||||
subtitle = [subtitle stringByAppendingString:[NSString stringWithFormat:@"%@", searchedPlace.placemark.country]];;
|
||||
}
|
||||
cell.detailTextLabel.text = subtitle;
|
||||
return cell;
|
||||
|
@ -324,4 +326,21 @@ typedef enum ShareLocationSection {
|
|||
return nil;
|
||||
}
|
||||
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
// Search result table view
|
||||
if (tableView == _resultTableViewController.tableView) {
|
||||
MKMapItem *searchedPlace = [_searchedPlaces objectAtIndex:indexPath.row];
|
||||
[self.delegate shareLocationViewController:self didSelectLocationWithLatitude:searchedPlace.placemark.location.coordinate.latitude longitude:searchedPlace.placemark.location.coordinate.longitude andName:searchedPlace.name];
|
||||
}
|
||||
|
||||
// Main view table view
|
||||
if (indexPath.section == kShareLocationSectionCurrent) {
|
||||
[self.delegate shareLocationViewController:self didSelectLocationWithLatitude:_currentLocation.coordinate.latitude longitude:_currentLocation.coordinate.longitude andName:NSLocalizedString(@"My location", nil)];
|
||||
} else if (indexPath.section == kShareLocationSectionNearby) {
|
||||
MKMapItem *nearbyPlace = [_nearbyPlaces objectAtIndex:indexPath.row];
|
||||
[self.delegate shareLocationViewController:self didSelectLocationWithLatitude:nearbyPlace.placemark.location.coordinate.latitude longitude:nearbyPlace.placemark.location.coordinate.longitude andName:nearbyPlace.name];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Загрузка…
Ссылка в новой задаче