Commit 67496a77 authored by Ujvari Gergely's avatar Ujvari Gergely

Redirect user and tag stream to stream/ and remove their template.

parent 23f6b4d7
get_quote = (annotation) ->
if annotation.quote? then return annotation.quote
if not 'target' in annotation then return ''
quote = '(Reply annotation)'
for target in annotation['target']
for selector in target['selector']
if selector['type'] is 'TextQuoteSelector'
quote = selector['exact'] + ' '
quote
class Stream
path: window.location.protocol + '//' + window.location.hostname + ':' +
window.location.port + '/__streamer__'
this.$inject = ['$location','$scope','$timeout','streamfilter']
constructor: ($location, $scope, $timeout, streamfilter) ->
$scope.annotations = []
urlParts = $location.absUrl().split('/')
$scope.filterValue = urlParts.pop()
filterType = urlParts.pop()
if filterType == "t"
$scope.filterDescription = "Annotations with tag '#{ $scope.filterValue }'"
filterClause = 'tags:i#' + $scope.filterValue
else
$scope.filterDescription = "Annotations by user '#{ $scope.filterValue }'"
filterClause = 'user:i=' + $scope.filterValue
# Generate client ID
buffer = new Array(16)
uuid.v4 null, buffer, 0
@clientID = uuid.unparse buffer
$scope.filter =
streamfilter
.setPastDataHits(150)
.setMatchPolicyIncludeAny()
.setClausesParse(filterClause)
.getFilter()
$scope.manage_new_data = (data, action) =>
for annotation in data
annotation.action = action
annotation.quote = get_quote annotation
annotation._share_link = window.location.protocol +
'//' + window.location.hostname + ':' + window.location.port + "/a/" + annotation.id
annotation._anim = 'fade'
switch action
when 'create', 'past'
unless annotation in $scope.annotations
$scope.annotations.unshift annotation
when 'update'
index = 0
for ann in $scope.annotations
if ann.id is annotation.id
# Remove the original
$scope.annotations.splice index,1
# Put back the edited
$scope.annotations.unshift annotation
break
index +=1
when 'delete'
for ann in $scope.annotations
if ann.id is annotation.id
$scope.annotations.splice index,1
break
index +=1
$scope.open = =>
$scope.sock = new SockJS(@path)
$scope.sock.onopen = =>
sockmsg =
filter: $scope.filter
clientID: @clientID
$scope.sock.send JSON.stringify sockmsg
$scope.sock.onclose = =>
$timeout $scope.open, 5000
$scope.sock.onmessage = (msg) =>
console.log 'Got something'
console.log msg
unless msg.data.type? and msg.data.type is 'annotation-notification'
return
data = msg.data.payload
action = msg.data.options.action
unless data instanceof Array then data = [data]
$scope.$apply =>
$scope.manage_new_data data, action
$scope.open()
angular.module('h.stream',['h.streamfilter', 'h.filters','h.directives','bootstrap'])
.controller('StreamCtrl', Stream)
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