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)` ?
|
||||
|
||||
- Qt 5.12
|
||||
- See about ECMAScript 6 and 7 features
|
||||
- .mjs modules
|
||||
|
||||
- Refactoring
|
||||
|
@ -18,6 +17,7 @@
|
|||
- Unfinished work in button-refactor branch
|
||||
- Button can get "hoverEnabled: false" to let HoverHandlers work
|
||||
- Room Sidepane
|
||||
- When qml syntax highlighting supports string interpolation, use them
|
||||
|
||||
- Bug fixes
|
||||
- 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":
|
||||
return cls(
|
||||
user_id = user.user_id,
|
||||
display_name = user.display_name,
|
||||
avatar_url = user.avatar_url,
|
||||
display_name = user.display_name or "",
|
||||
avatar_url = user.avatar_url or "",
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -7,8 +7,7 @@ HAvatar {
|
|||
property string userId: ""
|
||||
property string roomId: ""
|
||||
|
||||
readonly property var roomInfo:
|
||||
rooms.getWhere({"userId": userId, "roomId": roomId}, 1)[0]
|
||||
readonly property var roomInfo: rooms.getWhere({userId, roomId}, 1)[0]
|
||||
|
||||
// roomInfo ? → Avoid error messages when a room is forgotten
|
||||
readonly property var dname: roomInfo ? roomInfo.displayName : ""
|
||||
|
|
|
@ -34,8 +34,8 @@ Banner {
|
|||
}
|
||||
]
|
||||
|
||||
buttonCallbacks: {
|
||||
"accept": button => {
|
||||
buttonCallbacks: ({
|
||||
accept: button => {
|
||||
button.loading = true
|
||||
py.callClientCoro(
|
||||
chatPage.userId, "join", [chatPage.roomId], () => {
|
||||
|
@ -43,12 +43,12 @@ Banner {
|
|||
})
|
||||
},
|
||||
|
||||
"decline": button => {
|
||||
decline: button => {
|
||||
button.loading = true
|
||||
py.callClientCoro(
|
||||
chatPage.userId, "room_leave", [chatPage.roomId], () => {
|
||||
button.loading = false
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -22,13 +22,13 @@ Banner {
|
|||
}
|
||||
]
|
||||
|
||||
buttonCallbacks: {
|
||||
"forget": button => {
|
||||
buttonCallbacks: ({
|
||||
forget: button => {
|
||||
button.loading = true
|
||||
py.callClientCoro(
|
||||
chatPage.userId, "room_forget", [chatPage.roomId], () => {
|
||||
button.loading = false
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -20,9 +20,9 @@ Banner {
|
|||
}
|
||||
]
|
||||
|
||||
buttonCallbacks: {
|
||||
"inspect": button => {
|
||||
buttonCallbacks: ({
|
||||
inspect: button => {
|
||||
print("show")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
// Copyright 2019 miruka
|
||||
// This file is part of harmonyqml, licensed under LGPLv3.
|
||||
|
||||
function onExitRequested(exit_code) {
|
||||
Qt.exit(exit_code)
|
||||
function onExitRequested(exitCode) {
|
||||
Qt.exit(exitCode)
|
||||
}
|
||||
|
||||
function onCoroutineDone(uuid, result) {
|
||||
|
|
|
@ -3,13 +3,12 @@
|
|||
|
||||
Qt.include("../utils.js")
|
||||
|
||||
|
||||
function typingTextFor(members, our_user_id) {
|
||||
function typingTextFor(members, ourUserId) {
|
||||
var profiles = []
|
||||
var names = []
|
||||
|
||||
for (var i = 0; i < members.length; i++) {
|
||||
if (members[i] != our_user_id) {
|
||||
if (members[i] != ourUserId) {
|
||||
profiles.push(users.find(members[i]))
|
||||
}
|
||||
}
|
||||
|
@ -37,18 +36,13 @@ function typingTextFor(members, our_user_id) {
|
|||
|
||||
|
||||
function onRoomUpdated(
|
||||
user_id, category, room_id, display_name, avatar_url, topic,
|
||||
members, typing_members, inviter_id
|
||||
userId, category, roomId, displayName, avatarUrl, topic,
|
||||
members, typingMembers, inviterId
|
||||
) {
|
||||
roomCategories.upsert({"userId": user_id, "name": category}, {
|
||||
"userId": user_id,
|
||||
"name": category
|
||||
})
|
||||
roomCategories.upsert({userId, name: category}, {userId, name: category})
|
||||
|
||||
function find(for_category) {
|
||||
var found = rooms.getIndices(
|
||||
{"userId": user_id, "roomId": room_id, "category": for_category}, 1
|
||||
)
|
||||
function find(category) {
|
||||
var found = rooms.getIndices({userId, roomId, category}, 1)
|
||||
return found.length > 0 ? found[0] : null
|
||||
}
|
||||
|
||||
|
@ -58,71 +52,45 @@ function onRoomUpdated(
|
|||
else if (category == "Left") { replace = find("Invites") || find("Rooms")}
|
||||
|
||||
var item = {
|
||||
"userId": user_id,
|
||||
"category": category,
|
||||
"roomId": room_id,
|
||||
"displayName": display_name,
|
||||
"avatarUrl": avatar_url,
|
||||
"topic": topic,
|
||||
"members": members,
|
||||
"typingText": typingTextFor(typing_members, user_id),
|
||||
"inviterId": inviter_id
|
||||
typingText: typingTextFor(typingMembers, userId),
|
||||
|
||||
userId, category, roomId, displayName, avatarUrl, topic, members,
|
||||
inviterId
|
||||
}
|
||||
|
||||
if (replace === null) {
|
||||
rooms.upsert(
|
||||
{"userId": user_id, "roomId": room_id, "category": category},
|
||||
item
|
||||
)
|
||||
rooms.upsert({userId, roomId, category}, item)
|
||||
} else {
|
||||
rooms.set(replace, item)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function onRoomForgotten(user_id, room_id) {
|
||||
rooms.popWhere({"userId": user_id, "roomId": room_id})
|
||||
}
|
||||
|
||||
|
||||
function onRoomMemberUpdated(room_id, user_id, typing) {
|
||||
}
|
||||
|
||||
|
||||
function onRoomMemberDeleted(room_id, user_id) {
|
||||
function onRoomForgotten(userId, roomId) {
|
||||
rooms.popWhere({userId, roomId})
|
||||
}
|
||||
|
||||
|
||||
function onTimelineEventReceived(
|
||||
event_type, room_id, event_id, sender_id, date, content,
|
||||
content_type, is_local_echo, show_name_line, translatable, target_user_id
|
||||
eventType, roomId, eventId, senderId, date, content,
|
||||
contentType, isLocalEcho, showNameLine, translatable, targetUserId
|
||||
) {
|
||||
var item = {
|
||||
"eventType": py.getattr(event_type, "__name__"),
|
||||
"roomId": room_id,
|
||||
"eventId": event_id,
|
||||
"senderId": sender_id,
|
||||
"date": date,
|
||||
"content": content,
|
||||
"contentType": content_type,
|
||||
"isLocalEcho": is_local_echo,
|
||||
"showNameLine": show_name_line,
|
||||
"translatable": translatable,
|
||||
"targetUserId": target_user_id,
|
||||
eventType: py.getattr(eventType, "__name__"),
|
||||
|
||||
roomId, eventId, senderId, date, content, contentType, isLocalEcho,
|
||||
showNameLine, translatable, targetUserId
|
||||
}
|
||||
|
||||
if (is_local_echo) {
|
||||
if (isLocalEcho) {
|
||||
timelines.append(item)
|
||||
return
|
||||
}
|
||||
|
||||
// Replace first matching local echo
|
||||
var found = timelines.getIndices({
|
||||
"roomId": room_id,
|
||||
"senderId": sender_id,
|
||||
"content": content,
|
||||
"isLocalEcho": true
|
||||
}, 1, 250)
|
||||
var found = timelines.getIndices(
|
||||
{roomId, senderId, content, "isLocalEcho": true}, 1, 250
|
||||
)
|
||||
|
||||
if (found.length > 0) {
|
||||
timelines.set(found[0], item)
|
||||
|
@ -131,16 +99,12 @@ function onTimelineEventReceived(
|
|||
else if (item.eventType == "OlmEvent" || item.eventType == "MegolmEvent") {
|
||||
// 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.
|
||||
timelines.upsert({"eventId": event_id}, item, false, 250)
|
||||
timelines.upsert({eventId}, item, false, 250)
|
||||
}
|
||||
else {
|
||||
timelines.upsert({"eventId": event_id}, item, true, 250)
|
||||
timelines.upsert({eventId}, item, true, 250)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var onTimelineMessageReceived = onTimelineEventReceived
|
||||
|
||||
|
||||
function onTypingNoticeEvent(room_id, members) {
|
||||
}
|
||||
|
|
|
@ -1,26 +1,21 @@
|
|||
// Copyright 2019 miruka
|
||||
// This file is part of harmonyqml, licensed under LGPLv3.
|
||||
|
||||
function onAccountUpdated(user_id) {
|
||||
accounts.append({"userId": user_id})
|
||||
function onAccountUpdated(userId) {
|
||||
accounts.append({userId})
|
||||
}
|
||||
|
||||
function onAccountDeleted(user_id) {
|
||||
accounts.popWhere({"userId": user_id}, 1)
|
||||
function onAccountDeleted(userId) {
|
||||
accounts.popWhere({userId}, 1)
|
||||
}
|
||||
|
||||
function onUserUpdated(user_id, display_name, avatar_url, status_message) {
|
||||
users.upsert({"userId": user_id}, {
|
||||
"userId": user_id,
|
||||
"displayName": display_name,
|
||||
"avatarUrl": avatar_url,
|
||||
"statusMessage": status_message
|
||||
})
|
||||
function onUserUpdated(userId, displayName, avatarUrl, statusMessage) {
|
||||
users.upsert({userId}, {userId, displayName, avatarUrl, statusMessage})
|
||||
}
|
||||
|
||||
function onDeviceUpdated(user_id, device_id, ed25519_key, trust, display_name,
|
||||
last_seen_ip, last_seen_date) {
|
||||
function onDeviceUpdated(userId, deviceId, ed25519Key, trust, displayName,
|
||||
lastSeenIp, lastSeenDate) {
|
||||
}
|
||||
|
||||
function onDeviceDeleted(user_id, device_id) {
|
||||
function onDeviceDeleted(userId, deviceId) {
|
||||
}
|
||||
|
|
|
@ -6,21 +6,21 @@ import SortFilterProxyModel 0.2
|
|||
import "../Base"
|
||||
|
||||
HListModel {
|
||||
function find(user_id) {
|
||||
function find(userId) {
|
||||
// Happens when SortFilterProxyModel ExpressionFilter/Sorter/Role tests
|
||||
// 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] }
|
||||
|
||||
py.callCoro("request_user_update_event", [user_id])
|
||||
py.callCoro("request_user_update_event", [userId])
|
||||
|
||||
return {
|
||||
"userId": user_id,
|
||||
"displayName": "",
|
||||
"avatarUrl": "",
|
||||
"statusMessage": ""
|
||||
userId,
|
||||
displayName: "",
|
||||
avatarUrl: "",
|
||||
statusMessage: "",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,16 +21,16 @@ Item {
|
|||
{ name: "no", text: qsTr("No") },
|
||||
]
|
||||
|
||||
buttonCallbacks: {
|
||||
"yes": button => {
|
||||
buttonCallbacks: ({
|
||||
yes: button => {
|
||||
py.callCoro("save_account", [userId])
|
||||
pageStack.showPage("Default")
|
||||
},
|
||||
"no": button => {
|
||||
no: button => {
|
||||
py.callCoro("forget_account", [userId])
|
||||
pageStack.showPage("Default")
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
HLabel {
|
||||
text: qsTr(
|
||||
|
|
|
@ -22,24 +22,21 @@ Item {
|
|||
{ name: "forgot", text: qsTr("Forgot?") }
|
||||
]
|
||||
|
||||
buttonCallbacks: {
|
||||
"register": button => {},
|
||||
buttonCallbacks: ({
|
||||
register: button => {},
|
||||
|
||||
"login": button => {
|
||||
login: button => {
|
||||
button.loading = true
|
||||
var args = [idField.text, passwordField.text]
|
||||
|
||||
py.callCoro("login_client", args, user_id => {
|
||||
pageStack.showPage(
|
||||
"RememberAccount",
|
||||
{"loginWith": loginWith, "userId": user_id}
|
||||
)
|
||||
pageStack.showPage("RememberAccount", {loginWith, user_id})
|
||||
button.loading = false
|
||||
})
|
||||
},
|
||||
|
||||
"forgot": button => {}
|
||||
}
|
||||
forgot: button => {}
|
||||
})
|
||||
|
||||
HRowLayout {
|
||||
spacing: signInBox.margins * 1.25
|
||||
|
|
|
@ -64,11 +64,7 @@ Item {
|
|||
}
|
||||
|
||||
function showRoom(userId, category, roomId) {
|
||||
var info = rooms.getWhere({
|
||||
"userId": userId,
|
||||
"roomId": roomId,
|
||||
"category": category
|
||||
}, 1)[0]
|
||||
var info = rooms.getWhere({userId, roomId, category}, 1)[0]
|
||||
|
||||
pageStack.replace("Chat/Chat.qml", {"roomInfo": info})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user