// UpdateUserlist updates the userlist contents func UpdateUserlist() { chanData := data.GetChannel(GetActiveNetwork(), GetActiveChannel()) if chanData == nil || len(chanData.Userlist) == 0 { if !IsUserlistHidden() { ToggleUserlist(false) } jq("#open-user-list").AddClass("hidden-medium-down") jq("#open-settings").RemoveClass("hidden-medium-down") return } if IsUserlistHidden() && !WasUserlistHiddenManually() { ToggleUserlist(false) } userlistObj := jq("#userlist-list") userlistObj.SetText("") for i, user := range chanData.Userlist { templates.AppendObj("userlist-entry", userlistObj, map[string]interface{}{ "Network": GetActiveNetwork(), "Name": chanData.UserlistPlain[i], "DisplayName": user, }) } templates.AppendObj("userlist-invite", userlistObj, nil) jq("#open-user-list").RemoveClass("hidden-medium-down") jq("#open-settings").AddClass("hidden-medium-down") }
// Receive messages func Receive(msg messages.Message, isNew bool) { net := GetNetwork(msg.Network) if net.Length == 0 { if msg.Command == irc.PART && msg.Sender == data.MustGetNetwork(msg.Network).Nick { return } OpenNetwork(msg.Network) net = GetNetwork(msg.Network) } ch := GetChannel(msg.Network, msg.Channel) if ch.Length == 0 { if msg.Command == irc.PART && msg.Sender == data.MustGetNetwork(msg.Network).Nick { return } OpenChannel(msg.Network, msg.Channel, false) ch = GetChannel(msg.Network, msg.Channel) } templateData := parseMessage(msg) oldMsgWrap := jq(fmt.Sprintf("#msgwrap-%d", msg.ID)) if oldMsgWrap.Length != 0 { loadedTempl := jq("<div></div>") templates.AppendObj("message", loadedTempl, templateData) oldMsgWrap.ReplaceWith(loadedTempl.Children(":first")) } else { templates.AppendObj("message", ch, templateData) } if isNew { NotifyMessage(msg.Network, msg.Channel, templateData.Sender, templateData.Clipboard, templateData.Highlight) } }
// Send messages func Send() { if !data.Connected { console.Warn("Tried to send message without connection!") return } msg := jq("#message-text").Val() if len(msg) == 0 { return } var obj messages.Message if msg[0] == '/' { args := strings.Split(msg, " ") cmd := strings.ToLower(args[0][1:]) args = args[1:] switch cmd { case "me": obj = messages.Message{ Network: GetActiveNetwork(), Channel: GetActiveChannel(), Command: "action", Message: strings.Join(args, " "), } case "topic": fallthrough case "title": obj = messages.Message{ Network: GetActiveNetwork(), Channel: GetActiveChannel(), Command: irc.TOPIC, Message: strings.Join(args, " "), } case "nick": fallthrough case "name": fallthrough case "nickname": obj = messages.Message{ Network: GetActiveNetwork(), Channel: GetActiveChannel(), Command: irc.NICK, Message: strings.Join(args, " "), } case "msg": fallthrough case "message": fallthrough case "query": fallthrough case "q": fallthrough case "privmsg": if len(args) > 1 { obj = messages.Message{ Network: GetActiveNetwork(), Channel: args[0], Command: "privmsg", Message: strings.Join(args[1:], " "), } } case "join": if len(args) > 0 { net := GetActiveNetwork() ch := args[0] if len(args) > 0 { net = args[0] } obj = messages.Message{ Network: net, Channel: ch, Command: "action", Message: "Joining", } } case "part": fallthrough case "leave": fallthrough case "quit": fallthrough case "exit": net := GetActiveNetwork() ch := GetActiveChannel() if len(args) > 0 { ch = args[0] if len(args) > 1 { net = args[1] } } obj = messages.Message{ Network: net, Channel: ch, Command: irc.PART, Message: "Leaving", } default: templates.AppendObj("error", GetActiveChannelObj(), "Unknown command: "+cmd) ScrollDown() jq("#message-text").SetVal("") return } } else { obj = messages.Message{ Network: GetActiveNetwork(), Channel: GetActiveChannel(), Command: "privmsg", Message: util.EncodeMessage(msg), } } data.Messages <- messages.Container{ Type: messages.MsgMessage, Object: obj, } jq("#message-text").SetVal("") }