forked from cwtch.im/cwtch
fmt
This commit is contained in:
parent
c2d349a817
commit
979ad542f7
|
@ -1,15 +1,13 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
||||||
"fmt"
|
"fmt"
|
||||||
app2 "git.mascherari.press/cwtch/app"
|
app2 "git.mascherari.press/cwtch/app"
|
||||||
|
|
||||||
"strings"
|
|
||||||
"github.com/c-bata/go-prompt"
|
"github.com/c-bata/go-prompt"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
var app app2.Application
|
var app app2.Application
|
||||||
|
|
||||||
var suggestions = []prompt.Suggest{
|
var suggestions = []prompt.Suggest{
|
||||||
|
@ -29,21 +27,21 @@ var suggestions = []prompt.Suggest{
|
||||||
{Text: "help", Description: "print list of commands"},
|
{Text: "help", Description: "print list of commands"},
|
||||||
}
|
}
|
||||||
|
|
||||||
var usages = map[string]string {
|
var usages = map[string]string{
|
||||||
"new-profile": "newprofile [name] [filename]",
|
"new-profile": "newprofile [name] [filename]",
|
||||||
"load-profile": "loadprofile [filename]",
|
"load-profile": "loadprofile [filename]",
|
||||||
"quit": "",
|
"quit": "",
|
||||||
"servers": "",
|
"servers": "",
|
||||||
"peers": "",
|
"peers": "",
|
||||||
"contacts": "",
|
"contacts": "",
|
||||||
"groups": "",
|
"groups": "",
|
||||||
"send": "send [groupid] [message]",
|
"send": "send [groupid] [message]",
|
||||||
"timeline": "timeline [groupid]",
|
"timeline": "timeline [groupid]",
|
||||||
"accept-invite": "accept-invite [groupid]",
|
"accept-invite": "accept-invite [groupid]",
|
||||||
"invite": "invite [onion]",
|
"invite": "invite [onion]",
|
||||||
"invite-to-group": "invite-to-group [onion] [groupid]",
|
"invite-to-group": "invite-to-group [onion] [groupid]",
|
||||||
"new-group": "new-group [server]",
|
"new-group": "new-group [server]",
|
||||||
"help": "",
|
"help": "",
|
||||||
}
|
}
|
||||||
|
|
||||||
func completer(d prompt.Document) []prompt.Suggest {
|
func completer(d prompt.Document) []prompt.Suggest {
|
||||||
|
@ -99,11 +97,10 @@ func completer(d prompt.Document) []prompt.Suggest {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
cwtch :=
|
cwtch :=
|
||||||
`
|
`
|
||||||
#, #'
|
#, #'
|
||||||
@@@@@@:
|
@@@@@@:
|
||||||
@@@@@@.
|
@@@@@@.
|
||||||
|
@ -151,14 +148,12 @@ func main() {
|
||||||
}
|
}
|
||||||
prmpt := fmt.Sprintf("cwtch [%v]> ", profile)
|
prmpt := fmt.Sprintf("cwtch [%v]> ", profile)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
text := prompt.Input(prmpt, completer, prompt.OptionSuggestionBGColor(prompt.Purple),
|
text := prompt.Input(prmpt, completer, prompt.OptionSuggestionBGColor(prompt.Purple),
|
||||||
prompt.OptionDescriptionBGColor(prompt.White),
|
prompt.OptionDescriptionBGColor(prompt.White),
|
||||||
prompt.OptionHistory(history))
|
prompt.OptionHistory(history))
|
||||||
|
|
||||||
commands := strings.Split(text[0:len(text)], " ")
|
commands := strings.Split(text[0:], " ")
|
||||||
history = append(history,text)
|
history = append(history, text)
|
||||||
switch commands[0] {
|
switch commands[0] {
|
||||||
case "quit":
|
case "quit":
|
||||||
app.Peer.Save(profilefile)
|
app.Peer.Save(profilefile)
|
||||||
|
@ -220,7 +215,7 @@ func main() {
|
||||||
}
|
}
|
||||||
case "accept-invite":
|
case "accept-invite":
|
||||||
if len(commands) == 2 {
|
if len(commands) == 2 {
|
||||||
groupID:= commands[1]
|
groupID := commands[1]
|
||||||
err := app.Peer.AcceptInvite(groupID)
|
err := app.Peer.AcceptInvite(groupID)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
fmt.Printf("Error: %v\n", err)
|
fmt.Printf("Error: %v\n", err)
|
||||||
|
|
|
@ -59,7 +59,7 @@ func (t Timeline) Less(i, j int) bool {
|
||||||
func (t *Timeline) Insert(mi *Message) {
|
func (t *Timeline) Insert(mi *Message) {
|
||||||
t.lock.Lock()
|
t.lock.Lock()
|
||||||
|
|
||||||
for _,m := range t.Messages {
|
for _, m := range t.Messages {
|
||||||
if compareSignatures(m.Signature, mi.Signature) {
|
if compareSignatures(m.Signature, mi.Signature) {
|
||||||
t.lock.Unlock()
|
t.lock.Unlock()
|
||||||
return
|
return
|
||||||
|
|
|
@ -23,8 +23,7 @@ func NewConnectionsManager() *Manager {
|
||||||
func (m *Manager) ManagePeerConnection(host string, profile *model.Profile) {
|
func (m *Manager) ManagePeerConnection(host string, profile *model.Profile) {
|
||||||
m.lock.Lock()
|
m.lock.Lock()
|
||||||
|
|
||||||
|
_, exists := m.peerConnections[host]
|
||||||
_,exists := m.peerConnections[host]
|
|
||||||
if !exists {
|
if !exists {
|
||||||
ppc := NewPeerPeerConnection(host, profile)
|
ppc := NewPeerPeerConnection(host, profile)
|
||||||
go ppc.Run()
|
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)) {
|
func (m *Manager) ManageServerConnection(host string, handler func(string, *protocol.GroupMessage)) {
|
||||||
m.lock.Lock()
|
m.lock.Lock()
|
||||||
|
|
||||||
_,exists := m.serverConnections[host]
|
_, exists := m.serverConnections[host]
|
||||||
if !exists {
|
if !exists {
|
||||||
psc := NewPeerServerConnection(host)
|
psc := NewPeerServerConnection(host)
|
||||||
go psc.Run()
|
go psc.Run()
|
||||||
|
@ -57,7 +56,6 @@ func (m *Manager) GetPeers() map[string]ConnectionState {
|
||||||
return rm
|
return rm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (m *Manager) GetServers() map[string]ConnectionState {
|
func (m *Manager) GetServers() map[string]ConnectionState {
|
||||||
rm := make(map[string]ConnectionState)
|
rm := make(map[string]ConnectionState)
|
||||||
m.lock.Lock()
|
m.lock.Lock()
|
||||||
|
|
|
@ -46,7 +46,7 @@ func (cp *CwtchPeer) setup() {
|
||||||
cp.PeerWithOnion(onion)
|
cp.PeerWithOnion(onion)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _,group := range cp.Profile.Groups {
|
for _, group := range cp.Profile.Groups {
|
||||||
if group.Accepted || group.Owner == "self" {
|
if group.Accepted || group.Owner == "self" {
|
||||||
cp.JoinServer(group.GroupServer)
|
cp.JoinServer(group.GroupServer)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue