diff --git a/engine b/engine index f7ea15e9d2e8d813db5a2f706fcf930efc0b6de1..54fc4602ccfc6916f5dd344ca5145c6226169dcd 160000 --- a/engine +++ b/engine @@ -1 +1 @@ -Subproject commit f7ea15e9d2e8d813db5a2f706fcf930efc0b6de1 +Subproject commit 54fc4602ccfc6916f5dd344ca5145c6226169dcd diff --git a/fairchat/.DS_Store b/fairchat/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..7b478f8d25d99f6d6e9f6da028f4b8392e107d26 Binary files /dev/null and b/fairchat/.DS_Store differ diff --git a/fairchat/android/.DS_Store b/fairchat/android/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..87a78eee5da5dcac45e2dc8f3cb77b494112f1b4 Binary files /dev/null and b/fairchat/android/.DS_Store differ diff --git a/fairchat/android/src/com/osalliance/rocketchatMobile/FcmMessageReceiver.java b/fairchat/android/src/com/osalliance/rocketchatMobile/FcmMessageReceiver.java index 69cfa39d9b1b318c79e4d73d37348f69e821c3d1..6a4fb4af4c972a4167d6777be8a6ecf050ac3634 100644 --- a/fairchat/android/src/com/osalliance/rocketchatMobile/FcmMessageReceiver.java +++ b/fairchat/android/src/com/osalliance/rocketchatMobile/FcmMessageReceiver.java @@ -47,7 +47,7 @@ public class FcmMessageReceiver extends FirebaseMessagingService { @Override public void onMessageReceived(RemoteMessage remoteMessage){ - + super.onMessageReceived(remoteMessage); String appname = MainActivity.getApplicationName(context); Map msg = remoteMessage.getData(); @@ -138,6 +138,7 @@ public class FcmMessageReceiver extends FirebaseMessagingService { @Override public void onMessageSent(String msgId){ + super.onMessageSent(msgId); Log.i("push","push message sent"); } diff --git a/fairchat/android/src/com/osalliance/rocketchatMobile/FcmMessageTokenHandler.java b/fairchat/android/src/com/osalliance/rocketchatMobile/FcmMessageTokenHandler.java index 946f2b1875edda66d9296c5b5330f81e4224eefe..328cf5af53943b2d42696d0dcb2442db99c9ec61 100644 --- a/fairchat/android/src/com/osalliance/rocketchatMobile/FcmMessageTokenHandler.java +++ b/fairchat/android/src/com/osalliance/rocketchatMobile/FcmMessageTokenHandler.java @@ -15,6 +15,7 @@ public class FcmMessageTokenHandler extends FirebaseInstanceIdService { @Override public void onTokenRefresh(){ + super.onTokenRefresh(); String refreshedToken = FirebaseInstanceId.getInstance().getToken(); Log.i(TAG,"token received "+refreshedToken); diff --git a/fairchat/fairchat.pro b/fairchat/fairchat.pro index 28451140fc7ba0e86c3b51fe1ebc56d3b7029f5e..0d0780a599e706ef4a0efe455d4909bc0665d535 100755 --- a/fairchat/fairchat.pro +++ b/fairchat/fairchat.pro @@ -1,4 +1,4 @@ -QT += qml quick core network websockets sql quickcontrols2 multimedia svg xml concurrent +QT += qml quick core network websockets sql quickcontrols2 multimedia svg xml concurrent webview SOURCES += \ main.cpp \ @@ -60,7 +60,41 @@ contains(ANDROID_TARGET_ARCH,armeabi-v7a) { $$PWD/../openssl/android-arm/libssl.so \ $$PWD/../openssl/android-arm/libcrypto.so } + ios{ + QT += gui-private + + SOURCES += notifications/ios/applepushnotifications.cpp \ + notifications/ios/iosdevicetokenstorage.cpp \ + notifications/ios/iosnotificationreceiver.cpp \ + ios/src/ioshelper.cpp + + + HEADERS += notifications/ios/applepushnotifications.h \ + notifications/ios/iosdevicetokenstorage.h \ + ios/src/FileHandlerActivity.h \ + ios/src/fileopener.h \ + ios/src/IosGalleryPicker.h \ + ios/src/shareheplersingelton.h \ + notifications/ios/iosnotificationreceiver.h \ + notifications/ios/DelegateClass.h \ + ios/src/IosBadges.h \ + ios/src/ioshelper.h + + + + OBJECTIVE_SOURCES += ios/src/QIOSApplicationDelegate+PushDelegate.mm \ + notifications/ios/DelegateClass.mm \ + ios/src/FileHandlerActivity.mm \ + ios/src/IosGalleryPicker.mm \ + ios/src/fileopener.mm \ + ios/src/shareheplersingelton.mm \ + ios/src/IosBadges.mm \ + ios/src/shareheplersingelton.mm + + + LIBS += -framework UserNotifications + RESOURCES += ios.qrc QMAKE_INFO_PLIST = ios/Info.plist @@ -72,9 +106,9 @@ ios{ QMAKE_BUNDLE_DATA += ios_icon QMAKE_IOS_DEPLOYMENT_TARGET = 10 - QMAKE_IOS_TARGETED_DEVICE_FAMILY = 1 + QMAKE_APPLE_TARGETED_DEVICE_FAMILY = 1 PRODUCT_NAME = fairchat - PRODUCT_BUNDLE_IDENTIFIER = com.osalliance.rocketchatMobile + PRODUCT_BUNDLE_IDENTIFIER = com.osalliance.RocketChatMobile } winrt{ RESOURCES += winrt.qrc diff --git a/fairchat/ios/.DS_Store b/fairchat/ios/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..d698330d37fc50107fe56cfa1f56b7b711baae67 Binary files /dev/null and b/fairchat/ios/.DS_Store differ diff --git a/fairchat/ios/info.plist b/fairchat/ios/info.plist index 14bf61e25b8bc24810c39964dceb9f26c7715d5a..922f1856468cd92af7cae5160ddabbf190112ab0 100755 --- a/fairchat/ios/info.plist +++ b/fairchat/ios/info.plist @@ -5,7 +5,7 @@ Application requires iPhone environment CFBundleDisplayName - Ucom + fairchat CFBundleDocumentTypes @@ -70,7 +70,7 @@ CFBundleExecutable - ucom + fairchat CFBundleGetInfoString Created by Qt/QMake CFBundleIcons @@ -112,15 +112,13 @@ AppIcon76x76@2x~ipad.png AppIcon60x60@3x.png AppIcon83.5x83.5@2x~ipad.png - - CFBundleIdentifier $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleName - ucom + fairchat CFBundlePackageType APPL CFBundleShortVersionString @@ -151,31 +149,14 @@ This app allows the user to record audio, which could be sent as chat messages NSPhotoLibraryUsageDescription This app allows you to upload files from your photoroll as well as store downloaded photos to hte photoroll by using the UIActivityViewController + UIBackgroundModes + + remote-notification + UIFileSharingEnabled UILaunchImages - - - UILaunchImageMinimumOSVersion - 7.0 - UILaunchImageName - LaunchImage-iOS7 - UILaunchImageOrientation - Portrait - UILaunchImageSize - {320, 568} - - - UILaunchImageMinimumOSVersion - 7.0 - UILaunchImageName - LaunchImage-iOS7 - UILaunchImageOrientation - Portrait - UILaunchImageSize - {320, 480} - - + UILaunchImages~ipad diff --git a/fairchat/ios/launch/LaunchImage-iOS7-568h@2x.png b/fairchat/ios/launch/LaunchImage-iOS7-568h@2x.png index 228ba07071bf71a29f5b03436c5446accdb0b855..bf604e21e0b06cec491877cfeb6ddf4c05004e53 100755 Binary files a/fairchat/ios/launch/LaunchImage-iOS7-568h@2x.png and b/fairchat/ios/launch/LaunchImage-iOS7-568h@2x.png differ diff --git a/fairchat/ios/launch/LaunchImage-iOS7-Landscape.png b/fairchat/ios/launch/LaunchImage-iOS7-Landscape.png index ef6ab7bdc0b90c336aa8d53d5b31b6ef4f936fe6..bc654253f349063705a4c44f0d013fd9023357bd 100755 Binary files a/fairchat/ios/launch/LaunchImage-iOS7-Landscape.png and b/fairchat/ios/launch/LaunchImage-iOS7-Landscape.png differ diff --git a/fairchat/ios/launch/LaunchImage-iOS7-Landscape@2x.png b/fairchat/ios/launch/LaunchImage-iOS7-Landscape@2x.png index 6cafad74eb94cdfd38dafd203b3241c7daa135a3..cc5a3d64432552b1421dda5e1bd36d29d90a8112 100755 Binary files a/fairchat/ios/launch/LaunchImage-iOS7-Landscape@2x.png and b/fairchat/ios/launch/LaunchImage-iOS7-Landscape@2x.png differ diff --git a/fairchat/ios/launch/LaunchImage-iOS7-Portrait.png b/fairchat/ios/launch/LaunchImage-iOS7-Portrait.png index 196b31e0e3ba52d7b2271ea09e3a2cb2030a9c4a..e248c8fb26a133964d621d3c9cb7c749cbf76ad3 100755 Binary files a/fairchat/ios/launch/LaunchImage-iOS7-Portrait.png and b/fairchat/ios/launch/LaunchImage-iOS7-Portrait.png differ diff --git a/fairchat/ios/launch/LaunchImage-iOS7-Portrait@2x.png b/fairchat/ios/launch/LaunchImage-iOS7-Portrait@2x.png index cee267dc7ae37a517f2d9a7e72fe0b7f9d8a4ac1..d742a24c2555ed92ea96092f80d4fc9ddd92a079 100755 Binary files a/fairchat/ios/launch/LaunchImage-iOS7-Portrait@2x.png and b/fairchat/ios/launch/LaunchImage-iOS7-Portrait@2x.png differ diff --git a/fairchat/ios/launch/LaunchImage-iOS7@2x.png b/fairchat/ios/launch/LaunchImage-iOS7@2x.png index b6a4b80b185fdf1a32c3d7c0d9dacf5489b39b32..87885ce71f7a60a2885981f3f00718a8d20b9648 100755 Binary files a/fairchat/ios/launch/LaunchImage-iOS7@2x.png and b/fairchat/ios/launch/LaunchImage-iOS7@2x.png differ diff --git a/fairchat/ios/src/DelegateClass.h b/fairchat/ios/src/DelegateClass.h new file mode 100755 index 0000000000000000000000000000000000000000..623e49103b0a99b74878a100e9ea3381c5e5fad9 --- /dev/null +++ b/fairchat/ios/src/DelegateClass.h @@ -0,0 +1,21 @@ +#include "iosdevicetokenstorage.h" +#include "iosnotificationreceiver.h" + +class IosDeviceTokenStorage; + +@interface DelegateObject:NSObject +{ + IosDeviceTokenStorage *m_instance; + IosNotificationReceiver *mNotificationsInstance; +} + +- (id) initWithCPPInstance; + +- (void) setToken:(NSString *)token; + +- (void) sendMessage:(NSString *)pServer : (NSString *)pRid : (NSString *)pName : (NSString *)pType; + +- (void) openChannelByName:(NSString *)channelName; + +@end + diff --git a/fairchat/ios/src/DelegateClass.mm b/fairchat/ios/src/DelegateClass.mm new file mode 100755 index 0000000000000000000000000000000000000000..9e04a12ab22d89a755509015e7017f10b38c56db --- /dev/null +++ b/fairchat/ios/src/DelegateClass.mm @@ -0,0 +1,40 @@ +#include "iosdevicetokenstorage.h" +#include "iosnotificationreceiver.h" +#import +#import "DelegateClass.h" + + +@implementation DelegateObject + +-(id) initWithCPPInstance{ + if(self){ + m_instance = IosDeviceTokenStorage::getInstance(); + mNotificationsInstance = IosNotificationReceiver::getInstance(); + } + return self; +} + +-(void) setToken:(NSString*) token{ + m_instance->setToken([token UTF8String]); +} + +- (void) sendMessage:(NSString *)pServer : (NSString *)pRid : (NSString *)pName : (NSString *)pType{ + if(pServer!=NULL && pRid != NULL && pName !=NULL && pType!=NULL){ + QString server([pServer UTF8String]); + QString rid([pRid UTF8String]); + QString name([pName UTF8String]); + QString type([pType UTF8String]); + mNotificationsInstance->sendMessageReceived(server,rid,name,type); + } +} + +- (void) openChannelByName:(NSString *)channelName{ + if(channelName != NULL){ + QString channelNameString([channelName UTF8String]); + mNotificationsInstance->sendSwitchChannelByName(channelNameString); + + } +} + + +@end diff --git a/fairchat/ios/src/FileHandlerActivity.h b/fairchat/ios/src/FileHandlerActivity.h new file mode 100755 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/fairchat/ios/src/FileHandlerActivity.mm b/fairchat/ios/src/FileHandlerActivity.mm new file mode 100755 index 0000000000000000000000000000000000000000..4fb420d2db1df9371cab74f9f4d65fe3092c7836 --- /dev/null +++ b/fairchat/ios/src/FileHandlerActivity.mm @@ -0,0 +1,11 @@ +#import "FileHandlerActivity.h" +#include + +@implementation FileHandlerActivity + +-(void) callFileActiviy:(std::string)path{ + + +} + +@end \ No newline at end of file diff --git a/fairchat/ios/src/IosBadges.h b/fairchat/ios/src/IosBadges.h new file mode 100644 index 0000000000000000000000000000000000000000..d9286f38705c855076a1e6716a9e89ea3a3fbaf0 --- /dev/null +++ b/fairchat/ios/src/IosBadges.h @@ -0,0 +1,23 @@ +// +// IosBadges.h +// ucom +// +// Created by armin on 26/06/2017. +// +// + +#ifndef IosBadges_h +#define IosBadges_h + +class IosBadges{ +public: + IosBadges()= delete; + ~IosBadges() = delete; + + static void setBadges(int number); + + +}; + + +#endif /* IosBadges_h */ diff --git a/fairchat/ios/src/IosBadges.mm b/fairchat/ios/src/IosBadges.mm new file mode 100644 index 0000000000000000000000000000000000000000..a0efa404b71be208940ac6ea139a32b1f395af26 --- /dev/null +++ b/fairchat/ios/src/IosBadges.mm @@ -0,0 +1,16 @@ +// +// IosBadges.cpp +// ucom +// +// Created by armin on 26/06/2017. +// +// + +#include "IosBadges.h" +#import +#import + +void IosBadges::setBadges(int number){ + [UIApplication sharedApplication].applicationIconBadgeNumber = number; + [[UIApplication sharedApplication] cancelAllLocalNotifications]; +} diff --git a/fairchat/ios/src/IosGalleryPicker.h b/fairchat/ios/src/IosGalleryPicker.h new file mode 100644 index 0000000000000000000000000000000000000000..618a4b022433b283de7711644b675548c913f0ed --- /dev/null +++ b/fairchat/ios/src/IosGalleryPicker.h @@ -0,0 +1,38 @@ +// +// IosGalleryPicker.h +// ucom +// +// Created by armin on 08/03/17. +// +// + +#ifndef IosGalleryPicker_h +#define IosGalleryPicker_h + +#include +#include + +class IosGalleryPicker:public QObject +{ +Q_OBJECT + +public: + explicit IosGalleryPicker(); + + QString imagePath(){ + return mImagePath; + } + + void open(); + + void receiveFile(QString pFileUrl); + +private: + QString mImagePath; + void *mDelegate; + +signals: + void filePicked(QString fileUrl); +}; + +#endif /* IosGalleryPicker_h */ diff --git a/fairchat/ios/src/IosGalleryPicker.mm b/fairchat/ios/src/IosGalleryPicker.mm new file mode 100644 index 0000000000000000000000000000000000000000..fa80a5c5075792741b917bd9988c548e7e493d45 --- /dev/null +++ b/fairchat/ios/src/IosGalleryPicker.mm @@ -0,0 +1,76 @@ +// +// IosGalleryPicker.m +// ucom +// +// Created by armin on 08/03/17. +// +// + +#import +#import +#include +#include +#include +#include +#include "ios/IosGalleryPicker.h" + + +@interface IosGalleryPickerDelegate : NSObject{ + IosGalleryPicker *mIosPicker; +} + +@end + +@implementation IosGalleryPickerDelegate + +-(id) initWithIosGallery:(IosGalleryPicker *)iosPicker{ + self = [super init]; + if (self){ + mIosPicker = iosPicker; + } + return self; +} + +- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info +{ + + UIImage *orig = [info valueForKey:UIImagePickerControllerOriginalImage]; + NSData *imgData = UIImagePNGRepresentation(orig); + QByteArray qImgData = QByteArray::fromNSData(imgData); + QMimeDatabase mimeDb; + QMimeType mimeType = mimeDb.mimeTypeForData(qImgData); + QString path = QStandardPaths::writableLocation( QStandardPaths::DocumentsLocation ); + path += "/picker."+mimeType.preferredSuffix(); + QFile destFile(path); + destFile.open(QFile::WriteOnly); + destFile.write(qImgData); + + mIosPicker->receiveFile(path); + [picker dismissViewControllerAnimated:YES completion:NULL]; + [picker release]; + +} +@end + +IosGalleryPicker::IosGalleryPicker(): +mDelegate([[IosGalleryPickerDelegate alloc] initWithIosGallery:this]) +{ +} + +void IosGalleryPicker::receiveFile(QString pFileUrl){ + emit filePicked(pFileUrl); +} + + +void IosGalleryPicker::open() +{ + UIViewController *qtController = [[UIApplication sharedApplication].keyWindow rootViewController]; + + UIImagePickerController *imageController = [[UIImagePickerController alloc] init]; + [imageController setSourceType:UIImagePickerControllerSourceTypeSavedPhotosAlbum]; + [imageController setDelegate:id(mDelegate)]; + [imageController setAllowsEditing:YES]; + + + [qtController presentViewController:imageController animated:YES completion:NULL]; +} diff --git a/fairchat/ios/src/QIOSApplicationDelegate+PushDelegate.h b/fairchat/ios/src/QIOSApplicationDelegate+PushDelegate.h new file mode 100755 index 0000000000000000000000000000000000000000..832e1e55cbe75aef6e98a358d8974af868a06217 --- /dev/null +++ b/fairchat/ios/src/QIOSApplicationDelegate+PushDelegate.h @@ -0,0 +1,10 @@ +#import +#import + + +@interface QIOSApplicationDelegate : UIResponder +@end + +@interface QIOSApplicationDelegate (PushDelegate) +@end + diff --git a/fairchat/ios/src/QIOSApplicationDelegate+PushDelegate.mm b/fairchat/ios/src/QIOSApplicationDelegate+PushDelegate.mm new file mode 100755 index 0000000000000000000000000000000000000000..8c3da35cb94214ae96657f457927e8eae00d7b5d --- /dev/null +++ b/fairchat/ios/src/QIOSApplicationDelegate+PushDelegate.mm @@ -0,0 +1,171 @@ +#import "QIOSApplicationDelegate+PushDelegate.h" +#import + +#import "notifications/ios/DelegateClass.h" +#include "shareheplersingelton.h" +#include "notifications/ios/applepushnotifications.h" + + +#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) +#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending) + +@implementation QIOSApplicationDelegate (PushDelegate) + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + + + UIColor *color = [UIColor colorWithRed:0.486 green:0.717 blue:0.454 alpha:1 ]; + UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"]; + + if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) { + statusBar.backgroundColor = color; + } + + if( SYSTEM_VERSION_LESS_THAN( @"9.0" ) ){ + if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) + { + // for iOS 8 + [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; + [application registerForRemoteNotifications]; + }else{ + UIUserNotificationType myTypes = UIUserNotificationTypeBadge|UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound; + [application registerForRemoteNotificationTypes:myTypes]; + } + + }else if( SYSTEM_VERSION_LESS_THAN( @"10.0" ) ) + { + [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; + [[UIApplication sharedApplication] registerForRemoteNotifications]; + + if( launchOptions != nil ) + { + NSLog( @"registerForPushWithOptions:" ); + } + } + else + { + UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; + center.delegate = self; + [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error) + { + if( !error ) + { + [[UIApplication sharedApplication] registerForRemoteNotifications]; // required to get the app to do anything at all about push notifications + NSLog( @"Push registration success." ); + } + else + { + NSLog( @"Push registration FAILED" ); + NSLog( @"ERROR: %@ - %@", error.localizedFailureReason, error.localizedDescription ); + NSLog( @"SUGGESTIONS: %@ - %@", error.localizedRecoveryOptions, error.localizedRecoverySuggestion ); + } + }]; + } + + + volatile NSDictionary *remoteNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; + if(remoteNotif){ + NSLog(@"%@",remoteNotif); + } + + if([launchOptions objectForKey:UIApplicationLaunchOptionsURLKey]){ + NSURL *fileUrl = [launchOptions valueForKey:UIApplicationLaunchOptionsURLKey]; + NSString *fileStr = [fileUrl absoluteString]; + //QString qFileStr = QString::fromStdString([fileStr UTF8String]); + ShareHelperSingelton *instance = ShareHelperSingelton::getInstance(); + + instance->setPath([fileStr UTF8String]); + } + if([launchOptions objectForKey:UIApplicationLaunchOptionsUserActivityDictionaryKey]){ + NSDictionary *optionsDict = [launchOptions valueForKey:UIApplicationLaunchOptionsUserActivityDictionaryKey]; + [optionsDict enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) { + if ([obj isKindOfClass:[NSUserActivity class]]) { + NSUserActivity *userActivity = obj; + NSURL *url = userActivity.webpageURL; + if([url.pathComponents containsObject:@"direct"]||[url.pathComponents containsObject:@"channel"]||[url.pathComponents containsObject:@"group"]){ + NSArray *pathComponents = [url pathComponents]; + NSString *channel = pathComponents[pathComponents.count-1]; + NSLog(@"%@",channel); + DelegateObject *delegateObject = [[DelegateObject alloc] init]; + [delegateObject initWithCPPInstance]; + + [delegateObject openChannelByName:channel ]; + + + } + + } + }]; } + + + return YES; +} + +-(void)application:(UIApplication*)application didRegisterUserNotificationSettings:( UIUserNotificationSettings *)notificationSettings{ + [application registerForRemoteNotifications]; +} + + +- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken +{ + NSLog(@"My token is: %@", deviceToken); + NSString * deviceTokenString = [[[[deviceToken description] stringByReplacingOccurrencesOfString: @"<" withString: @""] stringByReplacingOccurrencesOfString: @">" withString: @""] stringByReplacingOccurrencesOfString: @" " withString: @""]; + NSLog(@"the generated device token string is : %@",deviceTokenString); + DelegateObject *delegateObject = [[DelegateObject alloc] init]; + [delegateObject initWithCPPInstance]; + [delegateObject setToken:deviceTokenString]; + +} +- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error +{ + NSLog(@"Failed to get token, error: %@", error); +} + +- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{ + +} + +- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{ + + + DelegateObject *delegateObject = [[DelegateObject alloc] init]; + [delegateObject initWithCPPInstance]; + + NSString *ejson = [userInfo valueForKey:@"ejson"]; + NSData *jsonData = [ejson dataUsingEncoding:NSUTF8StringEncoding]; + NSMutableDictionary *apns = [userInfo valueForKey:@"apns"]; + NSMutableDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:nil]; + NSMutableDictionary *sender = [dict valueForKey:@"sender"]; + NSLog(@"%@",sender); + NSString *username = [sender valueForKey:@"username"]; + NSString *name = [dict valueForKey:@"name"]; + if([[dict valueForKey:@"name"] isEqual:[NSNull null]]){ + name = username; + } + NSLog(@"%@",name); + NSString *server = [dict valueForKey:@"rid"]; + NSString *type = [dict objectForKey:@"type"]; + NSString *rid = [dict valueForKey:@"rid"]; + application.applicationIconBadgeNumber = 0; + if(server!=nil&&rid!=nil&&name!=nil&&type!=nil){ + [delegateObject sendMessage:server :rid :name :type ]; + } +} + +- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray * _Nullable))restorationHandler{ + NSURL *url = userActivity.webpageURL; + if([url.pathComponents containsObject:@"direct"]||[url.pathComponents containsObject:@"channel"]||[url.pathComponents containsObject:@"group"]){ + NSArray *pathComponents = [url pathComponents]; + NSString *channel = pathComponents[pathComponents.count-1]; + NSLog(@"%@",channel); + DelegateObject *delegateObject = [[DelegateObject alloc] init]; + [delegateObject initWithCPPInstance]; + + [delegateObject openChannelByName:channel ]; + + + } + return true; +} + +@end diff --git a/fairchat/ios/src/applepushnotifications.cpp b/fairchat/ios/src/applepushnotifications.cpp new file mode 100755 index 0000000000000000000000000000000000000000..28ff1d3c0015c831193afb0234df640dd54a19f5 --- /dev/null +++ b/fairchat/ios/src/applepushnotifications.cpp @@ -0,0 +1,40 @@ +#include "applepushnotifications.h" +#include + +ApplePushNotifications::ApplePushNotifications() +{ + mInstance = IosDeviceTokenStorage::getInstance(); + mNotificationInstance = IosNotificationReceiver::getInstance(); + connect(mInstance, &IosDeviceTokenStorage::tokenReceived, this, &ApplePushNotifications::receiveToken); + connect(mNotificationInstance, &IosNotificationReceiver::messageReceived, this, &ApplePushNotifications::receiveMessage); + connect(mNotificationInstance, &IosNotificationReceiver::switchChannelByName, this, &ApplePushNotifications::onSwitchRequest); +} + +void ApplePushNotifications::receiveMessage(QString pServer, QString pRid, QString pName, QString pType) +{ + emit messageReceived(pServer,pRid,pName,pType); +} + +void ApplePushNotifications::receiveToken(){ + qDebug()<<"token received"; + QString newToken = mInstance->getToken(); + if (newToken != ""){ + mToken = newToken; + emit tokenReceived(newToken); + } +} + +void ApplePushNotifications::registerWithService(){ + if(mInstance->getToken() != ""){ + receiveToken(); + } +} + +void ApplePushNotifications::checkForPendingMessages(){ + emit switchChannelByName(mRoomName); +} + +void ApplePushNotifications::onSwitchRequest(QString pName){ + mRoomName = pName; + emit switchChannelByName(pName); +} diff --git a/fairchat/ios/src/applepushnotifications.h b/fairchat/ios/src/applepushnotifications.h new file mode 100755 index 0000000000000000000000000000000000000000..46c161d17eb29d00b6ee403836a8f1aa88ae55c9 --- /dev/null +++ b/fairchat/ios/src/applepushnotifications.h @@ -0,0 +1,26 @@ +#ifndef APPLEPUSHNOTIFICATIONS_H +#define APPLEPUSHNOTIFICATIONS_H +#include "notifications/notificationabstract.h" +#include "iosdevicetokenstorage.h" +#include "iosnotificationreceiver.h" + +class ApplePushNotifications:public NotificationAbstract +{ +public: + virtual void registerWithService(); + ApplePushNotifications(); + void receiveMessage(QString server, QString rid, QString name, QString type); + + void checkForPendingMessages(); + + void onSwitchRequest(QString pName); +protected: + void receiveToken(); + + IosDeviceTokenStorage* mInstance = nullptr; + IosNotificationReceiver* mNotificationInstance = nullptr; + + QString mRoomName; +}; + +#endif // APPLEPUSHNOTIFICATIONS_H diff --git a/fairchat/ios/src/fileopener.h b/fairchat/ios/src/fileopener.h new file mode 100755 index 0000000000000000000000000000000000000000..9f6195dc8a188fc7d3c04923d21e6a3a337f1664 --- /dev/null +++ b/fairchat/ios/src/fileopener.h @@ -0,0 +1,16 @@ +#ifndef FILEOPENER_H +#define FILEOPENER_H + +#include + +class FileOpener : public QObject +{ + Q_OBJECT +public: + static void callFileOpenDialog(QString path); +private: + explicit FileOpener(QObject *parent = 0); + +}; + +#endif // FILEOPENER_H diff --git a/fairchat/ios/src/fileopener.mm b/fairchat/ios/src/fileopener.mm new file mode 100755 index 0000000000000000000000000000000000000000..e55b8f0210f3b8b85c542f854de93d8bf1f16cc3 --- /dev/null +++ b/fairchat/ios/src/fileopener.mm @@ -0,0 +1,37 @@ +#include "fileopener.h" +#import +#import +#include + +void FileOpener::callFileOpenDialog(QString path) +{ + path = path.right(path.length()-7); + QStringList pathParts = path.split("/"); + std::string fileName = pathParts.last().toStdString(); + std::string fullPath = path.toStdString(); + + NSString *completePath = [NSString stringWithUTF8String:fullPath.c_str()]; + NSString *activityItemName = [NSString stringWithUTF8String:fileName.c_str()]; + + NSData* data = [NSData dataWithContentsOfFile:completePath]; + if (data != nil){ + UIActivityViewController* activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[activityItemName, data] applicationActivities:nil]; + + activityViewController.excludedActivityTypes = nil; + + UIApplication * application = [UIApplication sharedApplication]; + + UIWindow *window = [application keyWindow]; + + UIViewController *viewController = [window rootViewController]; + + [viewController presentViewController:activityViewController animated:false completion:nil]; + + [activityViewController release]; + } +} + +FileOpener::FileOpener(QObject *parent) : QObject(parent) +{ + +} diff --git a/fairchat/ios/src/iosdevicetokenstorage.cpp b/fairchat/ios/src/iosdevicetokenstorage.cpp new file mode 100755 index 0000000000000000000000000000000000000000..6939f36f635630000bcc3444ead437e465b42b1e --- /dev/null +++ b/fairchat/ios/src/iosdevicetokenstorage.cpp @@ -0,0 +1,19 @@ +#include "iosdevicetokenstorage.h" + +IosDeviceTokenStorage* IosDeviceTokenStorage::mInstance = nullptr; + +IosDeviceTokenStorage* IosDeviceTokenStorage::getInstance(){ + if(mInstance == nullptr){ + mInstance = new IosDeviceTokenStorage; + } + return mInstance; +} + +void IosDeviceTokenStorage::setToken(QString stdToken){ + mToken = stdToken; + emit tokenReceived(); +} + +QString IosDeviceTokenStorage::getToken(){ + return mToken; +} diff --git a/fairchat/ios/src/iosdevicetokenstorage.h b/fairchat/ios/src/iosdevicetokenstorage.h new file mode 100755 index 0000000000000000000000000000000000000000..fa88f4055cf551e3d7ee54794a840e8061d9f3a5 --- /dev/null +++ b/fairchat/ios/src/iosdevicetokenstorage.h @@ -0,0 +1,28 @@ +#ifndef IOSDEVICETOKENSTORAGE_H +#define IOSDEVICETOKENSTORAGE_H + +#include +#include + +class IosDeviceTokenStorage: public QObject +{ + Q_OBJECT +public: + static IosDeviceTokenStorage* getInstance(); + + QString getToken(); + void setToken(QString mToken); + +private: + IosDeviceTokenStorage(){} + IosDeviceTokenStorage(const IosDeviceTokenStorage&) = delete; + + static IosDeviceTokenStorage* mInstance; + + QString mToken = ""; + +signals: + void tokenReceived(); +}; + +#endif // IOSDEVICETOKENSTORAGE_H diff --git a/fairchat/ios/src/ioshelper.cpp b/fairchat/ios/src/ioshelper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..890a2247eb127039255f1130800d92eee7b817b8 --- /dev/null +++ b/fairchat/ios/src/ioshelper.cpp @@ -0,0 +1,52 @@ +#include "ioshelper.h" + +IosHelper::IosHelper(QObject *parent) : QObject(parent) +{ + mShareHelper = ShareHelperSingelton::getInstance(); + mGalleryPicker = new IosGalleryPicker(); + + connect( mShareHelper, &ShareHelperSingelton::shareLinkReceived, this, &IosHelper::shareLinkReceived, Qt::UniqueConnection ); + connect( mGalleryPicker, &IosGalleryPicker::filePicked, this, &IosHelper::filePicked, Qt::UniqueConnection ); + connect( &mNotificationsObject, &Notifications::tokenReceived, this, &IosHelper::pushTokenReceived, Qt::UniqueConnection ); + connect( &mNotificationsObject, &Notifications::messageReceived, this, &IosHelper::pushMessageReceived, Qt::UniqueConnection ); + +} + +IosHelper::~IosHelper() +{ + mShareHelper->deleteLater(); + mGalleryPicker->deleteLater(); +} + +void IosHelper::checkForpendingNotification() +{ + mNotificationsObject.checkForPendingMessages(); +} + +void IosHelper::checkForFileLink() +{ + QString path = mShareHelper->getPath(); + if(!path.isEmpty()){ + emit shareLinkReceived(path); + } +} + +void IosHelper::openFileDialog(QString pPath) +{ + FileOpener::callFileOpenDialog( pPath ); +} + +void IosHelper::openGalleryPicker() +{ + mGalleryPicker->open(); +} + +void IosHelper::registerForPush() +{ + mNotificationsObject.registerWithService(); +} + +void IosHelper::setBadgeNumber(int pNumber) +{ + IosBadges::setBadges( pNumber ); +} diff --git a/fairchat/ios/src/ioshelper.h b/fairchat/ios/src/ioshelper.h new file mode 100644 index 0000000000000000000000000000000000000000..e9e78dda064dec55eefae1af3f87cfd767be455e --- /dev/null +++ b/fairchat/ios/src/ioshelper.h @@ -0,0 +1,41 @@ +#ifndef IOSHELPER_H +#define IOSHELPER_H + +#include + +#include "ios/fileopener.h" +#include "ios/urlhandler.h" +#include "ios/IosGalleryPicker.h" +#include "ios/shareheplersingelton.h" +#include "ios/IosBadges.h" + +#include "notifications/notifications.h" + + +class IosHelper : public QObject +{ + Q_OBJECT +public: + explicit IosHelper(QObject *parent = nullptr); + + ~IosHelper(); +protected: + IosGalleryPicker *mGalleryPicker = nullptr; + ShareHelperSingelton *mShareHelper = nullptr; + Notifications mNotificationsObject; + +signals: + void filePicked(QString pFile); + void shareLinkReceived(QString pLink); + void pushTokenReceived(QString pToken); + void pushMessageReceived(QString pServer, QString pRid, QString pName, QString pType); +public slots: + void checkForpendingNotification(); + void checkForFileLink(); + void openFileDialog(QString pPath); + void openGalleryPicker(); + void registerForPush(); + void setBadgeNumber(int pNumber); +}; + +#endif // IOSHELPER_H diff --git a/fairchat/ios/src/iosnotificationreceiver.cpp b/fairchat/ios/src/iosnotificationreceiver.cpp new file mode 100644 index 0000000000000000000000000000000000000000..be90800abb8b72376b232b3ef3fba13f6b54c2be --- /dev/null +++ b/fairchat/ios/src/iosnotificationreceiver.cpp @@ -0,0 +1,20 @@ +#include "iosnotificationreceiver.h" + +IosNotificationReceiver* IosNotificationReceiver::mInstance = nullptr; + +IosNotificationReceiver *IosNotificationReceiver::getInstance() +{ + if(mInstance == nullptr){ + mInstance = new IosNotificationReceiver; + } + return mInstance; +} + +void IosNotificationReceiver::sendMessageReceived(QString pServer, QString pRid, QString pName, QString pType) +{ + emit messageReceived(pServer,pRid,pName,pType); +} + +void IosNotificationReceiver::sendSwitchChannelByName(QString pName){ + emit switchChannelByName(pName); +} diff --git a/fairchat/ios/src/iosnotificationreceiver.h b/fairchat/ios/src/iosnotificationreceiver.h new file mode 100644 index 0000000000000000000000000000000000000000..e0e65f99422b1b4e40325922cda3de394779771a --- /dev/null +++ b/fairchat/ios/src/iosnotificationreceiver.h @@ -0,0 +1,27 @@ +#ifndef IOSNOTIFICATIONRECEIVER_H +#define IOSNOTIFICATIONRECEIVER_H + +#include + +class IosNotificationReceiver : public QObject +{ + Q_OBJECT +public: + static IosNotificationReceiver* getInstance(); + + void sendMessageReceived(QString pServer, QString pRid, QString pName, QString pType); + void sendSwitchChannelByName(QString pName); + +private: + IosNotificationReceiver(){} + IosNotificationReceiver(const IosNotificationReceiver&) = delete; + + static IosNotificationReceiver* mInstance; + + +signals: + void messageReceived(QString pServer, QString pRid, QString pName, QString pType); + void switchChannelByName(QString channelName); +}; + +#endif // IOSNOTIFICATIONRECEIVER_H diff --git a/fairchat/ios/src/shareheplersingelton.h b/fairchat/ios/src/shareheplersingelton.h new file mode 100644 index 0000000000000000000000000000000000000000..0c7b84b34682756e701a16159394c3185457b875 --- /dev/null +++ b/fairchat/ios/src/shareheplersingelton.h @@ -0,0 +1,31 @@ +#ifndef SHAREHEPLERSINGELTON_H +#define SHAREHEPLERSINGELTON_H + +#include +#include + +class ShareHelperSingelton:public QObject{ + Q_OBJECT + +public: + static ShareHelperSingelton* getInstance(); + + ShareHelperSingelton& operator=(ShareHelperSingelton const &) = delete; + ShareHelperSingelton (ShareHelperSingelton const &) = delete; + + QString getPath(); + void setPath(QString pPath); + +private: + ShareHelperSingelton(){} + static ShareHelperSingelton* mInstance; + QString mCurPath; + +signals: + void shareLinkReceived(QString link); + +}; + + + +#endif // SHAREHEPLERSINGELTON_H diff --git a/fairchat/ios/src/shareheplersingelton.mm b/fairchat/ios/src/shareheplersingelton.mm new file mode 100644 index 0000000000000000000000000000000000000000..6c5d9d9ca1f4a8796fb8d4a99099638925ef8911 --- /dev/null +++ b/fairchat/ios/src/shareheplersingelton.mm @@ -0,0 +1,22 @@ +#include "shareheplersingelton.h" + +ShareHelperSingelton *ShareHelperSingelton::mInstance = nullptr; + +ShareHelperSingelton *ShareHelperSingelton::getInstance() +{ + if(mInstance == nullptr){ + mInstance = new ShareHelperSingelton; + } + return mInstance; +} + +QString ShareHelperSingelton::getPath() +{ + return mCurPath; +} + +void ShareHelperSingelton::setPath(QString pPath) +{ + mCurPath = pPath; + emit shareLinkReceived(pPath); +} diff --git a/fairchat/ios/src/urlhandler.cpp b/fairchat/ios/src/urlhandler.cpp new file mode 100644 index 0000000000000000000000000000000000000000..91eb35bc49d4f63adf17df97b26c29cf5c3ed631 --- /dev/null +++ b/fairchat/ios/src/urlhandler.cpp @@ -0,0 +1,16 @@ +#include "urlhandler.h" +#include + +UrlHandler::UrlHandler(QObject *parent) : QObject(parent) +{ + +} + +void UrlHandler::files(const QUrl &url) +{ + emit openFile(url.toLocalFile()); +} + +UrlHandler::~UrlHandler(){ + +} \ No newline at end of file diff --git a/fairchat/ios/src/urlhandler.h b/fairchat/ios/src/urlhandler.h new file mode 100644 index 0000000000000000000000000000000000000000..71a7c4b05ae464dba1362d502f17800b09e83721 --- /dev/null +++ b/fairchat/ios/src/urlhandler.h @@ -0,0 +1,23 @@ +#ifndef URLHANDLER_H +#define URLHANDLER_H + +#include + +class UrlHandler : public QObject +{ + Q_OBJECT +public: + explicit UrlHandler(QObject *parent = 0); + + + ~UrlHandler(); + +public slots: + void files(const QUrl &url); + + +signals: + void openFile(const QString&); +}; + +#endif // URLHANDLER_H diff --git a/fairchat/main.cpp b/fairchat/main.cpp index 75bf111c6fcdf9dfb21f5d4894a2a7687062dbd7..0970846bc7272506f59c2f87f6105ba287ef3458 100755 --- a/fairchat/main.cpp +++ b/fairchat/main.cpp @@ -13,7 +13,11 @@ #include #include #include -#include +#include +#include +#include + +#include "models/serverchoicemodel.h" #include "CustomModels/channelmodel.h" #include "config.h" @@ -24,13 +28,11 @@ #include "notifications/notifications.h" #include "CustomModels/usermodel.h" #include "CustomModels/messagemodel.h" +#include "CustomModels/loginmethodsmodel.h" #include "utils.h" -#ifdef Q_OS_ANDROID - #include - #include - #include - +#ifdef Q_OS_IOS + #include "ios/src/ioshelper.h" #endif #ifdef Q_OS_WINRT @@ -40,54 +42,37 @@ int main( int argc, char *argv[] ) { - Q_INIT_RESOURCE(sql); + std::srand(static_cast(std::time(0))); QCoreApplication::setAttribute( Qt::AA_EnableHighDpiScaling ); QCoreApplication::setOrganizationName( ORGANIZATION ); QCoreApplication::setOrganizationDomain( ORGANIZATIONDOMAIN ); QCoreApplication::setApplicationName( APPLICATIONNAME ); + QGuiApplication app( argc, argv ); + + QtWebView::initialize(); + + ServerChoiceModel serverChoices; UserModel userModel; ChannelModel channelModel; ChannelModel groupsModel; MessagesModel messageModel; + LoginMethodsModel loginMethodsModel; channelModel.moveToThread(QThread::currentThread()); groupsModel.moveToThread(QThread::currentThread()); userModel.moveToThread(QThread::currentThread()); messageModel.moveToThread(QThread::currentThread()); - qDebug()<<"main thread: "<getSetting("cleanExit"); - if(cleanExit == "false"){ - qCritical()<<"app unclean exit last time"; - - if(storage->getSetting("Error").length()){ - #ifdef Q_OS_ANDROID - QAndroidJniObject errorStringJni = QAndroidJniObject::fromString(storage->getSetting("ERROR")); - - QAndroidJniObject::callStaticMethod("com/osalliance/rocketchatMobile/MainActivity", "catchError","(Ljava/lang/String;)V",errorStringJni.object()); - #endif - } - } - storage->setSetting("cleanExit","false"); - storage->setSetting("ERROR",""); - QString language = QLocale::system().bcp47Name().split("-")[0].toLower(); - qDebug()<<"locale : "<setContextProperty( "rocketChatController", &rocketChat ); -#ifdef QT_DEBUG - context->setContextProperty( "debug", QVariant(true) ); -#else - context->setContextProperty( "debug", QVariant(false) ); -#endif context->setContextProperty("buildTime",QVariant(buildTime)); context->setContextProperty("userModel",&userModel); context->setContextProperty("channelModel",&channelModel); @@ -129,14 +122,19 @@ int main( int argc, char *argv[] ) context->setContextProperty("pathPrefix", Utils::getPathPrefix()); context->setContextProperty("cmessagesModel", &messageModel); context->setContextProperty("serverChoices", &serverChoices); - + context->setContextProperty("loginMethodsModel", &loginMethodsModel); +#ifdef QT_DEBUG + context->setContextProperty( "debug", QVariant(true) ); +#else + context->setContextProperty( "debug", QVariant(false) ); +#endif engine.load( QUrl( QLatin1String( "qrc:/qml/main.qml" ) ) ); try { - result = app.exec(); - storage->setSetting("cleanExit","true"); + app.exec(); } catch (const std::exception &ex) { qCritical()< +#include +#include + +AndroidNotificationReceiver *AndroidNotificationReceiver::mAndroidReceiver = nullptr; + +AndroidNotificationReceiver::AndroidNotificationReceiver():mReceiver(0) +{ + JNINativeMethod methods[]{ + {"handleRegisterId", "(Ljava/lang/String;)V", reinterpret_cast(&AndroidNotificationReceiver::registrationIdHandler)}, + {"handleRegisterError", "(Ljava/lang/String;)V", reinterpret_cast(&AndroidNotificationReceiver::registrationIdHandler)} + }; + + JNINativeMethod messageReceivedMethod[]{ + {"messageReceived", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", reinterpret_cast(&AndroidNotificationReceiver::messageReceived)} + + }; + + + const char *className = "com.osalliance.rocketchatMobile/RegisterTask"; + const char *classNameReceive = "com.osalliance.rocketchatMobile/ReceiveTextMessage"; + + if(QAndroidJniObject::isClassAvailable(className)){ + QAndroidJniObject javaClass(className); + if (javaClass.isValid()){ + QAndroidJniEnvironment env; + jclass objectClass = env->GetObjectClass(javaClass.object()); + env->RegisterNatives(objectClass, + methods, + sizeof(methods) / sizeof(methods[0])); + env->DeleteLocalRef(objectClass); + }else{ + qDebug() << className << "is not valid"; + } + }else{ + qDebug() << className << "is not available"; + } + + if(QAndroidJniObject::isClassAvailable(classNameReceive)){ + QAndroidJniObject javaClass(classNameReceive); + if(javaClass.isValid()){ + QAndroidJniEnvironment env; + jclass objectClass = env->GetObjectClass(javaClass.object()); + env->RegisterNatives(objectClass, + messageReceivedMethod, + sizeof(messageReceivedMethod)/sizeof(messageReceivedMethod[0])); + env->DeleteLocalRef(objectClass); + + }else{ + qDebug() << classNameReceive << "is not valid"; + } + }else{ + qDebug() << classNameReceive << "is not available"; + } +} + +AndroidNotificationReceiver::~AndroidNotificationReceiver(){ + +} + +void AndroidNotificationReceiver::doRegister(GooglePushNotifications* pGooglePushNotifications){ + + qDebug()<<"called register"; + mReceiver = pGooglePushNotifications; + + QAndroidJniObject regIdObject = QAndroidJniObject::callStaticObjectMethod( + "com/osalliance/rocketchatMobile/FcmMessageTokenHandler", + "getToken", + "()Ljava/lang/String;"); + + QString qStr = regIdObject.toString(); + if(!qStr.isEmpty()){ + mAndroidReceiver->mReceiver->setGcmRegistrationId(qStr); + } +} + +AndroidNotificationReceiver *AndroidNotificationReceiver::instance(){ + if(!mAndroidReceiver){ + mAndroidReceiver = new AndroidNotificationReceiver; + } + return mAndroidReceiver; +} + +void AndroidNotificationReceiver::registrationIdHandler(JNIEnv *env, jobject thiz, jstring registrationId){ + Q_UNUSED(thiz) + qDebug()<<"received gcm token"; + const char* nativeString = env->GetStringUTFChars(registrationId, 0); + QString str = QString::fromUtf8(nativeString); + qDebug()<<"regId: "<ReleaseStringUTFChars(registrationId, nativeString); + mAndroidReceiver->mReceiver->setGcmRegistrationId(str); +} + +void AndroidNotificationReceiver::errorHandler(JNIEnv *env, jobject thiz, jstring errorMessage){ + Q_UNUSED(thiz) + const char* nativeString = env->GetStringUTFChars(errorMessage, 0); + qWarning(nativeString); + env->ReleaseStringUTFChars(errorMessage, nativeString); + +} + +void AndroidNotificationReceiver::messageReceived(JNIEnv *env, jobject thiz, jstring server, jstring rid, jstring name, jstring type) +{ + Q_UNUSED(thiz); + const char* ridCpp = env->GetStringUTFChars(rid, 0); + const char* serverCpp = env->GetStringUTFChars(server, 0); + const char* nameCpp = env->GetStringUTFChars(name, 0); + const char* typeCpp = env->GetStringUTFChars(type, 0); + QString ridStr = QString::fromUtf8(ridCpp); + QString serverStr = QString::fromUtf8(serverCpp); + QString nameStr = QString::fromUtf8(nameCpp); + QString typeStr = QString::fromUtf8(typeCpp); + + AndroidNotificationReceiver *androidNotificationReceiver = AndroidNotificationReceiver::instance(); + + if(androidNotificationReceiver->mReceiver != nullptr){ + androidNotificationReceiver->mReceiver->pushMessageReceived(serverStr, ridStr, nameStr, typeStr); + } + qDebug()<<"received push notification in cpp: "< +#include +#include +#include +#include "notifications/android/googlepushnotifications.h" + +class GooglePushNotifications; + +class AndroidNotificationReceiver +{ +public: + AndroidNotificationReceiver(); + ~AndroidNotificationReceiver(); + + void doRegister(GooglePushNotifications* pGooglePushNotifications); + + static AndroidNotificationReceiver *instance(); + static void registrationIdHandler(JNIEnv *env, jobject thiz, jstring errorMessge); + static void errorHandler(JNIEnv *env, jobject thiz, jstring errorMessage); + static void messageReceived(JNIEnv *env, jobject thiz, jstring server, jstring rid, jstring name, jstring type); + + GooglePushNotifications *receiver() const; + void setReceiver(GooglePushNotifications *receiver); + +private: + static AndroidNotificationReceiver *mAndroidReceiver; + + GooglePushNotifications *mReceiver = nullptr; + QString mSenderId; + +}; + +#endif // ANDROIDNOTIFICATIONRECEIVER_H diff --git a/fairchat/notifications/android/googlepushnotifications.cpp b/fairchat/notifications/android/googlepushnotifications.cpp new file mode 100755 index 0000000000000000000000000000000000000000..c8fea8fe775c0ac29d8e0eafc6cf69fd8c499bf9 --- /dev/null +++ b/fairchat/notifications/android/googlepushnotifications.cpp @@ -0,0 +1,59 @@ +#include "googlepushnotifications.h" +#include "androidnotificationreceiver.h" +#include + +GooglePushNotifications::GooglePushNotifications() +{ + mReceiver = AndroidNotificationReceiver::instance(); + mReceiver->setReceiver(this); +} + +//QString GooglePushNotifications::getGcmSenderId() const +//{ +// return mGcmSenderId; +//} + +//void GooglePushNotifications::setGcmSenderId(const QString &pSenderId) +//{ +// if(mGcmSenderId != pSenderId){ +// mGcmSenderId = pSenderId; +// } +//} + +QString GooglePushNotifications::getGcmRegistrationId() const +{ + return mGcmRegistrationId; +} + +void GooglePushNotifications::setGcmRegistrationId(QString pRegistrationId) +{ + if(!pRegistrationId.isEmpty()){ + if(mGcmRegistrationId != pRegistrationId){ + mGcmRegistrationId = pRegistrationId; + emit tokenReceived(pRegistrationId); + } + } +} + +void GooglePushNotifications::pushMessageReceived(QString pServer, QString pRid, QString pName, QString pType) +{ + emit messageReceived(pServer, pRid, pName, pType); +} + +void GooglePushNotifications::init() +{ + // if(!mGcmSenderId.isEmpty()){ + if(mGcmRegistrationId.isEmpty()){ + qDebug()<<"init gcm register called"; + mReceiver->doRegister(this); + } + else{ + + } + // } +} + +void GooglePushNotifications::registerWithService() +{ + init(); +} diff --git a/fairchat/notifications/android/googlepushnotifications.h b/fairchat/notifications/android/googlepushnotifications.h new file mode 100755 index 0000000000000000000000000000000000000000..01df7e3e9f44504f74979ea5379dca3d246055c3 --- /dev/null +++ b/fairchat/notifications/android/googlepushnotifications.h @@ -0,0 +1,33 @@ +#ifndef GOOGLEPUSHNOTIFICATIONS_H +#define GOOGLEPUSHNOTIFICATIONS_H +#include "notifications/notificationabstract.h" +#include "notifications/android/androidnotificationreceiver.h" +#include "config.h" + +class AndroidNotificationReceiver; +class GooglePushNotifications:public NotificationAbstract +{ + Q_OBJECT +public: + GooglePushNotifications(); + +// QString getGcmSenderId() const; +// void setGcmSenderId(const QString &pValue); + + QString getGcmRegistrationId() const; + void setGcmRegistrationId(QString pValue); + + void pushMessageReceived(QString pServer, QString pRid, QString pName, QString pType); + + void init(); + + virtual void registerWithService(); + +private: + // QString mGcmSenderId = GCM_SENDER_ID; + QString mGcmRegistrationId; + AndroidNotificationReceiver* mReceiver; + +}; + +#endif // GOOGLEPUSHNOTIFICATIONS_H diff --git a/fairchat/notifications/ios/DelegateClass.h b/fairchat/notifications/ios/DelegateClass.h new file mode 100755 index 0000000000000000000000000000000000000000..623e49103b0a99b74878a100e9ea3381c5e5fad9 --- /dev/null +++ b/fairchat/notifications/ios/DelegateClass.h @@ -0,0 +1,21 @@ +#include "iosdevicetokenstorage.h" +#include "iosnotificationreceiver.h" + +class IosDeviceTokenStorage; + +@interface DelegateObject:NSObject +{ + IosDeviceTokenStorage *m_instance; + IosNotificationReceiver *mNotificationsInstance; +} + +- (id) initWithCPPInstance; + +- (void) setToken:(NSString *)token; + +- (void) sendMessage:(NSString *)pServer : (NSString *)pRid : (NSString *)pName : (NSString *)pType; + +- (void) openChannelByName:(NSString *)channelName; + +@end + diff --git a/fairchat/notifications/ios/DelegateClass.mm b/fairchat/notifications/ios/DelegateClass.mm new file mode 100755 index 0000000000000000000000000000000000000000..9e04a12ab22d89a755509015e7017f10b38c56db --- /dev/null +++ b/fairchat/notifications/ios/DelegateClass.mm @@ -0,0 +1,40 @@ +#include "iosdevicetokenstorage.h" +#include "iosnotificationreceiver.h" +#import +#import "DelegateClass.h" + + +@implementation DelegateObject + +-(id) initWithCPPInstance{ + if(self){ + m_instance = IosDeviceTokenStorage::getInstance(); + mNotificationsInstance = IosNotificationReceiver::getInstance(); + } + return self; +} + +-(void) setToken:(NSString*) token{ + m_instance->setToken([token UTF8String]); +} + +- (void) sendMessage:(NSString *)pServer : (NSString *)pRid : (NSString *)pName : (NSString *)pType{ + if(pServer!=NULL && pRid != NULL && pName !=NULL && pType!=NULL){ + QString server([pServer UTF8String]); + QString rid([pRid UTF8String]); + QString name([pName UTF8String]); + QString type([pType UTF8String]); + mNotificationsInstance->sendMessageReceived(server,rid,name,type); + } +} + +- (void) openChannelByName:(NSString *)channelName{ + if(channelName != NULL){ + QString channelNameString([channelName UTF8String]); + mNotificationsInstance->sendSwitchChannelByName(channelNameString); + + } +} + + +@end diff --git a/fairchat/notifications/ios/applepushnotifications.cpp b/fairchat/notifications/ios/applepushnotifications.cpp new file mode 100755 index 0000000000000000000000000000000000000000..28ff1d3c0015c831193afb0234df640dd54a19f5 --- /dev/null +++ b/fairchat/notifications/ios/applepushnotifications.cpp @@ -0,0 +1,40 @@ +#include "applepushnotifications.h" +#include + +ApplePushNotifications::ApplePushNotifications() +{ + mInstance = IosDeviceTokenStorage::getInstance(); + mNotificationInstance = IosNotificationReceiver::getInstance(); + connect(mInstance, &IosDeviceTokenStorage::tokenReceived, this, &ApplePushNotifications::receiveToken); + connect(mNotificationInstance, &IosNotificationReceiver::messageReceived, this, &ApplePushNotifications::receiveMessage); + connect(mNotificationInstance, &IosNotificationReceiver::switchChannelByName, this, &ApplePushNotifications::onSwitchRequest); +} + +void ApplePushNotifications::receiveMessage(QString pServer, QString pRid, QString pName, QString pType) +{ + emit messageReceived(pServer,pRid,pName,pType); +} + +void ApplePushNotifications::receiveToken(){ + qDebug()<<"token received"; + QString newToken = mInstance->getToken(); + if (newToken != ""){ + mToken = newToken; + emit tokenReceived(newToken); + } +} + +void ApplePushNotifications::registerWithService(){ + if(mInstance->getToken() != ""){ + receiveToken(); + } +} + +void ApplePushNotifications::checkForPendingMessages(){ + emit switchChannelByName(mRoomName); +} + +void ApplePushNotifications::onSwitchRequest(QString pName){ + mRoomName = pName; + emit switchChannelByName(pName); +} diff --git a/fairchat/notifications/ios/applepushnotifications.h b/fairchat/notifications/ios/applepushnotifications.h new file mode 100755 index 0000000000000000000000000000000000000000..46c161d17eb29d00b6ee403836a8f1aa88ae55c9 --- /dev/null +++ b/fairchat/notifications/ios/applepushnotifications.h @@ -0,0 +1,26 @@ +#ifndef APPLEPUSHNOTIFICATIONS_H +#define APPLEPUSHNOTIFICATIONS_H +#include "notifications/notificationabstract.h" +#include "iosdevicetokenstorage.h" +#include "iosnotificationreceiver.h" + +class ApplePushNotifications:public NotificationAbstract +{ +public: + virtual void registerWithService(); + ApplePushNotifications(); + void receiveMessage(QString server, QString rid, QString name, QString type); + + void checkForPendingMessages(); + + void onSwitchRequest(QString pName); +protected: + void receiveToken(); + + IosDeviceTokenStorage* mInstance = nullptr; + IosNotificationReceiver* mNotificationInstance = nullptr; + + QString mRoomName; +}; + +#endif // APPLEPUSHNOTIFICATIONS_H diff --git a/fairchat/notifications/ios/iosdevicetokenstorage.cpp b/fairchat/notifications/ios/iosdevicetokenstorage.cpp new file mode 100755 index 0000000000000000000000000000000000000000..6939f36f635630000bcc3444ead437e465b42b1e --- /dev/null +++ b/fairchat/notifications/ios/iosdevicetokenstorage.cpp @@ -0,0 +1,19 @@ +#include "iosdevicetokenstorage.h" + +IosDeviceTokenStorage* IosDeviceTokenStorage::mInstance = nullptr; + +IosDeviceTokenStorage* IosDeviceTokenStorage::getInstance(){ + if(mInstance == nullptr){ + mInstance = new IosDeviceTokenStorage; + } + return mInstance; +} + +void IosDeviceTokenStorage::setToken(QString stdToken){ + mToken = stdToken; + emit tokenReceived(); +} + +QString IosDeviceTokenStorage::getToken(){ + return mToken; +} diff --git a/fairchat/notifications/ios/iosdevicetokenstorage.h b/fairchat/notifications/ios/iosdevicetokenstorage.h new file mode 100755 index 0000000000000000000000000000000000000000..fa88f4055cf551e3d7ee54794a840e8061d9f3a5 --- /dev/null +++ b/fairchat/notifications/ios/iosdevicetokenstorage.h @@ -0,0 +1,28 @@ +#ifndef IOSDEVICETOKENSTORAGE_H +#define IOSDEVICETOKENSTORAGE_H + +#include +#include + +class IosDeviceTokenStorage: public QObject +{ + Q_OBJECT +public: + static IosDeviceTokenStorage* getInstance(); + + QString getToken(); + void setToken(QString mToken); + +private: + IosDeviceTokenStorage(){} + IosDeviceTokenStorage(const IosDeviceTokenStorage&) = delete; + + static IosDeviceTokenStorage* mInstance; + + QString mToken = ""; + +signals: + void tokenReceived(); +}; + +#endif // IOSDEVICETOKENSTORAGE_H diff --git a/fairchat/notifications/ios/iosnotificationreceiver.cpp b/fairchat/notifications/ios/iosnotificationreceiver.cpp new file mode 100644 index 0000000000000000000000000000000000000000..be90800abb8b72376b232b3ef3fba13f6b54c2be --- /dev/null +++ b/fairchat/notifications/ios/iosnotificationreceiver.cpp @@ -0,0 +1,20 @@ +#include "iosnotificationreceiver.h" + +IosNotificationReceiver* IosNotificationReceiver::mInstance = nullptr; + +IosNotificationReceiver *IosNotificationReceiver::getInstance() +{ + if(mInstance == nullptr){ + mInstance = new IosNotificationReceiver; + } + return mInstance; +} + +void IosNotificationReceiver::sendMessageReceived(QString pServer, QString pRid, QString pName, QString pType) +{ + emit messageReceived(pServer,pRid,pName,pType); +} + +void IosNotificationReceiver::sendSwitchChannelByName(QString pName){ + emit switchChannelByName(pName); +} diff --git a/fairchat/notifications/ios/iosnotificationreceiver.h b/fairchat/notifications/ios/iosnotificationreceiver.h new file mode 100644 index 0000000000000000000000000000000000000000..e0e65f99422b1b4e40325922cda3de394779771a --- /dev/null +++ b/fairchat/notifications/ios/iosnotificationreceiver.h @@ -0,0 +1,27 @@ +#ifndef IOSNOTIFICATIONRECEIVER_H +#define IOSNOTIFICATIONRECEIVER_H + +#include + +class IosNotificationReceiver : public QObject +{ + Q_OBJECT +public: + static IosNotificationReceiver* getInstance(); + + void sendMessageReceived(QString pServer, QString pRid, QString pName, QString pType); + void sendSwitchChannelByName(QString pName); + +private: + IosNotificationReceiver(){} + IosNotificationReceiver(const IosNotificationReceiver&) = delete; + + static IosNotificationReceiver* mInstance; + + +signals: + void messageReceived(QString pServer, QString pRid, QString pName, QString pType); + void switchChannelByName(QString channelName); +}; + +#endif // IOSNOTIFICATIONRECEIVER_H diff --git a/fairchat/notifications/notificationabstract.cpp b/fairchat/notifications/notificationabstract.cpp new file mode 100755 index 0000000000000000000000000000000000000000..be10be907d1066117c4ad948e7d7e819af9d73ac --- /dev/null +++ b/fairchat/notifications/notificationabstract.cpp @@ -0,0 +1,16 @@ +#include "notificationabstract.h" + +NotificationAbstract::NotificationAbstract() +{ + +} + +QString NotificationAbstract::getToken() const +{ + return mToken; +} + +void NotificationAbstract::setToken(const QString &pValue) +{ + mToken = pValue; +} diff --git a/fairchat/notifications/notificationabstract.h b/fairchat/notifications/notificationabstract.h new file mode 100755 index 0000000000000000000000000000000000000000..0635093db0b1f5c97c770041ab7dac37be58e953 --- /dev/null +++ b/fairchat/notifications/notificationabstract.h @@ -0,0 +1,31 @@ +#ifndef NOTIFICATIONABSTRACT_H +#define NOTIFICATIONABSTRACT_H + +#include + +class NotificationAbstract : public QObject +{ + Q_OBJECT +public: + NotificationAbstract(); + + virtual void registerWithService() = 0; + + + + QString getToken() const; + void setToken(const QString &pValue); + + virtual void checkForPendingMessages() = 0; + +protected: + QString mToken; + +signals: + void tokenReceived(QString pToken); + void messageReceived(QString pServer, QString pRid, QString pName, QString pType); + void switchChannelByName(QString pChannel); + +}; + +#endif // NOTIFICATIONABSTRACT_H diff --git a/fairchat/notifications/notifications.cpp b/fairchat/notifications/notifications.cpp new file mode 100755 index 0000000000000000000000000000000000000000..a8c07dc7c4a4d9815a43a7479f9c9888b8f73119 --- /dev/null +++ b/fairchat/notifications/notifications.cpp @@ -0,0 +1,39 @@ +#include "notifications.h" +#ifdef Q_OS_ANDROID +#include "notifications/android/googlepushnotifications.h" +#endif +#ifdef Q_OS_IOS +#include "notifications/ios/ApplePushNotifications.h" +#endif +#include "QDebug" + +Notifications::Notifications() +{ +#ifdef Q_OS_ANDROID + mNotificationInstance = new GooglePushNotifications; +#endif +#ifdef Q_OS_IOS + mNotificationInstance = new ApplePushNotifications; +#endif +#ifdef Q_OS_WINRT + +#endif + + if(mNotificationInstance != nullptr){ + connect(mNotificationInstance,&Notifications::tokenReceived,this, &Notifications::tokenReceived); + connect(mNotificationInstance,&Notifications::messageReceived,this, &Notifications::messageReceived); + connect(mNotificationInstance,&Notifications::switchChannelByName,this, &Notifications::switchChannelByName); + } +} + +void Notifications::registerWithService() +{ + if(mNotificationInstance){ + qDebug()<<"register with service Notifications called"; + mNotificationInstance->registerWithService(); + } +} + +void Notifications::checkForPendingMessages(){ + mNotificationInstance->checkForPendingMessages(); +} diff --git a/fairchat/notifications/notifications.h b/fairchat/notifications/notifications.h new file mode 100755 index 0000000000000000000000000000000000000000..f83832ae2e167a977839a1f4a30fc39b4e12ed2d --- /dev/null +++ b/fairchat/notifications/notifications.h @@ -0,0 +1,20 @@ +#ifndef NOTIFICATIONS_H +#define NOTIFICATIONS_H + +#include "notificationabstract.h" + +class Notifications : public NotificationAbstract +{ +public: + Notifications(); + + // NotificationAbstract interface +public: + void registerWithService(); + void checkForPendingMessages(); + +private: + NotificationAbstract *mNotificationInstance = NULL; +}; + +#endif // NOTIFICATIONS_H diff --git a/fairchat/notifications/winrt/windowspushnotifications.cpp b/fairchat/notifications/winrt/windowspushnotifications.cpp new file mode 100755 index 0000000000000000000000000000000000000000..e6d629950adcbca61a3373c8df30a2691027c6e6 --- /dev/null +++ b/fairchat/notifications/winrt/windowspushnotifications.cpp @@ -0,0 +1,6 @@ +#include "windowspushnotifications.h" + +WindowsPushNotifications::WindowsPushNotifications() +{ + +} diff --git a/fairchat/notifications/winrt/windowspushnotifications.h b/fairchat/notifications/winrt/windowspushnotifications.h new file mode 100755 index 0000000000000000000000000000000000000000..dcc5597c325b9160c14342ca4f8ce9691b70a188 --- /dev/null +++ b/fairchat/notifications/winrt/windowspushnotifications.h @@ -0,0 +1,11 @@ +#ifndef WINDOWSPUSHNOTIFICATIONS_H +#define WINDOWSPUSHNOTIFICATIONS_H + + +class WindowsPushNotifications +{ +public: + WindowsPushNotifications(); +}; + +#endif // WINDOWSPUSHNOTIFICATIONS_H \ No newline at end of file diff --git a/fairchat/qml.qrc b/fairchat/qml.qrc index 00855f151132fb7ca5d547c1fb4d2ff7fce733a4..20cf588a3a27b33f42d2c8e737c2cc4204fa5bc6 100755 --- a/fairchat/qml.qrc +++ b/fairchat/qml.qrc @@ -134,5 +134,8 @@ qml/popups/DeleteEntry.qml qml/pages/channelView/messageTypes/JoinMessage.qml res/buttons/other/messages-videocall-v2.svg + qml/pages/OpenIDLogin.qml + qml/pages/login/LoginMethod.qml + qml/pages/login/LoginUserPassword.qml diff --git a/fairchat/qml/.DS_Store b/fairchat/qml/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..86e0199dcb05ef622b3e9caabf531297c89f833a Binary files /dev/null and b/fairchat/qml/.DS_Store differ diff --git a/fairchat/qml/main.qml b/fairchat/qml/main.qml index e1fd332ec479542cd1f7d8f18d2e490408bda2f6..8785111f1b4f2bf5f031becf64cbc47f25400e90 100755 --- a/fairchat/qml/main.qml +++ b/fairchat/qml/main.qml @@ -32,7 +32,7 @@ ApplicationWindow { property string activeChannel - background:StdImageHighDPI { + background: StdImageHighDPI { source: "qrc:/res/images/loginbg.png" width: parent.width height: parent.height diff --git a/fairchat/qml/main.qml.orig b/fairchat/qml/main.qml.orig deleted file mode 100755 index bd101c1bf52f14ff699ef7809e892141d447a450..0000000000000000000000000000000000000000 --- a/fairchat/qml/main.qml.orig +++ /dev/null @@ -1,237 +0,0 @@ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Window 2.2 -import QtQuick.Dialogs 1.2 -import "." - -import "qrc:/qml/popups" -import "qrc:/qml/pages" -import "qrc:/qml/various" -import "qrc:/qml/popups" -import "qrc:/qml/style" - -import "qrc:/javascript/emoji.js" as Emoji -import "qrc:/javascript/print.js" as Print - - -ApplicationWindow { - id: window - visible: true - title: qsTr("ucom") - - - width: Screen.desktopAvailableWidth - height: Screen.desktopAvailableHeight - property int connectionState: 0 - - //find better place for that - property var avatars: Object.create(null) - property var fileCache: Object.create(null) - property var channelModels: Object.create(null) -<<<<<<< HEAD - // property real baseFontSize: 1 -======= ->>>>>>> master - property bool firstLaunch: true - property string activeChannel - - background: StdImageHighDPI { - source: "qrc:/res/images/loginbg.png" - width: parent.width - height: parent.height - fillMode: Image.Stretch - } - - WelcomePopup { - id: welcomePopup - } - JitsiMeetMissing{ - id: jitsiMeetMissing - } - - Component { - id: loginComponent - LoginPage { - } - } - ListModel { - id: uploadsModel - } - - StackView { - width: parent.width - height: parent.height - property bool mainViewPushed: false - property bool channelPushed: false - id: mainStack - initialItem: loginComponent - function reset() { - rocketChatController.setUsername("default", "") - rocketChatController.setPassword("default", "") - rocketChatController.setCurrentChannel("default", "", "") - mainStack.clear() - mainViewPushed = false - channelPushed = false - mainStack.push(loginComponent) - } - function toMainView() { - if (!mainViewPushed) { - mainViewPushed = 1 - mainStack.push("qrc:/qml/pages/MainView.qml") - } - } - function navBack() { - if (mainStack.depth > 2) { - mainStack.pop() - } - if (mainStack.depth != 4){ - rocketChatController.setCurrentChannel("default","","") - } - } - pushEnter: Transition { - } - pushExit: Transition { - } - popExit: Transition { - } - popEnter: Transition { - } - } - MessageDialog { - id: messageDialog - title: "Ooops" - text: 'Sorry, some error occured.
Please close the App and restart.' - } - LogoutDialog { - id: logoutDialog - text: qsTr("logout ?") - - onYes: { - console.log("logout accepted") - rocketChatController.logout("default") - } - onRejected: { - - } - } - ListModel { - id: emojiCustomGridModel - property var contents: Object() - } - ListModel { - id: emojiPersonsGridModel - } - ListModel { - id: emojiNatureGridModel - } - ListModel { - id: emojiFoodGridModel - } - ListModel { - id: emojiCategoryGridModel - } - ListModel { - id: emojiTravelGridModel - } - ListModel { - id: emojiObjectsGridModel - } - ListModel { - id: emojiSymbolsGridModel - } - ListModel { - id: emojiFlagsGridModel - } - - Component.onCompleted: { - if(rocketChatController.customEmojisReady){ - // Emoji.addEmojisPerCategory() - } - if (rocketChatController.getDdpConnectionEstablished()) { - connectionState = 1 - } -<<<<<<< HEAD - } -======= - rocketChatController.checkLoggedIn(); - } ->>>>>>> master - Connections { - target: rocketChatController - onLoginError: { - Print.log("error login") - if (mainStack.mainViewPushed) { - mainStack.reset() - } - if (connectionState == 2) { - connectionState = 1 - } - } - onLoggedOut: { - mainStack.reset() - } - onServerConnected: { - connectionState = 1 - } - onLoggedIn: { - connectionState = 2 - } - onOffline: { - connectionState = 0 - } - onError: { - messageDialog.text = text + '
Please select a file.
We recommend the Amaze App as file manager. Get it from the f-droid.org or Google app store.' - messageDialog.open() - } - function getUserAvatar(url) {} - - onFileRessourceProcessed: { - // if(rocketChatController.isStorageReady()){ - // getUserAvatar(url); - // } - var user = rocketChatController.getUsername("default") - if (url == "/avatar/" + user + ".jpg") { - var suffix = path.substring(path.length - 3, path.length) - var file = pathPrefix + path - if (suffix === "svg") { - file = "qrc:res/user-identity.svg" - } - window.avatars[user] = file - } - } - /*onStorageReady:{ -<<<<<<< HEAD - getUserAvatar(); - }*/ -======= - getUserAvatar(); - }*/ - onEmojisReady:{ - Emoji.addEmojisPerCategory(emojis); - } ->>>>>>> master - } - onClosing: { - if (Qt.platform.os !== "linux" && Qt.platform.os !== "windows" - && Qt.platform.os !== "macOS") { - Print.log(close) - Print.log(mainStack.depth) - if (mainStack.depth <= 2) { - - close.accepted = true - } else { - close.accepted = false - mainStack.navBack() - } - } - } - Connections{ - target:rocketChatController - onStorageReady:{ - Fonts.updateSettings() - } - onNoJitsiMeetAvailable:{ - jitsiMeetMissing.open() - } - } -} diff --git a/fairchat/qml/navigation/TopBar.qml b/fairchat/qml/navigation/TopBar.qml index c11ea8a1f52fd5d01fadad18962ec5e1caf47cf7..1eb7659eb7625f3545325a9a25242ba6389e85ce 100755 --- a/fairchat/qml/navigation/TopBar.qml +++ b/fairchat/qml/navigation/TopBar.qml @@ -43,8 +43,7 @@ Item { } ConnectionIndicator { - // anchors.centerIn: parent - anchors.rightMargin: parent + anchors.centerIn: parent } } } diff --git a/fairchat/qml/pages/LoginPage.qml b/fairchat/qml/pages/LoginPage.qml index 9bf6a3c9dfaea88dd3ece003a1016488c2eedaec..86d31299d62c0665d3ae6593fc6fd941ed7207ea 100755 --- a/fairchat/qml/pages/LoginPage.qml +++ b/fairchat/qml/pages/LoginPage.qml @@ -1,22 +1,30 @@ -import QtQuick 2.8 -import QtQuick.Controls 2.1 +import QtQuick 2.9 +import QtQuick.Controls 2.2 import QtQuick.Layouts 1.3 import Qt.labs.settings 1.0 import "qrc:/qml/style" - +import "qrc:/qml/pages/login" import "qrc:/qml/various" import "qrc:/javascript/print.js" as Print Page { id: loginPage - property bool showLoginForm: true property string currentServer + property bool ddpConnected: false background: Rectangle { color: "transparent" // fairchat color: // color: "#7c9b6c" } + function resetLoginMethods(){ + loginMethodStack.push(loginMethodStack.data[0].qml,loginMethodStack.data[0].properties,StackView.Immediate) + var item = loginMethodStack.data[0] + loginMethodStack.data = Object() + loginMethodStack.data[0] = item + loginMethodsModel.reset() + } + Settings { id: currentServerSetting property alias currentServerChoice: currentServer.text @@ -47,12 +55,7 @@ Page { } } } - function login() { - rocketChatController.login("default", loginUsername.text, - loginPassword.text) - loginStatus.text = "" - loginButton.state = "LOGGINGIN" - } + Column { anchors.centerIn: parent @@ -61,13 +64,13 @@ Page { Layout.minimumHeight: serverSettings.implicitHeight spacing: 21 Column { - //anchors.verticalCenter: parent.verticalCenter + id: loginCol anchors.left: parent.left anchors.right: parent.right anchors.leftMargin: 65 anchors.rightMargin: 65 spacing: 40 - width: 340 + // width: 340 Button { id: serverSettings anchors.left: parent.left @@ -113,7 +116,7 @@ Page { id: connectStatus visible: debug text: { - if (rocketChatController.getDdpConnectionEstablished()) + if (ddpConnected) return "connected" else return "not connected" @@ -121,176 +124,83 @@ Page { color: Colors.white font.pointSize: Fonts.smallFontSize } - - TextField { - id: loginUsername - width: parent.width - color: Colors.white - visible: loginPage.showLoginForm - font.pointSize: Fonts.largeFontSize - leftPadding: 5 - rightPadding: 5 - bottomPadding: 5 - horizontalAlignment: TextField.AlignLeft - verticalAlignment: TextField.AlignBottom - selectByMouse: true - text: "" - inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText - | Qt.ImhPreferLowercase - focus: true - placeholderText: qsTr("username or e-mail") - background: Rectangle { - // anchors.horizontalCenter: parent - implicitWidth: parent.width - implicitHeight: 30 - - color: "transparent" - Rectangle { - height: 1 - width: parent.width - color: Colors.white - anchors.bottom: parent.bottom - } + ComboBox{ + id:loginMethodSelection + currentIndex: 0 + anchors.left: parent.left + anchors.right: parent.right + visible: true + model: loginMethodsModel + delegate: ItemDelegate{ + anchors.left: parent.left + anchors.right: parent.right + text: model.service } - } - - TextField { - id: loginPassword - width: parent.width - visible: loginPage.showLoginForm - text: "" - color: Colors.white - font.pointSize: Fonts.largeFontSize - leftPadding: 5 - rightPadding: 5 - bottomPadding: 5 - horizontalAlignment: TextField.AlignLeft - verticalAlignment: TextField.AlignBottom - inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText - | Qt.ImhSensitiveData | Qt.ImhPreferLowercase - echoMode: TextInput.Password - selectByMouse: true - - placeholderText: qsTr("password") - - background: Rectangle { - - // anchors.horizontalCenter: parent - implicitWidth: parent.width - implicitHeight: 30 - color: "transparent" - Rectangle { - height: 1 - width: parent.width - color: Colors.white - anchors.bottom: parent.bottom + onCountChanged: { + if(count>1){ + var item = model.get(count-1); + var obj = Object() + obj.qml = "qrc:/qml/pages/login/LoginMethod.qml" + obj.properties = {loginButtonText:item.buttonText,idpUrl:item.idpUrl,redirectUrl:item.redirectUrl,loginMethod:item.service } + loginMethodStack.data[count-1] = obj; } } + onActivated: { + var item = model.get(index); + displayText = item.service + loginMethodStack.pop(StackView.Immediate) + loginMethodStack.push(loginMethodStack.data[index].qml,loginMethodStack.data[index].properties,StackView.Immediate) + } + Component.onCompleted: { + var item = model.get(0); + displayText = item.service + var obj = Object() + obj.qml = "qrc:/qml/pages/login/LoginUserPassword.qml" + obj.properties = {} + loginMethodStack.data[0] = obj + loginMethodStack.push(loginMethodStack.data[0].qml,loginMethodStack.data[0].properties,StackView.Immediate) + } } - StdButton { - id: loginButton + StackView{ + visible: ddpConnected + property var data: Object() anchors.left: parent.left anchors.right: parent.right - text: qsTr("login") - checked: false - checkable: false - visible: loginPage.showLoginForm - color: Colors.white - textColor: Colors.primary + id: loginMethodStack + height: 150 + } + BusyIndicator{ + visible: !ddpConnected + anchors.horizontalCenter: parent.horizontalCenter + } - states: [ - State { - name: "LOGGEDIN" - PropertyChanges { - target: loginButton - color: "green" - enabled: false - } - }, - State { - name: "LOGGINGIN" - PropertyChanges { - target: loginButton - text: qsTr("logging in…") - color: "orange" - enabled: false - } - }, - State { - name: "OFFLINE" - PropertyChanges { - target: loginButton - color: "yellow" - text: qsTr("connecting") - enabled: false - } - }, - State { - name: "CONNECTED" - PropertyChanges { - target: loginButton - color: Colors.white - enabled: true - } - } - ] - function setState(newState) { - if (newState === 0) { - state = "OFFLINE" - } else if (newState === 1) { - state = "CONNECTED" - } else if (newState === 2) { - state = "LOGGEDIN" - } - } - Component.onCompleted: { - var state = window.connectionState - setState(state) - } - Connections { - target: window - onConnectionStateChanged: { - loginButton.setState(window.connectionState) - } - } +// Connections { +// target: window +// onConnectionStateChanged: { +// loginButton.setState(window.connectionState) +// } +// } } Rectangle{ height: 25 - width: 100 + width: 80 + anchors.horizontalCenter: parent.horizontalCenter Layout.minimumWidth: 50 color: "transparent" Label { + anchors.horizontalCenter: parent.horizontalCenter id: loginStatus - Layout.alignment: Qt.AlignCenter color: "red" text: "" } } } - Connections { - target: loginPassword - onAccepted: { - loginUsername.focus = false - loginPassword.focus = false - loginPage.login() - } - } - Connections { - target: loginButton - onPressed: { - loginUsername.focus = false - loginPassword.focus = false - loginPage.login() - } - } Connections { target: rocketChatController onLoggedIn: { Print.log("logged in") - - //if (sessionCheckbox.checked) mainStack.toMainView() } onHashLoggedIn: { @@ -300,53 +210,22 @@ Page { onLoginError: { Print.log("error login") loginStatus.text = qsTr("username or password wrong") - loginButton.state = "CONNECTED" - } - onServerConnected: { - connectStatus.text = "connected" - - if (rocketChatController.getPassword("default") != "" - && rocketChatController.getUsername("default") != "") { - rocketChatController.login( - "default", - rocketChatController.getUsername("default"), - rocketChatController.getPassword("default")) - mainStack.toMainView() - } else { - loginPage.showLoginForm = true - } } onStorageReady: { setUserData() } - } - function setUserData() { - var username = rocketChatController.getUsername("default") - var password = rocketChatController.getPassword("default") - if (username !== "" && password !== "") { - loginPassword.text = password - loginUsername.text = username - mainStack.toMainView() + onServerConnected:{ + ddpConnected = true } - } - Component.onCompleted: { - rocketChatController.setStatusBarColor(Colors.secondary) - if (rocketChatController.isStorageReady()) { - setUserData() + onOffline: { + ddpConnected = false + resetLoginMethods() } - /*var username = rocketChatController.getPasswordFromDb("default") - var password = rocketChatController.getUsernameFromDb("default") - if (username !== "" && password !== "") { - mainStack.toMainView() - }*/ } - Timer { - running: false - repeat: false - onTriggered: { - rocketChatController.cur - } + Component.onCompleted: { + ddpConnected = rocketChatController.getDdpConnectionEstablished() + rocketChatController.checkLoggedIn() } } -} + diff --git a/fairchat/qml/pages/OpenIDLogin.qml b/fairchat/qml/pages/OpenIDLogin.qml new file mode 100644 index 0000000000000000000000000000000000000000..3c20113971891c8ac04c1e37c8abec8033e4107a --- /dev/null +++ b/fairchat/qml/pages/OpenIDLogin.qml @@ -0,0 +1,78 @@ +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtWebView 1.1 + +import "qrc:/qml/navigation" +import "qrc:/qml/various" +import "qrc:/qml/popups" +import "qrc:/qml/style" + +Page { + property string redirectUrl + property string idpUrl + property string loginMethod + header: ToolBar { + id: topToolbar + property string color: Colors.primary + height: 50 + anchors.left: parent.left + anchors.right: parent.right + background: Rectangle { + color: topToolbar.color + Rectangle { + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.right: parent.right + height: 1 + color: Colors.separatorGrey + } + } + Row { + anchors.left: parent.left + anchors.top: parent.top + anchors.bottom: parent.bottom + spacing: 9 + Backbutton { + id: backbutton + anchors.verticalCenter: parent.verticalCenter + onClicked: { + mainStack.pop() + } + } + + Text { + anchors.top: parent.top + anchors.bottom: parent.bottom + text: qsTr("Server Choice") + font.bold: false + font.family: Fonts.opensans.name + color: Colors.white + + verticalAlignment: Text.AlignVCenter + } + } + } + + WebView { + id: idpWebView + anchors.fill: parent + url: idpUrl + + onLoadingChanged: { + var state = loadRequest + var status = loadRequest.status + var url = Qt.resolvedUrl(loadRequest.url) + console.log(url) + if(url.startsWith(redirectUrl)){ + idpWebView.runJavaScript("document.getElementById(\"config\").textContent",function(result){ + console.log(result) + rocketChatController.loginWithMethod(loginMethod, result) + + }) + } + } + Component.onCompleted: { + console.log(idpUrl) + } + } +} diff --git a/fairchat/qml/pages/login/LoginMethod.qml b/fairchat/qml/pages/login/LoginMethod.qml new file mode 100644 index 0000000000000000000000000000000000000000..afd834deb7c62dacc5b92f81e8300206a4cd13ff --- /dev/null +++ b/fairchat/qml/pages/login/LoginMethod.qml @@ -0,0 +1,31 @@ +import QtQuick 2.0 + +import "qrc:/qml/style" + +import "qrc:/qml/various" +import "qrc:/javascript/print.js" as Print + +Item { + property string loginButtonText + property string idpUrl + property string redirectUrl + property string loginMethod + + anchors.fill: parent + StdButton { + id: loginButton + anchors.left: parent.left + anchors.right: parent.right + text: loginButtonText + checked: false + checkable: false + color: Colors.white + textColor: Colors.primary + + onClicked: { + mainStack.push("qrc:/qml/pages/OpenIDLogin.qml",{idpUrl:idpUrl,redirectUrl:redirectUrl,loginMethod:loginMethod}) + } + + } + +} diff --git a/fairchat/qml/pages/login/LoginUserPassword.qml b/fairchat/qml/pages/login/LoginUserPassword.qml new file mode 100644 index 0000000000000000000000000000000000000000..935278af5f500f681c195cc3122eb5a4a5b293a0 --- /dev/null +++ b/fairchat/qml/pages/login/LoginUserPassword.qml @@ -0,0 +1,201 @@ +import QtQuick 2.9 +import QtQuick.Controls 2.2 + +import "qrc:/qml/style" + +import "qrc:/qml/various" +import "qrc:/javascript/print.js" as Print + +Item { + function login() { + rocketChatController.login("default", loginUsername.text, + loginPassword.text) + loginStatus.text = "" + loginButton.state = "LOGGINGIN" + } + Column{ + anchors.fill: parent + spacing: 40 + TextField { + id: loginUsername + width: parent.width + color: Colors.white + font.pointSize: Fonts.largeFontSize + leftPadding: 5 + rightPadding: 5 + bottomPadding: 5 + horizontalAlignment: TextField.AlignLeft + verticalAlignment: TextField.AlignBottom + selectByMouse: true + text: "" + inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText + | Qt.ImhPreferLowercase + focus: true + placeholderText: qsTr("username or e-mail") + background: Rectangle { + // anchors.horizontalCenter: parent + implicitWidth: parent.width + implicitHeight: 30 + + color: "transparent" + Rectangle { + height: 1 + width: parent.width + color: Colors.white + anchors.bottom: parent.bottom + } + } + } + + TextField { + id: loginPassword + width: parent.width + text: "" + color: Colors.white + font.pointSize: Fonts.largeFontSize + leftPadding: 5 + rightPadding: 5 + bottomPadding: 5 + horizontalAlignment: TextField.AlignLeft + verticalAlignment: TextField.AlignBottom + inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText + | Qt.ImhSensitiveData | Qt.ImhPreferLowercase + echoMode: TextInput.Password + selectByMouse: true + + placeholderText: qsTr("password") + + background: Rectangle { + + implicitWidth: parent.width + implicitHeight: 30 + color: "transparent" + Rectangle { + height: 1 + width: parent.width + color: Colors.white + anchors.bottom: parent.bottom + } + } + } + + StdButton { + id: loginButton + anchors.left: parent.left + anchors.right: parent.right + text: qsTr("login") + checked: false + checkable: false + color: Colors.white + textColor: Colors.primary + + states: [ + State { + name: "LOGGEDIN" + PropertyChanges { + target: loginButton + color: "green" + enabled: false + } + }, + State { + name: "LOGGINGIN" + PropertyChanges { + target: loginButton + text: qsTr("logging in…") + color: "orange" + enabled: false + } + }, + State { + name: "OFFLINE" + PropertyChanges { + target: loginButton + color: "yellow" + text: qsTr("connecting") + enabled: false + } + }, + State { + name: "CONNECTED" + PropertyChanges { + target: loginButton + color: Colors.white + enabled: true + } + } + ] + function setState(newState) { + if (newState === 0) { + state = "OFFLINE" + } else if (newState === 1) { + state = "CONNECTED" + } else if (newState === 2) { + state = "LOGGEDIN" + } + } + + + + } + Connections { + target: loginPassword + onAccepted: { + loginUsername.focus = false + loginPassword.focus = false + login() + } + } + + Connections { + target: loginButton + onPressed: { + loginUsername.focus = false + loginPassword.focus = false + login() + } + } + function setUserData() { + // var username = rocketChatController.getUsername("default") + // var password = rocketChatController.getPassword("default") +// if (username !== "" && password !== "") { +// loginPassword.text = password +// loginUsername.text = username +// mainStack.toMainView() +// } + } + + Connections { + target: rocketChatController + + onStorageReady: { + setUserData() + } + + Component.onCompleted: { + if (rocketChatController.isStorageReady()) { + setUserData() + } + } + + onServerConnected: { + //TODO: should be checked on the c++ side, check for legacy +// if (rocketChatController.getPassword("default") != "" +// && rocketChatController.getUsername("default") != "") { +// rocketChatController.login( +// "default", +// rocketChatController.getUsername("default"), +// rocketChatController.getPassword("default")) +// mainStack.toMainView() +// } + } + onLoginError:{ + loginButton.state = "CONNECTED" + } + onLoggedIn:{ + loginButton.state = "CONNECTED" + } + } + + } +} diff --git a/fairchat/res/.DS_Store b/fairchat/res/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f260c86cdade441aca7d6fd63794b50faa5bfbea Binary files /dev/null and b/fairchat/res/.DS_Store differ diff --git a/fairchat/res/buttons/.DS_Store b/fairchat/res/buttons/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f0d0dd688d0193eb39747488a89442291f7fac99 Binary files /dev/null and b/fairchat/res/buttons/.DS_Store differ diff --git a/fairchat/res/icons/.DS_Store b/fairchat/res/icons/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..9e8a1101659337a9e9684c04f13e333b5492ef91 Binary files /dev/null and b/fairchat/res/icons/.DS_Store differ diff --git a/fairchat/translations/.DS_Store b/fairchat/translations/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..e2dc20531b6810a230f1dec040e0dcc5b5621807 Binary files /dev/null and b/fairchat/translations/.DS_Store differ diff --git a/fairchat/winrt/.DS_Store b/fairchat/winrt/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..fe8304d374cd5f6f49e395aeb028720a74b7475b Binary files /dev/null and b/fairchat/winrt/.DS_Store differ