~nicohman/signal-rs

ref: ad7bba6ed316afe281e38a8327baf7c1bbf824da signal-rs/qml/SignalState.qml -rw-r--r-- 3.0 KiB
ad7bba6e — nicohman Basic attachments 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
import QtQuick 2.0
import QtQuick.Controls 2.5

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;
        signal.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 = signal.resolve_name(i);
            console.log(name);
            signalState.editGroupMembersModel.append({
                c_name: name.toString(),
                id: i
            });
        });
    }
    function contact(tel) {
        return JSON.parse(signal.contact(tel));
    }
    function group(group_id) {
        return JSON.parse(signal.group(group_id));
    }
    function message(sent_at, chat_id) {
        return signal.message(chat_id, sent_at);
    }
    function setCurrent(cur) {
        signalState.current = cur;
        for (var i=0; i < signal.chats.rowCount(); i++) {
            var idx = signal.chats.index(i, 0);
            var str = signal.chats.data(idx, 2+256).toString();
            if (str == cur.toString()) {
                signalState.currentName = signal.chats.data(idx, 1+256).toString();
                break;
            }
        }
    }
}