From 0964363b89a69280c5cb051f5fdca1eebe9d75c4 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Tue, 5 Nov 2019 14:12:40 -0800 Subject: [PATCH] fixes for adding/imorting contacts; remove unused 'letter' class --- go/characters/incominglistener.go | 4 ++++ go/gobjects/letter.go | 7 ------- go/gothings/gcd.go | 19 +++++++++++++++---- main.go | 2 -- qml/widgets/ContactList.qml | 6 ++++++ qml/widgets/Message.qml | 1 + 6 files changed, 26 insertions(+), 13 deletions(-) delete mode 100644 go/gobjects/letter.go diff --git a/go/characters/incominglistener.go b/go/characters/incominglistener.go index b45a97be..ce183c2a 100644 --- a/go/characters/incominglistener.go +++ b/go/characters/incominglistener.go @@ -22,6 +22,7 @@ func IncomingListener(uiState *gothings.InterfaceState, subscribed chan bool) { the.EventBus.Subscribe(event.SendMessageToPeerError, q) the.EventBus.Subscribe(event.ServerStateChange, q) the.EventBus.Subscribe(event.PeerStateChange, q) + the.EventBus.Subscribe(event.PeerCreated, q) subscribed <- true for { @@ -75,6 +76,9 @@ func IncomingListener(uiState *gothings.InterfaceState, subscribed chan bool) { if err == nil && group != nil { uiState.AddContact(gid) } + case event.PeerCreated: + onion := e.Data[event.RemotePeer] + uiState.AddContact(onion) case event.SendMessageToGroupError: uiState.AddSendMessageError(e.Data[event.GroupServer], e.Data[event.Signature], e.Data[event.Error]) case event.SendMessageToPeerError: diff --git a/go/gobjects/letter.go b/go/gobjects/letter.go deleted file mode 100644 index fc35c26f..00000000 --- a/go/gobjects/letter.go +++ /dev/null @@ -1,7 +0,0 @@ -package gobjects - -// a Letter is a very simple message object passed to us from the UI -type Letter struct { - To, Message string - MID string -} diff --git a/go/gothings/gcd.go b/go/gothings/gcd.go index 46169e35..115abc64 100644 --- a/go/gothings/gcd.go +++ b/go/gothings/gcd.go @@ -19,10 +19,9 @@ import ( type GrandCentralDispatcher struct { core.QObject - OutgoingMessages chan gobjects.Letter - UIState InterfaceState - QMLEngine *qml.QQmlApplicationEngine - Translator *core.QTranslator + UIState InterfaceState + QMLEngine *qml.QQmlApplicationEngine + Translator *core.QTranslator _ string `property:"os"` _ string `property:"currentOpenConversation"` @@ -66,6 +65,7 @@ type GrandCentralDispatcher struct { _ func(onion string) `signal:"loadMessagesPane,auto"` _ func(signal string) `signal:"broadcast,auto"` // convenience relay signal _ func(str string) `signal:"importString,auto"` + _ func(str string) `signal:"createContact,auto"` _ func(str string) `signal:"popup,auto"` _ func(nick string) `signal:"updateNick,auto"` _ func(server, groupName string) `signal:"createGroup,auto"` @@ -339,6 +339,14 @@ func (this *GrandCentralDispatcher) broadcast(signal string) { } } +func (this *GrandCentralDispatcher) createContact(onion string) { + if contact := the.Peer.GetContact(onion); contact != nil { + return + } + the.Peer.AddContact(onion, onion, false) + the.Peer.PeerWithOnion(onion) +} + func (this *GrandCentralDispatcher) importString(str string) { if len(str) < 5 { log.Debugf("ignoring short string") @@ -397,6 +405,9 @@ func (this *GrandCentralDispatcher) importString(str string) { if checkc != nil { this.InvokePopup("already have this contact") return //TODO: bring them to the duplicate + } else { + the.Peer.AddContact(name, onion, false) + the.Peer.PeerWithOnion(onion) } this.UIState.AddContact(onion) diff --git a/main.go b/main.go index 483e3e3a..2c7e3320 100644 --- a/main.go +++ b/main.go @@ -4,7 +4,6 @@ import ( libapp "cwtch.im/cwtch/app" "cwtch.im/cwtch/event/bridge" "cwtch.im/ui/go/characters" - "cwtch.im/ui/go/gobjects" "cwtch.im/ui/go/gothings" "cwtch.im/ui/go/gothings/android" "cwtch.im/ui/go/the" @@ -139,7 +138,6 @@ func mainUi(flagLocal bool, flagClientUI bool) { gcd.SetBuildDate("now") } gcd.UIState = gothings.NewUIState(gcd) - gcd.OutgoingMessages = make(chan gobjects.Letter, 1000) //TODO: put theme stuff somewhere better gcd.SetThemeScale(1.0) diff --git a/qml/widgets/ContactList.qml b/qml/widgets/ContactList.qml index c0b81efc..5b88d033 100644 --- a/qml/widgets/ContactList.qml +++ b/qml/widgets/ContactList.qml @@ -48,6 +48,12 @@ ColumnLayout { target: gcd onAddContact: function(handle, displayName, image, server, badge, status, blocked, loading) { + for (var i = 0; i < contactsModel.count; i++) { + if (contactsModel.get(i)["_handle"] == handle) { + return + } + } + contactsModel.append({ "_handle": handle, "_displayName": displayName + (blocked ? " (blocked)" : "" ), diff --git a/qml/widgets/Message.qml b/qml/widgets/Message.qml index d1f1ca86..bea69643 100644 --- a/qml/widgets/Message.qml +++ b/qml/widgets/Message.qml @@ -62,6 +62,7 @@ Item { onClicked: { + gcd.createContact(from) gcd.broadcast("ResetMessagePane") theStack.pane = theStack.messagePane gcd.loadMessagesPane(from)