Exemplo n.º 1
0
func handleStickerMessage(parent *ChatWindow, msg *prot.Message) IMessage {
	from := msg.GetFrom()
	msgType := checkMessageType(from)

	meta := msg.ContentMetadata
	stkid := meta["STKID"]
	stkpkgid := meta["STKPKGID"]
	stkver := meta["STKVER"]
	url := api.LINE_STICKER_URL + stkver + "/" + stkpkgid + "/PC/stickers/" + stkid + ".png"
	filename := path.Join(goline.TempDirPath, "sticker", stkid+".png")
	if checkFileNotExist(filename) {
		err := downloadFile(url, filename)
		if err != nil {
			goline.LoggerPrintln(err)
			return NewTextMessage(parent, msgType, from, "Failed to download sticker.")

		}
	}
	return NewImageMessage(parent, msgType, from, filename)
}
Exemplo n.º 2
0
func handleTextPreviewMessage(parent *ChatWindow, msg *prot.Message, text, ext string) IMessage {
	from := msg.GetFrom()
	msgType := checkMessageType(from)

	label, err := gtk.LabelNew(text)
	if err != nil {
		goline.LoggerPanicln(err)
	}
	msgId := msg.GetId()
	meta := msg.GetContentMetadata()

	var url string
	if meta["PUBLIC"] == "TRUE" {
		url = meta["DOWNLOAD_URL"]
	} else {
		url = api.LINE_OBJECT_STORAGE_URL + msgId
	}

	return NewDownloadableMessage(parent, msgType, from, msgId, url, ext, label)

}
Exemplo n.º 3
0
func handleImagePreviewMessage(parent *ChatWindow, msg *prot.Message) IMessage {
	from := msg.GetFrom()
	msgType := checkMessageType(from)

	msgId := msg.GetId()
	preview := path.Join(goline.TempDirPath, "preview", msgId)
	meta := msg.GetContentMetadata()

	var url string
	if checkFileNotExist(preview) {
		if meta["PUBLIC"] == "TRUE" {
			url = meta["PREVIEW_URL"]
		} else {
			url = api.LINE_OBJECT_STORAGE_URL + msgId + "/preview"
		}
		err := downloadFile(url, preview)
		if err != nil {
			goline.LoggerPrintln(err)
			return NewTextMessage(parent, msgType, from, "Failed to download preview.")
		}
	}

	image, err := gtk.ImageNew()
	if err != nil {
		goline.LoggerPanicln(err)
	}
	image.SetFromFile(preview)

	if meta["PUBLIC"] == "TRUE" {
		url = meta["DOWNLOAD_URL"]
	} else {
		url = api.LINE_OBJECT_STORAGE_URL + msgId
	}

	return NewDownloadableMessage(parent, msgType, from, msgId, url, "", image)
}
Exemplo n.º 4
0
func handleTextMessage(parent *ChatWindow, msg *prot.Message, text string) IMessage {
	from := msg.GetFrom()

	msgType := checkMessageType(from)
	return NewTextMessage(parent, msgType, from, text)
}