Ejemplo n.º 1
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)

}
Ejemplo n.º 2
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)
}