Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix case of bot icons are invisible #107

Merged
merged 2 commits into from
May 11, 2020
Merged

Fix case of bot icons are invisible #107

merged 2 commits into from
May 11, 2020

Conversation

kuuote
Copy link
Member

@kuuote kuuote commented May 10, 2020

botのアイコンが表示されないケースがあったので修正
ついでにGetUserの部分を外に出して変数のokをuserFoundに変更していますが、問題があれば指摘をお願いします。
polly

@@ -208,19 +208,22 @@ func (g *HTMLGenerator) generateMessageDir(channel Channel, key MessageMonthKey,
return g.c.escapeSpecialChars(g.s.GetDisplayNameByUserID(msg.User))
},
"userIconUrl": func(msg *Message) string {
var user *User

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

early return ごり押しだと

  • !msg.IsVisible() であれば return "" // TODO show default icon
  • Bot からのメッセージで Icons が存在すれば return msg.Icons.Image48
    • 条件式が汚なくなりますが msg.Subtype == "bot_message" || msg.Subtype == "slackbot_response"IsBotMessage() とか名付ければ条件式もまだましになる...?
  • それ以外の場合は user を取得して存在すれば return user.Profile.Image48

とできそうです

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// ただの提案(? 思い付いたことをつぶやいただけとも言う...)なので、このままでも問題自体はないと思います

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

書いててすっきりしなかったんですよねこれ、early returnで考えてみますか

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

テンプレートでの使われかたを見るにIsVisibleの判定は必要なさそう

Copy link

@tennashi tennashi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

どっちにせよ、ここは修正が必要ですね

internal/slacklog/generator.go Outdated Show resolved Hide resolved
@kuuote
Copy link
Member Author

kuuote commented May 10, 2020

変数の使用をやめて、MessageにisBotMessageというメソッドを生やしてみました

Copy link

@tennashi tennashi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@koron koron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slackの僕の発言より引用

要は msg の横に表示すべきアイコンの正しい決定方法がわからんなぁ、と

たぶんAPI叩くと、各発言のアイコンを1個ずつ書き換えられるんですよね。

だから userIconUrl で最優先すべきは msg.Icons なのかなって。また関数名は messageIconURL になる。

  1. msg.Icons があればそれを使う
  2. なければ、ボットならmsg.BotIDをIDとして、ボットじゃなければ msg.User を ID として、Userをとってその user.Profile.Image48 を使う
  3. Userが取れなかったらデフォルトアイコンにフォールバック
    このロジックが正しいんじゃないかと思うんですが、確信が持てない。

@kuu ちょっと検討してみてください。

Copy link
Member

@koron koron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

おっとまちがえた。上記検討してみてください。

@kuuote
Copy link
Member Author

kuuote commented May 11, 2020

msg.Icons優先したほうがよさそうな雰囲気ありますね、修正してみました。

Copy link
Member

@koron koron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTMです! diff で 2か所のアイコンが挿入されたことを確認できました!

@koron koron merged commit c5af144 into master May 11, 2020
@koron koron deleted the fix/bot_icon branch May 11, 2020 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants