Skip to content

Commit

Permalink
Minor tweaks; add DM support
Browse files Browse the repository at this point in the history
  • Loading branch information
diamondburned committed Apr 11, 2022
1 parent ad6aaa6 commit 784dcd4
Show file tree
Hide file tree
Showing 14 changed files with 643 additions and 48 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ require (
github.com/diamondburned/arikawa/v3 v3.0.0-rc.6.0.20220408124721-4108d10b444c
github.com/diamondburned/chatkit v0.0.0-20220410003350-362494224d02
github.com/diamondburned/gotk4/pkg v0.0.0-20220408070453-08962439fbbc
github.com/diamondburned/gotkit v0.0.0-20220409081802-93f160de50f1
github.com/diamondburned/ningen/v3 v3.0.0-20220403055423-a7c9ced48403
github.com/diamondburned/gotkit v0.0.0-20220411012151-ec16933b1564
github.com/diamondburned/ningen/v3 v3.0.0-20220411010635-498c8aa4f724
)

require (
Expand Down
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ github.com/diamondburned/chatkit v0.0.0-20220410003350-362494224d02/go.mod h1:Qk
github.com/diamondburned/gotk4/pkg v0.0.0-20220225135826-2bb7260a63bb/go.mod h1:dJ2gfR0gvBsGg4IteP8aMBq/U5Q9boDw0DP7kAjXTwM=
github.com/diamondburned/gotk4/pkg v0.0.0-20220408070453-08962439fbbc h1:BkDOBlc7okNAJL5KYPXD7ZB4pB3x23XeCh79wmVC5x8=
github.com/diamondburned/gotk4/pkg v0.0.0-20220408070453-08962439fbbc/go.mod h1:rLH6FHos690jFgAM/GYEpMykuE/9NmN6zOvFlr8JTvE=
github.com/diamondburned/gotkit v0.0.0-20220409081802-93f160de50f1 h1:kxl7YYH055wP3Zf+d3Tf/GqbOPVU/lg90nP7ebUFcP8=
github.com/diamondburned/gotkit v0.0.0-20220409081802-93f160de50f1/go.mod h1:TXAbYeGcMkR6RLo9ZlCR6W1lvD9ZhxA8iSS3KYEes3Q=
github.com/diamondburned/ningen/v3 v3.0.0-20220403055423-a7c9ced48403 h1:AkOW2alRfcPRbfqwca4IczAnjBPYxc1Iiy6y/xZjuk8=
github.com/diamondburned/ningen/v3 v3.0.0-20220403055423-a7c9ced48403/go.mod h1:WLSUx3megnWk5I6rYLE+yPHN3iPJf4Nag2B5Y7l+Vmc=
github.com/diamondburned/gotkit v0.0.0-20220411012151-ec16933b1564 h1:I8X4y8FBR+rjL9Y3nXX7n2Pe8+wq/Mz9WJ5Gs2BMO1o=
github.com/diamondburned/gotkit v0.0.0-20220411012151-ec16933b1564/go.mod h1:TXAbYeGcMkR6RLo9ZlCR6W1lvD9ZhxA8iSS3KYEes3Q=
github.com/diamondburned/ningen/v3 v3.0.0-20220411010635-498c8aa4f724 h1:5aDwei68fV5SUInrkhGBbadVGZYAZxrXMCOAo/KUk6k=
github.com/diamondburned/ningen/v3 v3.0.0-20220411010635-498c8aa4f724/go.mod h1:WLSUx3megnWk5I6rYLE+yPHN3iPJf4Nag2B5Y7l+Vmc=
github.com/dlclark/regexp2 v1.4.0 h1:F1rxgk7p4uKjwIQxBs9oAXe5CqrXlCduYEJvrF4u93E=
github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
Expand Down
2 changes: 1 addition & 1 deletion internal/gtkcord/dimensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
HeaderHeight = 42
HeaderPadding = 16
GuildIconSize = 48
ChannelIconSize = 20
ChannelIconSize = 32
MessageAvatarSize = 42
EmbedMaxWidth = 300
EmbedImgHeight = 300
Expand Down
4 changes: 3 additions & 1 deletion internal/gtkcord/message/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ func NewView(ctx context.Context, chID discord.ChannelID) *View {
}

// Use this to update existing messages' members as well.
v.updateMember(ev.Member)
if ev.Member != nil {
v.updateMember(ev.Member)
}

if ev.Nonce != "" {
// Try and look up the nonce.
Expand Down
8 changes: 7 additions & 1 deletion internal/gtkcord/sidebar/channels/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ func NewView(ctx context.Context, ctrl Controller, guildID discord.GuildID) *Vie
v.Child.Tree.SetHeadersVisible(false)
v.Child.Tree.SetLevelIndentation(4)
v.Child.Tree.SetActivateOnSingleClick(true)
v.Child.Tree.SetEnableSearch(false)
// v.Child.Tree.SetVAdjustment(v.Scroll.VAdjustment())
// v.Child.Tree.SetHAdjustment(v.Scroll.HAdjustment())

Expand Down Expand Up @@ -290,6 +291,11 @@ func NewView(ctx context.Context, ctrl Controller, guildID discord.GuildID) *Vie
return &v
}

// GuildID returns the view's guild ID.
func (v *View) GuildID() discord.GuildID {
return v.guildID
}

func (v *View) setDone() {
v.LoadablePage.SetChild(v.Overlay)
}
Expand Down Expand Up @@ -348,7 +354,7 @@ func newTreeColumns() []*gtk.TreeViewColumn {
return []*gtk.TreeViewColumn{
func() *gtk.TreeViewColumn {
ren := gtk.NewCellRendererText()
ren.SetPadding(0, 6)
ren.SetPadding(0, 4)
ren.SetObjectProperty("sensitive", true)
ren.SetObjectProperty("ellipsize", pango.EllipsizeEnd)
ren.SetObjectProperty("ellipsize-set", true)
Expand Down
109 changes: 109 additions & 0 deletions internal/gtkcord/sidebar/direct/channel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package direct

import (
"context"

"github.com/diamondburned/arikawa/v3/discord"
"github.com/diamondburned/gotk4/pkg/gtk/v4"
"github.com/diamondburned/gotk4/pkg/pango"
"github.com/diamondburned/gotkit/components/onlineimage"
"github.com/diamondburned/gotkit/gtkutil/cssutil"
"github.com/diamondburned/gotkit/gtkutil/imgutil"
"github.com/diamondburned/gtkcord4/internal/gtkcord"
)

// Channel is an individual direct messaging channel.
type Channel struct {
*gtk.ListBoxRow
box *gtk.Box
avatar *onlineimage.Avatar
name *gtk.Label

ctx context.Context
id discord.ChannelID
}

var channelCSS = cssutil.Applier("direct-channel", `
.direct-channel {
padding: 4px 6px;
}
.direct-channel-avatar {
margin-right: 6px;
}
`)

// NewChannel creates a new Channel.
func NewChannel(ctx context.Context, id discord.ChannelID) *Channel {
ch := Channel{
ctx: ctx,
id: id,
}

ch.name = gtk.NewLabel("")
ch.name.AddCSSClass("direct-channel-name")
ch.name.SetXAlign(0)
ch.name.SetHExpand(true)
ch.name.SetEllipsize(pango.EllipsizeEnd)
ch.name.SetSingleLineMode(true)

ch.avatar = onlineimage.NewAvatar(ctx, imgutil.HTTPProvider, gtkcord.ChannelIconSize)
ch.avatar.AddCSSClass("direct-channel-avatar")

ch.box = gtk.NewBox(gtk.OrientationHorizontal, 0)
ch.box.Append(ch.avatar)
ch.box.Append(ch.name)

ch.ListBoxRow = gtk.NewListBoxRow()
ch.SetChild(ch.box)
ch.SetName(id.String())
channelCSS(ch)

return &ch
}

// Invalidate fetches the same channel from the state and updates itself.
func (ch *Channel) Invalidate() {
state := gtkcord.FromContext(ch.ctx)

if channel, _ := state.Cabinet.Channel(ch.id); channel != nil {
ch.Update(channel)
}
}

// Update updates the channel to show information from the instance given. ID is
// not checked.
func (ch *Channel) Update(channel *discord.Channel) {
name := gtkcord.ChannelName(ch.ctx, channel)
ch.name.SetText(name)
ch.avatar.SetInitials(name)

if channel.Type == discord.DirectMessage && len(channel.DMRecipients) > 0 {
u := channel.DMRecipients[0]
ch.avatar.SetFromURL(gtkcord.InjectAvatarSize(u.AvatarURL()))
} else {
ch.avatar.SetFromURL(gtkcord.InjectAvatarSize(channel.IconURL()))
}
}

// LastMessageID queries the local state for the channel's last message ID.
func (ch *Channel) LastMessageID() discord.MessageID {
state := gtkcord.FromContext(ch.ctx)

channel, _ := state.Cabinet.Channel(ch.id)
if channel == nil {
return 0
}

return channel.LastMessageID
}

// Name returns the current displaying name of the channel.
func (ch *Channel) Name() string {
return ch.name.Text()
}

// InvalidateSort invalidates the sorting position of this channel within the
// major channel list.
func (ch *Channel) InvalidateSort() {
ch.Changed()
}
Loading

0 comments on commit 784dcd4

Please sign in to comment.