Esempio n. 1
0
File: topics.go Progetto: ovh/tat
// Create creates a new topic
func (*TopicsController) Create(ctx *gin.Context) {
	var topicIn tat.TopicCreateJSON
	ctx.Bind(&topicIn)

	var user = tat.User{}
	found, err := userDB.FindByUsername(&user, getCtxUsername(ctx))
	if !found {
		ctx.JSON(http.StatusUnauthorized, gin.H{"error": "User unknown"})
		return
	} else if err != nil {
		ctx.JSON(http.StatusInternalServerError, gin.H{"error": "Error while fetching user."})
		return
	}

	var topic tat.Topic
	topic.Topic = topicIn.Topic
	topic.Description = topicIn.Description

	err = topicDB.Insert(&topic, &user)
	if err != nil {
		log.Errorf("Error while InsertTopic %s", err)
		ctx.JSON(tat.Error(err))
		return
	}
	ctx.JSON(http.StatusCreated, topic)
}
Esempio n. 2
0
File: messages.go Progetto: ovh/tat
func insertTopicDM(userFrom, userTo tat.User) (tat.Topic, error) {
	var topic = tat.Topic{}
	topicName := "/Private/" + userFrom.Username + "/DM/" + userTo.Username
	topic.Topic = topicName
	topic.Description = userTo.Fullname
	if err := topicDB.Insert(&topic, &userFrom); err != nil {
		log.Errorf("Error while InsertTopic %s", err)
		return topic, err
	}
	return topic, nil
}
Esempio n. 3
0
File: messages.go Progetto: ovh/tat
func checkTopicParentDM(user tat.User) error {
	topicName := "/Private/" + user.Username + "/DM"
	topicParent, err := topicDB.FindByTopic(topicName, false, false, false, nil)
	if err != nil {
		topicParent.Topic = topicName
		topicParent.Description = "DM Topics"
		if err := topicDB.Insert(topicParent, &user); err != nil {
			log.Errorf("Error while InsertTopic Parent %s", err)
			return err
		}
	}
	return nil
}
Esempio n. 4
0
File: user.go Progetto: ovh/tat
// CreatePrivateTopic creates a Private Topic. Name of topic will be :
// /Private/username and if subTopic != "", it will be :
// /Private/username/subTopic
// CanUpdateMsg, CanDeleteMsg set to true
func CreatePrivateTopic(user *tat.User, subTopic string) error {
	topicName := "/Private/" + user.Username
	description := "Private Topic"

	if subTopic != "" {
		topicName = fmt.Sprintf("%s/%s", topicName, subTopic)
		description = fmt.Sprintf("%s - %s of %s", description, subTopic, user.Username)
	} else {
		description = fmt.Sprintf("%s - %s", description, user.Username)
	}
	t := &tat.Topic{
		Topic:        topicName,
		Description:  description,
		CanUpdateMsg: true,
		CanDeleteMsg: true,
	}
	e := topic.Insert(t, user)
	if e != nil {
		log.Errorf("Error while creating Private topic %s: %s", topicName, e.Error())
	}
	return e
}