Skip to content
This repository has been archived by the owner on Jan 15, 2022. It is now read-only.

Commit

Permalink
MOB-1839 Use UTF-8 for message post from Share Extension
Browse files Browse the repository at this point in the history
- The POST Activity request from Share Extension doesn't specify the charset as UFT-8 so sometime this may cause a font text problem.- Use Method convertStringFromHTML in NSString+HTML Category to convert html to plain text.
- Don't sent the page title while sharing link activity to avoid dupblicate with the message (which by default contain the title of the page web)
  • Loading branch information
diego10bk committed Oct 13, 2015
1 parent 6482f74 commit 219c116
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
9 changes: 2 additions & 7 deletions Sources/Shared/Data Manager/Model/Social/SocialActivity.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#import "NSDate+Formatting.h"
#import "GTMNSString+HTML.h"
#import "ActivityHelper.h"
#import "NSString+HTML.h"

@implementation SocialActivity

Expand Down Expand Up @@ -152,13 +153,7 @@ -(NSAttributedString * ) getHTMLAttributedStringFromHTML:(NSString *) html {
string = [string stringByReplacingOccurrencesOfString:@"</a>" withString:@""];

//remove all others HTML TAG
NSRange range;
while ((range = [string rangeOfString:@"<[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound) {
string = [string stringByReplacingCharactersInRange:range withString:@""];

}

string = [string gtm_stringByUnescapingFromHTML];
string = [string stringByConvertingHTMLToPlainText];
NSMutableAttributedString * htmlAttributedString = [[NSMutableAttributedString alloc] initWithString:string];
for (NSString * link in links){
[htmlAttributedString addAttributes:kAttributeURL range:[string rangeOfString:link]];
Expand Down
2 changes: 1 addition & 1 deletion share-extension/PostItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ -(void) searchForImageInURL {
range = [pagesource rangeOfString:@"<title>"];
NSRange endTagRange = [pagesource rangeOfString:@"</title>"];
if (range.location!= NSNotFound && endTagRange.location != NSNotFound && endTagRange.location > range.location + range.length){
NSString * title = [pagesource substringWithRange:NSMakeRange(range.location+range.length, endTagRange.location-range.location)];
NSString * title = [pagesource substringWithRange:NSMakeRange(range.location+range.length, endTagRange.location-range.location-range.length)];
if (title.length >0) {
self.pageWebTitle = title;
}
Expand Down
8 changes: 2 additions & 6 deletions share-extension/ShareViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -873,8 +873,8 @@ -(void) postMessage:(NSString *) message fileURL:(NSString *) fileURL fileName:(
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:postURL]];
request.HTTPMethod = @"POST";
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"UTF-8" forHTTPHeaderField:@"charset"];
[request setValue:kUserAgentHeader forHTTPHeaderField:@"User-Agent"];


if (fileURL) {
type = @"DOC_ACTIVITY";
Expand Down Expand Up @@ -939,17 +939,13 @@ -(void) postLinkActivity:(PostItem*) item {
postURL = [NSString stringWithFormat:@"%@?identity_id=%@", postURL, selectedSpace.spaceId];
}
NSString * imgSrc = item.imageURLFromLink? item.imageURLFromLink : @"";
NSString * pageWebTitle = item.pageWebTitle;
if (pageWebTitle==nil || pageWebTitle.length ==0){
pageWebTitle = postActivity.message;
}

NSDictionary * templateParams = @{
@"comment":postActivity.message,
@"link":item.url.absoluteString,
@"description":@"",
@"image":imgSrc,
@"title":pageWebTitle
@"title":@" "
};
NSDictionary * dictionary = @{@"type": item.type,
@"title":postActivity.message,
Expand Down

0 comments on commit 219c116

Please sign in to comment.