2019-12-19 22:46:16 +11:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2019-12-18 08:59:53 +11:00
|
|
|
import QtQuick 2.12
|
2019-12-27 23:58:24 +11:00
|
|
|
import CppUtils 0.1
|
2019-12-18 08:59:53 +11:00
|
|
|
|
|
|
|
QtObject {
|
2020-07-20 10:10:31 +10:00
|
|
|
enum Media { Page, File, Image, Video, Audio }
|
|
|
|
|
|
|
|
readonly property var imageExtensions: [
|
|
|
|
"bmp", "gif", "jpg", "jpeg", "png", "pbm", "pgm", "ppm", "xbm", "xpm",
|
|
|
|
"tiff", "webp", "svg",
|
|
|
|
]
|
|
|
|
|
|
|
|
readonly property var videoExtensions: [
|
|
|
|
"3gp", "avi", "flv", "m4p", "m4v", "mkv", "mov", "mp4",
|
|
|
|
"mpeg", "mpg", "ogv", "qt", "vob", "webm", "wmv", "yuv",
|
|
|
|
]
|
|
|
|
|
|
|
|
readonly property var audioExtensions: [
|
|
|
|
"pcm", "wav", "raw", "aiff", "flac", "m4a", "tta", "aac", "mp3",
|
|
|
|
"ogg", "oga", "opus",
|
|
|
|
]
|
|
|
|
|
2019-12-18 08:59:53 +11:00
|
|
|
function makeObject(urlComponent, parent=null, properties={},
|
|
|
|
callback=null) {
|
|
|
|
let comp = urlComponent
|
|
|
|
|
|
|
|
if (! Qt.isQtObject(urlComponent)) {
|
|
|
|
// It's an url or path string to a component
|
|
|
|
comp = Qt.createComponent(urlComponent, Component.Asynchronous)
|
|
|
|
}
|
|
|
|
|
|
|
|
let ready = false
|
|
|
|
|
|
|
|
comp.statusChanged.connect(status => {
|
|
|
|
if ([Component.Null, Component.Error].includes(status)) {
|
|
|
|
console.error("Failed creating component: ", comp.errorString())
|
|
|
|
|
|
|
|
} else if (! ready && status === Component.Ready) {
|
2020-03-08 19:46:20 +11:00
|
|
|
const incu = comp.incubateObject(
|
2019-12-18 08:59:53 +11:00
|
|
|
parent, properties, Qt.Asynchronous,
|
|
|
|
)
|
|
|
|
|
|
|
|
if (incu.status === Component.Ready) {
|
|
|
|
if (callback) callback(incu.object)
|
|
|
|
ready = true
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
incu.onStatusChanged = (istatus) => {
|
|
|
|
if (incu.status === Component.Error) {
|
|
|
|
console.error("Failed incubating object: ",
|
|
|
|
incu.errorString())
|
|
|
|
|
|
|
|
} else if (istatus === Component.Ready &&
|
|
|
|
callback && ! ready) {
|
|
|
|
if (callback) callback(incu.object)
|
|
|
|
ready = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
if (comp.status === Component.Ready) comp.statusChanged(comp.status)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-26 20:34:06 +10:00
|
|
|
function makePopup(urlComponent, properties={}, callback=null,
|
2020-07-09 01:33:05 +10:00
|
|
|
autoDestruct=true, parent=window) {
|
|
|
|
makeObject(urlComponent, parent, properties, (popup) => {
|
2019-12-18 08:59:53 +11:00
|
|
|
popup.open()
|
|
|
|
if (autoDestruct) popup.closed.connect(() => { popup.destroy() })
|
|
|
|
if (callback) callback(popup)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-23 11:58:24 +11:00
|
|
|
function showError(type, traceback, sourceIndication="", message="") {
|
2020-03-16 06:40:53 +11:00
|
|
|
console.error(`python: ${sourceIndication}\n${traceback}`)
|
|
|
|
|
|
|
|
if (window.hideErrorTypes.has(type)) {
|
2020-06-03 09:07:12 +10:00
|
|
|
console.info("Not showing popup for ignored error type " + type)
|
2020-03-16 06:40:53 +11:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
utils.makePopup(
|
|
|
|
"Popups/UnexpectedErrorPopup.qml",
|
2020-03-23 11:58:24 +11:00
|
|
|
{ errorType: type, message, traceback },
|
2020-03-16 06:40:53 +11:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-20 06:56:07 +11:00
|
|
|
function sum(array) {
|
|
|
|
if (array.length < 1) return 0
|
|
|
|
return array.reduce((a, b) => (isNaN(a) ? 0 : a) + (isNaN(b) ? 0 : b))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-27 14:24:37 +11:00
|
|
|
function range(startOrEnd, end=null, ) {
|
|
|
|
// range(3) → [0, 1, 2, 3]
|
|
|
|
// range(3, 6) → [3, 4, 5, 6]
|
|
|
|
// range(3, -1) → [3, 2, 1, 0, -1]
|
|
|
|
|
|
|
|
const numbers = []
|
|
|
|
let realStart = end ? startOrEnd : 0
|
|
|
|
let realEnd = end ? end : startOrEnd
|
|
|
|
|
|
|
|
if (realEnd < realStart)
|
|
|
|
for (let i = realStart; i >= realEnd; i--)
|
|
|
|
numbers.push(i)
|
|
|
|
else
|
|
|
|
for (let i = realStart; i <= realEnd; i++)
|
|
|
|
numbers.push(i)
|
|
|
|
|
|
|
|
return numbers
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-30 00:52:43 +10:00
|
|
|
function chunk(array, chunkSize) {
|
|
|
|
const chunks = []
|
|
|
|
|
|
|
|
for (let i = 0; i < array.length; i += chunkSize) {
|
|
|
|
chunks.push(array.slice(i, i + chunkSize))
|
|
|
|
}
|
|
|
|
|
|
|
|
return chunks
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-18 08:59:53 +11:00
|
|
|
function isEmptyObject(obj) {
|
|
|
|
return Object.entries(obj).length === 0 && obj.constructor === Object
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-21 01:29:45 +11:00
|
|
|
function objectUpdate(current, update) {
|
|
|
|
return Object.assign({}, current, update)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-18 08:59:53 +11:00
|
|
|
function objectUpdateRecursive(current, update) {
|
|
|
|
for (const key of Object.keys(update)) {
|
|
|
|
if ((key in current) && typeof(current[key]) === "object" &&
|
|
|
|
typeof(update[key]) === "object") {
|
|
|
|
objectUpdateRecursive(current[key], update[key])
|
|
|
|
} else {
|
|
|
|
current[key] = update[key]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function numberWrapAt(num, max) {
|
|
|
|
return num < 0 ? max + (num % max) : (num % max)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function hsluv(hue, saturation, lightness, alpha=1.0) {
|
2019-12-27 23:19:56 +11:00
|
|
|
return CppUtils.hsluv(hue, saturation, lightness, alpha)
|
2019-12-18 08:59:53 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function hueFrom(string) {
|
|
|
|
// Calculate and return a unique hue between 0 and 360 for the string
|
|
|
|
let hue = 0
|
|
|
|
for (let i = 0; i < string.length; i++) {
|
|
|
|
hue += string.charCodeAt(i) * 99
|
|
|
|
}
|
|
|
|
return hue % 360
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-03 04:54:06 +11:00
|
|
|
function nameColor(name, dim=false) {
|
2019-12-18 08:59:53 +11:00
|
|
|
return hsluv(
|
|
|
|
hueFrom(name),
|
2020-04-03 04:54:06 +11:00
|
|
|
|
|
|
|
dim ?
|
|
|
|
theme.controls.displayName.dimSaturation :
|
2019-12-18 08:59:53 +11:00
|
|
|
theme.controls.displayName.saturation,
|
2020-04-03 04:54:06 +11:00
|
|
|
|
|
|
|
dim ?
|
|
|
|
theme.controls.displayName.dimLightness :
|
2019-12-18 08:59:53 +11:00
|
|
|
theme.controls.displayName.lightness,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-20 01:12:35 +10:00
|
|
|
function coloredNameHtml(name, userId, displayText=null, dim=false) {
|
2019-12-18 08:59:53 +11:00
|
|
|
// substring: remove leading @
|
2020-04-03 04:54:06 +11:00
|
|
|
return `<font color="${nameColor(name || userId.substring(1), dim)}">`+
|
2019-12-18 08:59:53 +11:00
|
|
|
escapeHtml(displayText || name || userId) +
|
|
|
|
"</font>"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-27 19:58:49 +11:00
|
|
|
function escapeHtml(text) {
|
2019-12-18 08:59:53 +11:00
|
|
|
// Replace special HTML characters by encoded alternatives
|
2020-04-02 04:33:19 +11:00
|
|
|
return text.replace(/&/g, "&")
|
|
|
|
.replace(/</g, "<")
|
|
|
|
.replace(/>/g, ">")
|
|
|
|
.replace(/"/g, """)
|
|
|
|
.replace(/'/g, "'")
|
2020-03-27 19:58:49 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function stripHtmlTags(text) {
|
|
|
|
// XXX: Potentially unsafe!
|
|
|
|
return text.replace(/<\/?[^>]+(>|$)/g, "")
|
2019-12-18 08:59:53 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-16 10:22:29 +10:00
|
|
|
function htmlColorize(text, color) {
|
|
|
|
return `<font color="${color}">${text}</font>`
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-18 08:59:53 +11:00
|
|
|
function processedEventText(ev) {
|
2019-12-03 07:29:29 +11:00
|
|
|
const type = ev.event_type
|
|
|
|
const unknownMsg = type === "RoomMessageUnknown"
|
|
|
|
const sender = coloredNameHtml(ev.sender_name, ev.sender_id)
|
2019-12-18 08:59:53 +11:00
|
|
|
|
2019-12-03 07:29:29 +11:00
|
|
|
if (type === "RoomMessageEmote")
|
2020-03-24 04:49:19 +11:00
|
|
|
return ev.content.match(/^\s*<(p|h[1-6])>/) ?
|
|
|
|
ev.content.replace(/(^\s*<(p|h[1-6])>)/, `$1 ${sender} `) :
|
|
|
|
sender + " " + ev.content
|
2019-12-18 08:59:53 +11:00
|
|
|
|
2019-12-03 07:29:29 +11:00
|
|
|
if (type.startsWith("RoomMessage") && ! unknownMsg)
|
2019-12-18 08:59:53 +11:00
|
|
|
return ev.content
|
|
|
|
|
2019-12-03 07:29:29 +11:00
|
|
|
if (type.startsWith("RoomEncrypted"))
|
|
|
|
return ev.content
|
2019-12-18 08:59:53 +11:00
|
|
|
|
2020-03-30 09:06:13 +11:00
|
|
|
if (type === "RedactedEvent") {
|
2020-04-03 20:36:55 +11:00
|
|
|
// FIXME: this can generate an "argument missing" warning because
|
|
|
|
// QML first gets notified of the event type change, *then* of the
|
|
|
|
// content change.
|
2020-04-03 04:54:06 +11:00
|
|
|
let content = qsTr(escapeHtml(ev.content)).arg(sender)
|
|
|
|
|
|
|
|
if (ev.content.includes("%2"))
|
|
|
|
content = content.arg(coloredNameHtml(
|
2020-04-20 01:12:35 +10:00
|
|
|
ev.redacter_name, ev.redacter_id, "", true,
|
2020-04-03 04:54:06 +11:00
|
|
|
))
|
|
|
|
|
2020-03-29 04:24:05 +11:00
|
|
|
return qsTr(
|
2020-04-03 04:54:06 +11:00
|
|
|
`<font color="${theme.chat.message.redactedBody}">` +
|
|
|
|
content +
|
|
|
|
"</font>"
|
2020-03-29 04:24:05 +11:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-04-03 04:54:06 +11:00
|
|
|
if (ev.content.includes("%2")) {
|
|
|
|
const target = coloredNameHtml(ev.target_name, ev.target_id)
|
|
|
|
return qsTr(ev.content).arg(sender).arg(target)
|
|
|
|
}
|
|
|
|
|
2019-12-03 07:29:29 +11:00
|
|
|
return qsTr(ev.content).arg(sender)
|
2019-12-18 08:59:53 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
function filterMatches(filter, text) {
|
2020-05-01 06:37:03 +10:00
|
|
|
if (! filter) return true
|
|
|
|
|
2019-12-03 07:29:29 +11:00
|
|
|
const filter_lower = filter.toLowerCase()
|
2019-12-18 08:59:53 +11:00
|
|
|
|
|
|
|
if (filter_lower === filter) {
|
|
|
|
// Consider case only if filter isn't all lowercase (smart case)
|
|
|
|
filter = filter_lower
|
|
|
|
text = text.toLowerCase()
|
|
|
|
}
|
|
|
|
|
2020-03-08 19:46:20 +11:00
|
|
|
for (const word of filter.split(" ")) {
|
2019-12-18 08:59:53 +11:00
|
|
|
if (word && ! text.includes(word)) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-03 07:29:29 +11:00
|
|
|
function filterMatchesAny(filter, ...texts) {
|
2020-03-08 19:46:20 +11:00
|
|
|
for (const text of texts) {
|
2019-12-03 07:29:29 +11:00
|
|
|
if (filterMatches(filter, text)) return true
|
2019-12-18 08:59:53 +11:00
|
|
|
}
|
2019-12-03 07:29:29 +11:00
|
|
|
return false
|
2019-12-18 08:59:53 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function fitSize(minWidth, minHeight, width, height, maxWidth, maxHeight) {
|
|
|
|
if (width >= height) {
|
2020-03-08 19:46:20 +11:00
|
|
|
const new_width = Math.min(Math.max(width, minWidth), maxWidth)
|
2019-12-18 08:59:53 +11:00
|
|
|
return Qt.size(new_width, height / (width / new_width))
|
|
|
|
}
|
|
|
|
|
2020-03-08 19:46:20 +11:00
|
|
|
const new_height = Math.min(Math.max(height, minHeight), maxHeight)
|
2019-12-18 08:59:53 +11:00
|
|
|
return Qt.size(width / (height / new_height), new_height)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function minutesBetween(date1, date2) {
|
|
|
|
return ((date2 - date1) / 1000) / 60
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
// also remove the timezone at the end
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-24 22:14:54 +10:00
|
|
|
function smartFormatDate(date) {
|
|
|
|
return (
|
|
|
|
date < new Date(1) ?
|
|
|
|
"" :
|
|
|
|
|
|
|
|
// e.g. "03:24"
|
|
|
|
dateIsToday(date) ?
|
|
|
|
formatTime(date, false) :
|
|
|
|
|
|
|
|
// e.g. "5 Dec"
|
|
|
|
date.getFullYear() === new Date().getFullYear() ?
|
|
|
|
Qt.formatDate(date, "d MMM") :
|
|
|
|
|
|
|
|
// e.g. "Jan 2020"
|
|
|
|
Qt.formatDate(date, "MMM yyyy")
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-11 06:44:08 +10:00
|
|
|
function formatRelativeTime(milliseconds, shortForm=true) {
|
2020-06-03 08:43:05 +10:00
|
|
|
const seconds = Math.floor(milliseconds / 1000)
|
|
|
|
|
2020-07-11 06:44:08 +10:00
|
|
|
if (shortForm) {
|
|
|
|
return (
|
|
|
|
seconds < 60 ?
|
|
|
|
qsTr("%1s").arg(seconds) :
|
|
|
|
|
|
|
|
seconds < 60 * 60 ?
|
|
|
|
qsTr("%1mn").arg(Math.floor(seconds / 60)) :
|
|
|
|
|
|
|
|
seconds < 60 * 60 * 24 ?
|
|
|
|
qsTr("%1h").arg(Math.floor(seconds / 60 / 60)) :
|
|
|
|
|
|
|
|
seconds < 60 * 60 * 24 * 30 ?
|
|
|
|
qsTr("%1d").arg(Math.floor(seconds / 60 / 60 / 24)) :
|
|
|
|
|
|
|
|
seconds < 60 * 60 * 24 * 30 * 12 ?
|
|
|
|
qsTr("%1mo").arg(Math.floor(seconds / 60 / 60 / 24 / 30)) :
|
|
|
|
|
|
|
|
qsTr("%1y").arg(Math.floor(seconds / 60 / 60 / 24 / 30 / 12))
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-06-03 08:43:05 +10:00
|
|
|
return (
|
|
|
|
seconds < 60 ?
|
2020-07-11 06:44:08 +10:00
|
|
|
qsTr("%1 seconds").arg(seconds) :
|
2020-06-03 08:43:05 +10:00
|
|
|
|
|
|
|
seconds < 60 * 60 ?
|
2020-07-11 06:44:08 +10:00
|
|
|
qsTr("%1 minutes").arg(Math.floor(seconds / 60)) :
|
2020-06-03 08:43:05 +10:00
|
|
|
|
|
|
|
seconds < 60 * 60 * 24 ?
|
2020-07-11 06:44:08 +10:00
|
|
|
qsTr("%1 hours").arg(Math.floor(seconds / 60 / 60)) :
|
2020-06-03 08:43:05 +10:00
|
|
|
|
|
|
|
seconds < 60 * 60 * 24 * 30 ?
|
2020-07-11 06:44:08 +10:00
|
|
|
qsTr("%1 days").arg(Math.floor(seconds / 60 / 60 / 24)) :
|
2020-06-03 08:43:05 +10:00
|
|
|
|
|
|
|
seconds < 60 * 60 * 24 * 30 * 12 ?
|
2020-07-11 06:44:08 +10:00
|
|
|
qsTr("%1 months").arg(Math.floor(seconds / 60 / 60 / 24 / 30)) :
|
2020-06-03 08:43:05 +10:00
|
|
|
|
2020-07-11 06:44:08 +10:00
|
|
|
qsTr("%1 years").arg(Math.floor(seconds / 60 / 60 / 24 / 30 / 12))
|
2020-06-03 08:43:05 +10:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-18 08:59:53 +11:00
|
|
|
function formatDuration(milliseconds) {
|
2020-03-08 19:46:20 +11:00
|
|
|
const totalSeconds = milliseconds / 1000
|
2019-12-18 08:59:53 +11:00
|
|
|
|
2020-03-08 19:46:20 +11:00
|
|
|
const hours = Math.floor(totalSeconds / 3600)
|
2019-12-18 08:59:53 +11:00
|
|
|
let minutes = Math.floor((totalSeconds % 3600) / 60)
|
|
|
|
let seconds = Math.floor(totalSeconds % 60)
|
|
|
|
|
|
|
|
if (seconds < 10) seconds = `0${seconds}`
|
|
|
|
if (hours < 1) return `${minutes}:${seconds}`
|
|
|
|
|
|
|
|
if (minutes < 10) minutes = `0${minutes}`
|
|
|
|
return `${hours}:${minutes}:${seconds}`
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function round(floatNumber) {
|
|
|
|
return parseFloat(floatNumber.toFixed(2))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-21 11:34:00 +10:00
|
|
|
function flickPages(flickable, pages, horizontal=false, multiplier=8) {
|
2019-12-18 08:59:53 +11:00
|
|
|
// Adapt velocity and deceleration for the number of pages to flick.
|
|
|
|
// If this is a repeated flicking, flick faster than a single flick.
|
2020-05-16 09:23:20 +10:00
|
|
|
if (! flickable.interactive) return
|
2019-12-18 08:59:53 +11:00
|
|
|
|
2020-07-21 11:34:00 +10:00
|
|
|
const futureVelocity =
|
|
|
|
(horizontal ? -flickable.width : -flickable.height) * pages
|
|
|
|
|
|
|
|
const currentVelocity =
|
|
|
|
horizontal ?
|
|
|
|
-flickable.horizontalVelocity :
|
|
|
|
-flickable.verticalVelocity
|
|
|
|
|
2019-12-18 08:59:53 +11:00
|
|
|
const goFaster =
|
|
|
|
(futureVelocity < 0 && currentVelocity < futureVelocity / 2) ||
|
|
|
|
(futureVelocity > 0 && currentVelocity > futureVelocity / 2)
|
|
|
|
|
|
|
|
const magicNumber = 2.5
|
2020-07-21 11:34:00 +10:00
|
|
|
const normalDecel = flickable.flickDeceleration
|
|
|
|
const fastMultiply =
|
|
|
|
pages && multiplier / (1 - Math.log10(Math.abs(pages)))
|
2019-12-18 08:59:53 +11:00
|
|
|
|
|
|
|
flickable.flickDeceleration = Math.max(
|
|
|
|
goFaster ? normalDecel : -Infinity,
|
|
|
|
Math.abs(normalDecel * magicNumber * pages),
|
|
|
|
)
|
|
|
|
|
2020-07-21 11:34:00 +10:00
|
|
|
const flick =
|
|
|
|
futureVelocity * magicNumber * (goFaster ? fastMultiply : 1)
|
|
|
|
|
|
|
|
horizontal ? flickable.flick(flick, 0) : flickable.flick(0, flick)
|
2019-12-18 08:59:53 +11:00
|
|
|
|
|
|
|
flickable.flickDeceleration = normalDecel
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function flickToTop(flickable) {
|
2020-05-16 09:23:20 +10:00
|
|
|
if (! flickable.interactive) return
|
2019-12-18 08:59:53 +11:00
|
|
|
if (flickable.visibleArea.yPosition < 0) return
|
|
|
|
|
|
|
|
flickable.contentY -= flickable.contentHeight
|
|
|
|
flickable.returnToBounds()
|
|
|
|
flickable.flick(0, -100) // Force the delegates to load
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function flickToBottom(flickable) {
|
2020-05-16 09:23:20 +10:00
|
|
|
if (! flickable.interactive) return
|
2019-12-18 08:59:53 +11:00
|
|
|
if (flickable.visibleArea.yPosition < 0) return
|
|
|
|
|
2019-12-18 09:07:15 +11:00
|
|
|
flickable.contentY = flickable.contentHeight - flickable.height
|
2019-12-18 08:59:53 +11:00
|
|
|
flickable.returnToBounds()
|
|
|
|
flickable.flick(0, 100)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-10 02:08:07 +11:00
|
|
|
function urlFileName(url) {
|
|
|
|
return url.toString().split("/").slice(-1)[0].split("?")[0]
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-18 08:59:53 +11:00
|
|
|
function urlExtension(url) {
|
2020-03-10 02:08:07 +11:00
|
|
|
return urlFileName(url).split(".").slice(-1)[0]
|
2019-12-18 08:59:53 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-20 10:10:31 +10:00
|
|
|
function getLinkType(url) {
|
|
|
|
const ext = urlExtension(url).toLowerCase()
|
|
|
|
|
|
|
|
return (
|
|
|
|
imageExtensions.includes(ext) ? Utils.Media.Image :
|
|
|
|
videoExtensions.includes(ext) ? Utils.Media.Video :
|
|
|
|
audioExtensions.includes(ext) ? Utils.Media.Audio :
|
|
|
|
Utils.Media.Page
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-18 08:59:53 +11:00
|
|
|
function sendFile(userId, roomId, path, onSuccess, onError) {
|
|
|
|
py.callClientCoro(
|
|
|
|
userId, "send_file", [roomId, path], onSuccess, onError,
|
|
|
|
)
|
|
|
|
}
|
2020-07-21 11:37:08 +10:00
|
|
|
|
|
|
|
function sumChildrenImplicitWidths(visibleChildren, spacing=0) {
|
|
|
|
let sum = 0
|
|
|
|
|
|
|
|
for (let i = 0; i < visibleChildren.length; i++) {
|
|
|
|
const item = visibleChildren[i]
|
|
|
|
|
|
|
|
if (item)
|
|
|
|
sum += (item.width > 0 ? item.implicitWidth : 0) + spacing
|
|
|
|
}
|
|
|
|
|
|
|
|
return sum
|
|
|
|
}
|
2019-12-18 08:59:53 +11:00
|
|
|
}
|