- {props.channels?.map((cr, i) => {
+ {chainChannels.map((cr, i) => {
const initials = cr.display_name
.split(" ")
.map((word) => word[0])
.join("");
const isSelected = cr.id === props.selectedChannel?.id;
return (
-
- {isSelected ? (
-
- ) : (
-
+
);
})}
{isChainAdmin ? (
diff --git a/app/src/pages/Chat.tsx b/app/src/pages/Chat.tsx
index 06baa0977..82408280e 100644
--- a/app/src/pages/Chat.tsx
+++ b/app/src/pages/Chat.tsx
@@ -44,7 +44,8 @@ type WebSocketMessagePosted = WebSocketMessage<{
// This follows the controller / view component pattern
export default function Chat() {
const { t } = useTranslation();
- const { chain, mmData, setMmData, isThemeDefault } = useContext(StoreContext);
+ const { chain, setChain, mmData, setMmData, isThemeDefault } =
+ useContext(StoreContext);
const [mmWsClient, setMmWsClient] = useState
(null);
const [channels, setChannels] = useState([]);
@@ -163,9 +164,12 @@ export default function Chat() {
...(chain.chat_room_ids || []),
id,
]);
+ const _channel = _channels.find((c) => c.id == id) || null;
+
setChannels(_channels);
- const _channel = _channels.at(-1) || null;
setSelectedChannel(_channel);
+ // update chain object from server to update chain.room_ids value
+ await setChain(chain.uid, authUser);
if (!_channel) return;
reqPostList(mmClient, _channel, "");
} catch (err) {
@@ -173,7 +177,7 @@ export default function Chat() {
}
}
- async function onRenameChannel(name: string) {
+ async function onRenameChannel(channel: Channel, name: string) {
if (!chain || !mmClient) {
if (!chain) console.error("chain not found");
if (!mmClient) console.error("mmClient not found");
@@ -181,7 +185,14 @@ export default function Chat() {
}
try {
console.info("Updating channel name", name);
- // Update channel name
+ channel.display_name = name;
+ await mmClient.updateChannel(channel);
+ const _channels = await getChannels(
+ mmClient,
+ mmData,
+ chain?.chat_room_ids || [],
+ );
+ setChannels(_channels);
} catch (err) {
console.error(err);
}
diff --git a/server/internal/controllers/chat.go b/server/internal/controllers/chat.go
index a6698a68d..b3dd31883 100644
--- a/server/internal/controllers/chat.go
+++ b/server/internal/controllers/chat.go
@@ -85,6 +85,32 @@ func ChatCreateChannel(c *gin.Context) {
})
}
+func ChatDeleteChannel(c *gin.Context) {
+ db := getDB(c)
+
+ var body struct {
+ ChainUID string `json:"chain_uid" binding:"required,uuid"`
+ ChannelID string `json:"channel_id" binding:"required"`
+ }
+ if err := c.ShouldBindJSON(&body); err != nil {
+ c.AbortWithError(http.StatusBadRequest, err)
+ return
+ }
+
+ ok, _, chain := auth.Authenticate(c, db, auth.AuthState3AdminChainUser, body.ChainUID)
+ if !ok {
+ return
+ }
+
+ err := services.ChatDeleteChannel(db, c.Request.Context(), chain, body.ChannelID)
+ if err != nil {
+ c.AbortWithError(http.StatusInternalServerError, err)
+ return
+ }
+
+ c.Status(http.StatusOK)
+}
+
func ChatJoinChannels(c *gin.Context) {
db := getDB(c)
diff --git a/server/internal/services/chat.go b/server/internal/services/chat.go
index 12e92c085..ae19ccc5a 100644
--- a/server/internal/services/chat.go
+++ b/server/internal/services/chat.go
@@ -88,6 +88,22 @@ func ChatCreateChannel(db *gorm.DB, ctx context.Context, chain *models.Chain, mm
return newChannel, nil
}
+func ChatDeleteChannel(db *gorm.DB, ctx context.Context, chain *models.Chain, mmChannelID string) error {
+ _, err := app.ChatClient.DeleteChannel(ctx, mmChannelID)
+ if err != nil {
+ return err
+ }
+
+ chain.ChatRoomIDs = lo.Filter(chain.ChatRoomIDs, func(roomID string, _ int) bool {
+ return roomID != mmChannelID
+ })
+ err = chain.SaveChannelIDs(db)
+ if err != nil {
+ return err
+ }
+ return nil
+}
+
func chatChannelAddUser(ctx context.Context, mmChannelId string, mmUserId string, setRoleAdmin bool) error {
member, _, err := app.ChatClient.AddChannelMember(ctx, mmChannelId, mmUserId)
if err != nil {