Adium

Changeset 22163

Show
Ignore:
Timestamp:
01/06/2008 10:55:57 PM (11 months ago)
Author:
evands
Message:

Translate links into the form "title (link)" when sending over MSN without OTR, as the protocol doesn't support proper links. Fixes #8535

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Frameworks/AIUtilities Framework/Source/AIAttributedStringAdditions.m

    r19438 r22163  
    527527                         
    528528                        if (URL) { 
    529                                 NSString        *replacementString = [URL absoluteString]; 
    530                                  
    531529                                if (!newAttributedString) { 
    532530                                        newAttributedString = [[self mutableCopy] autorelease]; 
     
    534532                                } 
    535533 
    536                                 //Replace the URL with the NSString of where it was pointing 
     534                                NSString        *absoluteString = [URL absoluteString]; 
     535                                NSString        *originalTitle = [[newAttributedString string] substringWithRange:searchRange]; 
     536                                NSString        *replacementString; 
     537                                 
     538                                if ([originalTitle caseInsensitiveCompare:absoluteString] == NSOrderedSame) { 
     539                                        replacementString = originalTitle; 
     540 
     541                                } else { 
     542                                        replacementString = [NSString stringWithFormat:@"%@ (%@)", originalTitle, absoluteString]; 
     543                                } 
     544 
    537545                                [newAttributedString replaceCharactersInRange:searchRange  
    538546                                                                                                   withString:replacementString]; 
    539547                                 
    540                                 /*The attributed string may have changed length; modify our  
    541                                         *       searchRange and cached length to reflect the string we just 
    542                                         *       inserted. 
    543                                         */ 
     548                                //Modify our searchRange and cached length to reflect the string we just inserted. 
    544549                                searchRange.length = [replacementString length]; 
    545550                                length = [newAttributedString length]; 
    546551                                 
    547                                 //Now remove the URL 
     552                                //Now remove the link attribute 
    548553                                [newAttributedString removeAttribute:NSLinkAttributeName range:searchRange]; 
    549554                        } 
  • trunk/Plugins/Purple Service/ESPurpleMSNAccount.m

    r21876 r22163  
    187187{ 
    188188        return [AIHTMLDecoder encodeHTML:inAttributedString 
     189                                                         headers:NO 
     190                                                        fontTags:YES 
     191                                  includingColorTags:YES 
     192                                           closeFontTags:YES 
     193                                                   styleTags:YES 
     194                  closeStyleTagsOnFontChange:YES 
     195                                          encodeNonASCII:NO 
     196                                                encodeSpaces:NO 
     197                                                  imagesPath:nil 
     198                                   attachmentsAsText:YES 
     199                   onlyIncludeOutgoingImages:NO 
     200                                          simpleTagsOnly:YES 
     201                                          bodyBackground:NO 
     202                                 allowJavascriptURLs:YES]; 
     203} 
     204 
     205- (NSString *)encodedAttributedStringForSendingContentMessage:(AIContentMessage *)inContentMessage 
     206{ 
     207        /* If we're sending a message on an encryption chat, we can encode the HTML normally, as links will go through fine. 
     208         * If we're sending a message normally, MSN will drop the title of any link, so we preprocess it to be in the form "title (link)" 
     209         */ 
     210        return [AIHTMLDecoder encodeHTML:([[inContentMessage chat] isSecure] ? inAttributedString : [inAttributedString attributedStringByConvertingLinksToStrings]) 
    189211                                                         headers:NO 
    190212                                                        fontTags:YES