mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-30 05:06:58 +02:00
add the typing area above the text input in the roomviewcontroller.
This commit is contained in:
@@ -21,6 +21,8 @@
|
||||
|
||||
#import "RoomInputToolbarView.h"
|
||||
|
||||
#import "RoomActivitiesView.h"
|
||||
|
||||
#import "RoomParticipantsViewController.h"
|
||||
|
||||
#import "RoomDetailsViewController.h"
|
||||
@@ -32,6 +34,12 @@
|
||||
|
||||
// the user taps on a member thumbnail
|
||||
MXRoomMember *selectedRoomMember;
|
||||
|
||||
// List of members who are typing in the room.
|
||||
NSArray *currentTypingUsers;
|
||||
|
||||
// Typing notifications listener.
|
||||
id typingNotifListener;
|
||||
}
|
||||
|
||||
@property (strong, nonatomic) MXKAlert *currentAlert;
|
||||
@@ -51,6 +59,9 @@
|
||||
[self setRoomInputToolbarViewClass:RoomInputToolbarView.class];
|
||||
[self roomInputToolbarView:self.inputToolbarView heightDidChanged:((RoomInputToolbarView*)self.inputToolbarView).mainToolbarHeightConstraint.constant completion:nil];
|
||||
|
||||
// set extra area
|
||||
[self setRoomActivitiesViewClass:RoomActivitiesView.class];
|
||||
|
||||
// Set rageShake handler
|
||||
self.rageShakeManager = [RageShakeManager sharedManager];
|
||||
|
||||
@@ -117,6 +128,12 @@
|
||||
[self.menuListView addConstraint:heightConstraint];
|
||||
}
|
||||
[self.view setNeedsUpdateConstraints];
|
||||
|
||||
if (self.roomDataSource)
|
||||
{
|
||||
// this room view controller has its own typing management.
|
||||
self.roomDataSource.showTypingNotifications = NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning
|
||||
@@ -128,6 +145,8 @@
|
||||
- (void)viewWillAppear:(BOOL)animated
|
||||
{
|
||||
[super viewWillAppear:animated];
|
||||
|
||||
[self listenTypingNotifications];
|
||||
}
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated
|
||||
@@ -143,6 +162,8 @@
|
||||
|
||||
// Hide menu list view
|
||||
menuListTopConstraint.constant = 0;
|
||||
|
||||
[self removeTypingNotificationsListener];
|
||||
}
|
||||
|
||||
- (void)viewDidAppear:(BOOL)animated
|
||||
@@ -416,6 +437,103 @@
|
||||
return NO;
|
||||
}
|
||||
|
||||
#pragma mark - typing management
|
||||
|
||||
- (void)removeTypingNotificationsListener
|
||||
{
|
||||
if (self.roomDataSource)
|
||||
{
|
||||
// Remove the previous live listener
|
||||
if (typingNotifListener)
|
||||
{
|
||||
[self.roomDataSource.room removeListener:typingNotifListener];
|
||||
currentTypingUsers = nil;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)listenTypingNotifications
|
||||
{
|
||||
if (self.roomDataSource)
|
||||
{
|
||||
// Add typing notification listener
|
||||
typingNotifListener = [self.roomDataSource.room listenToEventsOfTypes:@[kMXEventTypeStringTypingNotification] onEvent:^(MXEvent *event, MXEventDirection direction, MXRoomState *roomState)
|
||||
{
|
||||
|
||||
// Handle only live events
|
||||
if (direction == MXEventDirectionForwards)
|
||||
{
|
||||
// Retrieve typing users list
|
||||
NSMutableArray *typingUsers = [NSMutableArray arrayWithArray:self.roomDataSource.room.typingUsers];
|
||||
// Remove typing info for the current user
|
||||
NSUInteger index = [typingUsers indexOfObject:self.mainSession.myUser.userId];
|
||||
if (index != NSNotFound)
|
||||
{
|
||||
[typingUsers removeObjectAtIndex:index];
|
||||
}
|
||||
// Ignore this notification if both arrays are empty
|
||||
if (currentTypingUsers.count || typingUsers.count)
|
||||
{
|
||||
currentTypingUsers = typingUsers;
|
||||
[self refreshTypingView];
|
||||
}
|
||||
}
|
||||
}];
|
||||
|
||||
currentTypingUsers = self.roomDataSource.room.typingUsers;
|
||||
[self refreshTypingView];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void)refreshTypingView
|
||||
{
|
||||
NSString* text = nil;
|
||||
NSUInteger count = currentTypingUsers.count;
|
||||
|
||||
// get the room member names
|
||||
NSMutableArray *names = [[NSMutableArray alloc] init];
|
||||
|
||||
// keeps the only the first two users
|
||||
//
|
||||
for(int i = 0; i < MIN(count, 2); i++) {
|
||||
NSString* name = [currentTypingUsers objectAtIndex:i];
|
||||
|
||||
MXRoomMember* member = [self.roomDataSource.room.state memberWithUserId:name];
|
||||
|
||||
if (nil != member)
|
||||
{
|
||||
name = member.displayname;
|
||||
}
|
||||
|
||||
[names addObject:name];
|
||||
}
|
||||
|
||||
|
||||
if (0 == count)
|
||||
{
|
||||
// something to do ?
|
||||
}
|
||||
else if (1 == count)
|
||||
{
|
||||
text = [NSString stringWithFormat:NSLocalizedStringFromTable(@"room_one_user_is_typing", @"Vector", nil), [names objectAtIndex:0]];
|
||||
}
|
||||
else if (2 == count)
|
||||
{
|
||||
text = [NSString stringWithFormat:NSLocalizedStringFromTable(@"room_two_users_are_typing", @"Vector", nil), [names objectAtIndex:0], [names objectAtIndex:1]];
|
||||
}
|
||||
else
|
||||
{
|
||||
text = [NSString stringWithFormat:NSLocalizedStringFromTable(@"room_many_users_are_typing", @"Vector", nil), [names objectAtIndex:0], [names objectAtIndex:1]];
|
||||
}
|
||||
|
||||
if (self.activitiesView)
|
||||
{
|
||||
[((RoomActivitiesView*) self.activitiesView) updateTypingMessage:text];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user