~nicohman/signal-rs

ref: 5084c926fb753fdc6dda5f3cc2c8af2df5f1190b signal-rs/qml/SignalState.qml -rw-r--r-- 3.1 KiB
5084c926 — nicohman Make SignalUI a singleton and add application icon 4 months ago
                                                                                
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
import QtQuick 2.0
import QtQuick.Controls 2.5
import SignalUI 0.1

Item {
    id: signalState
    property var messages: ({})
    property string current: ""
    property string currentName: ""
    property string currentView: ""
    property string currentTel: ""
    property var currentChat : {}
    property var headerItems: []
    property var editGroupMembersModel: ListModel {}
    property var currentGroup
    property bool currentIsGroup: false
    property bool desktopView: false
    function openView(viewName) {
        signalState.currentView = viewName;
        SignalUI.show_view(viewName);
        switch (viewName) {
            case "about":
                window.pageStack.layers.push(Qt.resolvedUrl("About.qml"));
                break;
            case "chats":
                window.pageStack.push(chatViewStack);
                break;
            case "createContact":
                window.pageStack.layers.push(Qt.resolvedUrl("CreateContact.qml"));
                break;
            case "settings":
                window.pageStack.layers.push(Qt.resolvedUrl("Settings.qml"));
                break;
            case "chatHistory":
                if (!signalState.desktopView) {
                                console.log("show");

                    window.pageStack.push(messagesViewStack);
                }
                break;
            case "editContact":
                let contact = signalState.contact(signalState.current);
                console.log(JSON.stringify(contact));
                signalState.currentTel = contact.Tel;
                window.pageStack.layers.push(Qt.resolvedUrl("EditContact.qml"));
                break;
            case "editGroup":
                window.pageStack.layers.push(editGroupStack);
                break;
            case "createChat":
                window.pageStack.layers.push(createChatStack);
                break;
        }
    }
    function editGroup(groupId) {
        signalState.editGroupMembersModel.clear();
        let group = signalState.group(groupId);
        signalState.currentGroup = group;
        console.log(group.members);
        group.members.forEach((i) => {
            console.log(i);
            let name = SignalUI.resolve_name(i);
            console.log(name);
            signalState.editGroupMembersModel.append({
                c_name: name.toString(),
                id: i
            });
        });
    }
    function contact(tel) {
        return JSON.parse(SignalUI.contact(tel));
    }
    function group(group_id) {
        return JSON.parse(SignalUI.group(group_id));
    }
    function message(sent_at, chat_id) {
        return SignalUI.message(chat_id, sent_at);
    }
    function setCurrent(cur) {
        signalState.current = cur;
        for (var i=0; i < SignalUI.chats.rowCount(); i++) {
            var idx = SignalUI.chats.index(i, 0);
            var str = SignalUI.chats.data(idx, 2+256).toString();
            if (str == cur.toString()) {
                signalState.currentName = SignalUI.chats.data(idx, 1+256).toString();
                break;
            }
        }
    }
}