Skip to content

Commit

Permalink
Merge pull request #960 from meganz/release/v2.3.8
Browse files Browse the repository at this point in the history
Release/v2.3.8
  • Loading branch information
sergiohs84 authored Oct 15, 2020
2 parents 7e3adf4 + d1d8cc9 commit e70a1de
Show file tree
Hide file tree
Showing 24 changed files with 421 additions and 151 deletions.
1 change: 1 addition & 0 deletions bindings/Objective-C/MEGAChatMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ typedef NS_ENUM(NSInteger, MEGAChatMessageEndCallReason) {
@property (readonly, nonatomic) NSInteger messageIndex;
@property (readonly, nonatomic) uint64_t userHandle;
@property (readonly, nonatomic) MEGAChatMessageType type;
@property (readonly, nonatomic) BOOL hasConfirmedReactions;
@property (readonly, nonatomic) NSDate *timestamp;
@property (readonly, nonatomic) NSString *content;
@property (readonly, nonatomic, getter=isEdited) BOOL edited;
Expand Down
4 changes: 4 additions & 0 deletions bindings/Objective-C/MEGAChatMessage.mm
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ - (MEGAChatMessageType)type {
return (MEGAChatMessageType) (self.megaChatMessage ? self.megaChatMessage->getType() : 0);
}

- (BOOL)hasConfirmedReactions {
return self.megaChatMessage ? self.megaChatMessage->hasConfirmedReactions() : NO;
}

- (NSDate *)timestamp {
return self.megaChatMessage ? [[NSDate alloc] initWithTimeIntervalSince1970:self.megaChatMessage->getTimestamp()] : nil;
}
Expand Down
1 change: 1 addition & 0 deletions bindings/Objective-C/MEGAChatRoomDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
- (void)onMessageReceived:(MEGAChatSdk *)api message:(MEGAChatMessage *)message;
- (void)onMessageUpdate:(MEGAChatSdk *)api message:(MEGAChatMessage *)message;
- (void)onHistoryReloaded:(MEGAChatSdk *)api chat:(MEGAChatRoom *)chat;
- (void)onReactionUpdate:(MEGAChatSdk *)api messageId:(uint64_t)messageId reaction:(NSString *)reaction count:(NSInteger)count;

@end
6 changes: 6 additions & 0 deletions bindings/Objective-C/MEGAChatSdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ typedef NS_ENUM (NSInteger, MEGAChatConnection) {
- (MEGAChatMessage *)lastChatMessageSeenForChat:(uint64_t)chatId;
- (void)removeUnsentMessageForChat:(uint64_t)chatId rowId:(uint64_t)rowId;

- (void)addReactionForChat:(uint64_t)chatId messageId:(uint64_t)messageId reaction:(NSString *)reaction;
- (void)deleteReactionForChat:(uint64_t)chatId messageId:(uint64_t)messageId reaction:(NSString *)reaction;
- (NSInteger)messageReactionCountForChat:(uint64_t)chatId messageId:(uint64_t)messageId reaction:(NSString *)reaction;
- (MEGAStringList *)messageReactionsForChat:(uint64_t)chatId messageId:(uint64_t)messageId;
- (MEGAHandleList *)reactionUsersForChat:(uint64_t)chatId messageId:(uint64_t)messageId reaction:(NSString *)reaction;

- (void)sendTypingNotificationForChat:(uint64_t)chatId;
- (void)sendStopTypingNotificationForChat:(uint64_t)chatId;
- (void)saveCurrentState;
Expand Down
20 changes: 20 additions & 0 deletions bindings/Objective-C/MEGAChatSdk.mm
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,26 @@ - (void)removeUnsentMessageForChat:(uint64_t)chatId rowId:(uint64_t)rowId {
self.megaChatApi->removeUnsentMessage(chatId, rowId);
}

- (void)addReactionForChat:(uint64_t)chatId messageId:(uint64_t)messageId reaction:(NSString *)reaction {
self.megaChatApi->addReaction(chatId, messageId, reaction ? [reaction UTF8String] : NULL);
}

- (void)deleteReactionForChat:(uint64_t)chatId messageId:(uint64_t)messageId reaction:(NSString *)reaction {
self.megaChatApi->delReaction(chatId, messageId, reaction ? [reaction UTF8String] : NULL);
}

- (NSInteger)messageReactionCountForChat:(uint64_t)chatId messageId:(uint64_t)messageId reaction:(NSString *)reaction {
return self.megaChatApi->getMessageReactionCount(chatId, messageId, reaction.UTF8String);
}

- (MEGAStringList *)messageReactionsForChat:(uint64_t)chatId messageId:(uint64_t)messageId {
return self.megaChatApi ? [MEGAStringList.alloc initWithMegaStringList:self.megaChatApi->getMessageReactions(chatId, messageId) cMemoryOwn:YES] : nil;
}

- (MEGAHandleList *)reactionUsersForChat:(uint64_t)chatId messageId:(uint64_t)messageId reaction:(NSString *)reaction {
return self.megaChatApi ? [MEGAHandleList.alloc initWithMegaHandleList:self.megaChatApi->getReactionUsers(chatId, messageId, reaction.UTF8String) cMemoryOwn:YES] : nil;
}

- (void)sendTypingNotificationForChat:(uint64_t)chatId {
self.megaChatApi->sendTypingNotification(chatId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class DelegateMEGAChatRoomListener : public megachat::MegaChatRoomListener {
void onMessageReceived(megachat::MegaChatApi *api, megachat::MegaChatMessage *message);
void onMessageUpdate(megachat::MegaChatApi *api, megachat::MegaChatMessage *message);
void onHistoryReloaded(megachat::MegaChatApi *api, megachat::MegaChatRoom *chat);
void onReactionUpdate(megachat::MegaChatApi *api, megachat::MegaChatHandle msgid, const char *reaction, int count);

private:
__weak MEGAChatSdk *megaChatSDK;
Expand Down
11 changes: 11 additions & 0 deletions bindings/Objective-C/Private/DelegateMEGAChatRoomListener.mm
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,14 @@
});
}
}

void DelegateMEGAChatRoomListener::onReactionUpdate(MegaChatApi *api, MegaChatHandle msgid, const char *reaction, int count) {
if (listener != nil && [listener respondsToSelector:@selector(onReactionUpdate:messageId:reaction:count:)]) {
MEGAChatSdk *tempMegaChatSDK = this->megaChatSDK;
id<MEGAChatRoomDelegate> tempListener = this->listener;
NSString *str = [NSString stringWithUTF8String:reaction];
dispatch_async(dispatch_get_main_queue(), ^{
[tempListener onReactionUpdate:tempMegaChatSDK messageId:msgid reaction:str count:count];
});
}
}
10 changes: 10 additions & 0 deletions bindings/java/nz/mega/sdk/DelegateMegaChatRoomListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,14 @@ public void run() {
});
}
}

@Override
public void onReactionUpdate(MegaChatApi api, long msgid, String reaction, int count){
if (listener != null) {
megaChatApi.runCallback((Runnable) () -> {
if (listener != null)
listener.onReactionUpdate(megaChatApi, msgid, reaction, count);
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ public interface MegaChatRoomListenerInterface {
public void onMessageReceived(MegaChatApiJava api, MegaChatMessage msg);
public void onMessageUpdate(MegaChatApiJava api, MegaChatMessage msg);
public void onHistoryReloaded(MegaChatApiJava api, MegaChatRoom chat);
public void onReactionUpdate(MegaChatApiJava api, long msgid, String reaction, int count);
}
8 changes: 7 additions & 1 deletion contrib/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# At this stage, this file is intended for building MEGAChat library directly on windows with Visual Studio (just for chat so far), and/or exploring the chat API with example app MEGAclc
# Build chat and the SDK with CURL and OPENSSL

cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.15)
project(karere)

# Qt settings
if (USE_QT)
set (MEGA_QT_REQUIRED_COMPONENTS Core Gui)
set (MEGA_QT_LINK_LIBRARIES Qt5::Core Qt5::Gui)
endif()

if (WIN32)
if("${CMAKE_GENERATOR}" MATCHES "(Win64|IA64)")
SET(build_64_bit 1)
Expand Down
31 changes: 30 additions & 1 deletion examples/megaclc/megaclc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,23 @@ class OneShotRequestListener : public m::MegaRequestListener
}
};

class OneShotTransferListener : public m::MegaTransferListener
{
public:
std::function<void(m::MegaApi* api, m::MegaTransfer *request, m::MegaError* e)> onTransferFinishFunc;

explicit OneShotTransferListener(std::function<void(m::MegaApi* api, m::MegaTransfer* transfer, m::MegaError* e)> f = {})
:onTransferFinishFunc(f)
{
}

void onTransferFinish(m::MegaApi* api, m::MegaTransfer *request, m::MegaError* e) override
{
if (onTransferFinishFunc) onTransferFinishFunc(api, request, e);
delete this; // one-shot is done so auto-delete
}
};

class OneShotChatRequestListener : public c::MegaChatRequestListener
{
public:
Expand Down Expand Up @@ -3459,7 +3476,18 @@ void exec_renamenode(ac::ACState& s)
{
g_megaApi->renameNode(node.get(), s.words[2].s.c_str(), new OneShotRequestListener([](m::MegaApi*, m::MegaRequest *, m::MegaError* e)
{
check_err("renamenode", e);
check_err("renamenode", e, ReportResult);
}));
}
}

void exec_startupload(ac::ACState& s)
{
if (auto node = GetNodeByPath(s.words[2].s))
{
g_megaApi->startUpload(s.words[1].s.c_str(), node.get(), new OneShotTransferListener([](m::MegaApi*, m::MegaTransfer*, m::MegaError* e)
{
check_err("startUpload", e, ReportResult);
}));
}
}
Expand Down Expand Up @@ -3890,6 +3918,7 @@ ac::ACN autocompleteSyntax()
p->Add(exec_getnodebypath, sequence(text("getnodebypath"), param("remotepath")));
p->Add(exec_ls, sequence(text("ls"), repeat(either(flag("-recursive"), flag("-handles"), flag("-ctime"), flag("-mtime"), flag("-size"), flag("-versions"), sequence(flag("-order"), param("order")), sequence(flag("-refilter"), param("regex")))), param("path")));
p->Add(exec_renamenode, sequence(text("renamenode"), param("remotepath"), param("newname")));
p->Add(exec_startupload, sequence(text("startupload"), param("localpath"), param("remotepath")));

p->Add(exec_pushreceived, sequence(text("pushreceived"), opt(flag("-beep")), opt(param("chatid"))));
p->Add(exec_getcloudstorageused, sequence(text("getcloudstorageused")));
Expand Down
11 changes: 11 additions & 0 deletions examples/qtmegachatapi/MegaChatApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,17 @@ void MegaChatApplication::onRequestFinish(MegaChatApi *, MegaChatRequest *reques
}
}
}
else if (error == MegaChatError::ERROR_NOENT && request->getFlag() )
{
if (request->getNumber() == -1)
{
QMessageBox::warning(nullptr, tr("Add reaction"), tr("This message reached the maximum limit of 50 reactions"));
}
else if (request->getNumber() == 1)
{
QMessageBox::warning(nullptr, tr("Add reaction"), tr("Our own user has reached the maximum limit of 24 reactions"));
}
}
break;
}

Expand Down
40 changes: 31 additions & 9 deletions examples/qtmegachatapi/chatMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,16 @@ ChatMessage::ChatMessage(ChatWindow *parent, megachat::MegaChatApi *mChatApi, me
mMessage = msg;
setAuthor(NULL);
setTimestamp(mMessage->getTimestamp());
megachat::MegaChatRoom *chatRoom = megaChatApi->getChatRoom(chatId);
mReactWidget = new QWidget();
ui->mReactions->setWidget(mReactWidget);
mReactLayout = new QHBoxLayout();
mReactWidget->setLayout(mReactLayout);
mReactWidget->setStyleSheet("text-align:left");
mReactWidget->setSizePolicy(QSizePolicy ::Expanding , QSizePolicy ::Expanding);
mReactLayout->setAlignment(Qt::AlignLeft);
ui->mReactions->setFrameShape(QFrame::NoFrame);

megachat::MegaChatRoom *chatRoom = megaChatApi->getChatRoom(chatId);
assert (chatRoom);
if (chatRoom->isGroup() && mMessage->getStatus() == megachat::MegaChatMessage::STATUS_DELIVERED)
{
Expand All @@ -41,7 +49,7 @@ ChatMessage::ChatMessage(ChatWindow *parent, megachat::MegaChatApi *mChatApi, me
{
int count = megaChatApi->getMessageReactionCount(mChatId, mMessage->getMsgId(), reactions->get(i));
Reaction *reaction = new Reaction(this, reactions->get(i), count);
ui->mReactions->layout()->addWidget(reaction); // takes ownership
mReactWidget->layout()->addWidget(reaction); // takes ownership
}

connect(ui->mMsgDisplay, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(onMessageCtxMenu(const QPoint&)));
Expand All @@ -52,16 +60,18 @@ ChatMessage::ChatMessage(ChatWindow *parent, megachat::MegaChatApi *mChatApi, me
ChatMessage::~ChatMessage()
{
clearReactions();
mReactLayout->deleteLater();
mReactWidget->deleteLater();
delete mMessage;
delete ui;
}

const Reaction *ChatMessage::getLocalReaction(const char *reactionStr) const
{
assert(reactionStr);
for (int i = 0; i < ui->mReactions->layout()->count(); i++)
for (int i = 0; i < mReactWidget->layout()->count(); i++)
{
QLayoutItem *item = ui->mReactions->layout()->itemAt(i);
QLayoutItem *item = mReactWidget->layout()->itemAt(i);
Reaction *reaction = static_cast<Reaction*>(item->widget());
if (reaction->getReactionString() == reactionStr)
{
Expand All @@ -75,18 +85,18 @@ void ChatMessage::updateReaction(const char *reactionStr, int count)
{
assert(reactionStr);
bool found = false;
int size = ui->mReactions->layout()->count();
int size = mReactWidget->layout()->count();
for (int i = 0; i < size; i++)
{
QLayoutItem *item = ui->mReactions->layout()->itemAt(i);
QLayoutItem *item = mReactWidget->layout()->itemAt(i);
Reaction *reaction = static_cast<Reaction*>(item->widget());
if (reaction->getReactionString() == reactionStr)
{
found = true;
if (count == 0)
{
item->widget()->deleteLater();
delete ui->mReactions->layout()->takeAt(i);
delete mReactWidget->layout()->takeAt(i);
}
else
{
Expand All @@ -99,7 +109,7 @@ void ChatMessage::updateReaction(const char *reactionStr, int count)
if (!found && count)
{
Reaction *reaction = new Reaction(this, reactionStr, count);
ui->mReactions->layout()->addWidget(reaction);
mReactWidget->layout()->addWidget(reaction);
}
}

Expand Down Expand Up @@ -273,7 +283,7 @@ ChatWindow *ChatMessage::getChatWindow() const
void ChatMessage::clearReactions()
{
QLayoutItem *item;
while ((item = ui->mReactions->layout()->takeAt(0)))
while ((item = mReactWidget->layout()->takeAt(0)))
{
item->widget()->deleteLater();
delete item;
Expand Down Expand Up @@ -579,6 +589,9 @@ void ChatMessage::onMessageCtxMenu(const QPoint& point)
{
QMenu *menu = ui->mMsgDisplay->createStandardContextMenu(point);

auto actReactCount = menu->addAction(tr("Get reactions count"));
connect(actReactCount, &QAction::triggered, this, [=](){onReactCount();});

QMenu *addReactMenu = menu->addMenu("React to this message");
for (int i = 0; i < utf8reactionsList.size(); i++)
{
Expand Down Expand Up @@ -641,6 +654,15 @@ void ChatMessage::onMessageEditAction()
startEditingMsgWidget();
}

void ChatMessage::onReactCount()
{
mega::unique_ptr<::mega::MegaStringList> reactions(mChatWindow->mMegaChatApi->getMessageReactions(mChatId, mMessage->getMsgId()));
QMessageBox msg;
msg.setIcon(QMessageBox::Information);
msg.setText(std::to_string(reactions->size()).c_str());
msg.exec();
}

void ChatMessage::onManageReaction(bool del, const char *reactionStr)
{
QString reaction = reactionStr
Expand Down
3 changes: 3 additions & 0 deletions examples/qtmegachatapi/chatMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class ChatMessage: public QWidget
megachat::MegaChatMessage *mMessage = NULL;
megachat::MegaChatApi *megaChatApi;
QListWidgetItem *mListWidgetItem;
QWidget *mReactWidget;
QHBoxLayout *mReactLayout;
ChatWindow *mChatWindow;
friend class ChatWindow;

Expand Down Expand Up @@ -66,6 +68,7 @@ class ChatMessage: public QWidget
void onMessageCtxMenu(const QPoint& point);
void onMessageDelAction();
void onMessageEditAction();
void onReactCount();
void onManageReaction(bool del, const char *reactionStr = nullptr);
void onMessageRemoveLinkAction();
void onNodeDownloadOrImport(mega::MegaNode *node, bool import);
Expand Down
Loading

0 comments on commit e70a1de

Please sign in to comment.