Skip to content

Commit

Permalink
Merge branch 'feature/giphy-support-ios-binding' into 'release/v2.3.9'
Browse files Browse the repository at this point in the history
Feature/giphy support ios binding

See merge request megachat/MEGAchat!952
  • Loading branch information
sergiohs84 committed Nov 13, 2020
2 parents 240665a + 06a704c commit e45360d
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 2 deletions.
8 changes: 8 additions & 0 deletions bindings/Objective-C/Karere.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
2F59F49F251C5B3600DDD2D0 /* MEGAChatGiphy.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2F59F49E251C5B3600DDD2D0 /* MEGAChatGiphy.mm */; };
77875CDA2097A69400B8340F /* MEGAChatContainsMeta.mm in Sources */ = {isa = PBXBuildFile; fileRef = 77875CD92097A69400B8340F /* MEGAChatContainsMeta.mm */; };
77875CDD2097A80700B8340F /* MEGAChatRichPreview.mm in Sources */ = {isa = PBXBuildFile; fileRef = 77875CDC2097A80700B8340F /* MEGAChatRichPreview.mm */; };
77CB2DCF2356FFD50095FF8C /* OBJCCaptureModule.mm in Sources */ = {isa = PBXBuildFile; fileRef = 77CB2DCE2356FFD50095FF8C /* OBJCCaptureModule.mm */; };
Expand Down Expand Up @@ -66,6 +67,9 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
2F59F49D251C5B3600DDD2D0 /* MEGAChatGiphy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MEGAChatGiphy.h; sourceTree = "<group>"; };
2F59F49E251C5B3600DDD2D0 /* MEGAChatGiphy.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MEGAChatGiphy.mm; sourceTree = "<group>"; };
2F59F4A2251C5F9100DDD2D0 /* MEGAChatGiphy+init.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MEGAChatGiphy+init.h"; sourceTree = "<group>"; };
77875CD82097A69400B8340F /* MEGAChatContainsMeta.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MEGAChatContainsMeta.h; sourceTree = "<group>"; };
77875CD92097A69400B8340F /* MEGAChatContainsMeta.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MEGAChatContainsMeta.mm; sourceTree = "<group>"; };
77875CDB2097A80700B8340F /* MEGAChatRichPreview.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MEGAChatRichPreview.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -392,6 +396,7 @@
A8AA1BF72195B21800E15B60 /* DelegateMEGAChatNodeHistoryListener.h */,
A8AA1BF82195B21800E15B60 /* DelegateMEGAChatNodeHistoryListener.mm */,
A819DE8D219EE12E00EA9C22 /* MEGAChatGeolocation+init.h */,
2F59F4A2251C5F9100DDD2D0 /* MEGAChatGiphy+init.h */,
);
name = private;
path = Private;
Expand Down Expand Up @@ -437,6 +442,8 @@
8394CF9C211992A200A1634A /* MEGAChatSession.h */,
8394CF9D211992A200A1634A /* MEGAChatSession.mm */,
A8AA1BF62195B11B00E15B60 /* MEGAChatNodeHistoryDelegate.h */,
2F59F49D251C5B3600DDD2D0 /* MEGAChatGiphy.h */,
2F59F49E251C5B3600DDD2D0 /* MEGAChatGiphy.mm */,
A8F96C18219DE3A2005A3EB6 /* MEGAChatGeolocation.h */,
A8F96C19219DE3A2005A3EB6 /* MEGAChatGeolocation.mm */,
);
Expand Down Expand Up @@ -597,6 +604,7 @@
A835A8AB1F979CDC0075646F /* MEGAChatCall.mm in Sources */,
A879F3C21F96683A007C5394 /* presenced.cpp in Sources */,
A82750EE1E9788D8007CD9E2 /* DelegateMEGAChatListener.mm in Sources */,
2F59F49F251C5B3600DDD2D0 /* MEGAChatGiphy.mm in Sources */,
A82750D81E9788A3007CD9E2 /* MEGAChatRequest.mm in Sources */,
A8F96C1A219DE3A2005A3EB6 /* MEGAChatGeolocation.mm in Sources */,
A82750DB1E9788A3007CD9E2 /* MEGAChatSdk.mm in Sources */,
Expand Down
6 changes: 4 additions & 2 deletions bindings/Objective-C/MEGAChatContainsMeta.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

#import "MEGAChatRichPreview.h"
#import "MEGAChatGeolocation.h"
#import "MEGAChatGiphy.h"

typedef NS_ENUM(NSInteger, MEGAChatContainsMetaType) {
MEGAChatContainsMetaTypeInvalid = -1,
MEGAChatContainsMetaTypeRichPreview = 0,
MEGAChatContainsMetaTypeGeolocation = 1
MEGAChatContainsMetaTypeGeolocation = 1,
MEGAChatContainsMetaTypeGiphy = 3
};

@interface MEGAChatContainsMeta : NSObject
Expand All @@ -16,6 +18,6 @@ typedef NS_ENUM(NSInteger, MEGAChatContainsMetaType) {
@property (readonly, nonatomic) NSString *textMessage;
@property (readonly, nonatomic) MEGAChatRichPreview *richPreview;
@property (readonly, nonatomic) MEGAChatGeolocation *geolocation;

@property (readonly, nonatomic) MEGAChatGiphy *giphy;

@end
5 changes: 5 additions & 0 deletions bindings/Objective-C/MEGAChatContainsMeta.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#import "MEGAChatRichPreview+init.h"
#import "MEGAChatGeolocation+init.h"
#import "MEGAChatGiphy+init.h"

using namespace megachat;

Expand Down Expand Up @@ -60,4 +61,8 @@ - (MEGAChatGeolocation *)geolocation {
return self.megaChatContainsMeta->getGeolocation() ? [[MEGAChatGeolocation alloc] initWithMegaChatGeolocation:self.megaChatContainsMeta->getGeolocation()->copy() cMemoryOwn:YES] : nil;
}

- (MEGAChatGiphy *)giphy {
return self.megaChatContainsMeta->getGiphy() ? [[MEGAChatGiphy alloc] initWithMegaChatGiphy:self.megaChatContainsMeta->getGiphy()->copy() cMemoryOwn:YES] : nil;
}

@end
19 changes: 19 additions & 0 deletions bindings/Objective-C/MEGAChatGiphy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface MEGAChatGiphy : NSObject

@property (nullable, readonly, nonatomic) NSString *mp4Src;
@property (nullable, readonly, nonatomic) NSString *webpSrc;

@property (readonly, nonatomic) long mp4Size;
@property (readonly, nonatomic) long webpSize;
@property (nullable, readonly, nonatomic) NSString *title;
@property (readonly, nonatomic) int width;
@property (readonly, nonatomic) int height;

@end

NS_ASSUME_NONNULL_END
65 changes: 65 additions & 0 deletions bindings/Objective-C/MEGAChatGiphy.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

#import "MEGAChatGiphy.h"

#import "megachatapi.h"

using namespace megachat;

@interface MEGAChatGiphy ()

@property MegaChatGiphy *megaChatGiphy;
@property BOOL cMemoryOwn;

@end

@implementation MEGAChatGiphy

- (instancetype)initWithMegaChatGiphy:(MegaChatGiphy *)megaChatGiphy cMemoryOwn:(BOOL)cMemoryOwn {
NSParameterAssert(megaChatGiphy);

if (self = [super init]) {
_megaChatGiphy = megaChatGiphy;
_cMemoryOwn = cMemoryOwn;
}

return self;
}

- (NSString *)mp4Src {
if (!self.megaChatGiphy) return nil;
return self.megaChatGiphy->getMp4Src() ? [[NSString alloc] initWithUTF8String:self.megaChatGiphy->getMp4Src()] : nil;
}

- (NSString *)webpSrc {
if (!self.megaChatGiphy) return nil;
return self.megaChatGiphy->getWebpSrc() ? [[NSString alloc] initWithUTF8String:self.megaChatGiphy->getWebpSrc()] : nil;
}

- (NSString *)title {
if (!self.megaChatGiphy) return nil;
return self.megaChatGiphy->getTitle() ? [[NSString alloc] initWithUTF8String:self.megaChatGiphy->getTitle()] : nil;
}

- (long)mp4Size {
return self.megaChatGiphy->getMp4Size();
}

- (long)webpSize {
return self.megaChatGiphy->getWebpSize();
}

- (int)width {
return self.megaChatGiphy->getWidth();
}

- (int)height {
return self.megaChatGiphy->getHeight();
}

- (void)dealloc {
if (self.cMemoryOwn) {
delete _megaChatGiphy;
}
}

@end
1 change: 1 addition & 0 deletions bindings/Objective-C/MEGAChatSdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ typedef NS_ENUM (NSInteger, MEGAChatConnection) {
- (MEGAChatMessage *)forwardContactFromChat:(uint64_t)sourceChatId messageId:(uint64_t)messageId targetChatId:(uint64_t)targetChatId;
- (void)attachNodesToChat:(uint64_t)chatId nodes:(NSArray *)nodesArray delegate:(id<MEGAChatRequestDelegate>)delegate;
- (void)attachNodesToChat:(uint64_t)chatId nodes:(NSArray *)nodesArray;
- (MEGAChatMessage *)sendGiphyToChat:(uint64_t)chatId srcMp4:(NSString *)srcMp4 srcWebp:(NSString *)srcWebp sizeMp4:(uint64_t)sizeMp4 sizeWebp:(uint64_t)sizeWebp width:(int)width height:(int)height title:(NSString *)title;
- (MEGAChatMessage *)sendGeolocationToChat:(uint64_t)chatId longitude:(float)longitude latitude:(float)latitude image:(NSString *)image;
- (MEGAChatMessage *)editGeolocationForChat:(uint64_t)chatId messageId:(uint64_t)messageId longitude:(float)longitude latitude:(float)latitude image:(NSString *)image;
- (void)revokeAttachmentToChat:(uint64_t)chatId node:(uint64_t)nodeHandle delegate:(id<MEGAChatRequestDelegate>)delegate;
Expand Down
5 changes: 5 additions & 0 deletions bindings/Objective-C/MEGAChatSdk.mm
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,11 @@ - (void)attachNodesToChat:(uint64_t)chatId nodes:(NSArray *)nodesArray {
self.megaChatApi->attachNodes(chatId, (nodeList != nil) ? [nodeList getCPtr] : NULL);
}

- (MEGAChatMessage *)sendGiphyToChat:(uint64_t)chatId srcMp4:(NSString *)srcMp4 srcWebp:(NSString *)srcWebp sizeMp4:(uint64_t)sizeMp4 sizeWebp:(uint64_t)sizeWebp width:(int)width height:(int)height title:(NSString *)title {
MegaChatMessage *message = self.megaChatApi->sendGiphy(chatId, srcMp4.UTF8String, srcWebp.UTF8String, sizeMp4, sizeWebp, width, height, title.UTF8String);
return message ? [[MEGAChatMessage alloc] initWithMegaChatMessage:message cMemoryOwn:YES] : nil;
}

- (MEGAChatMessage *)sendGeolocationToChat:(uint64_t)chatId longitude:(float)longitude latitude:(float)latitude image:(NSString *)image {
MegaChatMessage *message = self.megaChatApi->sendGeolocation(chatId, longitude, latitude, image ? [image UTF8String] : NULL);
return message ? [[MEGAChatMessage alloc] initWithMegaChatMessage:message cMemoryOwn:YES] : nil;
Expand Down
13 changes: 13 additions & 0 deletions bindings/Objective-C/Private/MEGAChatGiphy+init.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

#import "MEGAChatGiphy.h"
#import "megachatapi.h"

NS_ASSUME_NONNULL_BEGIN

@interface MEGAChatGiphy (init)

- (instancetype)initWithMegaChatGiphy:(const megachat::MegaChatGiphy *)megaChatGiphy cMemoryOwn:(BOOL)cMemoryOwn;

@end

NS_ASSUME_NONNULL_END

0 comments on commit e45360d

Please sign in to comment.