This commit is contained in:
Sarah Jamie Lewis 2018-05-02 23:01:15 -07:00
parent c2d349a817
commit 979ad542f7
4 changed files with 25 additions and 32 deletions

View File

@ -1,15 +1,13 @@
package main
import (
"fmt"
app2 "git.mascherari.press/cwtch/app"
"strings"
"github.com/c-bata/go-prompt"
"strings"
)
var app app2.Application
var suggestions = []prompt.Suggest{
@ -29,21 +27,21 @@ var suggestions = []prompt.Suggest{
{Text: "help", Description: "print list of commands"},
}
var usages = map[string]string {
"new-profile": "newprofile [name] [filename]",
"load-profile": "loadprofile [filename]",
"quit": "",
"servers": "",
"peers": "",
"contacts": "",
"groups": "",
"send": "send [groupid] [message]",
"timeline": "timeline [groupid]",
"accept-invite": "accept-invite [groupid]",
"invite": "invite [onion]",
var usages = map[string]string{
"new-profile": "newprofile [name] [filename]",
"load-profile": "loadprofile [filename]",
"quit": "",
"servers": "",
"peers": "",
"contacts": "",
"groups": "",
"send": "send [groupid] [message]",
"timeline": "timeline [groupid]",
"accept-invite": "accept-invite [groupid]",
"invite": "invite [onion]",
"invite-to-group": "invite-to-group [onion] [groupid]",
"new-group": "new-group [server]",
"help": "",
"new-group": "new-group [server]",
"help": "",
}
func completer(d prompt.Document) []prompt.Suggest {
@ -99,11 +97,10 @@ func completer(d prompt.Document) []prompt.Suggest {
return s
}
func main() {
cwtch :=
`
`
#, #'
@@@@@@:
@@@@@@.
@ -151,14 +148,12 @@ func main() {
}
prmpt := fmt.Sprintf("cwtch [%v]> ", profile)
text := prompt.Input(prmpt, completer, prompt.OptionSuggestionBGColor(prompt.Purple),
prompt.OptionDescriptionBGColor(prompt.White),
prompt.OptionHistory(history))
prompt.OptionDescriptionBGColor(prompt.White),
prompt.OptionHistory(history))
commands := strings.Split(text[0:len(text)], " ")
history = append(history,text)
commands := strings.Split(text[0:], " ")
history = append(history, text)
switch commands[0] {
case "quit":
app.Peer.Save(profilefile)
@ -220,7 +215,7 @@ func main() {
}
case "accept-invite":
if len(commands) == 2 {
groupID:= commands[1]
groupID := commands[1]
err := app.Peer.AcceptInvite(groupID)
if err == nil {
fmt.Printf("Error: %v\n", err)

View File

@ -59,7 +59,7 @@ func (t Timeline) Less(i, j int) bool {
func (t *Timeline) Insert(mi *Message) {
t.lock.Lock()
for _,m := range t.Messages {
for _, m := range t.Messages {
if compareSignatures(m.Signature, mi.Signature) {
t.lock.Unlock()
return

View File

@ -23,8 +23,7 @@ func NewConnectionsManager() *Manager {
func (m *Manager) ManagePeerConnection(host string, profile *model.Profile) {
m.lock.Lock()
_,exists := m.peerConnections[host]
_, exists := m.peerConnections[host]
if !exists {
ppc := NewPeerPeerConnection(host, profile)
go ppc.Run()
@ -37,7 +36,7 @@ func (m *Manager) ManagePeerConnection(host string, profile *model.Profile) {
func (m *Manager) ManageServerConnection(host string, handler func(string, *protocol.GroupMessage)) {
m.lock.Lock()
_,exists := m.serverConnections[host]
_, exists := m.serverConnections[host]
if !exists {
psc := NewPeerServerConnection(host)
go psc.Run()
@ -57,7 +56,6 @@ func (m *Manager) GetPeers() map[string]ConnectionState {
return rm
}
func (m *Manager) GetServers() map[string]ConnectionState {
rm := make(map[string]ConnectionState)
m.lock.Lock()

View File

@ -46,7 +46,7 @@ func (cp *CwtchPeer) setup() {
cp.PeerWithOnion(onion)
}
for _,group := range cp.Profile.Groups {
for _, group := range cp.Profile.Groups {
if group.Accepted || group.Owner == "self" {
cp.JoinServer(group.GroupServer)
}