Skip to content

Commit

Permalink
Merge branch 'fix/sched-meetings-creation' into 'develop'
Browse files Browse the repository at this point in the history
CHT-847. Allow provide empty description for scheduled meetings

See merge request megachat/MEGAchat!1557
  • Loading branch information
jgandres committed Apr 14, 2023
2 parents 68b8e77 + ae7e925 commit 2f80edd
Show file tree
Hide file tree
Showing 10 changed files with 249 additions and 84 deletions.
4 changes: 2 additions & 2 deletions bindings/Objective-C/MEGAChatRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ enum {
@class MEGANodeList;
@class MEGAHandleList;
@class MEGAChatScheduledMeetingOccurrence;
@class MEGAChatScheduledMeetingList;
@class MEGAChatScheduledMeeting;

@interface MEGAChatRequest : NSObject

Expand All @@ -91,7 +91,7 @@ enum {
@property (readonly, nonatomic) MEGANodeList *nodeList;
@property (readonly, nonatomic) NSInteger paramType;
@property (readonly, nonatomic) MEGAHandleList *megaHandleList;
@property (readonly, nonatomic) MEGAChatScheduledMeetingList *scheduledMeetingList;
@property (readonly, nonatomic) NSArray<MEGAChatScheduledMeeting *> *scheduledMeetingList;
@property (readonly, nonatomic) NSArray<MEGAChatScheduledMeetingOccurrence *> *chatScheduledMeetingOccurrences;

- (instancetype)clone;
Expand Down
19 changes: 16 additions & 3 deletions bindings/Objective-C/MEGAChatRequest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#import "MEGANodeList+init.h"
#import "MEGAHandleList+init.h"
#import "MEGAChatScheduledMeetingOccurrence+init.h"
#import "MEGAChatScheduledMeetingList+init.h"
#import "MEGAChatScheduledMeeting+init.h"

using namespace megachat;

Expand Down Expand Up @@ -118,8 +118,21 @@ - (MEGAHandleList *)megaHandleListForChat:(uint64_t)chatId {
return self.megaChatRequest->getMegaHandleListByChat(chatId) ? [[MEGAHandleList alloc] initWithMegaHandleList:self.megaChatRequest->getMegaHandleListByChat(chatId)->copy() cMemoryOwn:YES] : nil;
}

- (MEGAChatScheduledMeetingList *)scheduledMeetingList {
return self.megaChatRequest ? [[MEGAChatScheduledMeetingList alloc] initWithMegaChatScheduledMeetingList:self.megaChatRequest->getMegaChatScheduledMeetingList() cMemoryOwn:YES] : nil;
- (NSArray<MEGAChatScheduledMeeting *> *)scheduledMeetingList {
if (!self.megaChatRequest) return nil;
MegaChatScheduledMeetingList *chatScheduledMeetingList = self.megaChatRequest->getMegaChatScheduledMeetingList();
if (!chatScheduledMeetingList) return nil;
NSMutableArray<MEGAChatScheduledMeeting *> *scheduledMeetings = [NSMutableArray arrayWithCapacity:chatScheduledMeetingList->size()];

for (int i = 0; i < chatScheduledMeetingList->size(); i++)
{
MegaChatScheduledMeeting *megaChatScheduledMeeting = chatScheduledMeetingList->at(i)->copy();

MEGAChatScheduledMeeting *scheduledMeeting = [[MEGAChatScheduledMeeting alloc] initWithMegaChatScheduledMeeting:megaChatScheduledMeeting cMemoryOwn:YES];
[scheduledMeetings addObject:scheduledMeeting];
}

return scheduledMeetings;
}

- (NSArray<MEGAChatScheduledMeetingOccurrence *> *)chatScheduledMeetingOccurrences {
Expand Down
2 changes: 2 additions & 0 deletions bindings/Objective-C/MEGAChatScheduledFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ typedef NS_ENUM (NSInteger, MEGAChatScheduledFlagsType) {
- (void)setEmailsDisabled:(BOOL)disable;
- (void)reset;

- (instancetype)initWithEmailsDisabled:(BOOL)emailsDisabled;

@end

NS_ASSUME_NONNULL_END
9 changes: 9 additions & 0 deletions bindings/Objective-C/MEGAChatScheduledFlags.mm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ @interface MEGAChatScheduledFlags()

@implementation MEGAChatScheduledFlags

- (instancetype)initWithEmailsDisabled:(BOOL)emailsDisabled {
self = [super init];

MegaChatScheduledFlags *megaChatScheduledFlags = MegaChatScheduledFlags::createInstance();
megaChatScheduledFlags->setEmailsDisabled(emailsDisabled);

return [self initWithMegaChatScheduledFlags:megaChatScheduledFlags cMemoryOwn:YES];
}

- (instancetype)initWithMegaChatScheduledFlags:(MegaChatScheduledFlags *)megaChatScheduledFlags cMemoryOwn:(BOOL)cMemoryOwn {
self = [super init];

Expand Down
256 changes: 191 additions & 65 deletions bindings/java/nz/mega/sdk/MegaChatApiJava.java

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/chatclientDb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void ChatClientSqliteDb::insertOrUpdateSchedMeeting(const KarereScheduledMeeting
sm.attributes().size() ? sm.attributes().c_str() : nullptr,
sm.overrides(),
sm.cancelled(),
static_cast<int64_t>(sm.flags()->getNumericValue()),
sm.flags() ? static_cast<int64_t>(sm.flags()->getNumericValue()) : 0,
rulesBuf);
}
else
Expand All @@ -56,7 +56,7 @@ void ChatClientSqliteDb::insertOrUpdateSchedMeeting(const KarereScheduledMeeting
sm.attributes().size() ? sm.attributes().c_str() : nullptr,
sm.overrides(),
sm.cancelled(),
static_cast<int64_t>(sm.flags()->getNumericValue()));
sm.flags() ? static_cast<int64_t>(sm.flags()->getNumericValue()) : 0);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/megachatapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2448,7 +2448,7 @@ int MegaChatScheduledMeeting::isValidTitleLength(const char* title)

int MegaChatScheduledMeeting::isValidDescriptionLength(const char* desc)
{
return desc && strlen(desc) <= MegaChatScheduledMeeting::MAX_DESC_LENGTH;
return !desc || strlen(desc) <= MegaChatScheduledMeeting::MAX_DESC_LENGTH;
}

/* Class MegaChatScheduledMeetingOccurr */
Expand Down
25 changes: 19 additions & 6 deletions src/megachatapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -4149,6 +4149,7 @@ class MegaChatApi
* @param startDate start date time of the meeting with the format (unix timestamp UTC)
* @param endDate end date time of the meeting with the format (unix timestamp UTC)
* @param description Null-terminated character string with the scheduled meeting description. Maximum allowed length is MegaChatScheduledMeeting::MAX_DESC_LENGTH characters
* Note that description is a mandatory field, so in case you want to set an empty description, please provide an empty string with Null-terminated character at the end
* @param flags Scheduled meeting flags to establish scheduled meetings flags like avoid email sending (Check MegaChatScheduledFlags class)
* @param rules Repetition rules for creating a recurrent meeting (Check MegaChatScheduledRules class)
* @param attributes - not supported yet
Expand Down Expand Up @@ -7662,12 +7663,24 @@ class MegaChatScheduledRules
/**
* @brief Creates a new instance of MegaChatScheduledRules
*
* @param freq : scheduled meeting frequency (DAILY | WEEKLY | MONTHLY), this is used in conjunction with interval
* @param interval : repetition interval in relation to the frequency
* @param until : specifies when the repetitions should end
* @param byWeekDay : allows us to specify that an event will only occur on given week day/s
* @param byMonthDay : allows us to specify that an event will only occur on a given day/s of the month
* @param byMonthWeekDay : allows us to specify that an event will only occurs on a specific weekday offset of the month. (i.e every 2nd Sunday of each month)
* @param freq: scheduled meeting frequency, this is used in conjunction with interval
* valid values for this param:
* + MegaChatScheduledRules::FREQ_DAILY
* + MegaChatScheduledRules::FREQ_WEEKLY
* + MegaChatScheduledRules::FREQ_MONTHLY
*
* @param interval: repetition interval in relation to the frequency
* @param until: specifies when the repetitions should end
* @param byWeekDay: allows us to specify that an event will only occur on given week day/s.
* to use this param, freq param must be set to MegaChatScheduledRules::FREQ_WEEKLY
*
* @param byMonthDay: allows us to specify that an event will only occur on a given day/s of the month
* to use this param, freq param must be set to MegaChatScheduledRules::FREQ_MONTHLY
*
* @param byMonthWeekDay: allows us to specify that an event will only occurs on a specific weekday offset of the month. (i.e every 2nd Sunday of each month)
* to use this param, freq param must be set to MegaChatScheduledRules::FREQ_MONTHLY
*
* Important: byWeekDay, byMonthDay and byMonthWeekDay are not compatible between them, so only one of these values, can be set at the same time.
*
* @return A pointer to the superclass of the private object
*/
Expand Down
2 changes: 1 addition & 1 deletion src/megachatapi_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ void MegaChatApiImpl::sendPendingRequests()
break;
}

if (!sm->timezone() || !sm->title() || !sm->description()
if (!sm->timezone() || !sm->title()
|| sm->startDateTime() == MEGACHAT_INVALID_TIMESTAMP
|| sm->endDateTime() == MEGACHAT_INVALID_TIMESTAMP)
{
Expand Down
10 changes: 6 additions & 4 deletions tests/sdk_test/sdk_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4172,8 +4172,8 @@ TEST_F(MegaChatApiTest, ScheduledMeetings)
smDataTests127.timeZone = timeZone;
smDataTests127.startDate = startDate;
smDataTests127.endDate = endDate;
smDataTests127.description = description;
smDataTests127.flags = flags;
smDataTests127.description = ""; // description is not a mandatory field
smDataTests127.flags = nullptr; // flags is not a mandatory field
smDataTests127.rules = rules;
createChatroomAndSchedMeeting (a1, smDataTests127);

Expand All @@ -4184,8 +4184,10 @@ TEST_F(MegaChatApiTest, ScheduledMeetings)
SchedMeetingData smData; // Designated initializers generate too many warnings (gcc)
smData.chatId = chatid[a1];
smData.schedId = MEGACHAT_INVALID_HANDLE;
ASSERT_TRUE(getSchedMeeting(a1, smData)) <<
"Can't retrieve scheduled meeting for new chat " << (chatIdB64 ? chatIdB64.get() : "INVALID chatId");

const auto schedMeet = getSchedMeeting(a1, smData);
ASSERT_TRUE(schedMeet) << "Can't retrieve scheduled meeting for new chat " << (chatIdB64 ? chatIdB64.get() : "INVALID chatId");
ASSERT_TRUE(!(*schedMeet)->flags() && !(*schedMeet)->description()) << "Scheduled meeting flags must be unset and description must be an empty string" ;

//================================================================================//
// TEST 2. Update a recurrent scheduled meeting with invalid TimeZone (Error)
Expand Down

0 comments on commit 2f80edd

Please sign in to comment.