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

Join MUC with an iPhone that contains a smiley in the device name #879

Closed
Bcow7 opened this issue Feb 23, 2017 · 2 comments
Closed

Join MUC with an iPhone that contains a smiley in the device name #879

Bcow7 opened this issue Feb 23, 2017 · 2 comments

Comments

@Bcow7
Copy link

Bcow7 commented Feb 23, 2017

Hi guys,

I just found a small issue. When I'm try to join a MUC with an iPhone that contains a smiley in the device name, it doesn't work. When I remove the smiley, everything works fine!

By "device name", I mean the parameter : Settings>General>About>Name

Cheers

@chrisballinger
Copy link
Collaborator

Does the MUC code in XMPPFramework use your device name, or is that in your code? This might be a problem with libxml.

Bcow7 pushed a commit to Bcow7/XMPPFramework that referenced this issue Feb 24, 2017
As reported in the issue robbiehanson#879, it isn’t possible to join a MUC with a
nickname that contains some Emojis.
Quick fix that prevent failure.
@Bcow7
Copy link
Author

Bcow7 commented Feb 24, 2017

Hi @chrisballinger ,

You're right! I was calling this method in my code
[myRoom joinRoomUsingNickname:[[UIDevice currentDevice] name] history:history];

And I wasn't handling Emojis in the nickname, so I added this in my code :

#include <unicode/utf8.h>
@implementation NSString (EmojiExtension)
- (NSString *)stringByRemovingEmoji {
    NSData *d = [self dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:NO];
    if(!d) return nil;
    const char *buf = d.bytes;
    unsigned int len = (unsigned int)[d length];
    char *s = (char *)malloc(len);
    unsigned int ii = 0, oi = 0; // in index, out index
    UChar32 uc;
    while (ii < len) {
        U8_NEXT_UNSAFE(buf, ii, uc);
        if(0x2100 <= uc && uc <= 0x26ff) continue;
        if(0x1d000 <= uc && uc <= 0x1f77f) continue;
        U8_APPEND_UNSAFE(s, oi, uc);
    }
    return [[NSString alloc] initWithBytesNoCopy:s length:oi encoding:NSUTF8StringEncoding freeWhenDone:YES];
}
@end

I call

[myRoom joinRoomUsingNickname:[[[UIDevice currentDevice] name] stringByRemovingEmoji] history:history];

and it works fine! So I update the code in XMPPFramework to handle this case and I created a pull request.

@Bcow7 Bcow7 closed this as completed Feb 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants