Beispiel #1
0
// HandleMessageEvent is called to handle a specific message event
func (e *OtrEventHandler) HandleMessageEvent(event otr3.MessageEvent, message []byte, err error, trace ...interface{}) {
	switch event {
	case otr3.MessageEventLogHeartbeatReceived:
		log.Printf("[%s] Heartbeat received from %s.", e.Account, e.Peer)
	case otr3.MessageEventLogHeartbeatSent:
		log.Printf("[%s] Heartbeat sent to %s.", e.Account, e.Peer)
	case otr3.MessageEventReceivedMessageUnrecognized:
		log.Printf("[%s] Unrecognized OTR message received from %s.", e.Account, e.Peer)
	case otr3.MessageEventEncryptionRequired:
		e.Delays[trace[0].(int)] = true
		e.PendingDelays++
		if e.PendingDelays == 1 {
			e.notify("Attempting to start a private conversation...")
		}
	case otr3.MessageEventEncryptionError:
		// This happens when something goes wrong putting together a new data packet in OTR
		e.notify("An error occurred when encrypting your message. The message was not sent.")
	case otr3.MessageEventConnectionEnded:
		// This happens when we have finished a conversation and tries to send a message afterwards
		e.notify("Your message was not sent, since the other person has already closed their private connection to you.")
	case otr3.MessageEventMessageReflected:
		e.notify("We are receiving our own OTR messages. You are either trying to talk to yourself, or someone is reflecting your messages back at you.")
	case otr3.MessageEventSetupError:
		e.notify("Error setting up private conversation.")
		if err != nil {
			log.Printf("[%s] Error setting up private conversation with %s: %s.", e.Account, e.Peer, err.Error())
		}
	case otr3.MessageEventMessageSent:
		if len(trace) > 0 {
			e.DelayedMessageSent <- trace[0].(int)
		}
	case otr3.MessageEventMessageResent:
		e.notify("The last message to the other person was resent, since we couldn't deliver the message previously.")
	case otr3.MessageEventReceivedMessageUnreadable:
		// This happens when the authenticator is wrong, message counters are out of whack
		// or several other things that indicate tampering or attack
		e.notify("We received an unreadable encrypted message. It has probably been tampered with, or was sent from an older client.")
	case otr3.MessageEventReceivedMessageMalformed:
		// This happens when the OTR header is malformed, or different deserialization issues
		e.notify("We received a malformed data message.")
	case otr3.MessageEventReceivedMessageGeneralError:
		// This happens when we receive an error from the other party
		e.notify(fmt.Sprintf("We received this error from the other person: %s.", string(message)))
	case otr3.MessageEventReceivedMessageNotInPrivate:
		// This happens when we receive what looks like a data message, but we're not in encrypted state
		// TODO: this should open conversation window
		e.notify("We received an encrypted message which can't be read, since private communication is not currently turned on. You should ask your peer to repeat what they said.")
	case otr3.MessageEventReceivedMessageUnencrypted:
		// This happens when we receive a non-OTR message, even though we have require encryption turned on
		e.notify("We received a message that was transferred without encryption")
	case otr3.MessageEventReceivedMessageForOtherInstance:
		// We ignore this message on purpose, for now it would be too noisy to notify about it
	default:
		log.Printf("[%s] Unhandled OTR3 Message Event(%s, %s, %v)", e.Account, event.String(), message, err)
	}
}
Beispiel #2
0
// HandleMessageEvent is called to handle a specific message event
func (e *OtrEventHandler) HandleMessageEvent(event otr3.MessageEvent, message []byte, err error) {
	log.Printf("HandleMessageEvent(%s, %s, %v)", event.String(), message, err)
}