Skip to content

Commit 282ba97

Browse files
committed
Migrate app.State to newer app.StateKey API
Note: this breaks PR #190.
1 parent a36db6a commit 282ba97

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/diamondburned/chatkit v0.0.0-20231111052812-ca02e3a0ae01
99
github.com/diamondburned/gotk4-adwaita/pkg v0.0.0-20230307050941-20a05fa3a9df
1010
github.com/diamondburned/gotk4/pkg v0.0.6-0.20230825053034-ad325703aa2e
11-
github.com/diamondburned/gotkit v0.0.0-20231108044328-9ac96cd5a778
11+
github.com/diamondburned/gotkit v0.0.0-20231111065921-0542a145d61e
1212
github.com/diamondburned/ningen/v3 v3.0.1-0.20231109131259-9140d0873f98
1313
github.com/dustin/go-humanize v1.0.0
1414
github.com/enescakir/emoji v1.0.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ github.com/diamondburned/gotk4-adwaita/pkg v0.0.0-20230307050941-20a05fa3a9df h1
4141
github.com/diamondburned/gotk4-adwaita/pkg v0.0.0-20230307050941-20a05fa3a9df/go.mod h1:f+Kv3QPlRGEW0nv0oyEZ4qhCcOY9qhxKnmPmrzmBkLo=
4242
github.com/diamondburned/gotk4/pkg v0.0.6-0.20230825053034-ad325703aa2e h1:fH47UZxCz7xvmJHQ1w+nizBZpDNHdYmHwMwnUAByaLg=
4343
github.com/diamondburned/gotk4/pkg v0.0.6-0.20230825053034-ad325703aa2e/go.mod h1:Jr5xzUuGyLsoMtE9LzE/Lay1gD0ONiFWAmQ0+Z6KLeA=
44-
github.com/diamondburned/gotkit v0.0.0-20231108044328-9ac96cd5a778 h1:Zu0e0YUhoz9IknVI1NfYPSV2qbsRevdrcrgISSmiJVA=
45-
github.com/diamondburned/gotkit v0.0.0-20231108044328-9ac96cd5a778/go.mod h1:N9XvN0kELfwPD/6qn1tEZIhni1vphE91lo7Pn0CxA+Q=
44+
github.com/diamondburned/gotkit v0.0.0-20231111065921-0542a145d61e h1:Ck/mTbJsDIrKKgZA5b91eJ7B5VNGaoYqwNSUZJig0Eg=
45+
github.com/diamondburned/gotkit v0.0.0-20231111065921-0542a145d61e/go.mod h1:N9XvN0kELfwPD/6qn1tEZIhni1vphE91lo7Pn0CxA+Q=
4646
github.com/diamondburned/ningen/v3 v3.0.1-0.20231109131259-9140d0873f98 h1:X6MZzOCMwLCUh193M6k66NARFIGy1fxWuINSOgBsYOI=
4747
github.com/diamondburned/ningen/v3 v3.0.1-0.20231109131259-9140d0873f98/go.mod h1:PUr2nk5xo+A5hguLIe6qJzCFhTJxdN5/1i7Lr8iCWpQ=
4848
github.com/dlclark/regexp2 v1.4.0 h1:F1rxgk7p4uKjwIQxBs9oAXe5CqrXlCduYEJvrF4u93E=

internal/message/composer/input.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ var inputWYSIWYG = prefs.NewBool(true, prefs.PropMeta{
7171
Description: "Enable a semi-WYSIWYG feature that decorates the input Markdown text.",
7272
})
7373

74+
// inputStateKey is the app state that stores the last input message.
75+
var inputStateKey = app.NewStateKey[string]("input-state")
76+
7477
// NewInput creates a new Input widget.
7578
func NewInput(ctx context.Context, ctrl InputController, chID discord.ChannelID) *Input {
7679
i := Input{
@@ -119,12 +122,12 @@ func NewInput(ctx context.Context, ctrl InputController, chID discord.ChannelID)
119122
start, end := i.Buffer.Bounds()
120123

121124
// Persist input.
122-
cfg := app.AcquireState(ctx, "input-state")
125+
inputState := inputStateKey.Acquire(ctx)
123126
if end.Offset() == 0 {
124-
cfg.Delete(chID.String())
127+
inputState.Delete(chID.String())
125128
} else {
126129
text := i.Buffer.Text(start, end, false)
127-
cfg.Set(chID.String(), text)
130+
inputState.Set(chID.String(), text)
128131
}
129132
})
130133

@@ -133,10 +136,10 @@ func NewInput(ctx context.Context, ctrl InputController, chID discord.ChannelID)
133136
i.AddController(enterKeyer)
134137

135138
gtkutil.Async(ctx, func() func() {
136-
var oldMessage string
139+
inputState := inputStateKey.Acquire(ctx)
137140

138-
cfg := app.AcquireState(ctx, "input-state")
139-
if !cfg.Get(chID.String(), &oldMessage) {
141+
oldMessage, ok := inputState.Get(chID.String())
142+
if !ok {
140143
return nil
141144
}
142145

0 commit comments

Comments
 (0)