Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/customization and some bug fixes #402

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b0a6153
Add customization for time label's color
Oct 30, 2019
a1d1664
Add customization for chat screen's background color
Oct 30, 2019
7de76d6
Allow adding of shadow on message bubble
Oct 30, 2019
7cd18e8
Add customization for chat screen's textview placeholder and font
Oct 30, 2019
98442c2
Allow hiding of user's name for each message bubble
Oct 30, 2019
faecb7f
Add customization for chat screen's attach/options icon
Oct 30, 2019
34e5892
Add customization for chat screen's send icon
Oct 30, 2019
bb1a1ba
Fix customization of options button icon
Nov 3, 2019
d5a79f5
Center align options button if a custom icon has been set
Nov 3, 2019
cf7b6c5
Add a temporary solution for showing message status icon
Nov 4, 2019
0ee5211
Add filtering of messages according to a given date
Nov 4, 2019
ef955a2
Update SDWebImage to 5.0
Nov 4, 2019
61b780c
Add boolean to keeps online status on did resign active
Nov 4, 2019
c6fe764
Fix wrong variable used for config
Nov 4, 2019
7395ff9
Revert "Fix wrong variable used for config"
Nov 4, 2019
ff21242
Fix implementation of keepAliveOnDidResignActive condition
Nov 4, 2019
42d22f5
Another fix for crashing unrecognized setKeepAliveOnDidResignActive
Nov 4, 2019
13615ff
Remove unused variable on BConfig
Nov 5, 2019
d36d381
Allow hiding of chat section header
Nov 5, 2019
767bae8
Allow showing of profile picture on every cell
Nov 5, 2019
0cbec2b
Fix overlapping image on time label
Nov 5, 2019
032d18d
ADD: Flag for tap action on message cell's profile picture
Nov 13, 2019
45c20b6
Merge branch 'master' into feature/customization
failynsedik Feb 21, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ChatSDKCore/Classes/Defines/BCoreDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
#define bTypingTimeout 5.0
#define bLocationDefaultArea 1000

#define bDefaultChatBgColor @"ffffff"

#define bDefaultMessageColorMe @"abcff4"
#define bDefaultMessageColorReply @"d7d4d3"
#define bDefaultMessageColorTime @"aaaaaa"

#define bDefaultProfileImage @"icn_100_anonymous.png"
#define bDefaultPublicGroupImage @"icn_100_anonymous_group.png"
Expand Down
1 change: 1 addition & 0 deletions ChatSDKCore/Classes/Session/BChatSDK.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
@property (nonatomic, readwrite) id<PInterfaceAdapter> interfaceAdapter;
@property (nonatomic, readwrite) id<PStorageAdapter> storageAdapter;
@property (nonatomic, readwrite) id<PNetworkAdapter> networkAdapter;
@property (nonatomic, readwrite) BOOL keepAliveOnDidResignActive;

+(BChatSDK *) shared;
+(BConfiguration *) config;
Expand Down
3 changes: 2 additions & 1 deletion ChatSDKCore/Classes/Session/BChatSDK.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ @implementation BChatSDK
@synthesize interfaceAdapter = _interfaceAdapter;
@synthesize storageAdapter = _storageAdapter;
@synthesize networkAdapter = _networkAdapter;
@synthesize keepAliveOnDidResignActive = _keepAliveOnDidResignActive;

static BChatSDK * instance;

Expand Down Expand Up @@ -77,7 +78,7 @@ +(void) initialize: (BConfiguration *) config app:(UIApplication *)application o
}

-(void) appDidResignActive {
if(self.networkAdapter) {
if(self.networkAdapter && self.keepAliveOnDidResignActive == NO) {
[self.networkAdapter.core save];
[self.networkAdapter.core goOffline];
}
Expand Down
35 changes: 35 additions & 0 deletions ChatSDKCore/Classes/Session/BConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,30 @@ typedef enum {

// Should we ask the user to allow notifications when the app initially loads up?
@property (nonatomic, readwrite) BOOL shouldAskForNotificationsPermission;

/// Custom background color of BChatViewController's main view.
@property (nonatomic, readwrite) NSString * chatBgColor;

/// Hide the section that shows "Today", "Yesterday", etc.
@property (nonatomic, readwrite) BOOL hideDayOfTheWeekSection;
/// Add a shadow to the message bubble using a default shadow configuration.
@property (nonatomic, readwrite) BOOL addShadowOnMessageBubble;
@property (nonatomic, readwrite) BOOL showReadStatus;
/// Format to be used for NSPredicate.
@property (nonatomic, readwrite) NSString * dateFilterFormat;
/// An NSDate filter used to filter thread messages to show only the messages that are greater than or equal
/// the set dateFilter.
@property (nonatomic, readwrite) NSDate * dateFilter;

// Background color of messages: hex value like "FFFFFF"
@property (nonatomic, readwrite) NSString * messageColorMe;
@property (nonatomic, readwrite) NSString * messageColorReply;

/// Custom placeholder for chat screen's textview.
@property (nonatomic, readwrite) NSString * chatTextViewPlaceholder;
/// Custom font for chat screen's textview.
@property (nonatomic, readwrite) UIFont * chatTextViewFont;

// The Firebase root path. Data will be added to Firebase root/rootPath...
// this allows you to run multiple chat instances on one Firebase database
@property (nonatomic, readwrite) NSString * rootPath;
Expand All @@ -55,6 +74,12 @@ typedef enum {
// Should empty chats be shown in the threads view?
@property (nonatomic, readwrite) BOOL showEmptyChats;

/// Show profile picture on every message cell.
@property (nonatomic, readwrite) BOOL showProfilePictureOnEveryCell;

/// Value of profilePictureOnCellTapEnabled is enabled by default to follow previous implementation.
@property (nonatomic, readwrite) BOOL profilePictureOnCellTapEnabled;

// User profile image
@property (nonatomic, readwrite) NSString * defaultAvatarURL;

Expand Down Expand Up @@ -142,6 +167,8 @@ typedef enum {
@property(nonatomic, readwrite) NSString * messageBubbleMaskLast;
@property(nonatomic, readwrite) NSString * messageBubbleMaskSingle;

/// Hide the name label for each message bubble.
@property(nonatomic, readwrite) BOOL hideNameLabel;
@property(nonatomic, readwrite) bNameLabelPosition nameLabelPosition;
@property(nonatomic, readwrite) BOOL combineTimeWithNameLabel;

Expand All @@ -167,6 +194,9 @@ typedef enum {
@property (nonatomic, readwrite) UIFont * messageTimeFont;
@property (nonatomic, readwrite) UIFont * messageNameFont;

/// Set the custom color of the time label. If not set, it will use the default color of time label.
@property (nonatomic, readwrite) NSString * messageTimeColor;

@property (nonatomic, readwrite) UIFont * threadTitleFont;
@property (nonatomic, readwrite) UIFont * threadTimeFont;
@property (nonatomic, readwrite) UIFont * threadSubtitleFont;
Expand Down Expand Up @@ -247,6 +277,11 @@ typedef enum {
// How much distance must be moved to update the server with our new location
@property (nonatomic, readwrite) int nearbyUsersMinimumLocationChangeToUpdateServer;

/// Custom icon for the options/attachment button.
@property (nonatomic, readwrite) NSString * optionsButtonIcon;
/// Custom icon for the send message button.
@property (nonatomic, readwrite) NSString * sendButtonIcon;

// XMPP Auth type used which can be:
// default, scramsha1, digestmd5, plain
@property (nonatomic, readwrite) NSString * xmppAuthType;
Expand Down
16 changes: 16 additions & 0 deletions ChatSDKCore/Classes/Session/BConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,17 @@

@implementation BConfiguration

@synthesize chatBgColor;
@synthesize hideDayOfTheWeekSection;
@synthesize addShadowOnMessageBubble;
@synthesize showReadStatus;
@synthesize dateFilterFormat;
@synthesize dateFilter;
@synthesize messageColorMe;
@synthesize messageColorReply;
@synthesize messageTimeColor;
@synthesize chatTextViewPlaceholder;
@synthesize chatTextViewFont;
@synthesize rootPath;
@synthesize appBadgeEnabled;
@synthesize defaultUserNamePrefix;
Expand All @@ -26,6 +35,8 @@ @implementation BConfiguration
@synthesize defaultServer;
@synthesize shouldOpenChatWhenPushNotificationClicked;
@synthesize loginUsernamePlaceholder;
@synthesize showProfilePictureOnEveryCell;
@synthesize profilePictureOnCellTapEnabled;
@synthesize defaultAvatarURL;
@synthesize defaultBlankAvatar;
@synthesize timeFormat;
Expand Down Expand Up @@ -70,6 +81,7 @@ @implementation BConfiguration
@synthesize messageBubbleMaskMiddle;
@synthesize messageBubbleMaskLast;
@synthesize messageBubbleMaskSingle;
@synthesize hideNameLabel;
@synthesize nameLabelPosition;
@synthesize combineTimeWithNameLabel;

Expand All @@ -94,6 +106,8 @@ @implementation BConfiguration
@synthesize publicChatRoomLifetimeMinutes;
@synthesize nearbyUsersMinimumLocationChangeToUpdateServer;

@synthesize optionsButtonIcon;
@synthesize sendButtonIcon;
@synthesize publicChatAutoSubscriptionEnabled;
@synthesize remote;
@synthesize remoteConfigEnabled;
Expand Down Expand Up @@ -160,6 +174,8 @@ -(instancetype) init {

shouldAskForNotificationsPermission = YES;

profilePictureOnCellTapEnabled = YES;

defaultBlankAvatar = [NSBundle imageNamed:bDefaultProfileImage bundle:bCoreBundleName];
defaultGroupChatAvatar = [NSBundle imageNamed:bDefaultPublicGroupImage bundle:bCoreBundleName];

Expand Down
11 changes: 11 additions & 0 deletions ChatSDKUI/Classes/Components/Chat View/BChatViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ -(instancetype) initWithThread: (id<PThread>) thread
-(void) viewDidLoad {
[super viewDidLoad];

self.view.backgroundColor = [BCoreUtilities colorWithHexString:bDefaultChatBgColor];
if(BChatSDK.config.chatBgColor) {
self.view.backgroundColor = [BCoreUtilities colorWithHexString:BChatSDK.config.chatBgColor];
}

[_sendBarView setMaxLines:BChatSDK.config.textInputViewMaxLines];
[_sendBarView setMaxCharacters:BChatSDK.config.textInputViewMaxCharacters];

Expand All @@ -44,6 +49,12 @@ -(void) viewDidLoad {
// Add the initial batch of messages
NSArray<PMessage> * messages = [BChatSDK.db loadMessagesForThread:_thread newest:BChatSDK.config.messagesToLoadPerBatch];
messages = [messages sortedArrayUsingComparator:[BMessageSorter oldestFirst]];

if(BChatSDK.config.dateFilter && BChatSDK.config.dateFilterFormat) {
NSPredicate *dateFilterPredicate = [NSPredicate predicateWithFormat:BChatSDK.config.dateFilterFormat, BChatSDK.config.dateFilter];
messages = (NSArray<PMessage> *)[messages filteredArrayUsingPredicate:dateFilterPredicate];
}

[self setMessages:messages scrollToBottom:NO animate:NO force: YES];
}

Expand Down
5 changes: 5 additions & 0 deletions ChatSDKUI/Classes/Components/Chat View/BLazyReloadManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ -(void) loadMessages: (UIScrollView *) scrollView {
float height = scrollView.contentSize.height;
float offsetY = scrollView.contentOffset.y;

if(BChatSDK.config.dateFilter && BChatSDK.config.dateFilterFormat) {
NSPredicate *dateFilterPredicate = [NSPredicate predicateWithFormat:BChatSDK.config.dateFilterFormat, BChatSDK.config.dateFilter];
messages = (NSArray<PMessage> *)[messages filteredArrayUsingPredicate:dateFilterPredicate];
}

[self.messageManager addMessages: messages];
[self.tableView reloadData];

Expand Down
55 changes: 46 additions & 9 deletions ChatSDKUI/Classes/Components/Chat View/BTextInputView.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ -(instancetype) initWithFrame:(CGRect)frame {
// self.barTintColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.7];
self.backgroundColor = [UIColor whiteColor];

if(BChatSDK.config.chatTextViewFont) {
_placeholderLabel.font = BChatSDK.config.chatTextViewFont;
}

// Decide how many lines the message should have
minLines = bMinLines;
maxLines = bMaxLines;
Expand All @@ -60,13 +64,25 @@ -(instancetype) initWithFrame:(CGRect)frame {
_sendButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[self addSubview: _sendButton];

[_optionsButton setImage:[NSBundle uiImageNamed:@"icn_24_options.png"] forState:UIControlStateNormal];
[_optionsButton setImage:[NSBundle uiImageNamed:@"icn_24_keyboard.png"] forState:UIControlStateSelected];
if(BChatSDK.config.optionsButtonIcon) {
[_optionsButton setImage:[NSBundle uiImageNamed:BChatSDK.config.optionsButtonIcon] forState:UIControlStateNormal];
[_optionsButton setImage:[NSBundle uiImageNamed:BChatSDK.config.optionsButtonIcon] forState:UIControlStateSelected];
} else {
[_optionsButton setImage:[NSBundle uiImageNamed:@"icn_24_options.png"] forState:UIControlStateNormal];
[_optionsButton setImage:[NSBundle uiImageNamed:@"icn_24_keyboard.png"] forState:UIControlStateSelected];
}

[_optionsButton addTarget:self action:@selector(optionsButtonPressed) forControlEvents:UIControlEventTouchUpInside];

NSString * sendButtonTitle = [NSBundle t:bSend];
[_sendButton setTitle:sendButtonTitle forState:UIControlStateNormal];
if(BChatSDK.config.sendButtonIcon) {
[_sendButton setTitle:Nil forState:UIControlStateNormal];
[_sendButton setImage:[UIImage imageNamed:BChatSDK.config.sendButtonIcon] forState:UIControlStateNormal];
[_sendButton setImage:[UIImage imageNamed:BChatSDK.config.sendButtonIcon] forState:UIControlStateSelected];
} else {
NSString * sendButtonTitle = [NSBundle t:bSend];
[_sendButton setImage:Nil forState:UIControlStateNormal];
[_sendButton setTitle:sendButtonTitle forState:UIControlStateNormal];
}

[_sendButton addTarget:self action:@selector(sendButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[_sendButton addTarget:self action:@selector(sendButtonHeld) forControlEvents:UIControlEventTouchDown];
Expand All @@ -91,9 +107,15 @@ -(instancetype) initWithFrame:(CGRect)frame {

// Constrain the elements
_optionsButton.keepLeftInset.equal = bMargin +keepRequired;

_optionsButton.keepBottomInset.equal = 8.0;
_optionsButton.keepHeight.equal = 24;

/// If a custom options button icon has been set, then center align it.
if(BChatSDK.config.optionsButtonIcon) {
_optionsButton.keepBottomInset.equal = bMargin;
_optionsButton.keepTopInset.equal = bMargin;
} else {
_optionsButton.keepBottomInset.equal = 8.0;
_optionsButton.keepHeight.equal = 24;
}

// If the user has no chat options available then remove the chat option button width
_optionsButton.keepWidth.equal = BChatSDK.ui.chatOptions.count ? 24 : 0;
Expand Down Expand Up @@ -125,6 +147,9 @@ -(instancetype) initWithFrame:(CGRect)frame {
[_placeholderLabel setTextColor:_placeholderColor];

[_placeholderLabel setText:[NSBundle t:bWriteSomething]];
if(BChatSDK.config.chatTextViewPlaceholder) {
[_placeholderLabel setText:BChatSDK.config.chatTextViewPlaceholder];
}

[self setFont:[UIFont systemFontOfSize:bFontSize]];

Expand Down Expand Up @@ -176,8 +201,14 @@ -(void) setMicButtonEnabled: (BOOL) enabled sendButtonEnabled: (BOOL) sendButton
forState:UIControlStateNormal];
}
else {
[_sendButton setTitle:[NSBundle t:bSend] forState:UIControlStateNormal];
[_sendButton setImage:Nil forState:UIControlStateNormal];
if(BChatSDK.config.sendButtonIcon) {
[_sendButton setTitle:Nil forState:UIControlStateNormal];
[_sendButton setImage:[UIImage imageNamed:BChatSDK.config.sendButtonIcon] forState:UIControlStateNormal];
[_sendButton setImage:[UIImage imageNamed:BChatSDK.config.sendButtonIcon] forState:UIControlStateSelected];
} else {
[_sendButton setTitle:[NSBundle t:bSend] forState:UIControlStateNormal];
[_sendButton setImage:Nil forState:UIControlStateNormal];
}
}
}

Expand Down Expand Up @@ -270,6 +301,9 @@ -(void) stopRecording {
[[BAudioManager sharedManager] finishRecording];
[_sendBarDelegate.view hideAllToasts];
[_placeholderLabel setText:[NSBundle t:bWriteSomething]];
if(BChatSDK.config.chatTextViewPlaceholder) {
[_placeholderLabel setText:BChatSDK.config.chatTextViewPlaceholder];
}
[self cancelRecordingToastTimer];
}

Expand Down Expand Up @@ -305,6 +339,9 @@ -(void) cancelRecordingToastTimer {
- (void)sendButtonCancelled {
[_sendBarDelegate.view hideAllToasts];
[_placeholderLabel setText:[NSBundle t:bWriteSomething]];
if(BChatSDK.config.chatTextViewPlaceholder) {
[_placeholderLabel setText:BChatSDK.config.chatTextViewPlaceholder];
}
CSToastStyle * style = [[CSToastStyle alloc] initWithDefaultStyle];
style.backgroundColor = [UIColor redColor];
[_sendBarDelegate.view makeToast:[NSBundle t:bCancelled]
Expand Down
Loading