Skip to content

Commit a3ecf14

Browse files
peterdemepeterdeme
and
peterdeme
authored
feat: add partial message update (#77)
Co-authored-by: peterdeme <peter.deme@getstream.io>
1 parent 74cf9f9 commit a3ecf14

File tree

6 files changed

+95
-0
lines changed

6 files changed

+95
-0
lines changed

.github/workflows/ci.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ jobs:
66
basic:
77
name: Run tests on ${{ matrix.os }}
88
runs-on: ${{ matrix.os }}
9+
env:
10+
DOTNET_CLI_TELEMETRY_OPTOUT: "true"
911
strategy:
1012
max-parallel: 1
1113
matrix:

.github/workflows/release.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ jobs:
99
Release:
1010
if: "${{ startsWith(github.event.head_commit.message, 'chore(release)') }}"
1111
runs-on: ubuntu-latest
12+
env:
13+
DOTNET_CLI_TELEMETRY_OPTOUT: "true"
1214
steps:
1315
- uses: actions/checkout@v2
1416
with:

src/stream-chat-net-test/ClientTests.cs

+40
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,46 @@ public async Task TestUpdateMessage()
172172
Assert.AreEqual("stuff", updatedMessage.GetData<string>("new"));
173173
}
174174

175+
[Test]
176+
public async Task TestUpdateMessagePartial()
177+
{
178+
var user1 = new User()
179+
{
180+
ID = Guid.NewGuid().ToString(),
181+
Role = Role.Admin,
182+
};
183+
184+
await this._client.Users.Upsert(user1);
185+
186+
var channel = this._client.Channel("messaging", Guid.NewGuid().ToString());
187+
await channel.Create(user1.ID, new string[] { user1.ID });
188+
189+
var initialMsg = new MessageInput
190+
{
191+
Text = Guid.NewGuid().ToString()
192+
};
193+
initialMsg.SetData("foo", "barsky");
194+
initialMsg.SetData("bar", "baz");
195+
196+
var msg = await channel.SendMessage(initialMsg, user1.ID);
197+
198+
var resp = await _client.UpdateMessagePartial(msg.ID, new MessagePartialUpdateRequest
199+
{
200+
UserId = user1.ID,
201+
Set = new Dictionary<string, object>
202+
{
203+
{ "foo", "new" }
204+
},
205+
Unset = new List<string> { "bar"},
206+
});
207+
208+
Assert.AreEqual(msg.ID, resp.Message.ID);
209+
Assert.AreEqual(msg.Text, resp.Message.Text);
210+
Assert.NotNull(resp.Duration);
211+
Assert.AreEqual(resp.Message.GetData<string>("foo"), "new");
212+
Assert.IsNull(resp.Message.GetData<string>("bar"));
213+
}
214+
175215
[Test]
176216
public async Task TestGetMessage()
177217
{

src/stream-chat-net/Client.cs

+26
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,32 @@ public async Task<Message> UpdateMessage(MessageInput msg)
292292
throw StreamChatException.FromResponse(response);
293293
}
294294

295+
public async Task<MessagePartialUpdateResponse> UpdateMessagePartial(string messageId, MessagePartialUpdateRequest partialUpdateRequest)
296+
{
297+
if (string.IsNullOrWhiteSpace(messageId))
298+
{
299+
throw new ArgumentException("The messageId must be set.", nameof(messageId));
300+
}
301+
302+
var endpoint = string.Format("messages/{0}", messageId);
303+
var request = this.BuildAppRequest(endpoint, HttpMethod.PUT);
304+
request.SetJsonBody(JsonConvert.SerializeObject(partialUpdateRequest));
305+
306+
var response = await MakeRequest(request);
307+
if (response.StatusCode == System.Net.HttpStatusCode.Created)
308+
{
309+
var respObj = JObject.Parse(response.Content);
310+
var msgObj = respObj.Property("message").Value as JObject;
311+
312+
return new MessagePartialUpdateResponse
313+
{
314+
Duration = respObj.Property("duration").Value.ToString(),
315+
Message = Message.FromJObject(msgObj)
316+
};
317+
}
318+
throw StreamChatException.FromResponse(response);
319+
}
320+
295321
public async Task<Message> DeleteMessage(string messageID, bool hardDelete = false)
296322
{
297323
var endpoint = string.Format("messages/{0}", messageID);

src/stream-chat-net/IClient.cs

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public interface IClient
3232
Task<MessageSearchResponse> Search(SearchOptions opts);
3333
Task<Message> GetMessage(string messageID);
3434
Task<Message> UpdateMessage(MessageInput msg);
35+
Task<MessagePartialUpdateResponse> UpdateMessagePartial(string messageId, MessagePartialUpdateRequest partialUpdateRequest);
3536
Task<Message> DeleteMessage(string messageID, bool hardDelete = false);
3637

3738

src/stream-chat-net/Message.cs

+24
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,28 @@ public class MessageSearchResult
189189

190190
public MessageSearchResult() { }
191191
}
192+
public class MessagePartialUpdateRequest
193+
{
194+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "user_id")]
195+
public string UserId { get; set; }
196+
197+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "user")]
198+
public User User { get; set; }
199+
200+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "set")]
201+
public Dictionary<string, object> Set { get; set; }
202+
203+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "unset")]
204+
public List<string> Unset { get; set; }
205+
206+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "skip_enrich_url")]
207+
public bool? SkipEnrichUrl { get; set; }
208+
}
209+
210+
public class MessagePartialUpdateResponse
211+
{
212+
public Message Message { get; internal set; }
213+
214+
public string Duration { get; internal set; }
215+
}
192216
}

0 commit comments

Comments
 (0)