Merge branch 'refactor' of dan/ui into master
the build was successful
Details
the build was successful
Details
This commit is contained in:
commit
54918e612f
|
@ -1,16 +0,0 @@
|
||||||
package gobjects
|
|
||||||
|
|
||||||
import "time"
|
|
||||||
|
|
||||||
type Message struct {
|
|
||||||
Handle string
|
|
||||||
From string
|
|
||||||
DisplayName string
|
|
||||||
Message string
|
|
||||||
Image string
|
|
||||||
FromMe bool
|
|
||||||
MessageID string
|
|
||||||
Timestamp time.Time
|
|
||||||
Acknowledged bool
|
|
||||||
Error bool
|
|
||||||
}
|
|
|
@ -1,18 +1,17 @@
|
||||||
package characters
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cwtch.im/cwtch/app/plugins"
|
"cwtch.im/cwtch/app/plugins"
|
||||||
"cwtch.im/cwtch/event"
|
"cwtch.im/cwtch/event"
|
||||||
"cwtch.im/ui/go/constants"
|
"cwtch.im/ui/go/constants"
|
||||||
"cwtch.im/ui/go/cwutil"
|
|
||||||
"cwtch.im/ui/go/gothings"
|
|
||||||
"cwtch.im/ui/go/the"
|
"cwtch.im/ui/go/the"
|
||||||
|
"cwtch.im/ui/go/ui"
|
||||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AppEventListener(gcd *gothings.GrandCentralDispatcher, subscribed chan bool) {
|
func App(gcd *ui.GrandCentralDispatcher, subscribed chan bool) {
|
||||||
q := event.NewQueue()
|
q := event.NewQueue()
|
||||||
the.AppBus.Subscribe(event.NewPeer, q)
|
the.AppBus.Subscribe(event.NewPeer, q)
|
||||||
the.AppBus.Subscribe(event.PeerError, q)
|
the.AppBus.Subscribe(event.PeerError, q)
|
||||||
|
@ -78,20 +77,25 @@ func AppEventListener(gcd *gothings.GrandCentralDispatcher, subscribed chan bool
|
||||||
the.EventBus = the.CwtchApp.GetEventBus(onion)
|
the.EventBus = the.CwtchApp.GetEventBus(onion)
|
||||||
|
|
||||||
incSubscribed := make(chan bool)
|
incSubscribed := make(chan bool)
|
||||||
go IncomingListener(&gcd.UIState, incSubscribed)
|
go PeerHandler(&gcd.UIManager, incSubscribed)
|
||||||
<-incSubscribed
|
<-incSubscribed
|
||||||
|
|
||||||
gcd.UpdateMyProfile(the.Peer.GetProfile().Name, the.Peer.GetProfile().Onion, cwutil.RandomProfileImage(the.Peer.GetProfile().Onion))
|
pic, exists := the.Peer.GetAttribute(constants.Picture)
|
||||||
|
if !exists {
|
||||||
|
pic = ui.RandomProfileImage(the.Peer.GetProfile().Onion)
|
||||||
|
the.Peer.SetAttribute(constants.Picture, pic)
|
||||||
|
}
|
||||||
|
gcd.UpdateMyProfile(the.Peer.GetProfile().Name, the.Peer.GetProfile().Onion, pic)
|
||||||
|
|
||||||
contacts := the.Peer.GetContacts()
|
contacts := the.Peer.GetContacts()
|
||||||
for i := range contacts {
|
for i := range contacts {
|
||||||
gcd.UIState.AddContact(contacts[i])
|
gcd.UIManager.AddContact(contacts[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
groups := the.Peer.GetGroups()
|
groups := the.Peer.GetGroups()
|
||||||
for i := range groups {
|
for i := range groups {
|
||||||
// Only join servers for active and explicitly accepted groups.
|
// Only join servers for active and explicitly accepted groups.
|
||||||
gcd.UIState.AddContact(groups[i])
|
gcd.UIManager.AddContact(groups[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
if e.Data[event.Status] != "running" {
|
if e.Data[event.Status] != "running" {
|
|
@ -1,18 +1,15 @@
|
||||||
package characters
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cwtch.im/cwtch/event"
|
"cwtch.im/cwtch/event"
|
||||||
"cwtch.im/cwtch/protocol/connections"
|
"cwtch.im/cwtch/protocol/connections"
|
||||||
"cwtch.im/ui/go/constants"
|
|
||||||
"cwtch.im/ui/go/cwutil"
|
|
||||||
"cwtch.im/ui/go/gobjects"
|
|
||||||
"cwtch.im/ui/go/gothings"
|
|
||||||
"cwtch.im/ui/go/the"
|
"cwtch.im/ui/go/the"
|
||||||
|
"cwtch.im/ui/go/ui"
|
||||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func IncomingListener(uiState *gothings.InterfaceState, subscribed chan bool) {
|
func PeerHandler(uiManager *ui.Manager, subscribed chan bool) {
|
||||||
q := event.NewQueue()
|
q := event.NewQueue()
|
||||||
the.EventBus.Subscribe(event.NewMessageFromPeer, q)
|
the.EventBus.Subscribe(event.NewMessageFromPeer, q)
|
||||||
the.EventBus.Subscribe(event.PeerAcknowledgement, q)
|
the.EventBus.Subscribe(event.PeerAcknowledgement, q)
|
||||||
|
@ -31,76 +28,48 @@ func IncomingListener(uiState *gothings.InterfaceState, subscribed chan bool) {
|
||||||
switch e.EventType {
|
switch e.EventType {
|
||||||
case event.NewMessageFromPeer: //event.TimestampReceived, event.RemotePeer, event.Data
|
case event.NewMessageFromPeer: //event.TimestampReceived, event.RemotePeer, event.Data
|
||||||
ts, _ := time.Parse(time.RFC3339Nano, e.Data[event.TimestampReceived])
|
ts, _ := time.Parse(time.RFC3339Nano, e.Data[event.TimestampReceived])
|
||||||
uiState.AddMessage(&gobjects.Message{
|
uiManager.AddMessage(e.Data[event.RemotePeer], e.Data[event.RemotePeer], e.Data[event.Data], false, e.EventID, ts, true)
|
||||||
Handle: e.Data[event.RemotePeer],
|
|
||||||
From: e.Data[event.RemotePeer],
|
|
||||||
Message: e.Data[event.Data],
|
|
||||||
Image: cwutil.RandomProfileImage(e.Data[event.RemotePeer]),
|
|
||||||
Timestamp: ts,
|
|
||||||
})
|
|
||||||
if the.Peer.GetContact(e.Data[event.RemotePeer]) == nil {
|
if the.Peer.GetContact(e.Data[event.RemotePeer]) == nil {
|
||||||
the.Peer.AddContact(e.Data[event.RemotePeer], e.Data[event.RemotePeer], false)
|
the.Peer.AddContact(e.Data[event.RemotePeer], e.Data[event.RemotePeer], false)
|
||||||
}
|
}
|
||||||
|
|
||||||
case event.PeerAcknowledgement:
|
case event.PeerAcknowledgement:
|
||||||
uiState.Acknowledge(e.Data[event.EventID])
|
uiManager.Acknowledge(e.Data[event.EventID])
|
||||||
|
|
||||||
case event.NewMessageFromGroup: //event.TimestampReceived, event.TimestampSent, event.Data, event.GroupID, event.RemotePeer
|
case event.NewMessageFromGroup: //event.TimestampReceived, event.TimestampSent, event.Data, event.GroupID, event.RemotePeer
|
||||||
var name string
|
|
||||||
var exists bool
|
|
||||||
ctc := the.Peer.GetContact(e.Data[event.RemotePeer])
|
|
||||||
if ctc != nil {
|
|
||||||
name, exists = ctc.GetAttribute(constants.Nick)
|
|
||||||
if !exists || name == "" {
|
|
||||||
name = e.Data[event.RemotePeer]
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
name = e.Data[event.RemotePeer]
|
|
||||||
}
|
|
||||||
|
|
||||||
ts, _ := time.Parse(time.RFC3339Nano, e.Data[event.TimestampSent])
|
ts, _ := time.Parse(time.RFC3339Nano, e.Data[event.TimestampSent])
|
||||||
uiState.AddMessage(&gobjects.Message{
|
uiManager.AddMessage(e.Data[event.GroupID], e.Data[event.RemotePeer], e.Data[event.Data], e.Data[event.RemotePeer] == the.Peer.GetProfile().Onion, e.Data[event.Signature], ts, true)
|
||||||
MessageID: e.Data[event.Signature],
|
|
||||||
Handle: e.Data[event.GroupID],
|
|
||||||
From: e.Data[event.RemotePeer],
|
|
||||||
Message: e.Data[event.Data],
|
|
||||||
Image: cwutil.RandomProfileImage(e.Data[event.RemotePeer]),
|
|
||||||
FromMe: e.Data[event.RemotePeer] == the.Peer.GetProfile().Onion,
|
|
||||||
Timestamp: ts,
|
|
||||||
Acknowledged: true,
|
|
||||||
DisplayName: name,
|
|
||||||
})
|
|
||||||
case event.NewGroupInvite:
|
case event.NewGroupInvite:
|
||||||
gid, err := the.Peer.GetProfile().ProcessInvite(e.Data[event.GroupInvite], e.Data[event.RemotePeer])
|
gid, err := the.Peer.GetProfile().ProcessInvite(e.Data[event.GroupInvite], e.Data[event.RemotePeer])
|
||||||
group := the.Peer.GetGroup(gid)
|
group := the.Peer.GetGroup(gid)
|
||||||
if err == nil && group != nil {
|
if err == nil && group != nil {
|
||||||
uiState.AddContact(gid)
|
uiManager.AddContact(gid)
|
||||||
}
|
}
|
||||||
case event.PeerCreated:
|
case event.PeerCreated:
|
||||||
onion := e.Data[event.RemotePeer]
|
onion := e.Data[event.RemotePeer]
|
||||||
uiState.AddContact(onion)
|
uiManager.AddContact(onion)
|
||||||
case event.SendMessageToGroupError:
|
case event.SendMessageToGroupError:
|
||||||
uiState.AddSendMessageError(e.Data[event.GroupServer], e.Data[event.Signature], e.Data[event.Error])
|
uiManager.AddSendMessageError(e.Data[event.GroupServer], e.Data[event.Signature], e.Data[event.Error])
|
||||||
case event.SendMessageToPeerError:
|
case event.SendMessageToPeerError:
|
||||||
uiState.AddSendMessageError(e.Data[event.RemotePeer], e.Data[event.EventID], e.Data[event.Error])
|
uiManager.AddSendMessageError(e.Data[event.RemotePeer], e.Data[event.EventID], e.Data[event.Error])
|
||||||
case event.PeerStateChange:
|
case event.PeerStateChange:
|
||||||
cxnState := connections.ConnectionStateToType[e.Data[event.ConnectionState]]
|
cxnState := connections.ConnectionStateToType[e.Data[event.ConnectionState]]
|
||||||
|
|
||||||
// if it's not in the.Peer it's new. Only add once Authed
|
// if it's not in the.PeerHandler it's new. Only add once Authed
|
||||||
if _, exists := the.Peer.GetProfile().Contacts[e.Data[event.RemotePeer]]; !exists {
|
if _, exists := the.Peer.GetProfile().Contacts[e.Data[event.RemotePeer]]; !exists {
|
||||||
// Contact does not exist, we will add them but we won't know who they are until they are authenticated
|
// Contact does not exist, we will add them but we won't know who they are until they are authenticated
|
||||||
// So if we get any other state from an unknown contact we do nothing
|
// So if we get any other state from an unknown contact we do nothing
|
||||||
// (the next exists check will fail)
|
// (the next exists check will fail)
|
||||||
if cxnState == connections.AUTHENTICATED {
|
if cxnState == connections.AUTHENTICATED {
|
||||||
the.Peer.AddContact(e.Data[event.RemotePeer], e.Data[event.RemotePeer], false)
|
the.Peer.AddContact(e.Data[event.RemotePeer], e.Data[event.RemotePeer], false)
|
||||||
uiState.AddContact(e.Data[event.RemotePeer])
|
uiManager.AddContact(e.Data[event.RemotePeer])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if it's in the.Peer its either existing and needs an update or not in the UI and needs to be added
|
// if it's in the.PeerHandler its either existing and needs an update or not in the UI and needs to be added
|
||||||
if contact, exists := the.Peer.GetProfile().Contacts[e.Data[event.RemotePeer]]; exists {
|
if contact, exists := the.Peer.GetProfile().Contacts[e.Data[event.RemotePeer]]; exists {
|
||||||
contact.State = e.Data[event.ConnectionState]
|
contact.State = e.Data[event.ConnectionState]
|
||||||
uiState.UpdateContactStatus(contact.Onion, int(cxnState), false)
|
uiManager.UpdateContactStatus(contact.Onion, int(cxnState), false)
|
||||||
|
|
||||||
}
|
}
|
||||||
case event.ServerStateChange:
|
case event.ServerStateChange:
|
||||||
|
@ -115,7 +84,7 @@ func IncomingListener(uiState *gothings.InterfaceState, subscribed chan bool) {
|
||||||
if state == connections.AUTHENTICATED {
|
if state == connections.AUTHENTICATED {
|
||||||
loading = true
|
loading = true
|
||||||
}
|
}
|
||||||
uiState.UpdateContactStatus(group.GroupID, int(state), loading)
|
uiManager.UpdateContactStatus(group.GroupID, int(state), loading)
|
||||||
} else {
|
} else {
|
||||||
log.Errorf("found group that is nil :/")
|
log.Errorf("found group that is nil :/")
|
||||||
}
|
}
|
|
@ -1,13 +1,11 @@
|
||||||
package gothings
|
package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cwtch.im/cwtch/event"
|
"cwtch.im/cwtch/event"
|
||||||
"cwtch.im/cwtch/protocol/connections"
|
"cwtch.im/cwtch/protocol/connections"
|
||||||
"cwtch.im/ui/go/constants"
|
"cwtch.im/ui/go/constants"
|
||||||
"cwtch.im/ui/go/cwutil"
|
|
||||||
"github.com/therecipe/qt/qml"
|
"github.com/therecipe/qt/qml"
|
||||||
|
|
||||||
"cwtch.im/ui/go/gobjects"
|
|
||||||
"cwtch.im/ui/go/the"
|
"cwtch.im/ui/go/the"
|
||||||
"encoding/base32"
|
"encoding/base32"
|
||||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||||
|
@ -19,7 +17,7 @@ import (
|
||||||
type GrandCentralDispatcher struct {
|
type GrandCentralDispatcher struct {
|
||||||
core.QObject
|
core.QObject
|
||||||
|
|
||||||
UIState InterfaceState
|
UIManager Manager
|
||||||
QMLEngine *qml.QQmlApplicationEngine
|
QMLEngine *qml.QQmlApplicationEngine
|
||||||
Translator *core.QTranslator
|
Translator *core.QTranslator
|
||||||
|
|
||||||
|
@ -109,18 +107,7 @@ func (this *GrandCentralDispatcher) sendMessage(message string, mID string) {
|
||||||
var err error
|
var err error
|
||||||
mID, err = the.Peer.SendMessageToGroupTracked(this.CurrentOpenConversation(), message)
|
mID, err = the.Peer.SendMessageToGroupTracked(this.CurrentOpenConversation(), message)
|
||||||
|
|
||||||
this.UIState.AddMessage(&gobjects.Message{
|
this.UIManager.AddMessage(this.CurrentOpenConversation(), "me", message, true, mID, time.Now(), false)
|
||||||
this.CurrentOpenConversation(),
|
|
||||||
"me",
|
|
||||||
"",
|
|
||||||
message,
|
|
||||||
"",
|
|
||||||
true,
|
|
||||||
mID,
|
|
||||||
time.Now(),
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
})
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.InvokePopup("failed to send message " + err.Error())
|
this.InvokePopup("failed to send message " + err.Error())
|
||||||
|
@ -130,18 +117,7 @@ func (this *GrandCentralDispatcher) sendMessage(message string, mID string) {
|
||||||
to := this.CurrentOpenConversation()
|
to := this.CurrentOpenConversation()
|
||||||
mID = the.Peer.SendMessageToPeer(to, message)
|
mID = the.Peer.SendMessageToPeer(to, message)
|
||||||
|
|
||||||
this.UIState.AddMessage(&gobjects.Message{
|
this.UIManager.AddMessage(to, "me", message, true, mID, time.Now(), false)
|
||||||
to,
|
|
||||||
"me",
|
|
||||||
"",
|
|
||||||
message,
|
|
||||||
"",
|
|
||||||
true,
|
|
||||||
mID,
|
|
||||||
time.Now(),
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -182,24 +158,16 @@ func (this *GrandCentralDispatcher) loadMessagesPaneHelper(handle string) {
|
||||||
} else {
|
} else {
|
||||||
handle = tl[i].PeerID
|
handle = tl[i].PeerID
|
||||||
}
|
}
|
||||||
var name string
|
|
||||||
var exists bool
|
name := getOrDefault(tl[i].PeerID, constants.Nick, tl[i].PeerID)
|
||||||
ctc := the.Peer.GetContact(tl[i].PeerID)
|
image := getProfilePic(tl[i].PeerID)
|
||||||
if ctc != nil {
|
|
||||||
name, exists = ctc.GetAttribute(constants.Nick)
|
|
||||||
if !exists || name == "" {
|
|
||||||
name = tl[i].PeerID
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
name = tl[i].PeerID
|
|
||||||
}
|
|
||||||
|
|
||||||
this.PrependMessage(
|
this.PrependMessage(
|
||||||
handle,
|
handle,
|
||||||
tl[i].PeerID,
|
tl[i].PeerID,
|
||||||
name,
|
name,
|
||||||
tl[i].Message,
|
tl[i].Message,
|
||||||
cwutil.RandomProfileImage(tl[i].PeerID),
|
image,
|
||||||
string(tl[i].Signature),
|
string(tl[i].Signature),
|
||||||
tl[i].PeerID == the.Peer.GetProfile().Onion,
|
tl[i].PeerID == the.Peer.GetProfile().Onion,
|
||||||
tl[i].Timestamp.Format(constants.TIME_FORMAT),
|
tl[i].Timestamp.Format(constants.TIME_FORMAT),
|
||||||
|
@ -233,24 +201,15 @@ func (this *GrandCentralDispatcher) loadMessagesPaneHelper(handle string) {
|
||||||
from = "me"
|
from = "me"
|
||||||
}
|
}
|
||||||
|
|
||||||
var displayname string
|
displayname := getOrDefault(messages[i].PeerID, constants.Nick, messages[i].PeerID)
|
||||||
ctc := the.Peer.GetContact(messages[i].PeerID)
|
image := getProfilePic(messages[i].PeerID)
|
||||||
if ctc != nil {
|
|
||||||
var exists bool
|
|
||||||
displayname, exists = ctc.GetAttribute(constants.Nick)
|
|
||||||
if !exists || displayname == "" {
|
|
||||||
displayname = messages[i].PeerID
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
displayname = messages[i].PeerID
|
|
||||||
}
|
|
||||||
|
|
||||||
this.AppendMessage(
|
this.AppendMessage(
|
||||||
from,
|
from,
|
||||||
messages[i].PeerID,
|
messages[i].PeerID,
|
||||||
displayname,
|
displayname,
|
||||||
messages[i].Message,
|
messages[i].Message,
|
||||||
cwutil.RandomProfileImage(handle),
|
image,
|
||||||
string(messages[i].Signature),
|
string(messages[i].Signature),
|
||||||
fromMe,
|
fromMe,
|
||||||
messages[i].Timestamp.Format(constants.TIME_FORMAT),
|
messages[i].Timestamp.Format(constants.TIME_FORMAT),
|
||||||
|
@ -397,7 +356,7 @@ func (this *GrandCentralDispatcher) importString(str string) {
|
||||||
_, err := base32.StdEncoding.DecodeString(strings.ToUpper(onion[:56]))
|
_, err := base32.StdEncoding.DecodeString(strings.ToUpper(onion[:56]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugln(err)
|
log.Debugln(err)
|
||||||
this.InvokePopup("bad format. missing characters?")
|
this.InvokePopup("bad format. missing handlers?")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,7 +369,7 @@ func (this *GrandCentralDispatcher) importString(str string) {
|
||||||
the.Peer.PeerWithOnion(onion)
|
the.Peer.PeerWithOnion(onion)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.UIState.AddContact(onion)
|
this.UIManager.AddContact(onion)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *GrandCentralDispatcher) popup(str string) {
|
func (this *GrandCentralDispatcher) popup(str string) {
|
||||||
|
@ -431,7 +390,7 @@ func (this *GrandCentralDispatcher) createGroup(server, groupName string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this.UIState.AddContact(groupID)
|
this.UIManager.AddContact(groupID)
|
||||||
|
|
||||||
the.Peer.SetGroupAttribute(groupID, constants.Nick, groupName)
|
the.Peer.SetGroupAttribute(groupID, constants.Nick, groupName)
|
||||||
|
|
||||||
|
@ -480,7 +439,7 @@ func (this *GrandCentralDispatcher) acceptGroup(groupID string) {
|
||||||
|
|
||||||
func (this *GrandCentralDispatcher) setAttribute(onion, key, value string) {
|
func (this *GrandCentralDispatcher) setAttribute(onion, key, value string) {
|
||||||
the.Peer.SetContactAttribute(onion, key, value)
|
the.Peer.SetContactAttribute(onion, key, value)
|
||||||
this.UIState.UpdateContactAttribute(onion, key, value)
|
this.UIManager.UpdateContactAttribute(onion, key, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *GrandCentralDispatcher) blockUnknownPeers() {
|
func (this *GrandCentralDispatcher) blockUnknownPeers() {
|
|
@ -1,11 +1,9 @@
|
||||||
package gothings
|
package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cwtch.im/cwtch/model"
|
"cwtch.im/cwtch/model"
|
||||||
"cwtch.im/cwtch/protocol/connections"
|
"cwtch.im/cwtch/protocol/connections"
|
||||||
"cwtch.im/ui/go/constants"
|
"cwtch.im/ui/go/constants"
|
||||||
"cwtch.im/ui/go/cwutil"
|
|
||||||
"cwtch.im/ui/go/gobjects"
|
|
||||||
"cwtch.im/ui/go/the"
|
"cwtch.im/ui/go/the"
|
||||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
|
@ -20,6 +18,21 @@ func isPeer(id string) bool {
|
||||||
return len(id) == 56
|
return len(id) == 56
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getOrDefault(id, key, defaultVal string) string {
|
||||||
|
var val string
|
||||||
|
var ok bool
|
||||||
|
if isGroup(id) {
|
||||||
|
val, ok = the.Peer.GetGroupAttribute(id, key)
|
||||||
|
} else {
|
||||||
|
val, ok = the.Peer.GetContactAttribute(id, key)
|
||||||
|
}
|
||||||
|
if ok {
|
||||||
|
return val
|
||||||
|
} else {
|
||||||
|
return defaultVal
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func getWithSetDefault(id string, key, defaultVal string) string {
|
func getWithSetDefault(id string, key, defaultVal string) string {
|
||||||
var val string
|
var val string
|
||||||
var ok bool
|
var ok bool
|
||||||
|
@ -49,11 +62,27 @@ func initLastReadTime(id string) time.Time {
|
||||||
}
|
}
|
||||||
|
|
||||||
func initProfilePicture(id string) string {
|
func initProfilePicture(id string) string {
|
||||||
log.Infof("initProfilePic: %v\n", id)
|
|
||||||
if isGroup(id) {
|
if isGroup(id) {
|
||||||
return getWithSetDefault(id, constants.Picture, cwutil.RandomGroupImage(id))
|
return getWithSetDefault(id, constants.Picture, RandomGroupImage(id))
|
||||||
} else {
|
} else {
|
||||||
return getWithSetDefault(id, constants.Picture, cwutil.RandomProfileImage(id))
|
return getWithSetDefault(id, constants.Picture, RandomProfileImage(id))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// getProfilePic supplies a profile pic to use. In groups we may not have a contact so it will generate one
|
||||||
|
func getProfilePic(id string) string {
|
||||||
|
if isGroup(id) {
|
||||||
|
if pic, exists := the.Peer.GetGroupAttribute(id, constants.Picture); !exists {
|
||||||
|
return RandomGroupImage(id)
|
||||||
|
} else {
|
||||||
|
return pic
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if pic, exists := the.Peer.GetContactAttribute(id, constants.Picture); !exists {
|
||||||
|
return RandomProfileImage(id)
|
||||||
|
} else {
|
||||||
|
return pic
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,20 +107,19 @@ func countUnread(messages []model.Message, lastRead time.Time) int {
|
||||||
return count
|
return count
|
||||||
}
|
}
|
||||||
|
|
||||||
type InterfaceState struct {
|
type Manager struct {
|
||||||
parentGcd *GrandCentralDispatcher
|
gcd *GrandCentralDispatcher
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUIState(gcd *GrandCentralDispatcher) (uis InterfaceState) {
|
func NewManager(gcd *GrandCentralDispatcher) Manager {
|
||||||
uis = InterfaceState{gcd}
|
return Manager{gcd}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *InterfaceState) Acknowledge(mID string) {
|
func (this *Manager) Acknowledge(mID string) {
|
||||||
this.parentGcd.Acknowledged(mID)
|
this.gcd.Acknowledged(mID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *InterfaceState) AddContact(Handle string) {
|
func (this *Manager) AddContact(Handle string) {
|
||||||
if isGroup(Handle) {
|
if isGroup(Handle) {
|
||||||
group := the.Peer.GetGroup(Handle)
|
group := the.Peer.GetGroup(Handle)
|
||||||
if group != nil {
|
if group != nil {
|
||||||
|
@ -103,7 +131,7 @@ func (this *InterfaceState) AddContact(Handle string) {
|
||||||
nick = Handle
|
nick = Handle
|
||||||
}
|
}
|
||||||
|
|
||||||
this.parentGcd.AddContact(Handle, nick, picture, group.GroupServer, unread, int(connections.ConnectionStateToType[group.State]), false, false)
|
this.gcd.AddContact(Handle, nick, picture, group.GroupServer, unread, int(connections.ConnectionStateToType[group.State]), false, false)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
} else if !isPeer(Handle) {
|
} else if !isPeer(Handle) {
|
||||||
|
@ -122,41 +150,48 @@ func (this *InterfaceState) AddContact(Handle string) {
|
||||||
nick = Handle
|
nick = Handle
|
||||||
}
|
}
|
||||||
|
|
||||||
this.parentGcd.AddContact(Handle, nick, picture, "", unread, int(connections.ConnectionStateToType[contact.State]), contact.Blocked, false)
|
this.gcd.AddContact(Handle, nick, picture, "", unread, int(connections.ConnectionStateToType[contact.State]), contact.Blocked, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *InterfaceState) AddSendMessageError(peer string, signature string, err string) {
|
func (this *Manager) AddSendMessageError(peer string, signature string, err string) {
|
||||||
log.Debugf("Received Error Sending Message: %v", err)
|
log.Debugf("Received Error Sending Message: %v", err)
|
||||||
// FIXME: Sometimes, for the first Peer message we send our error beats our message to the UI
|
// FIXME: Sometimes, for the first Peer message we send our error beats our message to the UI
|
||||||
time.Sleep(time.Second * 1)
|
time.Sleep(time.Second * 1)
|
||||||
this.parentGcd.GroupSendError(signature, err)
|
this.gcd.GroupSendError(signature, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *InterfaceState) AddMessage(m *gobjects.Message) {
|
func (this *Manager) AddMessage(handle string, from string, message string, fromMe bool, messageID string, timestamp time.Time, Acknowledged bool) {
|
||||||
updateLastReadTime(m.Handle)
|
updateLastReadTime(handle)
|
||||||
|
|
||||||
|
nick := getOrDefault(handle, constants.Nick, handle)
|
||||||
|
image := getProfilePic(handle)
|
||||||
|
|
||||||
// If we have this group loaded already
|
// If we have this group loaded already
|
||||||
if this.parentGcd.CurrentOpenConversation() == m.Handle {
|
if this.gcd.CurrentOpenConversation() == handle {
|
||||||
// If the message is not from the user then add it, otherwise, just acknowledge.
|
// If the message is not from the user then add it, otherwise, just acknowledge.
|
||||||
if !m.FromMe || !m.Acknowledged {
|
if !fromMe {
|
||||||
this.parentGcd.AppendMessage(m.Handle, m.From, m.DisplayName, m.Message, m.Image, m.MessageID, m.FromMe, m.Timestamp.Format(constants.TIME_FORMAT), m.Acknowledged, m.Error)
|
this.gcd.AppendMessage(handle, from, nick, message, image, messageID, fromMe, timestamp.Format(constants.TIME_FORMAT), false, false)
|
||||||
} else {
|
} else {
|
||||||
this.parentGcd.Acknowledged(m.MessageID)
|
if !Acknowledged {
|
||||||
|
this.gcd.AppendMessage(handle, from, nick, message, image, messageID, fromMe, timestamp.Format(constants.TIME_FORMAT), false, false)
|
||||||
|
} else {
|
||||||
|
this.gcd.Acknowledged(messageID)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.parentGcd.IncContactUnreadCount(m.Handle)
|
this.gcd.IncContactUnreadCount(handle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *InterfaceState) UpdateContactDisplayName(handle string, name string) {
|
func (this *Manager) UpdateContactDisplayName(handle string, name string) {
|
||||||
this.parentGcd.UpdateContactDisplayName(handle, name)
|
this.gcd.UpdateContactDisplayName(handle, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *InterfaceState) UpdateContactStatus(handle string, status int, loading bool) {
|
func (this *Manager) UpdateContactStatus(handle string, status int, loading bool) {
|
||||||
this.parentGcd.UpdateContactStatus(handle, status, loading)
|
this.gcd.UpdateContactStatus(handle, status, loading)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *InterfaceState) UpdateContactAttribute(handle, key, value string) {
|
func (this *Manager) UpdateContactAttribute(handle, key, value string) {
|
||||||
this.parentGcd.UpdateContactAttribute(handle, key, value)
|
this.gcd.UpdateContactAttribute(handle, key, value)
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package cwutil
|
package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base32"
|
"encoding/base32"
|
16
main.go
16
main.go
|
@ -3,10 +3,10 @@ package main
|
||||||
import (
|
import (
|
||||||
libapp "cwtch.im/cwtch/app"
|
libapp "cwtch.im/cwtch/app"
|
||||||
"cwtch.im/cwtch/event/bridge"
|
"cwtch.im/cwtch/event/bridge"
|
||||||
"cwtch.im/ui/go/characters"
|
"cwtch.im/ui/go/handlers"
|
||||||
"cwtch.im/ui/go/gothings"
|
|
||||||
"cwtch.im/ui/go/gothings/android"
|
|
||||||
"cwtch.im/ui/go/the"
|
"cwtch.im/ui/go/the"
|
||||||
|
"cwtch.im/ui/go/ui"
|
||||||
|
"cwtch.im/ui/go/ui/android"
|
||||||
"flag"
|
"flag"
|
||||||
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
|
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
|
||||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||||
|
@ -32,7 +32,7 @@ var (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// make go-defined types available in qml
|
// make go-defined types available in qml
|
||||||
gothings.GrandCentralDispatcher_QmlRegisterType2("CustomQmlTypes", 1, 0, "GrandCentralDispatcher")
|
ui.GrandCentralDispatcher_QmlRegisterType2("CustomQmlTypes", 1, 0, "GrandCentralDispatcher")
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -128,7 +128,7 @@ func mainUi(flagLocal bool, flagClientUI bool) {
|
||||||
app := gui.NewQGuiApplication(len(os.Args), os.Args)
|
app := gui.NewQGuiApplication(len(os.Args), os.Args)
|
||||||
|
|
||||||
// our globals
|
// our globals
|
||||||
gcd := gothings.NewGrandCentralDispatcher(nil)
|
gcd := ui.NewGrandCentralDispatcher(nil)
|
||||||
gcd.SetOs(runtime.GOOS)
|
gcd.SetOs(runtime.GOOS)
|
||||||
if buildVer != "" {
|
if buildVer != "" {
|
||||||
gcd.SetVersion(buildVer)
|
gcd.SetVersion(buildVer)
|
||||||
|
@ -137,7 +137,7 @@ func mainUi(flagLocal bool, flagClientUI bool) {
|
||||||
gcd.SetVersion("development")
|
gcd.SetVersion("development")
|
||||||
gcd.SetBuildDate("now")
|
gcd.SetBuildDate("now")
|
||||||
}
|
}
|
||||||
gcd.UIState = gothings.NewUIState(gcd)
|
gcd.UIManager = ui.NewManager(gcd)
|
||||||
|
|
||||||
//TODO: put theme stuff somewhere better
|
//TODO: put theme stuff somewhere better
|
||||||
gcd.SetThemeScale(1.0)
|
gcd.SetThemeScale(1.0)
|
||||||
|
@ -232,7 +232,7 @@ func loadACN() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadNetworkingAndFiles(gcd *gothings.GrandCentralDispatcher, service bool, clientUI bool) {
|
func loadNetworkingAndFiles(gcd *ui.GrandCentralDispatcher, service bool, clientUI bool) {
|
||||||
if service || clientUI || runtime.GOOS == "android" {
|
if service || clientUI || runtime.GOOS == "android" {
|
||||||
clientIn := path.Join(the.CwtchDir, "clientIn")
|
clientIn := path.Join(the.CwtchDir, "clientIn")
|
||||||
serviceIn := path.Join(the.CwtchDir, "serviceIn")
|
serviceIn := path.Join(the.CwtchDir, "serviceIn")
|
||||||
|
@ -255,7 +255,7 @@ func loadNetworkingAndFiles(gcd *gothings.GrandCentralDispatcher, service bool,
|
||||||
if !service {
|
if !service {
|
||||||
the.AppBus = the.CwtchApp.GetPrimaryBus()
|
the.AppBus = the.CwtchApp.GetPrimaryBus()
|
||||||
subscribed := make(chan bool)
|
subscribed := make(chan bool)
|
||||||
go characters.AppEventListener(gcd, subscribed)
|
go handlers.App(gcd, subscribed)
|
||||||
<-subscribed
|
<-subscribed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in New Issue