Beispiel #1
0
func (b *Backend) sendMessageToRoom(
	ctx scope.Context, rb *RoomBinding, msg proto.Message, exclude ...proto.Session) (proto.Message, error) {

	stored, err := NewMessage(rb.RoomName, msg.Sender, msg.ID, msg.Parent, msg.EncryptionKeyID, msg.Content)
	if err != nil {
		return proto.Message{}, err
	}

	t, err := b.DbMap.Begin()
	if err != nil {
		return proto.Message{}, err
	}

	if err := t.Insert(stored); err != nil {
		rollback(ctx, t)
		return proto.Message{}, err
	}

	result := stored.ToTransmission()
	event := proto.SendEvent(result)
	if err := rb.broadcast(ctx, t, proto.SendEventType, &event, exclude...); err != nil {
		rollback(ctx, t)
		return proto.Message{}, err
	}

	if err := t.Commit(); err != nil {
		return proto.Message{}, err
	}

	return result, nil
}
Beispiel #2
0
func (b *Backend) sendMessageToRoom(
	ctx scope.Context, room *Room, msg proto.Message, exclude ...proto.Session) (proto.Message, error) {

	stored, err := NewMessage(room, msg.Sender, msg.ID, msg.Parent, msg.EncryptionKeyID, msg.Content)
	if err != nil {
		return proto.Message{}, err
	}

	if err := b.DbMap.Insert(stored); err != nil {
		return proto.Message{}, err
	}

	result := stored.ToBackend()
	event := proto.SendEvent(result)
	return result, b.broadcast(ctx, room, proto.SendEventType, &event, exclude...)
}