forked from SoDOff-Project/sodoff
add `IsPrivate
field to
Message
`
This commit is contained in:
parent
c37a719aad
commit
b7b99cd353
@ -67,12 +67,13 @@ public class MessagingController : Controller {
|
||||
[HttpPost]
|
||||
[Produces("application/xml")]
|
||||
[Route("MessageWebService.asmx/GetCombinedListMessage")]
|
||||
public ArrayOfCombinedListMessage? GetCombinedListMessage([FromForm] Guid userId)
|
||||
[VikingSession(UseLock = false)]
|
||||
public ArrayOfCombinedListMessage? GetCombinedListMessage(Viking viking, [FromForm] Guid userId)
|
||||
{
|
||||
// find viking
|
||||
Viking? viking = ctx.Vikings.FirstOrDefault(e => e.Uid == userId);
|
||||
Viking? uidViking = ctx.Vikings.FirstOrDefault(e => e.Uid == userId);
|
||||
|
||||
if (viking != null) return messagingService.ConstructCombinedMessageArray(viking);
|
||||
if (viking != null && uidViking != null) return messagingService.ConstructCombinedMessageArray(viking, uidViking);
|
||||
else return new ArrayOfCombinedListMessage();
|
||||
}
|
||||
|
||||
|
1319
src/Migrations/20250306193218_Messaging_IsPrivate.Designer.cs
generated
Normal file
1319
src/Migrations/20250306193218_Messaging_IsPrivate.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
29
src/Migrations/20250306193218_Messaging_IsPrivate.cs
Normal file
29
src/Migrations/20250306193218_Messaging_IsPrivate.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace sodoff.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class Messaging_IsPrivate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "IsPrivate",
|
||||
table: "Messages",
|
||||
type: "INTEGER",
|
||||
nullable: false,
|
||||
defaultValue: false);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "IsPrivate",
|
||||
table: "Messages");
|
||||
}
|
||||
}
|
||||
}
|
@ -316,6 +316,9 @@ namespace sodoff.Migrations
|
||||
b.Property<bool>("IsNew")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("IsPrivate")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime?>("LastUpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
|
@ -29,6 +29,7 @@ public class Message
|
||||
|
||||
public bool IsDeleted { get; set; }
|
||||
public bool IsNew { get; set; }
|
||||
public bool IsPrivate { get; set; }
|
||||
|
||||
public virtual Viking? Viking { get; set; }
|
||||
public virtual Viking? ToViking { get; set; }
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using sodoff.Model;
|
||||
using sodoff.Schema;
|
||||
@ -15,7 +16,7 @@ public class MessagingService
|
||||
this.ctx = ctx;
|
||||
}
|
||||
|
||||
public Model.Message AddMessageToViking(Viking viking, Viking toViking, MessageType messageType, MessageTypeID messageTypeID, MessageLevel messageLevel, string data, string memberMessage = "", string nonMemberMessage = "", bool IsNew = true, bool IsDeleted = false, bool isReply = false, int parentMessageId = 0)
|
||||
public Model.Message AddMessageToViking(Viking viking, Viking toViking, MessageType messageType, MessageTypeID messageTypeID, MessageLevel messageLevel, string data, string memberMessage = "", string nonMemberMessage = "", bool IsNew = true, bool IsDeleted = false, bool isReply = false, bool isPrivate = false, int parentMessageId = 0)
|
||||
{
|
||||
// get execution UTC timestamp
|
||||
DateTime now = DateTime.UtcNow;
|
||||
@ -41,7 +42,8 @@ public class MessagingService
|
||||
CreatedAt = now,
|
||||
LastUpdatedAt = now,
|
||||
IsDeleted = IsDeleted,
|
||||
IsNew = IsNew
|
||||
IsNew = IsNew,
|
||||
IsPrivate = isPrivate
|
||||
};
|
||||
|
||||
if (isReply && parentMessageId > 0)
|
||||
@ -56,7 +58,7 @@ public class MessagingService
|
||||
message.ConversationID = messageToReplyTo.ConversationID;
|
||||
|
||||
// add a message to the replier's board saying a thread update has occured (if reply isn't to self)
|
||||
if (message.VikingId != message.ToVikingId) AddMessageToViking(message.Viking, message.ToViking, MessageType.Data, MessageTypeID.ThreadUpdate, MessageLevel.WhiteList, "[[Line1]]=[[{{BuddyUserName}} Replied To Your Message In {{BuddyUserName}}'s Message Board!]]", "[[Line1]]=[[{{BuddyUserName}} Replied To Your Message In {{BuddyUserName}}'s Message Board!]]", "[[Line1]]=[[{{BuddyUserName}} Replied To Your Message In {{BuddyUserName}}'s Message Board!]]");
|
||||
if (message.VikingId != message.ToVikingId) AddMessageToViking(message.Viking, message.ToViking, MessageType.Data, MessageTypeID.ThreadUpdate, MessageLevel.WhiteList, "[[Line1]]=[[{{BuddyUserName}} Replied To Your Message In {{BuddyUserName}}'s Message Board!]]", "[[Line1]]=[[{{BuddyUserName}} Replied To Your Message In {{BuddyUserName}}'s Message Board!]]", "[[Line1]]=[[{{BuddyUserName}} Replied To Your Message In {{BuddyUserName}}'s Message Board!]]", isPrivate: true);
|
||||
} else throw new InvalidOperationException("Tried To Reply To A Message That Doesn't Exist");
|
||||
}
|
||||
|
||||
@ -102,7 +104,7 @@ public class MessagingService
|
||||
} else return null;
|
||||
}
|
||||
|
||||
public ArrayOfCombinedListMessage ConstructCombinedMessageArray(Viking viking)
|
||||
public ArrayOfCombinedListMessage ConstructCombinedMessageArray(Viking viking, Viking publicViking)
|
||||
{
|
||||
// get all messages in viking board
|
||||
List<Model.Message> messages = ctx.Messages.Where(e => e.ToVikingId == viking.Id).ToList();
|
||||
@ -118,6 +120,8 @@ public class MessagingService
|
||||
continue;
|
||||
}
|
||||
|
||||
if (message.IsPrivate && (viking.Id != publicViking.Id)) continue;
|
||||
|
||||
Viking? msgAuthor = ctx.Vikings.FirstOrDefault(e => e.Id == message.VikingId) ?? new Viking();
|
||||
|
||||
// construct a CombinedListMessage based on Model.Message
|
||||
|
Loading…
x
Reference in New Issue
Block a user