-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return ni:/// URIs (or, optionally, /.well-known/ni/ paths) for media. Provide a helper to serve the .well-known paths from a service worker. No more option to get media URIs from the persistence layer, instead each layer will provide a fit-for-platform mechanism to map ni URIs to data, file paths, whatever make sense in context. For web that's Response object or service worker interception. Avatars are now two-part: the possible-null ni URI and the never-null placeholder. Display the placeholder while loading the real avatar data, or if it is null or loading it fails for any reason.
- Loading branch information
1 parent
6a377c1
commit b483f8e
Showing
13 changed files
with
191 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package snikket; | ||
|
||
@:expose | ||
class Config { | ||
/** | ||
Produce /.well-known/ni/ paths instead of ni:/// URIs | ||
for referencing media by hash. | ||
This can be useful eg for intercepting with a Service Worker. | ||
**/ | ||
public static var relativeHashUri = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package snikket; | ||
|
||
import haxe.crypto.Base64; | ||
import haxe.io.Bytes; | ||
import haxe.io.BytesData; | ||
using StringTools; | ||
|
||
import snikket.Config; | ||
|
||
#if cpp | ||
import HaxeCBridge; | ||
#end | ||
|
||
@:expose | ||
@:nullSafety(Strict) | ||
#if cpp | ||
@:build(HaxeCBridge.expose()) | ||
@:build(HaxeSwiftBridge.expose()) | ||
#end | ||
class Hash { | ||
public final algorithm: String; | ||
@:allow(snikket) | ||
private final hash: BytesData; | ||
|
||
@:allow(snikket) | ||
private function new(algorithm: String, hash: BytesData) { | ||
this.algorithm = algorithm; | ||
this.hash = hash; | ||
} | ||
|
||
public static function fromHex(algorithm: String, hash: String) { | ||
return new Hash(algorithm, Bytes.ofHex(hash).getData()); | ||
} | ||
|
||
public static function fromUri(uri: String): Null<Hash> { | ||
if (uri.startsWith("cid:") && uri.endsWith("@bob.xmpp.org") && uri.contains("+")) { | ||
final parts = uri.substr(4).split("@")[0].split("+"); | ||
final algo = parts[0] == "sha1" ? "sha-1" : parts[0]; | ||
return Hash.fromHex(algo, parts[1]); | ||
} if (uri.startsWith("ni:///") && uri.contains(";")) { | ||
final parts = uri.substring(6).split(';'); | ||
return new Hash(parts[0], Base64.urlDecode(parts[1]).getData()); | ||
} else if (uri.startsWith("/.well-known/ni/")) { | ||
final parts = uri.substring(16).split('/'); | ||
return new Hash(parts[0], Base64.urlDecode(parts[1]).getData()); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public function toUri() { | ||
if (Config.relativeHashUri) { | ||
return "/.well-known/ni/" + algorithm.urlEncode() + "/" + toBase64Url(); | ||
} else { | ||
return "ni:///" + algorithm.urlEncode() + ";" + toBase64Url(); | ||
} | ||
} | ||
|
||
public function toHex() { | ||
return Bytes.ofData(hash).toHex(); | ||
} | ||
|
||
public function toBase64() { | ||
return Base64.encode(Bytes.ofData(hash)); | ||
} | ||
|
||
public function toBase64Url() { | ||
return Base64.urlEncode(Bytes.ofData(hash)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package snikket; | ||
|
||
#if cpp | ||
import HaxeCBridge; | ||
#end | ||
|
||
@:expose | ||
@:nullSafety(Strict) | ||
#if cpp | ||
@:build(HaxeCBridge.expose()) | ||
@:build(HaxeSwiftBridge.expose()) | ||
#end | ||
class Participant { | ||
public final displayName: String; | ||
public final photoUri: Null<String>; | ||
public final placeholderUri: String; | ||
|
||
@:allow(snikket) | ||
private function new(displayName: String, photoUri: Null<String>, placeholderUri: String) { | ||
this.displayName = displayName; | ||
this.photoUri = photoUri; | ||
this.placeholderUri = placeholderUri; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.