viezel/TiSocial.Framework

Send HTML texts for email and plain text for others Activities on Social.activityView()

Closed this issue · 4 comments

Guys, first, thanks for this module that every Titanium developer uses.
I was trying to send HTML messages by email and non-html for others, like Twitter, SMS or Facebook. The scenario was:

var message = "<html><b>HTML message is awesome</b><html>";
Social.activityView({
     subject : 'I would like to share this '+type+' with you',
     text: message,
     removeIcons : 'contact,camera',
     emailIsHTML : true
});

So when the "emailIsHTML" is set to "true" the issue appears: the others activities texts become empty "".

Diving in the module code I noticed this (NappItemProvider.m):

if ([activityType isEqualToString:UIActivityTypeMail]) {
        NSString *text = [NSString stringWithFormat:@"%@%@%@", @"<html><head></head><body>", _customText, @"</body></html>"];
        NSLog(@"[INFO] Sharing the following as HTML %@",text);

        return text;
    }

    return @"";

I think that's the problem!
So I fixed, and created a brand new option for Ti developers: htmlText
So now, if emailIsHTML is true, the e-mail activity will read this property to compose the email dialog.
The code in module files now looks like this:

-- DKNappSocialModule.m -> for both activityPopover & activityView

NSString *htmlshareText = [TiUtils stringValue:@"htmlText" properties:arguments def:nil];
NSString *shareText = [TiUtils stringValue:@"text" properties:arguments def:@""];

if(shareText){
        if (emailIsHTML) {
            NappItemProvider *textItem = [[NappItemProvider alloc] initWithPlaceholderItem:@""];
            textItem.customText = shareText;
            if(htmlshareText){
                textItem.customHtmlText = htmlshareText;
            }else{
                textItem.customHtmlText = shareText;
            }
            [activityItems addObject:textItem];
        } else {
            [activityItems addObject:shareText];
        }

    }

-- NappItemProvider.m

if ([activityType isEqualToString:UIActivityTypeMail]) {
        NSString *text = [NSString stringWithFormat:@"%@%@%@", @"<html><head></head><body>", _customHtmlText, @"</body></html>"];
        NSLog(@"[INFO] Sharing the following as HTML %@",text);

        return text;
    }else{
        NSString *nonhtmltext = [NSString stringWithFormat:@"%@", _customText];
        return nonhtmltext;
    }

    return @"";

And of course, the

@synthesize customHtmlText = _customHtmlText;

Now, back to Titanium, the code will looks like this:

var noHtmlMessage = "Non html message";
var htmlMessage = "<b>HTML message is awesome</b>";
Social.activityView({
       subject : 'Cool message subject',
       text: noHtmlMessage,
       htmlText : htmlMessage,
       removeIcons : 'contact,camera',
       emailIsHTML : true
});

So, will looks like this on Mobile
Bold for text! Yay \o/
img_2292

img_2293

Another detail, if 'htmlText' is null, I'm using the same text for both activities.

That's it. If Napp guys (@viezel) like this improvement, I think it would be awesome if it becomes part of the root module.
I've uploaded my version of the module, so you guys can check if you like it:
https://www.dropbox.com/s/x2xmpcux8x78hhr/dk.napp.social-iphone-1.8.2.zip?dl=0

PS
About Facebook empty message: This is a problem with iOS 8.2+ and new Facebook rules, this thread make it a little bit clear:
http://stackoverflow.com/questions/29943202/setinitialtext-method-in-slcomposeviewcontroller-ios-8-3-does-not-show-text-in-f

Looking forward for your feedbacks!
Code Strong

Looking great. Can you please make a PR?

I've created a new branch, commited, but I'm not able to push it (to make the pull request).
screen shot 2015-07-09 at 11 05 46

=(

you have to fork it to your own github account.
then create a new branch on that account.

done =)
#144