Ind.ie is now Small Technology Foundation.
Commit f860a823 authored by Aral Balkan's avatar Aral Balkan

Added special case for asset URL massaging for specific-friends timelines. Fixes #97.

parent 66c024fa
......@@ -342,9 +342,6 @@ class TimelineViewController: NSViewController, WKNavigationDelegate
let messageID = (message["key"]).string!
var messageHTML = (message["value"]).string!
var assetURLPrefix = CurrentTimeline.relativeWebPrefix!.stringByAppendingPathComponent(messageID)
var filePath = NSHomeDirectory().stringByAppendingPathComponent("Pulse/Sync").stringByAppendingPathComponent(CurrentTimeline.path!).stringByAppendingPathComponent(messageID)
//
// Check if this is a message *from* someone to the all friends timeline.
// If so, we need to massage the assetURLPrefix and filePath to take this into consideration.
......@@ -352,9 +349,26 @@ class TimelineViewController: NSViewController, WKNavigationDelegate
println("Message ID: \(messageID)")
var fromPersonHandle:String = (messageID as NSString).firstMatchedGroupWithRegex(".+?Z-(.+?)$")
println("From person: \(fromPersonHandle).")
var relativeWebPrefix = CurrentTimeline.relativeWebPrefix!
if self.currentTimeline.id == fromPersonHandle
{
// For the specific friends timeline, massage the assetURLPrefix to remove the person handle first.
relativeWebPrefix = relativeWebPrefix.stringByReplacingOccurrencesOfString("\(fromPersonHandle)/", replacement: "\(SetupData.accountHandle!)/")
println("Relative web prefix after massaging for specific friends timeline: \(relativeWebPrefix)")
}
var assetURLPrefix = relativeWebPrefix.stringByAppendingPathComponent(messageID)
var filePath = NSHomeDirectory().stringByAppendingPathComponent("Pulse/Sync").stringByAppendingPathComponent(CurrentTimeline.path!).stringByAppendingPathComponent(messageID)
// println("Asset URL prefix: \(assetURLPrefix)")
// println("filePath: \(filePath)")
if fromPersonHandle != ""
{
println("The message was sent from person \(fromPersonHandle). Massaging the asset URL prefix and the file path.")
......@@ -370,7 +384,15 @@ class TimelineViewController: NSViewController, WKNavigationDelegate
let oldAssetURLPrefix = assetURLPrefix
// Add the correct folder path.
assetURLPrefix = assetURLPrefix.stringByReplacingOccurrencesOfString("/to", replacement: "/from/\(fromPersonHandle)")
if self.currentTimeline.id == fromPersonHandle
{
// Specific friends
assetURLPrefix = assetURLPrefix.stringByReplacingOccurrencesOfString("/\(SetupData.accountHandle!)/to", replacement: "/\(fromPersonHandle)/from")
}
else
{
assetURLPrefix = assetURLPrefix.stringByReplacingOccurrencesOfString("/to", replacement: "/from/\(fromPersonHandle)")
}
filePath = filePath.stringByReplacingOccurrencesOfString("/to", replacement: "/from/\(fromPersonHandle)")
......@@ -378,15 +400,15 @@ class TimelineViewController: NSViewController, WKNavigationDelegate
let filePathIndexOfThePersonsHandle = count(filePath)-fromPersonHandleLengthIncludingDash
filePath = filePath.substringToIndex(filePathIndexOfThePersonsHandle)
println("Message HTML: \(messageHTML)")
println("Old assetURLPrefix: \(oldAssetURLPrefix)")
println("New assetURLPrefix: \(assetURLPrefix)")
println("New filePath: \(filePath)")
// println("Message HTML: \(messageHTML)")
// println("Old assetURLPrefix: \(oldAssetURLPrefix)")
// println("New assetURLPrefix: \(assetURLPrefix)")
// println("New filePath: \(filePath)")
// Actually replace the old asset URL prefix with the new one in the message HTML.
messageHTML = messageHTML.stringByReplacingOccurrencesOfString(oldAssetURLPrefix, replacement: assetURLPrefix)
println("Message HTML after: \(messageHTML)")
// println("Message HTML after: \(messageHTML)")
}
else
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment