remove frontend message storage #228
2
go.mod
2
go.mod
|
@ -3,7 +3,7 @@ module cwtch.im/ui
|
|||
go 1.12
|
||||
|
||||
require (
|
||||
cwtch.im/cwtch v0.3.1
|
||||
cwtch.im/cwtch v0.3.2
|
||||
git.openprivacy.ca/openprivacy/libricochet-go v1.0.6
|
||||
github.com/gopherjs/gopherjs v0.0.0-20190812055157-5d271430af9f // indirect
|
||||
github.com/kr/pretty v0.1.0 // indirect
|
||||
|
|
4
go.sum
4
go.sum
|
@ -2,8 +2,12 @@ cwtch.im/cwtch v0.3.0 h1:RFZyc2m9BowFNdngBs7GcQE41w75jMp3Ku5zEE92v9I=
|
|||
cwtch.im/cwtch v0.3.0/go.mod h1:8tmtp3c7fccWw9H7s9u6E8GD2PKI3ar21i0fjN8pzd0=
|
||||
cwtch.im/cwtch v0.3.1 h1:C0DLIrOqpNs5aecKTjNJZhpMq4/EvWNmLiKklIS8RTM=
|
||||
cwtch.im/cwtch v0.3.1/go.mod h1:8tmtp3c7fccWw9H7s9u6E8GD2PKI3ar21i0fjN8pzd0=
|
||||
cwtch.im/cwtch v0.3.2 h1:JxoauToMckHjmQz3QCmI7XG9pun1tF3pV/o5ziuqV1A=
|
||||
cwtch.im/cwtch v0.3.2/go.mod h1:4b2qGW5bZKm4CwYxqc0+4pgpDU0LjjyoihC8a/ezOoQ=
|
||||
cwtch.im/tapir v0.1.10 h1:V+TkmwXNd6gySZqlVw468wMYEkmDwMSyvhkkpOfUw7w=
|
||||
cwtch.im/tapir v0.1.10/go.mod h1:EuRYdVrwijeaGBQ4OijDDRHf7R2MDSypqHkSl5DxI34=
|
||||
cwtch.im/tapir v0.1.11 h1:JLm1MIYq4VXKzhj68+P8OuVPllAU9U6G0DtUor2fbc4=
|
||||
cwtch.im/tapir v0.1.11/go.mod h1:EuRYdVrwijeaGBQ4OijDDRHf7R2MDSypqHkSl5DxI34=
|
||||
git.openprivacy.ca/openprivacy/libricochet-go v1.0.4/go.mod h1:yMSG1gBaP4f1U+RMZXN85d29D39OK5s8aTpyVRoH5FY=
|
||||
git.openprivacy.ca/openprivacy/libricochet-go v1.0.6 h1:5o4K2qn3otEE1InC5v5CzU0yL7Wl7DhVp4s8H3K6mXY=
|
||||
git.openprivacy.ca/openprivacy/libricochet-go v1.0.6/go.mod h1:yMSG1gBaP4f1U+RMZXN85d29D39OK5s8aTpyVRoH5FY=
|
||||
|
|
|
@ -41,16 +41,8 @@ func IncomingListener(uiState *gothings.InterfaceState, subscribed chan bool) {
|
|||
}
|
||||
|
||||
case event.PeerAcknowledgement:
|
||||
ackI, ok := the.AcknowledgementIDs.Load(e.Data[event.EventID])
|
||||
if ok {
|
||||
ack := ackI.(*the.AckId)
|
||||
if ack.Peer == e.Data[event.RemotePeer] {
|
||||
ack.Ack = true
|
||||
uiState.Acknowledge(e.Data[event.EventID])
|
||||
continue
|
||||
}
|
||||
}
|
||||
log.Debugf("Received Ack ID for unknown message or peer: %v", e)
|
||||
uiState.Acknowledge(e.Data[event.EventID])
|
||||
|
||||
case event.NewMessageFromGroup: //event.TimestampReceived, event.TimestampSent, event.Data, event.GroupID, event.RemotePeer
|
||||
var name string
|
||||
var exists bool
|
||||
|
@ -92,7 +84,7 @@ func IncomingListener(uiState *gothings.InterfaceState, subscribed chan bool) {
|
|||
case event.SendMessageToGroupError:
|
||||
uiState.AddSendMessageError(e.Data[event.GroupServer], e.Data[event.Signature], e.Data[event.Error])
|
||||
case event.SendMessageToPeerError:
|
||||
uiState.AddSendMessageError(e.Data[event.RemotePeer], e.Data[event.Signature], e.Data[event.Error])
|
||||
uiState.AddSendMessageError(e.Data[event.RemotePeer], e.Data[event.EventID], e.Data[event.Error])
|
||||
case event.PeerStateChange:
|
||||
cxnState := connections.ConnectionStateToType[e.Data[event.ConnectionState]]
|
||||
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
package constants
|
||||
|
||||
const Nick = "nick"
|
||||
const LastRead = "last-read"
|
|
@ -5,7 +5,7 @@ type Contact struct {
|
|||
DisplayName string
|
||||
Image string
|
||||
Server string
|
||||
Badge int
|
||||
Badge int // # of unread
|
||||
Status int
|
||||
Trusted bool
|
||||
Blocked bool
|
||||
|
|
|
@ -148,12 +148,6 @@ func (this *GrandCentralDispatcher) sendMessage(message string, mID string) {
|
|||
false,
|
||||
false,
|
||||
})
|
||||
|
||||
ackID := new(the.AckId)
|
||||
ackID.ID = mID
|
||||
ackID.Ack = false
|
||||
ackID.Peer = to
|
||||
the.AcknowledgementIDs.Store(mID, ackID)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -232,42 +226,48 @@ func (this *GrandCentralDispatcher) loadMessagesPaneHelper(handle string) {
|
|||
} // ELSE LOAD CONTACT
|
||||
|
||||
contact, _ := the.Peer.GetProfile().GetContact(handle)
|
||||
var nick string
|
||||
if contact != nil {
|
||||
nick, _ := contact.GetAttribute("nick")
|
||||
nick, _ = contact.GetAttribute("nick")
|
||||
if nick == "" {
|
||||
this.SetToolbarTitle(handle)
|
||||
} else {
|
||||
this.SetToolbarTitle(nick)
|
||||
nick = handle
|
||||
}
|
||||
}
|
||||
this.SetToolbarTitle(nick)
|
||||
|
||||
messages := this.UIState.GetMessages(handle)
|
||||
peer := the.Peer.GetContact(handle)
|
||||
messages := peer.Timeline.GetMessages()
|
||||
for i := range messages {
|
||||
from := messages[i].From
|
||||
if messages[i].FromMe {
|
||||
from := messages[i].PeerID
|
||||
fromMe := messages[i].PeerID == the.Peer.GetProfile().Onion
|
||||
if fromMe {
|
||||
from = "me"
|
||||
}
|
||||
|
||||
ackI, ok := the.AcknowledgementIDs.Load(messages[i].MessageID)
|
||||
acked := false
|
||||
if ok {
|
||||
ack := ackI.(*the.AckId)
|
||||
acked = ack.Ack
|
||||
var displayname string
|
||||
ctc := the.Peer.GetContact(messages[i].PeerID)
|
||||
if ctc != nil {
|
||||
var exists bool
|
||||
displayname, exists = ctc.GetAttribute("nick")
|
||||
if !exists || displayname == "" {
|
||||
displayname = messages[i].PeerID
|
||||
}
|
||||
} else {
|
||||
displayname = messages[i].PeerID
|
||||
}
|
||||
|
||||
this.AppendMessage(
|
||||
messages[i].Handle,
|
||||
from,
|
||||
messages[i].DisplayName,
|
||||
messages[i].PeerID,
|
||||
displayname,
|
||||
messages[i].Message,
|
||||
cwutil.RandomProfileImage(handle),
|
||||
messages[i].MessageID,
|
||||
messages[i].FromMe,
|
||||
string(messages[i].Signature),
|
||||
fromMe,
|
||||
messages[i].Timestamp.Format(constants.TIME_FORMAT),
|
||||
acked,
|
||||
messages[i].Error,
|
||||
messages[i].Acknowledged,
|
||||
messages[i].Error != "",
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,11 +14,10 @@ import (
|
|||
type InterfaceState struct {
|
||||
parentGcd *GrandCentralDispatcher
|
||||
contacts sync.Map // string : *gobjects.Contact
|
||||
messages sync.Map
|
||||
}
|
||||
|
||||
func NewUIState(gcd *GrandCentralDispatcher) (uis InterfaceState) {
|
||||
uis = InterfaceState{gcd, sync.Map{}, sync.Map{}}
|
||||
uis = InterfaceState{gcd, sync.Map{}}
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -109,20 +108,6 @@ func (this *InterfaceState) GetContact(handle string) *gobjects.Contact {
|
|||
}
|
||||
|
||||
func (this *InterfaceState) AddSendMessageError(peer string, signature string, err string) {
|
||||
ackI, ok := the.AcknowledgementIDs.Load(signature)
|
||||
if ok {
|
||||
ack := ackI.(*the.AckId)
|
||||
ack.Error = true
|
||||
}
|
||||
|
||||
messages, _ := this.messages.Load(peer)
|
||||
messageList, _ := messages.([]*gobjects.Message)
|
||||
|
||||
for _, message := range messageList {
|
||||
if message.MessageID == signature {
|
||||
message.Error = true
|
||||
}
|
||||
}
|
||||
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
|
||||
time.Sleep(time.Second * 1)
|
||||
|
@ -132,18 +117,6 @@ func (this *InterfaceState) AddSendMessageError(peer string, signature string, e
|
|||
func (this *InterfaceState) AddMessage(m *gobjects.Message) {
|
||||
this.GetContact(m.From)
|
||||
|
||||
_, found := this.messages.Load(m.Handle)
|
||||
if !found {
|
||||
this.messages.Store(m.Handle, make([]*gobjects.Message, 0))
|
||||
}
|
||||
|
||||
// Ack message sent to group
|
||||
this.parentGcd.Acknowledged(m.MessageID)
|
||||
|
||||
messages, _ := this.messages.Load(m.Handle)
|
||||
messageList, _ := messages.([]*gobjects.Message)
|
||||
this.messages.Store(m.Handle, append(messageList, m))
|
||||
|
||||
// If we have this group loaded already
|
||||
if this.parentGcd.CurrentOpenConversation() == m.Handle {
|
||||
// If the message is not from the user then add it, otherwise, just acknowledge.
|
||||
|
@ -159,34 +132,18 @@ func (this *InterfaceState) AddMessage(m *gobjects.Message) {
|
|||
this.UpdateContact(c.Handle)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (this *InterfaceState) GetMessages(handle string) []*gobjects.Message {
|
||||
_, found := this.messages.Load(handle)
|
||||
if !found {
|
||||
this.messages.Store(handle, make([]*gobjects.Message, 0))
|
||||
}
|
||||
messages, found := this.messages.Load(handle)
|
||||
messageList, _ := messages.([]*gobjects.Message)
|
||||
return messageList
|
||||
}
|
||||
|
||||
func (this *InterfaceState) UpdateContact(handle string) {
|
||||
contact := the.Peer.GetContact(handle)
|
||||
if contact != nil {
|
||||
cif, found := this.contacts.Load(handle)
|
||||
if found {
|
||||
c := cif.(*gobjects.Contact)
|
||||
cif, found := this.contacts.Load(handle)
|
||||
if found {
|
||||
c := cif.(*gobjects.Contact)
|
||||
if contact != nil {
|
||||
c.Blocked = contact.Blocked
|
||||
this.parentGcd.UpdateContact(c.Handle, c.DisplayName, c.Image, c.Server, c.Badge, c.Status, c.Trusted, c.Blocked, c.Loading)
|
||||
}
|
||||
} else {
|
||||
cif, found := this.contacts.Load(handle)
|
||||
if found {
|
||||
c := cif.(*gobjects.Contact)
|
||||
this.parentGcd.UpdateContact(c.Handle, c.DisplayName, c.Image, c.Server, c.Badge, c.Status, c.Trusted, c.Blocked, c.Loading)
|
||||
}
|
||||
this.parentGcd.UpdateContact(c.Handle, c.DisplayName, c.Image, c.Server, c.Badge, c.Status, c.Trusted, c.Blocked, c.Loading)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"cwtch.im/cwtch/event"
|
||||
libPeer "cwtch.im/cwtch/peer"
|
||||
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Terrible, to be replaced when proper profile/password management comes in ~ 0.2
|
||||
|
@ -19,12 +18,3 @@ var ACN connectivity.ACN
|
|||
var Peer libPeer.CwtchPeer
|
||||
var CwtchDir string
|
||||
var IPCBridge event.IPCBridge
|
||||
|
||||
type AckId struct {
|
||||
ID string
|
||||
Peer string
|
||||
Ack bool
|
||||
Error bool
|
||||
}
|
||||
|
||||
var AcknowledgementIDs sync.Map
|
||||
|
|
|
@ -131,8 +131,6 @@ ApplicationWindow {
|
|||
running: true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
RowLayout { // CONTAINS EVERYTHING EXCEPT THE TOOLBAR
|
||||
/* anchors.left: ratio >= 0.92 ? parent.left : toolbar.right
|
||||
anchors.top: ratio >= 0.92 ? toolbar.bottom : parent.top
|
||||
|
|
Reference in New Issue