From 8a8f1f98859123e162090538cbdbe7f5c9d34ea4 Mon Sep 17 00:00:00 2001 From: citrons Date: Sat, 7 Jun 2025 22:09:09 -0500 Subject: direct messages --- client/application.go | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'client/application.go') 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) { -- cgit v1.2.3