Skip to content
This repository has been archived by the owner on Nov 10, 2020. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Hassan Shahbazi committed Mar 18, 2020
2 parents f0ef68c + 904449e commit 0000863
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,19 @@ -(void) setSessionManager:(NINSessionManager*)sessionManager {
}

-(void) newMessageWasAddedAtIndex:(NSInteger)index {
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:0]] withRowAnimation:UITableViewRowAnimationTop];
[self.tableView endUpdates];
runOnMainThread(^{
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
});
}

-(void) messageWasRemovedAtIndex:(NSInteger)index {
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:0]] withRowAnimation:UITableViewRowAnimationTop];
[self.tableView endUpdates];
runOnMainThread(^{
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
});
}

#pragma mark - From UITableViewDelegate
Expand All @@ -185,7 +189,6 @@ -(nonnull UITableViewCell*)tableView:(nonnull UITableView *)tableView cellForRow
cell.uiComposeSendPressedCallback = ^(NINComposeContentView *composeContentView) {
[weakSelf.delegate uiActionSentByComposeContentView:composeContentView];
};
[cell populateWithChannelMessage:channelMessage siteConfiguration:self.sessionManager.siteConfiguration imageAssets:self.imageAssets colorAssets:self.colorAssets agentAvatarConfig:self.agentAvatarConfig userAvatarConfig:self.userAvatarConfig composeState:self.composeMessageStates[messageID]];
cell.uiComposeStateUpdateCallback = ^(NSArray* composeState) {
weakSelf.composeMessageStates[messageID] = composeState;
};
Expand All @@ -194,10 +197,14 @@ -(nonnull UITableViewCell*)tableView:(nonnull UITableView *)tableView cellForRow
};
cell.cellConstraintsUpdatedCallback = ^{
[UIView animateWithDuration:0.3 animations:^{
[weakSelf.tableView beginUpdates];
[weakSelf.tableView endUpdates];
runOnMainThread(^{
[weakSelf.tableView beginUpdates];
[weakSelf.tableView endUpdates];
});
}];
};

[cell populateWithChannelMessage:channelMessage siteConfiguration:self.sessionManager.siteConfiguration imageAssets:self.imageAssets colorAssets:self.colorAssets agentAvatarConfig:self.agentAvatarConfig userAvatarConfig:self.userAvatarConfig composeState:self.composeMessageStates[messageID]];
return cell;
} else if ([message isKindOfClass:NINUserTypingMessage.class]) {
NINChatBubbleCell* cell = [self.tableView dequeueReusableCellWithIdentifier:@"NINChatBubbleCell" forIndexPath:indexPath];
Expand All @@ -206,12 +213,11 @@ -(nonnull UITableViewCell*)tableView:(nonnull UITableView *)tableView cellForRow
return cell;
} else if ([message isKindOfClass:NINChatMetaMessage.class]) {
NINChatMetaCell* cell = [self.tableView dequeueReusableCellWithIdentifier:@"NINChatMetaCell" forIndexPath:indexPath];

[cell populateWithMessage:message colorAssets:self.colorAssets session:self.sessionManager.ninchatSession];
cell.closeChatCallback = ^{
[weakSelf.delegate closeChatRequestedByChatView:weakSelf];
};

[cell populateWithMessage:message colorAssets:self.colorAssets session:self.sessionManager.ninchatSession];
return cell;
} else {
NSCAssert(NO, @"Invalid message type");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,25 @@ -(void) clear {

-(void) removeSendButtonAction {
[self.sendButton removeTarget:self action:@selector(pressed:) forControlEvents:UIControlEventTouchUpInside];
for (NSUInteger i = 0; i < self.optionButtons.count; i++) {
[self.optionButtons[i] removeTarget:self action:@selector(pressed:) forControlEvents:UIControlEventTouchUpInside];
}
}

-(void) pressed:(UIButton*)button {
if (button == self.sendButton) {
if (button == self.sendButton && self.uiComposeSendPressedCallback) {
self.uiComposeSendPressedCallback(self);
[self applyButtonStyle:button selected:YES];
return;
}

for (int i=0; i<self.optionButtons.count; ++i) {
if (button == self.optionButtons[i]) {
BOOL selected = ![[self.options[i] valueForKey:@"selected"] boolValue];
self.options[i][@"selected"] = @(selected);
self.composeState[@(i)] = @(selected);
[self applyButtonStyle:button selected:selected];
self.uiComposeElementStateUpdateCallback(self.composeState);
return;
} else if (self.uiComposeElementStateUpdateCallback) {
for (int i=0; i<self.optionButtons.count; ++i) {
if (button == self.optionButtons[i]) {
BOOL selected = ![[self.options[i] valueForKey:@"selected"] boolValue];
self.options[i][@"selected"] = @(selected);
self.composeState[@(i)] = @(selected);
[self applyButtonStyle:button selected:selected];
self.uiComposeElementStateUpdateCallback(self.composeState);
return;
}
}
}
}
Expand Down Expand Up @@ -230,6 +232,11 @@ -(void) updateTitleScale:(UIButton *)button {
[button setTitleEdgeInsets:UIEdgeInsetsMake(0, 8, 2, 8)];
}

-(void) dealloc {
self.uiComposeElementStateUpdateCallback = nil;
self.uiComposeSendPressedCallback = nil;
}

@end

@interface NINComposeMessageView ()
Expand Down Expand Up @@ -313,20 +320,29 @@ -(void) populateWithComposeMessage:(NINUIComposeMessage*)composeMessage siteConf
__weak typeof(self) weakSelf = self;
BOOL enableSendButtons = (composeMessage.sendPressedIndex == -1);

for (int i = 0; i < self.contentViews.count; i++) {
for (NSUInteger i = 0; i < self.contentViews.count; i++) {
BOOL isSelected = composeMessage.content[i].sendPressed;
[self.contentViews[i] populateWithComposeMessage:composeMessage.content[i] siteConfiguration:siteConfiguration colorAssets:colorAssets composeState:composeState[i] enableSendButton:enableSendButtons isSelected:isSelected];
self.contentViews[i].uiComposeSendPressedCallback = ^(NINComposeContentView* composeContentView) {
/// Do an additional checking to ensure we won't get a null exception as described in
/// https://github.com/somia/ninchat-sdk-ios/issues/100
if (!weakSelf || !weakSelf.uiComposeSendPressedCallback)
return;

composeMessage.content[i].sendPressed = YES;

// Make the send buttons un-clickable for this message
for (int j = 0; j < self.contentViews.count; j++) {
for (NSUInteger j = 0; j < self.contentViews.count; j++) {
[weakSelf.contentViews[j] removeSendButtonAction];
}
weakSelf.uiComposeSendPressedCallback(composeContentView);
};
[self.contentViews[i] setHidden:NO];
self.contentViews[i].uiComposeElementStateUpdateCallback = ^(NSDictionary *composeState) {
/// Do an additional checking to ensure we won't get a null exception as described in
/// https://github.com/somia/ninchat-sdk-ios/issues/100
if (!weakSelf || !weakSelf.uiComposeStateUpdateCallback)
return;

weakSelf.composeStates[i] = composeState;
weakSelf.uiComposeStateUpdateCallback(weakSelf.composeStates);
};
Expand All @@ -351,4 +367,11 @@ -(void) awakeFromNib {
self.contentViews = [[NSMutableArray alloc] init];
}

-(void) dealloc {
/// To ensure that the blocks are deallocated to prevent the following issue to happening again
/// https://github.com/somia/ninchat-sdk-ios/issues/100
self.uiComposeStateUpdateCallback = nil;
self.uiComposeSendPressedCallback = nil;
}

@end

0 comments on commit 0000863

Please sign in to comment.