2019-08-22 02:32:14 +10:00
|
|
|
function numberWrapAround(num, max) {
|
|
|
|
return num < 0 ? max + (num % max) : (num % max)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-24 16:14:34 +10:00
|
|
|
function hsluv(hue, saturation, lightness, alpha=1.0) {
|
2019-08-22 02:32:14 +10:00
|
|
|
hue = numberWrapAround(hue, 360)
|
2019-07-26 09:19:24 +10:00
|
|
|
let rgb = py.callSync("hsluv", [hue, saturation, lightness])
|
2019-07-24 16:14:34 +10:00
|
|
|
return Qt.rgba(rgb[0], rgb[1], rgb[2], alpha)
|
|
|
|
}
|
2019-07-18 18:38:22 +10:00
|
|
|
|
2019-07-18 15:27:14 +10:00
|
|
|
|
2019-07-04 12:31:29 +10:00
|
|
|
function hueFrom(string) {
|
2019-07-24 16:14:34 +10:00
|
|
|
// Calculate and return a unique hue between 0 and 360 for the string
|
2019-07-18 19:18:13 +10:00
|
|
|
let hue = 0
|
|
|
|
for (let i = 0; i < string.length; i++) {
|
2019-07-04 12:31:29 +10:00
|
|
|
hue += string.charCodeAt(i) * 99
|
|
|
|
}
|
2019-07-24 16:14:34 +10:00
|
|
|
return hue % 360
|
2019-07-04 12:31:29 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-05 06:56:34 +10:00
|
|
|
function nameColor(name) {
|
2019-08-22 02:38:01 +10:00
|
|
|
return hsluv(
|
2019-07-04 12:31:29 +10:00
|
|
|
hueFrom(name),
|
2019-07-24 16:14:34 +10:00
|
|
|
theme.controls.displayName.saturation,
|
|
|
|
theme.controls.displayName.lightness,
|
2019-07-04 12:31:29 +10:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Big performance refactoring & various improvements
Instead of passing all sorts of events for the JS to handle and manually
add to different data models, we now handle everything we can in Python.
For any change, the python models send a sync event with their
contents (no more than 4 times per second) to JS, and the QSyncable
library's JsonListModel takes care of converting it to a QML ListModel
and sending the appropriate signals.
The SortFilterProxyModel library is not used anymore, the only case
where we need to filter/sort something now is when the user interacts
with the "Filter rooms" or "Filter members" fields. These cases are
handled by a simple JS function.
We now keep separated room and timeline models for different accounts,
the previous approach of sharing all the data we could between accounts
created a lot of complications (local echoes, decrypted messages
replacing others, etc).
The users's own account profile changes are now hidden in the timeline.
On startup, if all events for a room were only own profile changes, more
events will be loaded.
Any kind of image format supported by Qt is now handled by the
pyotherside image provider, instead of just PNG/JPG.
SVGs which previously caused errors are supported as well.
The typing members bar paddings/margins are fixed.
The behavior of the avatar/"upload a profile picture" overlay is fixed.
Config files read from disk are now cached (TODO: make them reloadable
again).
Pylint is not used anymore because of all its annoying false warnings
and lack of understanding for dataclasses, it is replaced by flake8 with
a custom config and various plugins.
Debug mode is now considered on if the program was compiled with
the right option, instead of taking an argument from CLI.
When on, C++ will set a flag in the Window QML component.
The loading screen is now unloaded after the UI is ready, where
previously it just stayed in the background invisible and wasted CPU.
The overall refactoring and improvements make us now able to handle
rooms with thousand of members and no lazy-loading, where previously
everything would freeze and simply scrolling up to load past events
in any room would block the UI for a few seconds.
2019-08-11 22:01:22 +10:00
|
|
|
function coloredNameHtml(name, userId, displayText=null, disambiguate=false) {
|
2019-07-07 14:24:23 +10:00
|
|
|
// substring: remove leading @
|
2019-07-18 18:46:37 +10:00
|
|
|
return "<font color='" + nameColor(name || userId.substring(1)) + "'>" +
|
|
|
|
escapeHtml(displayText || name || userId) +
|
2019-07-05 06:56:34 +10:00
|
|
|
"</font>"
|
2019-07-04 14:24:21 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-04 12:31:29 +10:00
|
|
|
function escapeHtml(string) {
|
|
|
|
// Replace special HTML characters by encoded alternatives
|
|
|
|
return string.replace("&", "&")
|
|
|
|
.replace("<", "<")
|
|
|
|
.replace(">", ">")
|
|
|
|
.replace('"', """)
|
|
|
|
.replace("'", "'")
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-20 13:07:26 +10:00
|
|
|
function processedEventText(ev) {
|
Big performance refactoring & various improvements
Instead of passing all sorts of events for the JS to handle and manually
add to different data models, we now handle everything we can in Python.
For any change, the python models send a sync event with their
contents (no more than 4 times per second) to JS, and the QSyncable
library's JsonListModel takes care of converting it to a QML ListModel
and sending the appropriate signals.
The SortFilterProxyModel library is not used anymore, the only case
where we need to filter/sort something now is when the user interacts
with the "Filter rooms" or "Filter members" fields. These cases are
handled by a simple JS function.
We now keep separated room and timeline models for different accounts,
the previous approach of sharing all the data we could between accounts
created a lot of complications (local echoes, decrypted messages
replacing others, etc).
The users's own account profile changes are now hidden in the timeline.
On startup, if all events for a room were only own profile changes, more
events will be loaded.
Any kind of image format supported by Qt is now handled by the
pyotherside image provider, instead of just PNG/JPG.
SVGs which previously caused errors are supported as well.
The typing members bar paddings/margins are fixed.
The behavior of the avatar/"upload a profile picture" overlay is fixed.
Config files read from disk are now cached (TODO: make them reloadable
again).
Pylint is not used anymore because of all its annoying false warnings
and lack of understanding for dataclasses, it is replaced by flake8 with
a custom config and various plugins.
Debug mode is now considered on if the program was compiled with
the right option, instead of taking an argument from CLI.
When on, C++ will set a flag in the Window QML component.
The loading screen is now unloaded after the UI is ready, where
previously it just stayed in the background invisible and wasted CPU.
The overall refactoring and improvements make us now able to handle
rooms with thousand of members and no lazy-loading, where previously
everything would freeze and simply scrolling up to load past events
in any room would block the UI for a few seconds.
2019-08-11 22:01:22 +10:00
|
|
|
if (ev.event_type == "RoomMessageEmote") {
|
|
|
|
return "<i>" +
|
|
|
|
coloredNameHtml(ev.sender_name, ev.sender_id) + " " +
|
|
|
|
ev.content + "</i>"
|
2019-07-20 13:07:26 +10:00
|
|
|
}
|
2019-07-04 14:24:21 +10:00
|
|
|
|
Big performance refactoring & various improvements
Instead of passing all sorts of events for the JS to handle and manually
add to different data models, we now handle everything we can in Python.
For any change, the python models send a sync event with their
contents (no more than 4 times per second) to JS, and the QSyncable
library's JsonListModel takes care of converting it to a QML ListModel
and sending the appropriate signals.
The SortFilterProxyModel library is not used anymore, the only case
where we need to filter/sort something now is when the user interacts
with the "Filter rooms" or "Filter members" fields. These cases are
handled by a simple JS function.
We now keep separated room and timeline models for different accounts,
the previous approach of sharing all the data we could between accounts
created a lot of complications (local echoes, decrypted messages
replacing others, etc).
The users's own account profile changes are now hidden in the timeline.
On startup, if all events for a room were only own profile changes, more
events will be loaded.
Any kind of image format supported by Qt is now handled by the
pyotherside image provider, instead of just PNG/JPG.
SVGs which previously caused errors are supported as well.
The typing members bar paddings/margins are fixed.
The behavior of the avatar/"upload a profile picture" overlay is fixed.
Config files read from disk are now cached (TODO: make them reloadable
again).
Pylint is not used anymore because of all its annoying false warnings
and lack of understanding for dataclasses, it is replaced by flake8 with
a custom config and various plugins.
Debug mode is now considered on if the program was compiled with
the right option, instead of taking an argument from CLI.
When on, C++ will set a flag in the Window QML component.
The loading screen is now unloaded after the UI is ready, where
previously it just stayed in the background invisible and wasted CPU.
The overall refactoring and improvements make us now able to handle
rooms with thousand of members and no lazy-loading, where previously
everything would freeze and simply scrolling up to load past events
in any room would block the UI for a few seconds.
2019-08-11 22:01:22 +10:00
|
|
|
if (ev.event_type.startsWith("RoomMessage")) { return ev.content }
|
2019-07-04 12:31:29 +10:00
|
|
|
|
Big performance refactoring & various improvements
Instead of passing all sorts of events for the JS to handle and manually
add to different data models, we now handle everything we can in Python.
For any change, the python models send a sync event with their
contents (no more than 4 times per second) to JS, and the QSyncable
library's JsonListModel takes care of converting it to a QML ListModel
and sending the appropriate signals.
The SortFilterProxyModel library is not used anymore, the only case
where we need to filter/sort something now is when the user interacts
with the "Filter rooms" or "Filter members" fields. These cases are
handled by a simple JS function.
We now keep separated room and timeline models for different accounts,
the previous approach of sharing all the data we could between accounts
created a lot of complications (local echoes, decrypted messages
replacing others, etc).
The users's own account profile changes are now hidden in the timeline.
On startup, if all events for a room were only own profile changes, more
events will be loaded.
Any kind of image format supported by Qt is now handled by the
pyotherside image provider, instead of just PNG/JPG.
SVGs which previously caused errors are supported as well.
The typing members bar paddings/margins are fixed.
The behavior of the avatar/"upload a profile picture" overlay is fixed.
Config files read from disk are now cached (TODO: make them reloadable
again).
Pylint is not used anymore because of all its annoying false warnings
and lack of understanding for dataclasses, it is replaced by flake8 with
a custom config and various plugins.
Debug mode is now considered on if the program was compiled with
the right option, instead of taking an argument from CLI.
When on, C++ will set a flag in the Window QML component.
The loading screen is now unloaded after the UI is ready, where
previously it just stayed in the background invisible and wasted CPU.
The overall refactoring and improvements make us now able to handle
rooms with thousand of members and no lazy-loading, where previously
everything would freeze and simply scrolling up to load past events
in any room would block the UI for a few seconds.
2019-08-11 22:01:22 +10:00
|
|
|
let text = qsTr(ev.content).arg(
|
|
|
|
coloredNameHtml(ev.sender_name, ev.sender_id)
|
|
|
|
)
|
2019-07-04 12:31:29 +10:00
|
|
|
|
Big performance refactoring & various improvements
Instead of passing all sorts of events for the JS to handle and manually
add to different data models, we now handle everything we can in Python.
For any change, the python models send a sync event with their
contents (no more than 4 times per second) to JS, and the QSyncable
library's JsonListModel takes care of converting it to a QML ListModel
and sending the appropriate signals.
The SortFilterProxyModel library is not used anymore, the only case
where we need to filter/sort something now is when the user interacts
with the "Filter rooms" or "Filter members" fields. These cases are
handled by a simple JS function.
We now keep separated room and timeline models for different accounts,
the previous approach of sharing all the data we could between accounts
created a lot of complications (local echoes, decrypted messages
replacing others, etc).
The users's own account profile changes are now hidden in the timeline.
On startup, if all events for a room were only own profile changes, more
events will be loaded.
Any kind of image format supported by Qt is now handled by the
pyotherside image provider, instead of just PNG/JPG.
SVGs which previously caused errors are supported as well.
The typing members bar paddings/margins are fixed.
The behavior of the avatar/"upload a profile picture" overlay is fixed.
Config files read from disk are now cached (TODO: make them reloadable
again).
Pylint is not used anymore because of all its annoying false warnings
and lack of understanding for dataclasses, it is replaced by flake8 with
a custom config and various plugins.
Debug mode is now considered on if the program was compiled with
the right option, instead of taking an argument from CLI.
When on, C++ will set a flag in the Window QML component.
The loading screen is now unloaded after the UI is ready, where
previously it just stayed in the background invisible and wasted CPU.
The overall refactoring and improvements make us now able to handle
rooms with thousand of members and no lazy-loading, where previously
everything would freeze and simply scrolling up to load past events
in any room would block the UI for a few seconds.
2019-08-11 22:01:22 +10:00
|
|
|
if (text.includes("%2") && ev.target_id) {
|
|
|
|
text = text.arg(coloredNameHtml(ev.target_name, ev.target_id))
|
2019-07-04 12:31:29 +10:00
|
|
|
}
|
|
|
|
|
2019-07-20 13:07:26 +10:00
|
|
|
return text
|
2019-07-04 12:31:29 +10:00
|
|
|
}
|
2019-07-07 19:49:02 +10:00
|
|
|
|
|
|
|
|
|
|
|
function filterMatches(filter, text) {
|
2019-08-20 08:25:00 +10:00
|
|
|
let filter_lower = filter.toLowerCase()
|
2019-07-07 19:49:02 +10:00
|
|
|
|
2019-08-20 08:25:00 +10:00
|
|
|
if (filter_lower == filter) {
|
|
|
|
// Consider case only if filter isn't all lowercase (smart case)
|
|
|
|
filter = filter_lower
|
|
|
|
text = text.toLowerCase()
|
|
|
|
}
|
2019-07-07 19:49:02 +10:00
|
|
|
|
2019-08-20 08:25:00 +10:00
|
|
|
for (let word of filter.split(" ")) {
|
2019-07-18 19:18:13 +10:00
|
|
|
if (word && ! text.includes(word)) {
|
2019-07-07 19:49:02 +10:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
2019-07-14 10:15:20 +10:00
|
|
|
|
|
|
|
|
Big performance refactoring & various improvements
Instead of passing all sorts of events for the JS to handle and manually
add to different data models, we now handle everything we can in Python.
For any change, the python models send a sync event with their
contents (no more than 4 times per second) to JS, and the QSyncable
library's JsonListModel takes care of converting it to a QML ListModel
and sending the appropriate signals.
The SortFilterProxyModel library is not used anymore, the only case
where we need to filter/sort something now is when the user interacts
with the "Filter rooms" or "Filter members" fields. These cases are
handled by a simple JS function.
We now keep separated room and timeline models for different accounts,
the previous approach of sharing all the data we could between accounts
created a lot of complications (local echoes, decrypted messages
replacing others, etc).
The users's own account profile changes are now hidden in the timeline.
On startup, if all events for a room were only own profile changes, more
events will be loaded.
Any kind of image format supported by Qt is now handled by the
pyotherside image provider, instead of just PNG/JPG.
SVGs which previously caused errors are supported as well.
The typing members bar paddings/margins are fixed.
The behavior of the avatar/"upload a profile picture" overlay is fixed.
Config files read from disk are now cached (TODO: make them reloadable
again).
Pylint is not used anymore because of all its annoying false warnings
and lack of understanding for dataclasses, it is replaced by flake8 with
a custom config and various plugins.
Debug mode is now considered on if the program was compiled with
the right option, instead of taking an argument from CLI.
When on, C++ will set a flag in the Window QML component.
The loading screen is now unloaded after the UI is ready, where
previously it just stayed in the background invisible and wasted CPU.
The overall refactoring and improvements make us now able to handle
rooms with thousand of members and no lazy-loading, where previously
everything would freeze and simply scrolling up to load past events
in any room would block the UI for a few seconds.
2019-08-11 22:01:22 +10:00
|
|
|
function filterModelSource(source, filter_text, property="filter_string") {
|
2019-08-20 00:28:49 +10:00
|
|
|
if (! filter_text) return source
|
Big performance refactoring & various improvements
Instead of passing all sorts of events for the JS to handle and manually
add to different data models, we now handle everything we can in Python.
For any change, the python models send a sync event with their
contents (no more than 4 times per second) to JS, and the QSyncable
library's JsonListModel takes care of converting it to a QML ListModel
and sending the appropriate signals.
The SortFilterProxyModel library is not used anymore, the only case
where we need to filter/sort something now is when the user interacts
with the "Filter rooms" or "Filter members" fields. These cases are
handled by a simple JS function.
We now keep separated room and timeline models for different accounts,
the previous approach of sharing all the data we could between accounts
created a lot of complications (local echoes, decrypted messages
replacing others, etc).
The users's own account profile changes are now hidden in the timeline.
On startup, if all events for a room were only own profile changes, more
events will be loaded.
Any kind of image format supported by Qt is now handled by the
pyotherside image provider, instead of just PNG/JPG.
SVGs which previously caused errors are supported as well.
The typing members bar paddings/margins are fixed.
The behavior of the avatar/"upload a profile picture" overlay is fixed.
Config files read from disk are now cached (TODO: make them reloadable
again).
Pylint is not used anymore because of all its annoying false warnings
and lack of understanding for dataclasses, it is replaced by flake8 with
a custom config and various plugins.
Debug mode is now considered on if the program was compiled with
the right option, instead of taking an argument from CLI.
When on, C++ will set a flag in the Window QML component.
The loading screen is now unloaded after the UI is ready, where
previously it just stayed in the background invisible and wasted CPU.
The overall refactoring and improvements make us now able to handle
rooms with thousand of members and no lazy-loading, where previously
everything would freeze and simply scrolling up to load past events
in any room would block the UI for a few seconds.
2019-08-11 22:01:22 +10:00
|
|
|
let results = []
|
2019-08-20 00:28:49 +10:00
|
|
|
|
|
|
|
for (let i = 0; i < source.length; i++) {
|
|
|
|
if (filterMatches(filter_text, source[i][property])) {
|
2019-08-22 02:17:12 +10:00
|
|
|
results.push(source[i])
|
2019-08-20 00:28:49 +10:00
|
|
|
}
|
Big performance refactoring & various improvements
Instead of passing all sorts of events for the JS to handle and manually
add to different data models, we now handle everything we can in Python.
For any change, the python models send a sync event with their
contents (no more than 4 times per second) to JS, and the QSyncable
library's JsonListModel takes care of converting it to a QML ListModel
and sending the appropriate signals.
The SortFilterProxyModel library is not used anymore, the only case
where we need to filter/sort something now is when the user interacts
with the "Filter rooms" or "Filter members" fields. These cases are
handled by a simple JS function.
We now keep separated room and timeline models for different accounts,
the previous approach of sharing all the data we could between accounts
created a lot of complications (local echoes, decrypted messages
replacing others, etc).
The users's own account profile changes are now hidden in the timeline.
On startup, if all events for a room were only own profile changes, more
events will be loaded.
Any kind of image format supported by Qt is now handled by the
pyotherside image provider, instead of just PNG/JPG.
SVGs which previously caused errors are supported as well.
The typing members bar paddings/margins are fixed.
The behavior of the avatar/"upload a profile picture" overlay is fixed.
Config files read from disk are now cached (TODO: make them reloadable
again).
Pylint is not used anymore because of all its annoying false warnings
and lack of understanding for dataclasses, it is replaced by flake8 with
a custom config and various plugins.
Debug mode is now considered on if the program was compiled with
the right option, instead of taking an argument from CLI.
When on, C++ will set a flag in the Window QML component.
The loading screen is now unloaded after the UI is ready, where
previously it just stayed in the background invisible and wasted CPU.
The overall refactoring and improvements make us now able to handle
rooms with thousand of members and no lazy-loading, where previously
everything would freeze and simply scrolling up to load past events
in any room would block the UI for a few seconds.
2019-08-11 22:01:22 +10:00
|
|
|
}
|
2019-08-22 02:17:12 +10:00
|
|
|
|
Big performance refactoring & various improvements
Instead of passing all sorts of events for the JS to handle and manually
add to different data models, we now handle everything we can in Python.
For any change, the python models send a sync event with their
contents (no more than 4 times per second) to JS, and the QSyncable
library's JsonListModel takes care of converting it to a QML ListModel
and sending the appropriate signals.
The SortFilterProxyModel library is not used anymore, the only case
where we need to filter/sort something now is when the user interacts
with the "Filter rooms" or "Filter members" fields. These cases are
handled by a simple JS function.
We now keep separated room and timeline models for different accounts,
the previous approach of sharing all the data we could between accounts
created a lot of complications (local echoes, decrypted messages
replacing others, etc).
The users's own account profile changes are now hidden in the timeline.
On startup, if all events for a room were only own profile changes, more
events will be loaded.
Any kind of image format supported by Qt is now handled by the
pyotherside image provider, instead of just PNG/JPG.
SVGs which previously caused errors are supported as well.
The typing members bar paddings/margins are fixed.
The behavior of the avatar/"upload a profile picture" overlay is fixed.
Config files read from disk are now cached (TODO: make them reloadable
again).
Pylint is not used anymore because of all its annoying false warnings
and lack of understanding for dataclasses, it is replaced by flake8 with
a custom config and various plugins.
Debug mode is now considered on if the program was compiled with
the right option, instead of taking an argument from CLI.
When on, C++ will set a flag in the Window QML component.
The loading screen is now unloaded after the UI is ready, where
previously it just stayed in the background invisible and wasted CPU.
The overall refactoring and improvements make us now able to handle
rooms with thousand of members and no lazy-loading, where previously
everything would freeze and simply scrolling up to load past events
in any room would block the UI for a few seconds.
2019-08-11 22:01:22 +10:00
|
|
|
return results
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-14 10:15:20 +10:00
|
|
|
function thumbnailParametersFor(width, height) {
|
|
|
|
// https://matrix.org/docs/spec/client_server/latest#thumbnails
|
|
|
|
|
|
|
|
if (width > 640 || height > 480)
|
|
|
|
return {width: 800, height: 600, fillMode: Image.PreserveAspectFit}
|
|
|
|
|
|
|
|
if (width > 320 || height > 240)
|
|
|
|
return {width: 640, height: 480, fillMode: Image.PreserveAspectFit}
|
|
|
|
|
|
|
|
if (width > 96 || height > 96)
|
|
|
|
return {width: 320, height: 240, fillMode: Image.PreserveAspectFit}
|
|
|
|
|
|
|
|
if (width > 32 || height > 32)
|
|
|
|
return {width: 96, height: 96, fillMode: Image.PreserveAspectCrop}
|
|
|
|
|
|
|
|
return {width: 32, height: 32, fillMode: Image.PreserveAspectCrop}
|
|
|
|
}
|
2019-07-20 13:07:26 +10:00
|
|
|
|
|
|
|
|
|
|
|
function minutesBetween(date1, date2) {
|
|
|
|
return Math.round((((date2 - date1) % 86400000) % 3600000) / 60000)
|
|
|
|
}
|
Big performance refactoring & various improvements
Instead of passing all sorts of events for the JS to handle and manually
add to different data models, we now handle everything we can in Python.
For any change, the python models send a sync event with their
contents (no more than 4 times per second) to JS, and the QSyncable
library's JsonListModel takes care of converting it to a QML ListModel
and sending the appropriate signals.
The SortFilterProxyModel library is not used anymore, the only case
where we need to filter/sort something now is when the user interacts
with the "Filter rooms" or "Filter members" fields. These cases are
handled by a simple JS function.
We now keep separated room and timeline models for different accounts,
the previous approach of sharing all the data we could between accounts
created a lot of complications (local echoes, decrypted messages
replacing others, etc).
The users's own account profile changes are now hidden in the timeline.
On startup, if all events for a room were only own profile changes, more
events will be loaded.
Any kind of image format supported by Qt is now handled by the
pyotherside image provider, instead of just PNG/JPG.
SVGs which previously caused errors are supported as well.
The typing members bar paddings/margins are fixed.
The behavior of the avatar/"upload a profile picture" overlay is fixed.
Config files read from disk are now cached (TODO: make them reloadable
again).
Pylint is not used anymore because of all its annoying false warnings
and lack of understanding for dataclasses, it is replaced by flake8 with
a custom config and various plugins.
Debug mode is now considered on if the program was compiled with
the right option, instead of taking an argument from CLI.
When on, C++ will set a flag in the Window QML component.
The loading screen is now unloaded after the UI is ready, where
previously it just stayed in the background invisible and wasted CPU.
The overall refactoring and improvements make us now able to handle
rooms with thousand of members and no lazy-loading, where previously
everything would freeze and simply scrolling up to load past events
in any room would block the UI for a few seconds.
2019-08-11 22:01:22 +10:00
|
|
|
|
|
|
|
|
2019-08-17 02:07:22 +10:00
|
|
|
function dateIsDay(date, dayDate) {
|
|
|
|
return date.getDate() == dayDate.getDate() &&
|
|
|
|
date.getMonth() == dayDate.getMonth() &&
|
|
|
|
date.getFullYear() == dayDate.getFullYear()
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function dateIsToday(date) {
|
|
|
|
return dateIsDay(date, new Date())
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function dateIsYesterday(date) {
|
|
|
|
const yesterday = new Date()
|
|
|
|
yesterday.setDate(yesterday.getDate() - 1)
|
|
|
|
return dateIsDay(date, yesterday)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function formatTime(time, seconds=true) {
|
|
|
|
return Qt.formatTime(
|
|
|
|
time,
|
|
|
|
|
|
|
|
Qt.locale().timeFormat(
|
|
|
|
seconds ? Locale.LongFormat : Locale.NarrowFormat
|
|
|
|
).replace(/\./g, ":").replace(/ t$/, "")
|
|
|
|
// en_DK.UTF-8 locale wrongfully gives "." separators;
|
|
|
|
// remove the timezone at the end
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Big performance refactoring & various improvements
Instead of passing all sorts of events for the JS to handle and manually
add to different data models, we now handle everything we can in Python.
For any change, the python models send a sync event with their
contents (no more than 4 times per second) to JS, and the QSyncable
library's JsonListModel takes care of converting it to a QML ListModel
and sending the appropriate signals.
The SortFilterProxyModel library is not used anymore, the only case
where we need to filter/sort something now is when the user interacts
with the "Filter rooms" or "Filter members" fields. These cases are
handled by a simple JS function.
We now keep separated room and timeline models for different accounts,
the previous approach of sharing all the data we could between accounts
created a lot of complications (local echoes, decrypted messages
replacing others, etc).
The users's own account profile changes are now hidden in the timeline.
On startup, if all events for a room were only own profile changes, more
events will be loaded.
Any kind of image format supported by Qt is now handled by the
pyotherside image provider, instead of just PNG/JPG.
SVGs which previously caused errors are supported as well.
The typing members bar paddings/margins are fixed.
The behavior of the avatar/"upload a profile picture" overlay is fixed.
Config files read from disk are now cached (TODO: make them reloadable
again).
Pylint is not used anymore because of all its annoying false warnings
and lack of understanding for dataclasses, it is replaced by flake8 with
a custom config and various plugins.
Debug mode is now considered on if the program was compiled with
the right option, instead of taking an argument from CLI.
When on, C++ will set a flag in the Window QML component.
The loading screen is now unloaded after the UI is ready, where
previously it just stayed in the background invisible and wasted CPU.
The overall refactoring and improvements make us now able to handle
rooms with thousand of members and no lazy-loading, where previously
everything would freeze and simply scrolling up to load past events
in any room would block the UI for a few seconds.
2019-08-11 22:01:22 +10:00
|
|
|
function getItem(array, mainKey, value) {
|
|
|
|
for (let i = 0; i < array.length; i++) {
|
|
|
|
if (array[i][mainKey] === value) { return array[i] }
|
|
|
|
}
|
|
|
|
return undefined
|
|
|
|
}
|
2019-08-23 03:03:26 +10:00
|
|
|
|
|
|
|
|
|
|
|
function smartVerticalFlick(flickTarget, baseVelocity, fastMultiply=3) {
|
|
|
|
if (! flickTarget.interactive) { return }
|
|
|
|
|
|
|
|
baseVelocity = -baseVelocity
|
|
|
|
let vel = -flickTarget.verticalVelocity
|
|
|
|
let fast = (baseVelocity < 0 && vel < baseVelocity / 2) ||
|
|
|
|
(baseVelocity > 0 && vel > baseVelocity / 2)
|
|
|
|
|
|
|
|
flickTarget.flick(0, baseVelocity * (fast ? fastMultiply : 1))
|
|
|
|
}
|