0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-13 09:03:01 +01:00
construct/share/webapp/js/room/controller.js

183 lines
3.7 KiB
JavaScript
Raw Normal View History

/*
2018-02-04 03:22:01 +01:00
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
*/
'use strict';
mc.ng.app.controller('room', class extends mc.ng.controller
{
constructor($scope)
{
super("room", $scope);
$scope.open_bracket = this.open_bracket;
$scope.close_bracket = this.close_bracket;
2017-11-16 02:34:42 +01:00
$scope.sender_domid = this.sender_domid;
$scope.sender_sid = this.sender_sid;
$scope.delta = this.delta;
$scope.should_show_target = this.should_show_target;
$scope.should_show_avatar = this.should_show_avatar;
2017-11-16 02:34:42 +01:00
$scope.dots_to_underscores = this.dots_to_underscores;
$scope.handler_path = this.handler_path;
2017-11-16 02:34:42 +01:00
$scope.handler_exists = this.handler_exists;
$scope.sender_is_server = this.sender_is_server;
}
destructor()
{
}
constructed()
{
}
delta(newval)
{
//if(!$scope.room.opts.local)
// window.console.log("room id: " + $scope.room.id);
debug.object({W: $scope.$$watchers}, 3);
//console.log("A " + debug.stringify(oldval, 1));
console.log("B " + debug.stringify(newval, 1));
//window.console.log("C " + debug.stringify($scope.room.timeline, 1));
//$scope.room.timeline = newval;
return newval;
}
//$scope.$watchCollection('room.timeline', delta);
//$scope.$watchCollection('room.state.history_visibility.content', hist);
should_show_target(event)
{
if(!event.target || Object.keys(event.target) == 0)
return false;
if(event.target == event.sender)
return false;
return true;
}
should_show_avatar(url)
{
if(!url)
return false;
return url.startsWith("http://") ||
url.startsWith("https://");
}
2017-11-16 02:34:42 +01:00
sender_domid(sender)
{
2017-11-25 23:23:15 +01:00
if(!sender)
return sender;
2017-11-16 02:34:42 +01:00
let sid = this.sender_sid(sender);
let domid = mc.m.domid(sender);
2017-11-25 23:23:15 +01:00
if(!domid)
return sender;
let remain = 24 - sid.length;
2017-11-16 02:34:42 +01:00
let start = remain < domid.length? domid.length - remain : 0;
let ret = domid.substr(start, remain);
if(ret.length < domid.length)
ret = "..." + ret;
return ret;
}
sender_sid(sender)
{
let displayname = maybe(() => mc.users[sender].displayname);
let str = displayname? displayname : mc.m.sid(sender);
2017-11-25 23:23:15 +01:00
let len = 28 - 3;
return str? str.substr(0, len) : sender;
2017-11-16 02:34:42 +01:00
}
open_bracket(event)
{
if(event.state_key !== undefined)
return '';
switch(event.type)
{
case "m.room.message":
{
switch(maybe(() => event.content.msgtype))
{
case "m.notice": return '(';
case "m.emote": return '';
default: return '<';
}
}
case "m.room.member":
return '';
default:
return '<';
}
}
close_bracket(event)
{
if(event.state_key !== undefined)
return '';
switch(event.type)
{
case "m.room.message":
{
switch(maybe(() => event.content.msgtype))
{
case "m.notice": return ')';
case "m.emote": return '';
default: return '>';
}
}
case "m.room.member":
return '';
default:
return '>';
}
}
2017-11-16 02:34:42 +01:00
dots_to_underscores(str)
{
2017-11-25 23:23:15 +01:00
return defined(str)? str.replace(/\./g, '_') : str;
2017-11-16 02:34:42 +01:00
}
handler_path(type)
{
let part = Array.isArray(type)? type : [type];
let sel = "ircd_room_event";
for(let i in part)
sel += "__" + this.dots_to_underscores(part[i]);
return sel;
}
2017-11-16 02:34:42 +01:00
handler_exists(type)
{
let path = "#" + this.handler_path(type);
return $(path).length > 0;
2017-11-16 02:34:42 +01:00
}
//TODO: arbitrary
sender_is_server(event)
{
let sender = maybe(() => event.sender);
if(!sender)
return false;
return mc.m.sid(sender) == "ircd";
}
});