Add forwarding, friend controls, and benefits

Add message forwarding and reply lookup, friend removal and blocking endpoints, and database-backed Govor+ privileges with customizable profile tags. Include migrations, integration tests, and updated API and operations documentation.
This commit is contained in:
Artemy
2026-10-31 18:29:40 +07:00
parent a3401ceedf
commit 632ac04b56
78 changed files with 5284 additions and 720 deletions
+8
View File
@@ -11,6 +11,7 @@ namespace Govor.Domain;
public class GovorDbContext(DbContextOptions<GovorDbContext> options) : DbContext(options)
{
public virtual DbSet<User> Users { get; set; }
public DbSet<UserBenefits> UserBenefits { get; set; }
public virtual DbSet<UserSession> UserSessions { get; set; }
public virtual DbSet<UserPushToken> UserPushTokens { get; set; }
public virtual DbSet<UserCryptoSession> UserCryptoSessions { get; set; }
@@ -43,6 +44,13 @@ public class GovorDbContext(DbContextOptions<GovorDbContext> options) : DbContex
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<UserBenefits>(b =>
{
b.HasKey(x => x.UserId);
b.Property(x => x.Revision).IsConcurrencyToken();
b.Property(x => x.TagJson).HasMaxLength(4000);
b.HasOne<User>().WithOne().HasForeignKey<UserBenefits>(x => x.UserId).OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<E2eeIdentityChange>(b =>
{
b.HasKey(c => new { c.UserId, c.Epoch });
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,71 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Govor.Domain.Migrations
{
/// <inheritdoc />
public partial class MessagingAndUserBenefits : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<Guid>(
name: "ForwardedFromMessageId",
table: "Messages",
type: "uuid",
nullable: true);
migrationBuilder.AddColumn<DateTime>(
name: "ForwardedFromSentAt",
table: "Messages",
type: "timestamp with time zone",
nullable: true);
migrationBuilder.AddColumn<Guid>(
name: "ForwardedFromUserId",
table: "Messages",
type: "uuid",
nullable: true);
migrationBuilder.CreateTable(
name: "UserBenefits",
columns: table => new
{
UserId = table.Column<Guid>(type: "uuid", nullable: false),
Privileges = table.Column<long>(type: "bigint", nullable: false),
TagJson = table.Column<string>(type: "character varying(4000)", maxLength: 4000, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_UserBenefits", x => x.UserId);
table.ForeignKey(
name: "FK_UserBenefits_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "UserBenefits");
migrationBuilder.DropColumn(
name: "ForwardedFromMessageId",
table: "Messages");
migrationBuilder.DropColumn(
name: "ForwardedFromSentAt",
table: "Messages");
migrationBuilder.DropColumn(
name: "ForwardedFromUserId",
table: "Messages");
}
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Govor.Domain.Migrations
{
/// <inheritdoc />
public partial class UserBenefitsRevision : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<long>(
name: "Revision",
table: "UserBenefits",
type: "bigint",
nullable: false,
defaultValue: 0L);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Revision",
table: "UserBenefits");
}
}
}
@@ -322,6 +322,15 @@ namespace Govor.Domain.Migrations
.IsRequired()
.HasColumnType("text");
b.Property<Guid?>("ForwardedFromMessageId")
.HasColumnType("uuid");
b.Property<DateTime?>("ForwardedFromSentAt")
.HasColumnType("timestamp with time zone");
b.Property<Guid?>("ForwardedFromUserId")
.HasColumnType("uuid");
b.Property<bool>("IsEdited")
.HasColumnType("boolean");
@@ -1027,6 +1036,27 @@ namespace Govor.Domain.Migrations
b.ToTable("Users");
});
modelBuilder.Entity("Govor.Domain.Models.Users.UserBenefits", b =>
{
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.Property<long>("Privileges")
.HasColumnType("bigint");
b.Property<long>("Revision")
.IsConcurrencyToken()
.HasColumnType("bigint");
b.Property<string>("TagJson")
.HasMaxLength(4000)
.HasColumnType("character varying(4000)");
b.HasKey("UserId");
b.ToTable("UserBenefits");
});
modelBuilder.Entity("Govor.Domain.Models.Users.UserPushToken", b =>
{
b.Property<Guid>("Id")
@@ -1404,6 +1434,15 @@ namespace Govor.Domain.Migrations
b.Navigation("Invite");
});
modelBuilder.Entity("Govor.Domain.Models.Users.UserBenefits", b =>
{
b.HasOne("Govor.Domain.Models.Users.User", null)
.WithOne()
.HasForeignKey("Govor.Domain.Models.Users.UserBenefits", "UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Govor.Domain.Models.Users.UserSession", b =>
{
b.HasOne("Govor.Domain.Models.Users.User", "User")
+8 -1
View File
@@ -15,6 +15,10 @@ public class Message
public List<MessageView> MessageViews { get; set; } = new List<MessageView>();
public Guid? ReplyToMessageId { get; set; }
// Attribution is a snapshot: deleting the source must not delete the forwarded message.
public Guid? ForwardedFromMessageId { get; set; }
public Guid? ForwardedFromUserId { get; set; }
public DateTime? ForwardedFromSentAt { get; set; }
public long ReactionsVersion { get; set; }
public override bool Equals(object? obj)
@@ -29,7 +33,10 @@ public class Message
SentAt == other.SentAt &&
IsEdited == other.IsEdited &&
EditedAt == other.EditedAt &&
ReplyToMessageId == other.ReplyToMessageId;
ReplyToMessageId == other.ReplyToMessageId &&
ForwardedFromMessageId == other.ForwardedFromMessageId &&
ForwardedFromUserId == other.ForwardedFromUserId &&
ForwardedFromSentAt == other.ForwardedFromSentAt;
}
}
+41
View File
@@ -0,0 +1,41 @@
namespace Govor.Domain.Models.Users;
[Flags]
public enum UserPrivileges : long
{
None = 0,
GovorPlus = 1,
CustomProfileTag = 2
}
public sealed class UserBenefits
{
public Guid UserId { get; set; }
public UserPrivileges Privileges { get; set; }
public long Revision { get; set; }
public string? TagJson { get; set; }
}
/// <summary>Portable appearance values; clients render these as data, never as CSS or HTML.</summary>
public sealed record ProfileTagStyle
{
public string Text { get; init; } = "Govor+";
public string TextColor { get; init; } = "#FFFFFF";
public string? TextGradientEndColor { get; init; }
public string BackgroundColor { get; init; } = "#2455DD";
public string? GradientEndColor { get; init; }
public int GradientAngle { get; init; } = 90;
public string BorderColor { get; init; } = "#6688FF";
public string? BorderGradientEndColor { get; init; }
public double BorderWidth { get; init; } = 1;
public string ShadowColor { get; init; } = "#00000080";
public double ShadowBlur { get; init; } = 4;
public double ShadowOffsetX { get; init; }
public double ShadowOffsetY { get; init; } = 1;
public string FontFamily { get; init; } = "Inter";
public int FontWeight { get; init; } = 600;
public int FontSize { get; init; } = 12;
}
public sealed record UserBenefitsView(UserPrivileges Privileges, bool IsGovorPlus,
bool CanCustomizeProfileTag, ProfileTagStyle? Tag, long Revision = 0);