diff options
| author | citrons <citrons@mondecitronne.com> | 2025-06-07 22:09:09 -0500 |
|---|---|---|
| committer | citrons <citrons@mondecitronne.com> | 2025-06-07 22:09:09 -0500 |
| commit | 8a8f1f98859123e162090538cbdbe7f5c9d34ea4 (patch) | |
| tree | 548d9ef52bfa1579c17ce1ee600ba3356fa1ffbe /client | |
| parent | f38d6eb807e2b921123dd5efd0b2d632a632e579 (diff) | |
direct messages
Diffstat (limited to 'client')
| -rw-r--r-- | client/application.go | 40 | ||||
| -rw-r--r-- | client/command.go | 16 |
2 files changed, 51 insertions, 5 deletions
diff --git a/client/application.go b/client/application.go index f77e0e1..e45ed5a 100644 --- a/client/application.go +++ b/client/application.go @@ -185,12 +185,21 @@ func (a *application) sendUpdate(o proto.Object, cb func(proto.Command)) { func (a *application) lookup( name string, kind string, callback func(*proto.Object, *proto.Fail)) { + a.lookupAll([]string {name}, kind, func(os []proto.Object, f *proto.Fail) { + if f == nil { + callback(&os[0], f) + } else { + callback(nil, f) + } + }) +} + +func (a *application) lookupAll(names []string, + kind string, callback func([]proto.Object, *proto.Fail)) { cb := func(response proto.Command) { switch response.Kind { case "i": - if len(response.Args) > 0 { - callback(&response.Args[0], nil) - } + callback(response.Args, nil) case "fail": if len(response.Args) > 0 { f := proto.Fail(response.Args[0]) @@ -198,8 +207,11 @@ func (a *application) lookup( } } } - o := proto.Object {kind, "", map[string]string {"": name}} - a.Request(proto.NewCmd("lookup", "", o), cb) + var os []proto.Object + for _, name := range names { + os = append(os, proto.Object {kind, "", map[string]string {"": name}}) + } + a.Request(proto.NewCmd("lookup", "", os...), cb) } func (a *application) join(channelName string) { @@ -227,6 +239,24 @@ func (a *application) join(channelName string) { }) } +func (a *application) joinDirect(among []proto.Object) { + cb := func(response proto.Command) { + switch response.Kind { + case "direct": + if len(response.Args) > 0 { + ch := response.Args[0] + a.goTo(channelLocation {id: ch.Id}) + } + case "fail": + if len(response.Args) > 0 { + f := proto.Fail(response.Args[0]) + a.cmdWindow.err(f.Error()) + } + } + } + a.Request(proto.Command{"direct", "", among}, cb) +} + func (a *application) createChannel(name string) { ch := proto.Object {"channel", "", map[string]string {"": name}} a.Request(proto.NewCmd("create", "", ch), func(response proto.Command) { diff --git a/client/command.go b/client/command.go index 2bc7868..6079070 100644 --- a/client/command.go +++ b/client/command.go @@ -117,6 +117,22 @@ func (a *application) doCommand(command string, args []string, text string) { a.cmdWindow.who(u.Id) } }) + case "msg": + a.lookup(text, "u", func(u *proto.Object, fail *proto.Fail) { + if fail != nil { + a.cmdWindow.fail(proto.Object(*fail)) + } else { + a.joinDirect([]proto.Object {*u}) + } + }) + case "msgall": + a.lookupAll(args, "u", func(us []proto.Object, fail *proto.Fail) { + if fail != nil { + a.cmdWindow.fail(proto.Object(*fail)) + } else { + a.joinDirect(us) + } + }) case "create": if a.authenticated { a.createChannel(text) |
