quality
This commit is contained in:
parent
87c7d7719b
commit
44655bb57b
|
@ -0,0 +1,24 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
echo "Checking code quality (you want to see no output here)"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "Vetting:"
|
||||||
|
go list ./... | xargs go vet
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "Linting:"
|
||||||
|
|
||||||
|
go list ./... | xargs golint
|
||||||
|
|
||||||
|
|
||||||
|
echo "Time to format"
|
||||||
|
gofmt -l -s -w .
|
||||||
|
|
||||||
|
# ineffassign (https://github.com/gordonklaus/ineffassign)
|
||||||
|
echo "Checking for ineffectual assignment of errors (unchecked errors...)"
|
||||||
|
ineffassign .
|
||||||
|
|
||||||
|
# misspell (https://github.com/client9/misspell/cmd/misspell)
|
||||||
|
echo "Checking for misspelled words..."
|
||||||
|
misspell . | grep -v "vendor/" | grep -v "go.sum" | grep -v ".idea"
|
|
@ -11,15 +11,14 @@ import (
|
||||||
)
|
)
|
||||||
import "cwtch.im/cwtch/event"
|
import "cwtch.im/cwtch/event"
|
||||||
|
|
||||||
|
|
||||||
type EventProfileEnvelope struct {
|
type EventProfileEnvelope struct {
|
||||||
event event.Event
|
event event.Event
|
||||||
profile string
|
profile string
|
||||||
}
|
}
|
||||||
|
|
||||||
type EventHandler struct {
|
type EventHandler struct {
|
||||||
app app.Application
|
app app.Application
|
||||||
appBusQueue event.Queue
|
appBusQueue event.Queue
|
||||||
profileEvents chan EventProfileEnvelope
|
profileEvents chan EventProfileEnvelope
|
||||||
|
|
||||||
profileQueues map[string]event.Queue
|
profileQueues map[string]event.Queue
|
||||||
|
@ -34,7 +33,7 @@ func NewEventHandler(application app.Application) *EventHandler {
|
||||||
application.GetPrimaryBus().Subscribe(event.ReloadDone, appBusQueue)
|
application.GetPrimaryBus().Subscribe(event.ReloadDone, appBusQueue)
|
||||||
application.GetPrimaryBus().Subscribe(event.ACNVersion, appBusQueue)
|
application.GetPrimaryBus().Subscribe(event.ACNVersion, appBusQueue)
|
||||||
|
|
||||||
return &EventHandler{ appBusQueue: appBusQueue, profileQueues: make(map[string]event.Queue), profileEvents: make(chan EventProfileEnvelope)}
|
return &EventHandler{appBusQueue: appBusQueue, profileQueues: make(map[string]event.Queue), profileEvents: make(chan EventProfileEnvelope)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (eh *EventHandler) GetNextEvent() string {
|
func (eh *EventHandler) GetNextEvent() string {
|
||||||
|
@ -104,15 +103,15 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
||||||
switch ev.event.EventType {
|
switch ev.event.EventType {
|
||||||
|
|
||||||
/*case event.NetworkStatus:
|
/*case event.NetworkStatus:
|
||||||
online, _ := peer.GetAttribute(attr.GetLocalScope(constants.PeerOnline))
|
online, _ := peer.GetAttribute(attr.GetLocalScope(constants.PeerOnline))
|
||||||
if e.Data[event.Status] == plugins.NetworkCheckSuccess && online == event.False {
|
if e.Data[event.Status] == plugins.NetworkCheckSuccess && online == event.False {
|
||||||
peer.SetAttribute(attr.GetLocalScope(constants.PeerOnline), event.True)
|
peer.SetAttribute(attr.GetLocalScope(constants.PeerOnline), event.True)
|
||||||
uiManager.UpdateNetworkStatus(true)
|
uiManager.UpdateNetworkStatus(true)
|
||||||
// TODO we may have to reinitialize the peer
|
// TODO we may have to reinitialize the peer
|
||||||
} else if e.Data[event.Status] == plugins.NetworkCheckError && online == event.True {
|
} else if e.Data[event.Status] == plugins.NetworkCheckError && online == event.True {
|
||||||
peer.SetAttribute(attr.GetLocalScope(constants.PeerOnline), event.False)
|
peer.SetAttribute(attr.GetLocalScope(constants.PeerOnline), event.False)
|
||||||
uiManager.UpdateNetworkStatus(false)
|
uiManager.UpdateNetworkStatus(false)
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
case event.NewMessageFromPeer: //event.TimestampReceived, event.RemotePeer, event.Data
|
case event.NewMessageFromPeer: //event.TimestampReceived, event.RemotePeer, event.Data
|
||||||
// I Don't think we need to enrich
|
// I Don't think we need to enrich
|
||||||
|
@ -134,17 +133,17 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
||||||
// No enrichement required
|
// No enrichement required
|
||||||
//Acknowledge(ev.event.Data[event.RemotePeer], ev.event.Data[event.EventID])
|
//Acknowledge(ev.event.Data[event.RemotePeer], ev.event.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
|
||||||
ts, _ := time.Parse(time.RFC3339Nano, e.Data[event.TimestampSent])
|
ts, _ := time.Parse(time.RFC3339Nano, e.Data[event.TimestampSent])
|
||||||
uiManager.AddMessage(e.Data[event.GroupID], e.Data[event.RemotePeer], e.Data[event.Data], e.Data[event.RemotePeer] == peer.GetOnion(), hex.EncodeToString([]byte(e.Data[event.Signature])), ts, true)
|
uiManager.AddMessage(e.Data[event.GroupID], e.Data[event.RemotePeer], e.Data[event.Data], e.Data[event.RemotePeer] == peer.GetOnion(), hex.EncodeToString([]byte(e.Data[event.Signature])), ts, true)
|
||||||
|
|
||||||
case event.NewGroupInvite:
|
case event.NewGroupInvite:
|
||||||
gid, err := peer.ProcessInvite(e.Data[event.GroupInvite], e.Data[event.RemotePeer])
|
gid, err := peer.ProcessInvite(e.Data[event.GroupInvite], e.Data[event.RemotePeer])
|
||||||
group := peer.GetGroup(gid)
|
group := peer.GetGroup(gid)
|
||||||
if err == nil && group != nil {
|
if err == nil && group != nil {
|
||||||
uiManager.AddContact(gid)
|
uiManager.AddContact(gid)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
case event.PeerCreated:
|
case event.PeerCreated:
|
||||||
handle := ev.event.Data[event.RemotePeer]
|
handle := ev.event.Data[event.RemotePeer]
|
||||||
err := EnrichNewPeer(handle, ph, ev)
|
err := EnrichNewPeer(handle, ph, ev)
|
||||||
|
@ -152,10 +151,10 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
||||||
return err.Error()
|
return err.Error()
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
case event.SendMessageToGroupError:
|
case event.SendMessageToGroupError:
|
||||||
uiManager.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:
|
||||||
uiManager.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[ev.event.Data[event.ConnectionState]]
|
cxnState := connections.ConnectionStateToType[ev.event.Data[event.ConnectionState]]
|
||||||
|
@ -182,45 +181,45 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*case event.NewRetValMessageFromPeer:
|
/*case event.NewRetValMessageFromPeer:
|
||||||
onion := e.Data[event.RemotePeer]
|
onion := e.Data[event.RemotePeer]
|
||||||
scope := e.Data[event.Scope]
|
scope := e.Data[event.Scope]
|
||||||
path := e.Data[event.Path]
|
path := e.Data[event.Path]
|
||||||
val := e.Data[event.Data]
|
val := e.Data[event.Data]
|
||||||
exists, _ := strconv.ParseBool(e.Data[event.Exists])
|
exists, _ := strconv.ParseBool(e.Data[event.Exists])
|
||||||
|
|
||||||
if exists && scope == attr.PublicScope {
|
if exists && scope == attr.PublicScope {
|
||||||
switch path {
|
switch path {
|
||||||
case constants.Name:
|
case constants.Name:
|
||||||
peer.SetContactAttribute(onion, attr.GetPeerScope(constants.Name), val)
|
peer.SetContactAttribute(onion, attr.GetPeerScope(constants.Name), val)
|
||||||
uiManager.UpdateContactDisplayName(onion)
|
uiManager.UpdateContactDisplayName(onion)
|
||||||
case constants.Picture:
|
case constants.Picture:
|
||||||
peer.SetContactAttribute(onion, attr.GetPeerScope(constants.Picture), val)
|
peer.SetContactAttribute(onion, attr.GetPeerScope(constants.Picture), val)
|
||||||
uiManager.UpdateContactPicture(onion)
|
uiManager.UpdateContactPicture(onion)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
case event.ServerStateChange:
|
|
||||||
serverOnion := e.Data[event.GroupServer]
|
|
||||||
state := connections.ConnectionStateToType[e.Data[event.ConnectionState]]
|
|
||||||
groups := peer.GetGroups()
|
|
||||||
for _, groupID := range groups {
|
|
||||||
group := peer.GetGroup(groupID)
|
|
||||||
if group != nil && group.GroupServer == serverOnion {
|
|
||||||
group.State = e.Data[event.ConnectionState]
|
|
||||||
loading := false
|
|
||||||
if state == connections.AUTHENTICATED {
|
|
||||||
loading = true
|
|
||||||
}
|
}
|
||||||
uiManager.UpdateContactStatus(groupID, int(state), loading)
|
|
||||||
uiManager.UpdateContactStatus(serverOnion, int(state), loading)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
case event.DeletePeer:
|
case event.ServerStateChange:
|
||||||
log.Infof("PeerHandler got DeletePeer, SHUTTING down!\n")
|
serverOnion := e.Data[event.GroupServer]
|
||||||
uiManager.ReloadProfiles()
|
state := connections.ConnectionStateToType[e.Data[event.ConnectionState]]
|
||||||
return
|
groups := peer.GetGroups()
|
||||||
*/
|
for _, groupID := range groups {
|
||||||
|
group := peer.GetGroup(groupID)
|
||||||
|
if group != nil && group.GroupServer == serverOnion {
|
||||||
|
group.State = e.Data[event.ConnectionState]
|
||||||
|
loading := false
|
||||||
|
if state == connections.AUTHENTICATED {
|
||||||
|
loading = true
|
||||||
|
}
|
||||||
|
uiManager.UpdateContactStatus(groupID, int(state), loading)
|
||||||
|
uiManager.UpdateContactStatus(serverOnion, int(state), loading)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case event.DeletePeer:
|
||||||
|
log.Infof("PeerHandler got DeletePeer, SHUTTING down!\n")
|
||||||
|
uiManager.ReloadProfiles()
|
||||||
|
return
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
json, _ := json.Marshal(ev)
|
json, _ := json.Marshal(ev)
|
||||||
|
@ -251,7 +250,7 @@ func (eh *EventHandler) startHandlingPeer(onion string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (eh *EventHandler) forwardProfileMessages(onion string, q event.Queue) {
|
func (eh *EventHandler) forwardProfileMessages(onion string, q event.Queue) {
|
||||||
for {
|
for {
|
||||||
e := q.Next()
|
e := q.Next()
|
||||||
ev := EventProfileEnvelope{event: *e, profile: onion}
|
ev := EventProfileEnvelope{event: *e, profile: onion}
|
||||||
eh.profileEvents <- ev
|
eh.profileEvents <- ev
|
||||||
|
|
|
@ -153,7 +153,6 @@ func GetPicturePath(pic *image) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (p *PeerHelper) CountUnread(messages []model.Message, lastRead time.Time) int {
|
func (p *PeerHelper) CountUnread(messages []model.Message, lastRead time.Time) int {
|
||||||
count := 0
|
count := 0
|
||||||
for i := len(messages) - 1; i >= 0; i-- {
|
for i := len(messages) - 1; i >= 0; i-- {
|
||||||
|
|
Loading…
Reference in New Issue