Пример #1
0
func sendMessageLoop(to, message string, group bool, att io.Reader, flags int) uint64 {
	var err error
	var ts uint64
	for {
		err = nil
		if flags == msgFlagResetSession {
			ts, err = textsecure.EndSession(to, "TERMINATE")
		} else if flags == msgFlagGroupLeave {
			err = textsecure.LeaveGroup(to)
		} else if flags == msgFlagGroupUpdate {
			_, err = textsecure.UpdateGroup(to, groups[to].Name, strings.Split(groups[to].Members, ","))
		} else if att == nil {
			if group {
				ts, err = textsecure.SendGroupMessage(to, message)
			} else {
				ts, err = textsecure.SendMessage(to, message)
			}
		} else {
			if group {
				ts, err = textsecure.SendGroupAttachment(to, message, att)
			} else {
				ts, err = textsecure.SendAttachment(to, message, att)
			}
		}
		if err == nil {
			break
		}
		log.Println(err)
		//If sending failed, try again after a while
		time.Sleep(3 * time.Second)
	}
	return ts
}
Пример #2
0
// In addition to sending a message using janimo's library, also clears screen and resets buffer
func sendMsg(inputWin *gc.Window, msgWin *gc.Window) {
	if len(inputBuffer) != 0 {
		msg := string(inputBuffer)
		to := currentContact
		err := ts.SendMessage(to, msg)
		if err != nil {
			gc.End()
			log.Fatal("SendMessage failed yo: ", err)
		}

		var b bytes.Buffer
		t := time.Now()
		if t.Hour() < 10 {
			b.WriteString("0")
		}
		b.WriteString(strconv.Itoa(t.Hour()))
		b.WriteString(":")
		if t.Minute() < 10 {
			b.WriteString("0")
		}
		b.WriteString(strconv.Itoa(t.Minute()))
		b.WriteString(": ")
		b.WriteString(msg)

		printToMsgWindow(b.String(), msgWin, true)
		b.Reset()
		insertMessage("You", currentContact, []byte(msg), nil)
		inputBuffer = []byte{}
		inputWin.Erase()
	}
}
Пример #3
0
func sendMessage(isGroup bool, to, message string) error {
	var err error
	if isGroup {
		_, err = textsecure.SendGroupMessage(to, message)
	} else {
		_, err = textsecure.SendMessage(to, message)
		if nerr, ok := err.(axolotl.NotTrustedError); ok {
			log.Fatalf("Peer identity not trusted. Remove the file .storage/identity/remote_%s to approve\n", nerr.ID)
		}
	}
	return err
}
Пример #4
0
func sendMessage(w http.ResponseWriter, r *http.Request) (res jsonObject) {
	var attachmentPath string
	var attachment *os.File

	req, err := parseRequest(r)

	if err != nil {
		return errorResponse(err, "")
	}

	err = validateRequest(req, []string{"contact:s", "msg:s"})

	if err != nil {
		return errorResponse(err, "")
	}

	msg := req["msg"].(string)
	contactPath, err := absolutePath(req["contact"].(string))

	if err != nil {
		return errorResponse(err, "")
	}

	contact, err := parseContact(contactPath)

	if err != nil {
		return errorResponse(err, "")
	}

	if a, ok := req["attachment"]; ok {
		attachmentPath, err = absolutePath(a.(string))

		if err != nil {
			return errorResponse(err, "")
		}

		inKeyPath, private := detectKeyPath(attachmentPath)

		if inKeyPath && private {
			return errorResponse(errors.New("attaching private key(s) is not allowed"), "")
		}

		attachment, err = os.Open(attachmentPath)

		if err != nil {
			return errorResponse(err, "")
		}
		defer attachment.Close()

		// append attachment name with INTERLOCK specific metadata format
		msg = msg + " [" + attachmentMsg + path.Base(attachmentPath) + "]"
		err = textsecure.SendAttachment(contact.Number, msg, attachment)

		if err != nil {
			return errorResponse(err, "")
		}

		err = updateHistory(contact, msg, ">", time.Now())
	} else {
		err = textsecure.SendMessage(contact.Number, msg)

		if err != nil {
			return errorResponse(err, "")
		}

		err = updateHistory(contact, msg, ">", time.Now())
	}

	if err != nil {
		return errorResponse(err, "")
	}

	res = jsonObject{
		"status":   "OK",
		"response": nil,
	}

	return
}