ES5 → 7: Use enhanced object properties
http://es6-features.org/#PropertyShorthand Instead of doing {"foo": foo, "bar": bar, ...}, we can just do {foo, bar} now. The function parameters of EventHandlers have all been renamed to camelCase to make use of this, as the JS style conventions intend. Other functions will follow in a later commit.
This commit is contained in:
parent
4920ff6212
commit
ea02ce2316
2
TODO.md
2
TODO.md
|
@ -10,7 +10,6 @@
|
||||||
- `QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling)` ?
|
- `QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling)` ?
|
||||||
|
|
||||||
- Qt 5.12
|
- Qt 5.12
|
||||||
- See about ECMAScript 6 and 7 features
|
|
||||||
- .mjs modules
|
- .mjs modules
|
||||||
|
|
||||||
- Refactoring
|
- Refactoring
|
||||||
|
@ -18,6 +17,7 @@
|
||||||
- Unfinished work in button-refactor branch
|
- Unfinished work in button-refactor branch
|
||||||
- Button can get "hoverEnabled: false" to let HoverHandlers work
|
- Button can get "hoverEnabled: false" to let HoverHandlers work
|
||||||
- Room Sidepane
|
- Room Sidepane
|
||||||
|
- When qml syntax highlighting supports string interpolation, use them
|
||||||
|
|
||||||
- Bug fixes
|
- Bug fixes
|
||||||
- Past events loading (limit 100) freezes the GUI - need to move upsert func
|
- Past events loading (limit 100) freezes the GUI - need to move upsert func
|
||||||
|
|
|
@ -36,8 +36,8 @@ class UserUpdated(Event):
|
||||||
def from_nio(cls, user: MatrixUser) -> "UserUpdated":
|
def from_nio(cls, user: MatrixUser) -> "UserUpdated":
|
||||||
return cls(
|
return cls(
|
||||||
user_id = user.user_id,
|
user_id = user.user_id,
|
||||||
display_name = user.display_name,
|
display_name = user.display_name or "",
|
||||||
avatar_url = user.avatar_url,
|
avatar_url = user.avatar_url or "",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,7 @@ HAvatar {
|
||||||
property string userId: ""
|
property string userId: ""
|
||||||
property string roomId: ""
|
property string roomId: ""
|
||||||
|
|
||||||
readonly property var roomInfo:
|
readonly property var roomInfo: rooms.getWhere({userId, roomId}, 1)[0]
|
||||||
rooms.getWhere({"userId": userId, "roomId": roomId}, 1)[0]
|
|
||||||
|
|
||||||
// roomInfo ? → Avoid error messages when a room is forgotten
|
// roomInfo ? → Avoid error messages when a room is forgotten
|
||||||
readonly property var dname: roomInfo ? roomInfo.displayName : ""
|
readonly property var dname: roomInfo ? roomInfo.displayName : ""
|
||||||
|
|
|
@ -34,8 +34,8 @@ Banner {
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
buttonCallbacks: {
|
buttonCallbacks: ({
|
||||||
"accept": button => {
|
accept: button => {
|
||||||
button.loading = true
|
button.loading = true
|
||||||
py.callClientCoro(
|
py.callClientCoro(
|
||||||
chatPage.userId, "join", [chatPage.roomId], () => {
|
chatPage.userId, "join", [chatPage.roomId], () => {
|
||||||
|
@ -43,12 +43,12 @@ Banner {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
"decline": button => {
|
decline: button => {
|
||||||
button.loading = true
|
button.loading = true
|
||||||
py.callClientCoro(
|
py.callClientCoro(
|
||||||
chatPage.userId, "room_leave", [chatPage.roomId], () => {
|
chatPage.userId, "room_leave", [chatPage.roomId], () => {
|
||||||
button.loading = false
|
button.loading = false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,13 +22,13 @@ Banner {
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
buttonCallbacks: {
|
buttonCallbacks: ({
|
||||||
"forget": button => {
|
forget: button => {
|
||||||
button.loading = true
|
button.loading = true
|
||||||
py.callClientCoro(
|
py.callClientCoro(
|
||||||
chatPage.userId, "room_forget", [chatPage.roomId], () => {
|
chatPage.userId, "room_forget", [chatPage.roomId], () => {
|
||||||
button.loading = false
|
button.loading = false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,9 @@ Banner {
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
buttonCallbacks: {
|
buttonCallbacks: ({
|
||||||
"inspect": button => {
|
inspect: button => {
|
||||||
print("show")
|
print("show")
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
// Copyright 2019 miruka
|
// Copyright 2019 miruka
|
||||||
// This file is part of harmonyqml, licensed under LGPLv3.
|
// This file is part of harmonyqml, licensed under LGPLv3.
|
||||||
|
|
||||||
function onExitRequested(exit_code) {
|
function onExitRequested(exitCode) {
|
||||||
Qt.exit(exit_code)
|
Qt.exit(exitCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
function onCoroutineDone(uuid, result) {
|
function onCoroutineDone(uuid, result) {
|
||||||
|
|
|
@ -3,13 +3,12 @@
|
||||||
|
|
||||||
Qt.include("../utils.js")
|
Qt.include("../utils.js")
|
||||||
|
|
||||||
|
function typingTextFor(members, ourUserId) {
|
||||||
function typingTextFor(members, our_user_id) {
|
|
||||||
var profiles = []
|
var profiles = []
|
||||||
var names = []
|
var names = []
|
||||||
|
|
||||||
for (var i = 0; i < members.length; i++) {
|
for (var i = 0; i < members.length; i++) {
|
||||||
if (members[i] != our_user_id) {
|
if (members[i] != ourUserId) {
|
||||||
profiles.push(users.find(members[i]))
|
profiles.push(users.find(members[i]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,18 +36,13 @@ function typingTextFor(members, our_user_id) {
|
||||||
|
|
||||||
|
|
||||||
function onRoomUpdated(
|
function onRoomUpdated(
|
||||||
user_id, category, room_id, display_name, avatar_url, topic,
|
userId, category, roomId, displayName, avatarUrl, topic,
|
||||||
members, typing_members, inviter_id
|
members, typingMembers, inviterId
|
||||||
) {
|
) {
|
||||||
roomCategories.upsert({"userId": user_id, "name": category}, {
|
roomCategories.upsert({userId, name: category}, {userId, name: category})
|
||||||
"userId": user_id,
|
|
||||||
"name": category
|
|
||||||
})
|
|
||||||
|
|
||||||
function find(for_category) {
|
function find(category) {
|
||||||
var found = rooms.getIndices(
|
var found = rooms.getIndices({userId, roomId, category}, 1)
|
||||||
{"userId": user_id, "roomId": room_id, "category": for_category}, 1
|
|
||||||
)
|
|
||||||
return found.length > 0 ? found[0] : null
|
return found.length > 0 ? found[0] : null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,71 +52,45 @@ function onRoomUpdated(
|
||||||
else if (category == "Left") { replace = find("Invites") || find("Rooms")}
|
else if (category == "Left") { replace = find("Invites") || find("Rooms")}
|
||||||
|
|
||||||
var item = {
|
var item = {
|
||||||
"userId": user_id,
|
typingText: typingTextFor(typingMembers, userId),
|
||||||
"category": category,
|
|
||||||
"roomId": room_id,
|
userId, category, roomId, displayName, avatarUrl, topic, members,
|
||||||
"displayName": display_name,
|
inviterId
|
||||||
"avatarUrl": avatar_url,
|
|
||||||
"topic": topic,
|
|
||||||
"members": members,
|
|
||||||
"typingText": typingTextFor(typing_members, user_id),
|
|
||||||
"inviterId": inviter_id
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (replace === null) {
|
if (replace === null) {
|
||||||
rooms.upsert(
|
rooms.upsert({userId, roomId, category}, item)
|
||||||
{"userId": user_id, "roomId": room_id, "category": category},
|
|
||||||
item
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
rooms.set(replace, item)
|
rooms.set(replace, item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function onRoomForgotten(user_id, room_id) {
|
function onRoomForgotten(userId, roomId) {
|
||||||
rooms.popWhere({"userId": user_id, "roomId": room_id})
|
rooms.popWhere({userId, roomId})
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function onRoomMemberUpdated(room_id, user_id, typing) {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function onRoomMemberDeleted(room_id, user_id) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function onTimelineEventReceived(
|
function onTimelineEventReceived(
|
||||||
event_type, room_id, event_id, sender_id, date, content,
|
eventType, roomId, eventId, senderId, date, content,
|
||||||
content_type, is_local_echo, show_name_line, translatable, target_user_id
|
contentType, isLocalEcho, showNameLine, translatable, targetUserId
|
||||||
) {
|
) {
|
||||||
var item = {
|
var item = {
|
||||||
"eventType": py.getattr(event_type, "__name__"),
|
eventType: py.getattr(eventType, "__name__"),
|
||||||
"roomId": room_id,
|
|
||||||
"eventId": event_id,
|
roomId, eventId, senderId, date, content, contentType, isLocalEcho,
|
||||||
"senderId": sender_id,
|
showNameLine, translatable, targetUserId
|
||||||
"date": date,
|
|
||||||
"content": content,
|
|
||||||
"contentType": content_type,
|
|
||||||
"isLocalEcho": is_local_echo,
|
|
||||||
"showNameLine": show_name_line,
|
|
||||||
"translatable": translatable,
|
|
||||||
"targetUserId": target_user_id,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_local_echo) {
|
if (isLocalEcho) {
|
||||||
timelines.append(item)
|
timelines.append(item)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace first matching local echo
|
// Replace first matching local echo
|
||||||
var found = timelines.getIndices({
|
var found = timelines.getIndices(
|
||||||
"roomId": room_id,
|
{roomId, senderId, content, "isLocalEcho": true}, 1, 250
|
||||||
"senderId": sender_id,
|
)
|
||||||
"content": content,
|
|
||||||
"isLocalEcho": true
|
|
||||||
}, 1, 250)
|
|
||||||
|
|
||||||
if (found.length > 0) {
|
if (found.length > 0) {
|
||||||
timelines.set(found[0], item)
|
timelines.set(found[0], item)
|
||||||
|
@ -131,16 +99,12 @@ function onTimelineEventReceived(
|
||||||
else if (item.eventType == "OlmEvent" || item.eventType == "MegolmEvent") {
|
else if (item.eventType == "OlmEvent" || item.eventType == "MegolmEvent") {
|
||||||
// Don't replace if an item with the same eventId is found in these
|
// Don't replace if an item with the same eventId is found in these
|
||||||
// cases, because it would be the ecrypted version of the event.
|
// cases, because it would be the ecrypted version of the event.
|
||||||
timelines.upsert({"eventId": event_id}, item, false, 250)
|
timelines.upsert({eventId}, item, false, 250)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
timelines.upsert({"eventId": event_id}, item, true, 250)
|
timelines.upsert({eventId}, item, true, 250)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var onTimelineMessageReceived = onTimelineEventReceived
|
var onTimelineMessageReceived = onTimelineEventReceived
|
||||||
|
|
||||||
|
|
||||||
function onTypingNoticeEvent(room_id, members) {
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,26 +1,21 @@
|
||||||
// Copyright 2019 miruka
|
// Copyright 2019 miruka
|
||||||
// This file is part of harmonyqml, licensed under LGPLv3.
|
// This file is part of harmonyqml, licensed under LGPLv3.
|
||||||
|
|
||||||
function onAccountUpdated(user_id) {
|
function onAccountUpdated(userId) {
|
||||||
accounts.append({"userId": user_id})
|
accounts.append({userId})
|
||||||
}
|
}
|
||||||
|
|
||||||
function onAccountDeleted(user_id) {
|
function onAccountDeleted(userId) {
|
||||||
accounts.popWhere({"userId": user_id}, 1)
|
accounts.popWhere({userId}, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
function onUserUpdated(user_id, display_name, avatar_url, status_message) {
|
function onUserUpdated(userId, displayName, avatarUrl, statusMessage) {
|
||||||
users.upsert({"userId": user_id}, {
|
users.upsert({userId}, {userId, displayName, avatarUrl, statusMessage})
|
||||||
"userId": user_id,
|
|
||||||
"displayName": display_name,
|
|
||||||
"avatarUrl": avatar_url,
|
|
||||||
"statusMessage": status_message
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onDeviceUpdated(user_id, device_id, ed25519_key, trust, display_name,
|
function onDeviceUpdated(userId, deviceId, ed25519Key, trust, displayName,
|
||||||
last_seen_ip, last_seen_date) {
|
lastSeenIp, lastSeenDate) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function onDeviceDeleted(user_id, device_id) {
|
function onDeviceDeleted(userId, deviceId) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,21 +6,21 @@ import SortFilterProxyModel 0.2
|
||||||
import "../Base"
|
import "../Base"
|
||||||
|
|
||||||
HListModel {
|
HListModel {
|
||||||
function find(user_id) {
|
function find(userId) {
|
||||||
// Happens when SortFilterProxyModel ExpressionFilter/Sorter/Role tests
|
// Happens when SortFilterProxyModel ExpressionFilter/Sorter/Role tests
|
||||||
// the expression with invalid data to establish property bindings
|
// the expression with invalid data to establish property bindings
|
||||||
if (! user_id) { return }
|
if (! userId) { return }
|
||||||
|
|
||||||
var found = getWhere({"userId": user_id}, 1)
|
var found = getWhere({userId}, 1)
|
||||||
if (found.length > 0) { return found[0] }
|
if (found.length > 0) { return found[0] }
|
||||||
|
|
||||||
py.callCoro("request_user_update_event", [user_id])
|
py.callCoro("request_user_update_event", [userId])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"userId": user_id,
|
userId,
|
||||||
"displayName": "",
|
displayName: "",
|
||||||
"avatarUrl": "",
|
avatarUrl: "",
|
||||||
"statusMessage": ""
|
statusMessage: "",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,16 +21,16 @@ Item {
|
||||||
{ name: "no", text: qsTr("No") },
|
{ name: "no", text: qsTr("No") },
|
||||||
]
|
]
|
||||||
|
|
||||||
buttonCallbacks: {
|
buttonCallbacks: ({
|
||||||
"yes": button => {
|
yes: button => {
|
||||||
py.callCoro("save_account", [userId])
|
py.callCoro("save_account", [userId])
|
||||||
pageStack.showPage("Default")
|
pageStack.showPage("Default")
|
||||||
},
|
},
|
||||||
"no": button => {
|
no: button => {
|
||||||
py.callCoro("forget_account", [userId])
|
py.callCoro("forget_account", [userId])
|
||||||
pageStack.showPage("Default")
|
pageStack.showPage("Default")
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
|
|
||||||
HLabel {
|
HLabel {
|
||||||
text: qsTr(
|
text: qsTr(
|
||||||
|
|
|
@ -22,24 +22,21 @@ Item {
|
||||||
{ name: "forgot", text: qsTr("Forgot?") }
|
{ name: "forgot", text: qsTr("Forgot?") }
|
||||||
]
|
]
|
||||||
|
|
||||||
buttonCallbacks: {
|
buttonCallbacks: ({
|
||||||
"register": button => {},
|
register: button => {},
|
||||||
|
|
||||||
"login": button => {
|
login: button => {
|
||||||
button.loading = true
|
button.loading = true
|
||||||
var args = [idField.text, passwordField.text]
|
var args = [idField.text, passwordField.text]
|
||||||
|
|
||||||
py.callCoro("login_client", args, user_id => {
|
py.callCoro("login_client", args, user_id => {
|
||||||
pageStack.showPage(
|
pageStack.showPage("RememberAccount", {loginWith, user_id})
|
||||||
"RememberAccount",
|
|
||||||
{"loginWith": loginWith, "userId": user_id}
|
|
||||||
)
|
|
||||||
button.loading = false
|
button.loading = false
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
"forgot": button => {}
|
forgot: button => {}
|
||||||
}
|
})
|
||||||
|
|
||||||
HRowLayout {
|
HRowLayout {
|
||||||
spacing: signInBox.margins * 1.25
|
spacing: signInBox.margins * 1.25
|
||||||
|
|
|
@ -64,11 +64,7 @@ Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
function showRoom(userId, category, roomId) {
|
function showRoom(userId, category, roomId) {
|
||||||
var info = rooms.getWhere({
|
var info = rooms.getWhere({userId, roomId, category}, 1)[0]
|
||||||
"userId": userId,
|
|
||||||
"roomId": roomId,
|
|
||||||
"category": category
|
|
||||||
}, 1)[0]
|
|
||||||
|
|
||||||
pageStack.replace("Chat/Chat.qml", {"roomInfo": info})
|
pageStack.replace("Chat/Chat.qml", {"roomInfo": info})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user