aboutsummaryrefslogtreecommitdiffstats
path: root/view/tpl/messages_widget.tpl
blob: 8dece872e3a9330dbfc3b6daca56942379a9cce2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<ul class="nav nav-tabs nav-fill clearfix">
	<li class="nav-item">
		<a class="nav-link active messages-type" href="#" title="{{$strings.messages_title}}" data-messages_type="">
			<i class="fa fa-fw fa-comment-o"></i>
		</a>
	</li>
	<li class="nav-item">
		<a class="nav-link messages-type" href="#" title="{{$strings.direct_messages_title}}" data-messages_type="direct">
			<i class="fa fa-fw fa-envelope-o"></i>
		</a>
	</li>
	{{if $feature_star}}
	<li class="nav-item">
		<a class="nav-link messages-type" href="#" title="{{$strings.starred_messages_title}}" data-messages_type="starred">
			<i class="fa fa-fw fa-star"></i>
		</a>
	</li>
	{{/if}}
	<li class="nav-item">
		<a class="nav-link messages-type" href="#" title="{{$strings.notice_messages_title}}" data-messages_type="notification">
			<i class="fa fa-fw fa-exclamation"></i>
		</a>
	</li>
</ul>
<div id="messages-widget" class="border-start border-end border-bottom overflow-auto mb-3 clearfix" style="height: 70vh;">
	<div id="messages-template" rel="template" class="d-none">
		<a href="{6}" class="list-group-item list-group-item-action message" data-b64mid="{0}">
			<div class="d-flex w-100 justify-content-between">
				<div class="mb-1 text-truncate" title="{5}">
					{7}
					<strong>{4}</strong>
				</div>
				<small class="messages-timeago text-nowrap" title="{1}"></small>
			</div>
			<div class="mb-1">
				<div class="text-break">{2}</div>
			</div>
			<small>{3}</small>
			{8}
		</a>
	</div>
	<div id="messages-container" class="list-group list-group-flush" data-offset="10">
		<div id="messages-author-container" class="list-group-item notifications-textinput">
			<div class="text-muted notifications-textinput-filter"><i class="fa fa-fw fa-filter"></i></div>
			<input id="messages-author" type="text" class="form-control form-control-sm" placeholder="{{$strings.filter}}">
			<div id="messages-author-input-clear" class="text-muted notifications-textinput-clear d-none"><i class="fa fa-times"></i></div>
		</div>
		{{foreach $entries as $e}}
		<a href="{{$e.href}}" class="list-group-item list-group-item-action message" data-b64mid="{{$e.b64mid}}">
			<div class="d-flex w-100 justify-content-between">
				<div class="mb-1 text-truncate" title="{{$e.author_addr}}">
					{{$e.icon}}
					<strong>{{$e.author_name}}</strong>
				</div>
				<small class="messages-timeago text-nowrap" title="{{$e.created}}"></small>
			</div>
			<div class="mb-1">
				<div class="text-break">{{$e.summary}}</div>
			</div>
			<small>{{$e.info}}</small>
			{{if $e.unseen_count}}
			<span class="badge bg-transparent border border-{{$e.unseen_class}} text-{{$e.unseen_class}} rounded-pill position-absolute bottom-0 end-0 m-2" title="{{$strings.unseen_count}}">{{$e.unseen_count}}</span>
			{{/if}}
		</a>
		{{/foreach}}
		<div id="messages-empty" class="list-group-item border-0"{{if $entries}} style="display: none;"{{/if}}>
			{{$strings.empty}}...
		</div>
		<div id="messages-loading" class="list-group-item" style="display: none;">
			{{$strings.loading}}<span class="jumping-dots"><span class="dot-1">.</span><span class="dot-2">.</span><span class="dot-3">.</span></span>
		</div>
	</div>
</div>
<script>
	let messages_offset = {{$offset}};
	let get_messages_page_active = false;
	let messages_type;
	let author_hash;
	let author_url;
	let author;

	$(document).ready(function () {
		$('.messages-timeago').timeago();
		if (bParam_mid) {
			$('.message[data-b64mid=\'' + bParam_mid + '\']').addClass('active');
		}

		$("#messages-author").name_autocomplete(baseurl + '/acl', 'a', false, function(data) {
			// a workaround to not re-trigger autocomplete after initial click
			$("#messages-author").val('').attr('placeholder', data.name);
			$('#textcomplete-dropdown').hide();

			$('#messages-container .message').remove();
			$('#messages-author-container').addClass('active sticky-top');
			$('#messages-author-input-clear').removeClass('d-none');
			author_hash = data.xid;
			author_url = data.url;
			author = messages_type === 'notification' ? author_url : author_hash;
			messages_offset = 0;
			get_messages_page();
		});

		$(document).on('click', '#messages-author-input-clear', function() {
			$('#messages-author').val('');
			$("#messages-author").attr('placeholder', '{{$strings.filter}}');

			$('#messages-author-container').removeClass('active sticky-top');
			$('#messages-author-input-clear').addClass('d-none');
			$('#messages-container .message').remove();
			author = '';
			author_hash = '';
			author_url = '';
			messages_offset = 0;
			get_messages_page();
		});

	});

	$('#messages-widget').on('scroll', function() {
		if(this.scrollTop > this.scrollHeight - this.clientHeight - (this.scrollHeight/7)) {
			get_messages_page();
		}
	});

	$(document).on('click', '.messages-type', function(e) {
		e.preventDefault();
		$('.messages-type').removeClass('active');
		$(this).addClass('active');
		messages_offset = 0;
		messages_type = $(this).data('messages_type');
		author = messages_type === 'notification' ? author_url : author_hash;
		$('#messages-container .message').remove();
		get_messages_page();
	});

	function get_messages_page() {

		if (get_messages_page_active)
			return;

		if (messages_offset === -1)
			return;

		get_messages_page_active = true;
		$('#messages-loading').show();
		$('#messages-empty').hide();

		$.ajax({
			type: 'post',
			url: 'hq',
			data: {
				offset: messages_offset,
				type: messages_type,
				author: author
			}
		}).done(function(obj) {
			get_messages_page_active = false;
			messages_offset = obj.offset;
			let html;
			let tpl = $('#messages-template[rel=template]').html();
			if (obj.entries.length) {
				obj.entries.forEach(function(e) {
					html = tpl.format(
						e.b64mid,
						e.created,
						e.summary,
						e.info,
						e.author_name,
						e.author_addr,
						e.href,
						e.icon,
						e.unseen_count ? '<span class="badge bg-transparent border border-' + e.unseen_class + ' text-' + e.unseen_class + ' rounded-pill position-absolute bottom-0 end-0 m-2" title="{{$strings.unseen_count}}">' + e.unseen_count + '</span>' : ''
					);
					$('#messages-loading').before(html);
				});
			}
			else {
				$('#messages-empty').show();
			}
			if (bParam_mid) {
				$('.message[data-b64mid=\'' + bParam_mid + '\']').addClass('active');
			}
			$('#messages-loading').hide();
			$('.messages-timeago').timeago();

		});

	}
</script>