Ejemplo n.º 1
0
// ContextMessageClick ...
func ContextMessageClick(command string, id int64) {
	switch command {
	case "delete":
		data.Messages <- messages.Container{
			Type:   messages.MsgDelete,
			Object: messages.DeleteMessage(id),
		}
	case "copy":
		thisObj := jq(fmt.Sprintf("#msg-%d", id))
		textObj := thisObj.Find(".message-text")
		if textObj.Length == 0 {
			textObj = thisObj.Find(".clipboard-data")
			if textObj.Length == 0 {
				console.Warn("Failed to copy to clipboard: Text not found!")
				return
			}
		}

		wasHidden := false
		if textObj.HasClass("hidden") {
			wasHidden = true
			textObj.RemoveClass("hidden")
		}

		selection := js.Global.Get("window").Call("getSelection")
		rangee := js.Global.Get("document").Call("createRange")
		rangee.Call("selectNodeContents", textObj.Underlying().Index(0))
		selection.Call("removeAllRanges")
		selection.Call("addRange", rangee)
		js.Global.Get("document").Call("execCommand", "copy")
		selection.Call("removeAllRanges")

		if wasHidden {
			textObj.AddClass("hidden")
		}
	}
}
Ejemplo n.º 2
0
// 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("")
}