mirror of
https://shylinux.com/x/community
synced 2025-04-25 17:48:06 +08:00
109 lines
3.5 KiB
Go
109 lines
3.5 KiB
Go
package gonganxitong
|
|
|
|
import (
|
|
"shylinux.com/x/ice"
|
|
"shylinux.com/x/icebergs/base/ctx"
|
|
kit "shylinux.com/x/toolkits"
|
|
|
|
"shylinux.com/x/community/src/gonganxitong/model"
|
|
)
|
|
|
|
type message struct {
|
|
Table
|
|
command command
|
|
service service
|
|
order string `data:"102"`
|
|
create string `name:"create from_user_uid to_user_uid"`
|
|
read string `name:"read" role:"void"`
|
|
done string `name:"done" role:"void"`
|
|
sticky string `name:"sticky" role:"void"`
|
|
unSticky string `name:"unSticky" role:"void"`
|
|
}
|
|
|
|
func (s message) Create(m *ice.Message, arg ...string) {
|
|
kit.If(m.Option(ctx.ARGS) == "", func() {
|
|
arg = append(arg, ctx.ARGS, kit.JoinFields(m.Option(s.Keys(s.Place, model.UID)), m.Option(model.UID)))
|
|
})
|
|
s.Insert(m, arg...)
|
|
}
|
|
func (s message) Remove(m *ice.Message, arg ...string) {
|
|
s.Delete(m, arg...)
|
|
}
|
|
func (s message) List(m *ice.Message, arg ...string) {
|
|
s.Tables(m, s.command, s.service).FieldsWithCreatedAT(m, s,
|
|
model.FROM_USER_UID, s.Key(s, model.PLACE_NAME), s.Key(s.command, model.NAME), model.SCORE, model.MESSAGE_STATUS,
|
|
s.AS(model.NODENAME, model.SPACE), s.Key(s.command, model.INDEX), model.OPERATE, model.ARGS,
|
|
s.Key(s, model.CITY_NAME), s.Key(s, model.STREET_NAME), model.SERVICE_NAME, s.Key(s, model.DETAIL_NAME),
|
|
)
|
|
if len(arg) < 2 {
|
|
s.Orders(m, s.Desc(model.SCORE), s.Desc(model.CREATED_AT))
|
|
args := []string{model.TO_USER_UID, m.Option(model.USER_UID)}
|
|
kit.If(m.Option(model.MESSAGE_STATUS), func(p string) {
|
|
for i, v := range MessageStatusList {
|
|
if v == p {
|
|
args = append(args, model.STATUS, kit.Format(i))
|
|
}
|
|
}
|
|
})
|
|
s.Select(m, args...).Table(func(value ice.Maps) {
|
|
button := []ice.Any{}
|
|
if value[model.SCORE] == "0" {
|
|
button = append(button, s.Sticky)
|
|
} else {
|
|
button = append(button, s.UnSticky)
|
|
}
|
|
switch MessageStatus(kit.Int(value[model.MESSAGE_STATUS])) {
|
|
case MessageCreate:
|
|
button = append(button, s.Read)
|
|
case MessageRead:
|
|
button = append(button, s.Done)
|
|
default:
|
|
button = append(button, s.Remove)
|
|
}
|
|
m.PushButton(button...)
|
|
}).Action()
|
|
m.RenameAppend(model.FROM_USER_UID, model.USER_UID)
|
|
s.SelectJoinUser(m)
|
|
s.DisplayBase(m, "")
|
|
} else if len(arg) == 2 {
|
|
msg := s.SelectDetail(m.Spawn(), model.TO_USER_UID, m.Option(model.USER_UID), s.Key(s, model.UID), arg[1])
|
|
s.ProcessPodCmd(m, msg, model.MESSAGE_UID, arg[1])
|
|
if MessageStatus(kit.Int(msg.Append(model.STATUS))) == MessageCreate {
|
|
s.update(m.Spawn(kit.Dict(model.UID, arg[1])), kit.Dict(model.STATUS, MessageRead), model.STATUS, MessageCreate)
|
|
}
|
|
}
|
|
}
|
|
func (s message) Read(m *ice.Message, arg ...string) {
|
|
s.update(m, kit.Dict(model.STATUS, MessageRead), model.STATUS, MessageCreate)
|
|
}
|
|
func (s message) Done(m *ice.Message, arg ...string) {
|
|
s.update(m, kit.Dict(model.STATUS, MessageDone), model.STATUS, MessageRead)
|
|
}
|
|
func (s message) Sticky(m *ice.Message, arg ...string) {
|
|
s.update(m, ice.Map{model.SCORE: 100})
|
|
}
|
|
func (s message) UnSticky(m *ice.Message, arg ...string) {
|
|
s.update(m, ice.Map{model.SCORE: 0})
|
|
}
|
|
func (s message) update(m *ice.Message, data ice.Map, arg ...ice.Any) {
|
|
s.Table.Update(m, data, kit.Simple(model.TO_USER_UID, m.Option(model.USER_UID), m.OptionSimple(model.UID), arg)...)
|
|
}
|
|
|
|
func init() { ice.TeamCtxCmd(message{Table: newTable()}) }
|
|
|
|
type MessageStatus int
|
|
|
|
const (
|
|
MessageCreate MessageStatus = iota
|
|
MessageRead
|
|
MessageDone
|
|
)
|
|
|
|
var MessageStatusList = map[MessageStatus]string{
|
|
MessageCreate: "create",
|
|
MessageRead: "read",
|
|
MessageDone: "done",
|
|
}
|
|
|
|
func (s MessageStatus) String() string { return MessageStatusList[s] }
|